diff --git a/api/docgen/docgen.go b/api/docgen/docgen.go index b16a8691a9e..00db48d5fcb 100644 --- a/api/docgen/docgen.go +++ b/api/docgen/docgen.go @@ -375,10 +375,10 @@ func init() { addExample(ethint) addExample(ðint) - ethaddr, _ := ethtypes.EthAddressFromHex("0x5CbEeCF99d3fDB3f25E309Cc264f240bb0664031") + ethaddr, _ := ethtypes.ParseEthAddress("0x5CbEeCF99d3fDB3f25E309Cc264f240bb0664031") addExample(ethaddr) addExample(ðaddr) - ethhash, _ := ethtypes.NewEthHashFromCid(c) + ethhash, _ := ethtypes.EthHashFromCid(c) addExample(ethhash) addExample(ðhash) @@ -387,10 +387,10 @@ func init() { addExample(&uuid.UUID{}) - filterid, _ := ethtypes.NewEthHashFromHex("0x5CbEeC012345673f25E309Cc264f240bb0664031") + filterid, _ := ethtypes.ParseEthHash("0x5CbEeC012345673f25E309Cc264f240bb0664031") addExample(ethtypes.EthFilterID(filterid)) - subid, _ := ethtypes.NewEthHashFromHex("0x5CbEeCF99d3fDB301234567c264f240bb0664031") + subid, _ := ethtypes.ParseEthHash("0x5CbEeCF99d3fDB301234567c264f240bb0664031") addExample(ethtypes.EthSubscriptionID(subid)) pstring := func(s string) *string { return &s } diff --git a/chain/gen/genesis/genesis_eth.go b/chain/gen/genesis/genesis_eth.go index 59c54adf89a..d5aa2f0b51b 100644 --- a/chain/gen/genesis/genesis_eth.go +++ b/chain/gen/genesis/genesis_eth.go @@ -84,7 +84,7 @@ func SetupEthNullAddresses(ctx context.Context, st *state.StateTree, nv network. var ethAddresses []ethtypes.EthAddress for _, addr := range EthNullAddresses { - a, err := ethtypes.EthAddressFromHex(addr) + a, err := ethtypes.ParseEthAddress(addr) if err != nil { return nil, xerrors.Errorf("failed to represent the 0x0 as an EthAddress: %w", err) } diff --git a/chain/types/ethtypes/eth_transactions.go b/chain/types/ethtypes/eth_transactions.go index a2693d976b0..1f5bca36928 100644 --- a/chain/types/ethtypes/eth_transactions.go +++ b/chain/types/ethtypes/eth_transactions.go @@ -337,7 +337,12 @@ func (tx *EthTxArgs) Sender() (address.Address, error) { return address.Undef, err } - return address.NewDelegatedAddress(builtintypes.EthereumAddressManagerActorID, ethAddr) + ea, err := CastEthAddress(ethAddr) + if err != nil { + return address.Undef, err + } + + return ea.ToFilecoinAddress() } func RecoverSignature(sig typescrypto.Signature) (r, s, v EthBigInt, err error) { @@ -445,6 +450,13 @@ func parseEip1559Tx(data []byte) (*EthTxArgs, error) { return nil, err } + // EIP-1559 and EIP-2930 transactions only support 0 or 1 for v + // Legacy and EIP-155 transactions support other values + // https://github.com/ethers-io/ethers.js/blob/56fabe987bb8c1e4891fdf1e5d3fe8a4c0471751/packages/transactions/src.ts/index.ts#L333 + if !v.Equals(big.NewInt(0)) && !v.Equals(big.NewInt(1)) { + return nil, fmt.Errorf("EIP-1559 transactions only support 0 or 1 for v") + } + args := EthTxArgs{ ChainID: chainId, Nonce: nonce, @@ -575,7 +587,7 @@ func parseEthAddr(v interface{}) (*EthAddress, error) { if len(b) == 0 { return nil, nil } - addr, err := EthAddressFromBytes(b) + addr, err := CastEthAddress(b) if err != nil { return nil, err } diff --git a/chain/types/ethtypes/eth_transactions_test.go b/chain/types/ethtypes/eth_transactions_test.go index 9c6671943c6..10131d9ac9c 100644 --- a/chain/types/ethtypes/eth_transactions_test.go +++ b/chain/types/ethtypes/eth_transactions_test.go @@ -202,7 +202,7 @@ func TestDelegatedSigner(t *testing.T) { addrHash, err := EthAddressFromPubKey(pubk) require.NoError(t, err) - from, err := address.NewDelegatedAddress(builtintypes.EthereumAddressManagerActorID, addrHash[12:]) + from, err := address.NewDelegatedAddress(builtintypes.EthereumAddressManagerActorID, addrHash) require.NoError(t, err) sig := append(r, s...) diff --git a/chain/types/ethtypes/eth_types.go b/chain/types/ethtypes/eth_types.go index 2fe5fad8c2c..e33db917ec2 100644 --- a/chain/types/ethtypes/eth_types.go +++ b/chain/types/ethtypes/eth_types.go @@ -11,7 +11,6 @@ import ( "strings" "github.com/ipfs/go-cid" - "github.com/minio/blake2b-simd" "github.com/multiformats/go-multihash" "github.com/multiformats/go-varint" "golang.org/x/crypto/sha3" @@ -228,6 +227,62 @@ func (n *EthNonce) UnmarshalJSON(b []byte) error { type EthAddress [EthAddressLength]byte +// EthAddressFromPubKey returns the Ethereum address corresponding to an +// uncompressed secp256k1 public key. +func EthAddressFromPubKey(pubk []byte) ([]byte, error) { + // if we get an uncompressed public key (that's what we get from the library, + // but putting this check here for defensiveness), strip the prefix + const pubKeyLen = 65 + if len(pubk) != pubKeyLen { + return nil, fmt.Errorf("public key should have %d in length, but got %d", pubKeyLen, len(pubk)) + } + if pubk[0] != 0x04 { + return nil, fmt.Errorf("expected first byte of secp256k1 to be 0x04 (uncompressed)") + } + pubk = pubk[1:] + + // Calculate the Ethereum address based on the keccak hash of the pubkey. + hasher := sha3.NewLegacyKeccak256() + hasher.Write(pubk) + ethAddr := hasher.Sum(nil)[12:] + return ethAddr, nil +} + +func EthAddressFromFilecoinAddress(addr address.Address) (EthAddress, error) { + ethAddr, ok, err := TryEthAddressFromFilecoinAddress(addr, true) + if err != nil { + return EthAddress{}, xerrors.Errorf("failed to try converting filecoin to eth addr: %w", err) + } + + if !ok { + return EthAddress{}, xerrors.Errorf("failed to convert filecoin address %s to an equivalent eth address", addr) + } + + return ethAddr, nil +} + +// ParseEthAddress parses an Ethereum address from a hex string. +func ParseEthAddress(s string) (EthAddress, error) { + handlePrefix(&s) + b, err := decodeHexString(s, EthAddressLength) + if err != nil { + return EthAddress{}, err + } + var h EthAddress + copy(h[EthAddressLength-len(b):], b) + return h, nil +} + +// CastEthAddress interprets bytes as an EthAddress, performing some basic checks. +func CastEthAddress(b []byte) (EthAddress, error) { + var a EthAddress + if len(b) != EthAddressLength { + return EthAddress{}, xerrors.Errorf("cannot parse bytes into an EthAddress: incorrect input length") + } + copy(a[:], b[:]) + return a, nil +} + func (ea EthAddress) String() string { return "0x" + hex.EncodeToString(ea[:]) } @@ -241,7 +296,7 @@ func (ea *EthAddress) UnmarshalJSON(b []byte) error { if err := json.Unmarshal(b, &s); err != nil { return err } - addr, err := EthAddressFromHex(s) + addr, err := ParseEthAddress(s) if err != nil { return err } @@ -291,46 +346,13 @@ func TryEthAddressFromFilecoinAddress(addr address.Address, allowId bool) (EthAd } payload = payload[n:] if namespace == builtintypes.EthereumAddressManagerActorID { - addr, err := EthAddressFromBytes(payload) + addr, err := CastEthAddress(payload) return addr, err == nil, err } } return EthAddress{}, false, nil } -func EthAddressFromFilecoinAddress(addr address.Address) (EthAddress, error) { - ethAddr, ok, err := TryEthAddressFromFilecoinAddress(addr, true) - if err != nil { - return EthAddress{}, xerrors.Errorf("failed to try converting filecoin to eth addr: %w", err) - } - - if !ok { - return EthAddress{}, xerrors.Errorf("failed to convert filecoin address %s to an equivalent eth address", addr) - } - - return ethAddr, nil -} - -func EthAddressFromHex(s string) (EthAddress, error) { - handlePrefix(&s) - b, err := decodeHexString(s, EthAddressLength) - if err != nil { - return EthAddress{}, err - } - var h EthAddress - copy(h[EthAddressLength-len(b):], b) - return h, nil -} - -func EthAddressFromBytes(b []byte) (EthAddress, error) { - var a EthAddress - if len(b) != EthAddressLength { - return EthAddress{}, xerrors.Errorf("cannot parse bytes into an EthAddress: incorrect input length") - } - copy(a[:], b[:]) - return a, nil -} - type EthHash [EthHashLength]byte func (h EthHash) MarshalJSON() ([]byte, error) { @@ -342,7 +364,7 @@ func (h *EthHash) UnmarshalJSON(b []byte) error { if err := json.Unmarshal(b, &s); err != nil { return err } - hash, err := NewEthHashFromHex(s) + hash, err := ParseEthHash(s) if err != nil { return err } @@ -372,11 +394,11 @@ func decodeHexString(s string, length int) ([]byte, error) { return b, nil } -func NewEthHashFromCid(c cid.Cid) (EthHash, error) { - return NewEthHashFromHex(c.Hash().HexString()[8:]) +func EthHashFromCid(c cid.Cid) (EthHash, error) { + return ParseEthHash(c.Hash().HexString()[8:]) } -func NewEthHashFromHex(s string) (EthHash, error) { +func ParseEthHash(s string) (EthHash, error) { handlePrefix(&s) b, err := decodeHexString(s, EthHashLength) if err != nil { @@ -387,10 +409,6 @@ func NewEthHashFromHex(s string) (EthHash, error) { return h, nil } -func EthHashData(b []byte) EthHash { - return EthHash(blake2b.Sum256(b)) -} - func (h EthHash) String() string { return "0x" + hex.EncodeToString(h[:]) } @@ -614,27 +632,10 @@ func GetContractEthAddressFromCode(sender EthAddress, salt [32]byte, initcode [] hasher.Write(salt[:]) hasher.Write(inithash) - ethAddr, err := EthAddressFromBytes(hasher.Sum(nil)[12:]) + ethAddr, err := CastEthAddress(hasher.Sum(nil)[12:]) if err != nil { return [20]byte{}, err } return ethAddr, nil } - -// EthAddressFromPubKey returns the Ethereum address corresponding to an -// uncompressed secp256k1 public key. -func EthAddressFromPubKey(pubk []byte) ([]byte, error) { - // if we get an uncompressed public key (that's what we get from the library, - // but putting this check here for defensiveness), strip the prefix - if pubk[0] != 0x04 { - return nil, fmt.Errorf("expected first byte of secp256k1 to be 0x04 (uncompressed)") - } - pubk = pubk[1:] - - // Calculate the Ethereum address based on the keccak hash of the pubkey. - hasher := sha3.NewLegacyKeccak256() - hasher.Write(pubk) - ethAddr := hasher.Sum(nil)[12:] - return ethAddr, nil -} diff --git a/chain/types/ethtypes/eth_types_test.go b/chain/types/ethtypes/eth_types_test.go index cb9c607eac2..89c38ba29f8 100644 --- a/chain/types/ethtypes/eth_types_test.go +++ b/chain/types/ethtypes/eth_types_test.go @@ -90,7 +90,7 @@ func TestEthHash(t *testing.T) { require.Equal(t, h.String(), strings.Replace(hash, `"`, "", -1)) c := h.ToCid() - h1, err := NewEthHashFromCid(c) + h1, err := EthHashFromCid(c) require.Nil(t, err) require.Equal(t, h, h1) } @@ -158,13 +158,13 @@ func TestUnmarshalEthBytes(t *testing.T) { } func TestEthFilterResultMarshalJSON(t *testing.T) { - hash1, err := NewEthHashFromHex("013dbb9442ca9667baccc6230fcd5c1c4b2d4d2870f4bd20681d4d47cfd15184") + hash1, err := ParseEthHash("013dbb9442ca9667baccc6230fcd5c1c4b2d4d2870f4bd20681d4d47cfd15184") require.NoError(t, err, "eth hash") - hash2, err := NewEthHashFromHex("ab8653edf9f51785664a643b47605a7ba3d917b5339a0724e7642c114d0e4738") + hash2, err := ParseEthHash("ab8653edf9f51785664a643b47605a7ba3d917b5339a0724e7642c114d0e4738") require.NoError(t, err, "eth hash") - addr, err := EthAddressFromHex("d4c5fb16488Aa48081296299d54b0c648C9333dA") + addr, err := ParseEthAddress("d4c5fb16488Aa48081296299d54b0c648C9333dA") require.NoError(t, err, "eth address") log := EthLog{ @@ -223,13 +223,13 @@ func TestEthFilterResultMarshalJSON(t *testing.T) { } func TestEthFilterSpecUnmarshalJSON(t *testing.T) { - hash1, err := NewEthHashFromHex("013dbb9442ca9667baccc6230fcd5c1c4b2d4d2870f4bd20681d4d47cfd15184") + hash1, err := ParseEthHash("013dbb9442ca9667baccc6230fcd5c1c4b2d4d2870f4bd20681d4d47cfd15184") require.NoError(t, err, "eth hash") - hash2, err := NewEthHashFromHex("ab8653edf9f51785664a643b47605a7ba3d917b5339a0724e7642c114d0e4738") + hash2, err := ParseEthHash("ab8653edf9f51785664a643b47605a7ba3d917b5339a0724e7642c114d0e4738") require.NoError(t, err, "eth hash") - addr, err := EthAddressFromHex("d4c5fb16488Aa48081296299d54b0c648C9333dA") + addr, err := ParseEthAddress("d4c5fb16488Aa48081296299d54b0c648C9333dA") require.NoError(t, err, "eth address") pstring := func(s string) *string { return &s } @@ -305,10 +305,10 @@ func TestEthFilterSpecUnmarshalJSON(t *testing.T) { } func TestEthAddressListUnmarshalJSON(t *testing.T) { - addr1, err := EthAddressFromHex("d4c5fb16488Aa48081296299d54b0c648C9333dA") + addr1, err := ParseEthAddress("d4c5fb16488Aa48081296299d54b0c648C9333dA") require.NoError(t, err, "eth address") - addr2, err := EthAddressFromHex("abbbfb16488Aa48081296299d54b0c648C9333dA") + addr2, err := ParseEthAddress("abbbfb16488Aa48081296299d54b0c648C9333dA") require.NoError(t, err, "eth address") testcases := []struct { @@ -348,10 +348,10 @@ func TestEthAddressListUnmarshalJSON(t *testing.T) { } func TestEthHashListUnmarshalJSON(t *testing.T) { - hash1, err := NewEthHashFromHex("013dbb9442ca9667baccc6230fcd5c1c4b2d4d2870f4bd20681d4d47cfd15184") + hash1, err := ParseEthHash("013dbb9442ca9667baccc6230fcd5c1c4b2d4d2870f4bd20681d4d47cfd15184") require.NoError(t, err, "eth hash") - hash2, err := NewEthHashFromHex("ab8653edf9f51785664a643b47605a7ba3d917b5339a0724e7642c114d0e4738") + hash2, err := ParseEthHash("ab8653edf9f51785664a643b47605a7ba3d917b5339a0724e7642c114d0e4738") require.NoError(t, err, "eth hash") testcases := []struct { diff --git a/chain/wallet/key/key.go b/chain/wallet/key/key.go index 174381499fb..c973c16efd8 100644 --- a/chain/wallet/key/key.go +++ b/chain/wallet/key/key.go @@ -4,7 +4,6 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/builtin" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/lotus/chain/types" @@ -59,7 +58,12 @@ func NewKey(keyinfo types.KeyInfo) (*Key, error) { return nil, xerrors.Errorf("failed to calculate Eth address from public key: %w", err) } - k.Address, err = address.NewDelegatedAddress(builtin.EthereumAddressManagerActorID, ethAddr) + ea, err := ethtypes.CastEthAddress(ethAddr) + if err != nil { + return nil, xerrors.Errorf("failed to create ethereum address from bytes: %w", err) + } + + k.Address, err = ea.ToFilecoinAddress() if err != nil { return nil, xerrors.Errorf("converting Delegated to address: %w", err) } diff --git a/cli/eth.go b/cli/eth.go index d7a6145fc1b..4e706404d24 100644 --- a/cli/eth.go +++ b/cli/eth.go @@ -75,7 +75,7 @@ var EthGetInfoCmd = &cli.Command{ return err } } else if ethAddr != "" { - eaddr, err = ethtypes.EthAddressFromHex(ethAddr) + eaddr, err = ethtypes.ParseEthAddress(ethAddr) if err != nil { return err } @@ -111,12 +111,12 @@ var EthCallSimulateCmd = &cli.Command{ return IncorrectNumArgs(cctx) } - fromEthAddr, err := ethtypes.EthAddressFromHex(cctx.Args().Get(0)) + fromEthAddr, err := ethtypes.ParseEthAddress(cctx.Args().Get(0)) if err != nil { return err } - toEthAddr, err := ethtypes.EthAddressFromHex(cctx.Args().Get(1)) + toEthAddr, err := ethtypes.ParseEthAddress(cctx.Args().Get(1)) if err != nil { return err } @@ -160,7 +160,7 @@ var EthGetContractAddress = &cli.Command{ return IncorrectNumArgs(cctx) } - sender, err := ethtypes.EthAddressFromHex(cctx.Args().Get(0)) + sender, err := ethtypes.ParseEthAddress(cctx.Args().Get(0)) if err != nil { return err } @@ -308,7 +308,12 @@ var EthDeployCmd = &cli.Command{ afmt.Printf("Robust Address: %s\n", result.RobustAddress) afmt.Printf("Eth Address: %s\n", "0x"+hex.EncodeToString(result.EthAddress[:])) - delegated, err := address.NewDelegatedAddress(builtintypes.EthereumAddressManagerActorID, result.EthAddress[:]) + ea, err := ethtypes.CastEthAddress(result.EthAddress[:]) + if err != nil { + return fmt.Errorf("failed to create ethereum address: %w", err) + } + + delegated, err := ea.ToFilecoinAddress() if err != nil { return fmt.Errorf("failed to calculate f4 address: %w", err) } diff --git a/itests/eth_deploy_test.go b/itests/eth_deploy_test.go index 2b297e69921..af217bc0fd2 100644 --- a/itests/eth_deploy_test.go +++ b/itests/eth_deploy_test.go @@ -147,7 +147,7 @@ func TestDeployment(t *testing.T) { require.Equal(t, uint64(*chainTx.TransactionIndex), uint64(0)) // only transaction // should return error with non-existent block hash - nonExistentHash, err := ethtypes.NewEthHashFromHex("0x62a80aa9262a3e1d3db0706af41c8535257b6275a283174cabf9d108d8946059") + nonExistentHash, err := ethtypes.ParseEthHash("0x62a80aa9262a3e1d3db0706af41c8535257b6275a283174cabf9d108d8946059") require.Nil(t, err) _, err = client.EthGetBlockByHash(ctx, nonExistentHash, false) require.NotNil(t, err) diff --git a/itests/eth_filter_test.go b/itests/eth_filter_test.go index 9040f13ce27..bee9a8c3848 100644 --- a/itests/eth_filter_test.go +++ b/itests/eth_filter_test.go @@ -99,7 +99,7 @@ func TestEthNewPendingTransactionFilter(t *testing.T) { expected := make(map[string]bool) for _, sm := range sms { - hash, err := ethtypes.NewEthHashFromCid(sm.Cid()) + hash, err := ethtypes.EthHashFromCid(sm.Cid()) require.NoError(t, err) expected[hash.String()] = false } @@ -289,7 +289,7 @@ func TestEthNewFilterCatchAll(t *testing.T) { received := make(map[ethtypes.EthHash]msgInTipset) for m := range msgChan { - eh, err := ethtypes.NewEthHashFromCid(m.msg.Cid) + eh, err := ethtypes.EthHashFromCid(m.msg.Cid) require.NoError(err) received[eh] = m } @@ -334,7 +334,7 @@ func TestEthNewFilterCatchAll(t *testing.T) { tsCid, err := msg.ts.Key().Cid() require.NoError(err) - tsCidHash, err := ethtypes.NewEthHashFromCid(tsCid) + tsCidHash, err := ethtypes.EthHashFromCid(tsCid) require.NoError(err) require.Equal(tsCidHash, elog.BlockHash, "block hash") @@ -358,7 +358,7 @@ func ParseEthLog(in map[string]interface{}) (*ethtypes.EthLog, error) { if !ok { return ethtypes.EthHash{}, xerrors.Errorf(k + " not a string") } - return ethtypes.NewEthHashFromHex(s) + return ethtypes.ParseEthHash(s) } ethUint64 := func(k string, v interface{}) (ethtypes.EthUint64, error) { @@ -395,7 +395,7 @@ func ParseEthLog(in map[string]interface{}) (*ethtypes.EthLog, error) { if !ok { return nil, xerrors.Errorf(k + ": not a string") } - el.Address, err = ethtypes.EthAddressFromHex(s) + el.Address, err = ethtypes.ParseEthAddress(s) if err != nil { return nil, xerrors.Errorf("%s: %w", k, err) } @@ -545,7 +545,7 @@ func invokeContractAndWaitUntilAllOnChain(t *testing.T, client *kit.TestFullNode received := make(map[ethtypes.EthHash]msgInTipset) for m := range msgChan { - eh, err := ethtypes.NewEthHashFromCid(m.msg.Cid) + eh, err := ethtypes.EthHashFromCid(m.msg.Cid) require.NoError(err) received[eh] = m } @@ -610,7 +610,7 @@ func TestEthGetLogsAll(t *testing.T) { tsCid, err := msg.ts.Key().Cid() require.NoError(err) - tsCidHash, err := ethtypes.NewEthHashFromCid(tsCid) + tsCidHash, err := ethtypes.EthHashFromCid(tsCid) require.NoError(err) require.Equal(tsCidHash, elog.BlockHash, "block hash") @@ -674,7 +674,7 @@ func TestEthGetLogsByTopic(t *testing.T) { tsCid, err := msg.ts.Key().Cid() require.NoError(err) - tsCidHash, err := ethtypes.NewEthHashFromCid(tsCid) + tsCidHash, err := ethtypes.EthHashFromCid(tsCid) require.NoError(err) require.Equal(tsCidHash, elog.BlockHash, "block hash") @@ -794,7 +794,7 @@ func TestEthSubscribeLogs(t *testing.T) { received := make(map[ethtypes.EthHash]msgInTipset) for m := range msgChan { - eh, err := ethtypes.NewEthHashFromCid(m.msg.Cid) + eh, err := ethtypes.EthHashFromCid(m.msg.Cid) require.NoError(err) received[eh] = m } diff --git a/itests/eth_transactions_test.go b/itests/eth_transactions_test.go index 9c28f80e168..bf3ac573fe8 100644 --- a/itests/eth_transactions_test.go +++ b/itests/eth_transactions_test.go @@ -126,8 +126,8 @@ func TestContractDeploymentValidSignature(t *testing.T) { // send some funds to the f410 address kit.SendFunds(ctx, t, client, deployer, types.FromFil(10)) - // verify the deployer address is an embryo. - client.AssertActorType(ctx, deployer, manifest.EmbryoKey) + // verify the deployer address is a placeholder. + client.AssertActorType(ctx, deployer, manifest.PlaceholderKey) tx, err := deployContractTx(ctx, client, ethAddr, contract) require.NoError(t, err) diff --git a/itests/fevm_address_test.go b/itests/fevm_address_test.go index 41f4373c2cb..b185a16a765 100644 --- a/itests/fevm_address_test.go +++ b/itests/fevm_address_test.go @@ -109,7 +109,7 @@ func TestAddressCreationBeforeDeploy(t *testing.T) { err = create2Return.UnmarshalCBOR(bytes.NewReader(wait.Receipt.Return)) require.NoError(t, err) - createdEthAddr, err := ethtypes.EthAddressFromBytes(create2Return.EthAddress[:]) + createdEthAddr, err := ethtypes.CastEthAddress(create2Return.EthAddress[:]) require.NoError(t, err) require.Equal(t, ethAddr, createdEthAddr) diff --git a/itests/kit/evm.go b/itests/kit/evm.go index 6a4949722e6..06137778fcb 100644 --- a/itests/kit/evm.go +++ b/itests/kit/evm.go @@ -14,7 +14,6 @@ import ( "github.com/filecoin-project/go-address" amt4 "github.com/filecoin-project/go-amt-ipld/v4" - "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" builtintypes "github.com/filecoin-project/go-state-types/builtin" "github.com/filecoin-project/go-state-types/builtin/v10/eam" @@ -136,7 +135,10 @@ func (e *EVM) NewAccount() (*key.Key, ethtypes.EthAddress, address.Address) { ethAddr, err := ethtypes.EthAddressFromPubKey(key.PublicKey) require.NoError(e.t, err) - addr, err := address.NewDelegatedAddress(builtintypes.EthereumAddressManagerActorID, ethAddr) + ea, err := ethtypes.CastEthAddress(ethAddr) + require.NoError(e.t, err) + + addr, err := ea.ToFilecoinAddress() require.NoError(e.t, err) return key, *(*ethtypes.EthAddress)(ethAddr), addr diff --git a/lib/sigs/delegated/init.go b/lib/sigs/delegated/init.go index e25e8e9cbaa..4db83b3e76f 100644 --- a/lib/sigs/delegated/init.go +++ b/lib/sigs/delegated/init.go @@ -59,6 +59,9 @@ func (delegatedSigner) Verify(sig []byte, a address.Address, msg []byte) error { hasher.Write(pubk) addrHash := hasher.Sum(nil) + // The address hash will not start with [12]byte{0xff}, so we don't have to use + // EthAddr.ToFilecoinAddress() to handle the case with an id address + // Also, importing ethtypes here will cause circulating import maybeaddr, err := address.NewDelegatedAddress(builtin.EthereumAddressManagerActorID, addrHash[12:]) if err != nil { return err diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index e50e3a0d626..e402149a650 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -644,7 +644,7 @@ func (a *EthModule) EthSendRawTransaction(ctx context.Context, rawTx ethtypes.Et if err != nil { return ethtypes.EmptyEthHash, err } - return ethtypes.NewEthHashFromCid(cid) + return ethtypes.EthHashFromCid(cid) } func (a *EthModule) ethCallToFilecoinMessage(ctx context.Context, tx ethtypes.EthCall) (*types.Message, error) { @@ -1181,7 +1181,7 @@ func ethFilterResultFromEvents(evs []*filter.CollectedEvent) (*ethtypes.EthFilte return nil, err } - log.TransactionHash, err = ethtypes.NewEthHashFromCid(ev.MsgCid) + log.TransactionHash, err = ethtypes.EthHashFromCid(ev.MsgCid) if err != nil { return nil, err } @@ -1190,7 +1190,7 @@ func ethFilterResultFromEvents(evs []*filter.CollectedEvent) (*ethtypes.EthFilte if err != nil { return nil, err } - log.BlockHash, err = ethtypes.NewEthHashFromCid(c) + log.BlockHash, err = ethtypes.EthHashFromCid(c) if err != nil { return nil, err } @@ -1209,7 +1209,7 @@ func ethFilterResultFromTipSets(tsks []types.TipSetKey) (*ethtypes.EthFilterResu if err != nil { return nil, err } - hash, err := ethtypes.NewEthHashFromCid(c) + hash, err := ethtypes.EthHashFromCid(c) if err != nil { return nil, err } @@ -1224,7 +1224,7 @@ func ethFilterResultFromMessages(cs []cid.Cid) (*ethtypes.EthFilterResult, error res := ðtypes.EthFilterResult{} for _, c := range cs { - hash, err := ethtypes.NewEthHashFromCid(c) + hash, err := ethtypes.EthHashFromCid(c) if err != nil { return nil, err } @@ -1368,7 +1368,7 @@ func newEthBlockFromFilecoinTipSet(ctx context.Context, ts *types.TipSet, fullTx if err != nil { return ethtypes.EthBlock{}, err } - parentBlkHash, err := ethtypes.NewEthHashFromCid(parentKeyCid) + parentBlkHash, err := ethtypes.EthHashFromCid(parentKeyCid) if err != nil { return ethtypes.EthBlock{}, err } @@ -1377,7 +1377,7 @@ func newEthBlockFromFilecoinTipSet(ctx context.Context, ts *types.TipSet, fullTx if err != nil { return ethtypes.EthBlock{}, err } - blkHash, err := ethtypes.NewEthHashFromCid(blkCid) + blkHash, err := ethtypes.EthHashFromCid(blkCid) if err != nil { return ethtypes.EthBlock{}, err } @@ -1405,7 +1405,7 @@ func newEthBlockFromFilecoinTipSet(ctx context.Context, ts *types.TipSet, fullTx } block.Transactions = append(block.Transactions, tx) } else { - hash, err := ethtypes.NewEthHashFromCid(msg.Cid()) + hash, err := ethtypes.EthHashFromCid(msg.Cid()) if err != nil { return ethtypes.EthBlock{}, err } @@ -1512,7 +1512,7 @@ func newEthTxFromFilecoinMessage(ctx context.Context, smsg *types.SignedMessage, r, s, v = ethtypes.EthBigIntZero, ethtypes.EthBigIntZero, ethtypes.EthBigIntZero } - hash, err := ethtypes.NewEthHashFromCid(smsg.Cid()) + hash, err := ethtypes.EthHashFromCid(smsg.Cid()) if err != nil { return ethtypes.EthTx{}, err } @@ -1545,7 +1545,7 @@ func newEthTxFromFilecoinMessageLookup(ctx context.Context, msgLookup *api.MsgLo return ethtypes.EthTx{}, fmt.Errorf("msg does not exist") } cid := msgLookup.Message - txHash, err := ethtypes.NewEthHashFromCid(cid) + txHash, err := ethtypes.EthHashFromCid(cid) if err != nil { return ethtypes.EthTx{}, err } @@ -1583,7 +1583,7 @@ func newEthTxFromFilecoinMessageLookup(ctx context.Context, msgLookup *api.MsgLo } } - blkHash, err := ethtypes.NewEthHashFromCid(parentTsCid) + blkHash, err := ethtypes.EthHashFromCid(parentTsCid) if err != nil { return ethtypes.EthTx{}, err }