diff --git a/chain/messagesigner/messagesigner.go b/chain/messagesigner/messagesigner.go index 6a622dd5755..905addd4dc2 100644 --- a/chain/messagesigner/messagesigner.go +++ b/chain/messagesigner/messagesigner.go @@ -202,9 +202,9 @@ func (ms *MessageSigner) dstoreKey(addr address.Address) datastore.Key { func SigningBytes(msg *types.Message, sigType crypto.SigType) ([]byte, error) { if sigType == crypto.SigTypeDelegated { - txArgs, err := ethtypes.EthTxArgsFromMessage(msg) + txArgs, err := ethtypes.EthTxArgsFromUnsignedEthMessage(msg) if err != nil { - return nil, xerrors.Errorf("failed to reconstruct eth transaction: %w", err) + return nil, xerrors.Errorf("failed to convert to eth message: %w", err) } rlpEncodedMsg, err := txArgs.ToRlpUnsignedMsg() if err != nil { diff --git a/chain/signatures.go b/chain/signatures.go index 78bfb91c9d8..1dc67fd2c27 100644 --- a/chain/signatures.go +++ b/chain/signatures.go @@ -22,7 +22,7 @@ func AuthenticateMessage(msg *types.SignedMessage, signer address.Address) error typ := msg.Signature.Type switch typ { case crypto.SigTypeDelegated: - txArgs, err := ethtypes.EthTxArgsFromUnsignedMessage(&msg.Message) + txArgs, err := ethtypes.EthTxArgsFromUnsignedEthMessage(&msg.Message) if err != nil { return xerrors.Errorf("failed to reconstruct eth transaction: %w", err) } diff --git a/chain/types/ethtypes/eth_transactions.go b/chain/types/ethtypes/eth_transactions.go index 6d695530356..1c0a8d33a6e 100644 --- a/chain/types/ethtypes/eth_transactions.go +++ b/chain/types/ethtypes/eth_transactions.go @@ -58,13 +58,18 @@ type EthTxArgs struct { S big.Int `json:"s"` } -// EthTxFromSignedMessage does NOT populate: +// EthTxFromMessageDelegatedSignature does NOT populate: // - BlockHash // - BlockNumber // - TransactionIndex // - From -func EthTxFromSignedMessage(smsg *types.SignedMessage) (EthTx, error) { - txArgs, err := EthTxArgsFromUnsignedMessage(&smsg.Message) +// - Hash +func EthTxFromMessageDelegatedSignature(smsg *types.SignedMessage) (EthTx, error) { + if smsg.Signature.Type != typescrypto.SigTypeDelegated { + return EthTx{}, xerrors.Errorf("signature is not delegated type, is type: %d", smsg.Signature.Type) + } + + txArgs, err := EthTxArgsFromUnsignedEthMessage(&smsg.Message) if err != nil { return EthTx{}, xerrors.Errorf("failed to convert the unsigned message: %w", err) } @@ -75,13 +80,7 @@ func EthTxFromSignedMessage(smsg *types.SignedMessage) (EthTx, error) { r, s, v = EthBigIntZero, EthBigIntZero, EthBigIntZero } - hash, err := EthHashFromCid(smsg.Cid()) - if err != nil { - return EthTx{}, xerrors.Errorf("failed to calculate EthHash: %w", err) - } - return EthTx{ - Hash: hash, Nonce: EthUint64(txArgs.Nonce), ChainID: EthUint64(txArgs.ChainID), To: txArgs.To, @@ -97,7 +96,26 @@ func EthTxFromSignedMessage(smsg *types.SignedMessage) (EthTx, error) { }, nil } -func EthTxArgsFromUnsignedMessage(msg *types.Message) (EthTxArgs, error) { +// EthTxFromFilecoinMessage does NOT populate: +// - BlockHash +// - BlockNumber +// - TransactionIndex +// - Hash +// - From (not valid) +// - To (not valid) +func EthTxFromFilecoinMessage(msg *types.Message) EthTx { + return EthTx{ + Nonce: EthUint64(msg.Nonce), + ChainID: EthUint64(build.Eip155ChainId), + Value: EthBigInt(msg.Value), + Type: Eip1559TxType, + Gas: EthUint64(msg.GasLimit), + MaxFeePerGas: EthBigInt(msg.GasFeeCap), + MaxPriorityFeePerGas: EthBigInt(msg.GasPremium), + } +} + +func EthTxArgsFromUnsignedEthMessage(msg *types.Message) (EthTxArgs, error) { var ( to *EthAddress params []byte diff --git a/itests/eth_account_abstraction_test.go b/itests/eth_account_abstraction_test.go index b8b4c639491..cfc67b54eed 100644 --- a/itests/eth_account_abstraction_test.go +++ b/itests/eth_account_abstraction_test.go @@ -70,7 +70,7 @@ func TestEthAccountAbstraction(t *testing.T) { msgFromPlaceholder, err = client.GasEstimateMessageGas(ctx, msgFromPlaceholder, nil, types.EmptyTSK) require.NoError(t, err) - txArgs, err := ethtypes.EthTxArgsFromUnsignedMessage(msgFromPlaceholder) + txArgs, err := ethtypes.EthTxArgsFromUnsignedEthMessage(msgFromPlaceholder) require.NoError(t, err) digest, err := txArgs.ToRlpUnsignedMsg() @@ -106,7 +106,7 @@ func TestEthAccountAbstraction(t *testing.T) { msgFromPlaceholder, err = client.GasEstimateMessageGas(ctx, msgFromPlaceholder, nil, types.EmptyTSK) require.NoError(t, err) - txArgs, err = ethtypes.EthTxArgsFromUnsignedMessage(msgFromPlaceholder) + txArgs, err = ethtypes.EthTxArgsFromUnsignedEthMessage(msgFromPlaceholder) require.NoError(t, err) digest, err = txArgs.ToRlpUnsignedMsg() @@ -178,7 +178,7 @@ func TestEthAccountAbstractionFailure(t *testing.T) { require.NoError(t, err) msgFromPlaceholder.Value = abi.TokenAmount(types.MustParseFIL("1000")) - txArgs, err := ethtypes.EthTxArgsFromUnsignedMessage(msgFromPlaceholder) + txArgs, err := ethtypes.EthTxArgsFromUnsignedEthMessage(msgFromPlaceholder) require.NoError(t, err) digest, err := txArgs.ToRlpUnsignedMsg() @@ -216,7 +216,7 @@ func TestEthAccountAbstractionFailure(t *testing.T) { msgFromPlaceholder, err = client.GasEstimateMessageGas(ctx, msgFromPlaceholder, nil, types.EmptyTSK) require.NoError(t, err) - txArgs, err = ethtypes.EthTxArgsFromUnsignedMessage(msgFromPlaceholder) + txArgs, err = ethtypes.EthTxArgsFromUnsignedEthMessage(msgFromPlaceholder) require.NoError(t, err) digest, err = txArgs.ToRlpUnsignedMsg() diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index 62dcda9fb76..c62c81b9e0b 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -1551,23 +1551,38 @@ func EthTxHashFromSignedFilecoinMessage(ctx context.Context, smsg *types.SignedM } func newEthTxFromFilecoinMessage(ctx context.Context, smsg *types.SignedMessage, sa StateAPI) (ethtypes.EthTx, error) { - tx, err := ethtypes.EthTxFromSignedMessage(smsg) - if err != nil { - return ethtypes.EthTx{}, xerrors.Errorf("failed to convert from signed message: %w", err) - } + var tx ethtypes.EthTx + var err error - fromEthAddr, err := lookupEthAddress(ctx, smsg.Message.From, sa) - if err != nil { - return ethtypes.EthTx{}, xerrors.Errorf("failed to lookup from ethaddress: %w", err) - } + // This is an eth tx + if smsg.Signature.Type == crypto.SigTypeDelegated { + tx, err = ethtypes.EthTxFromMessageDelegatedSignature(smsg) + if err != nil { + return ethtypes.EthTx{}, xerrors.Errorf("failed to convert from signed message: %w", err) + } - toEthAddr, err := lookupEthAddress(ctx, smsg.Message.To, sa) - if err != nil { - return ethtypes.EthTx{}, xerrors.Errorf("failed to lookup to ethaddress: %w", err) - } + tx.From, err = lookupEthAddress(ctx, smsg.Message.From, sa) + if err != nil { + return ethtypes.EthTx{}, xerrors.Errorf("failed to lookup from ethaddress: %w", err) + } - tx.From = fromEthAddr - tx.To = &toEthAddr + tx.Hash, err = tx.TxHash() + if err != nil { + return tx, err + } + } else if smsg.Signature.Type == crypto.SigTypeUnknown { // Executed BLS Filecoin message + tx = ethtypes.EthTxFromFilecoinMessage(smsg.VMMessage()) + tx.Hash, err = ethtypes.EthHashFromCid(smsg.Message.Cid()) + if err != nil { + return tx, err + } + } else { // Secp Filecoin Message or BLS Filecoin message in the mpool + tx = ethtypes.EthTxFromFilecoinMessage(smsg.VMMessage()) + tx.Hash, err = ethtypes.EthHashFromCid(smsg.Cid()) + if err != nil { + return tx, err + } + } return tx, nil } @@ -1680,7 +1695,8 @@ func newEthTxReceipt(ctx context.Context, tx ethtypes.EthTx, lookup *api.MsgLook LogsBloom: ethtypes.EmptyEthBloom[:], } - if receipt.To == nil && lookup.Receipt.ExitCode.IsSuccess() { + // V.Int will be nil for non-eth transactions, so we want to skip unmarshalling the create return. + if receipt.To == nil && lookup.Receipt.ExitCode.IsSuccess() && tx.V.Int != nil { // Create and Create2 return the same things. var ret eam.CreateReturn if err := ret.UnmarshalCBOR(bytes.NewReader(lookup.Receipt.Return)); err != nil {