Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ETH compatibility in Filecoin : Support Homestead and EIP-155 Ethereum transactions("legacy" transactions) in Filecoin #11969

Merged
merged 28 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c95d4b3
poc for eth legacy tx
aarshkshah1992 Apr 25, 2024
369787f
print statements
aarshkshah1992 Apr 25, 2024
fca57fc
finished
aarshkshah1992 Apr 25, 2024
440040e
tests work
aarshkshah1992 Apr 25, 2024
6695369
remove print statements
aarshkshah1992 Apr 25, 2024
9e63361
Remove all print statements
aarshkshah1992 Apr 25, 2024
266826d
remove extraneous changes
aarshkshah1992 Apr 26, 2024
4d01481
cleaned up code and interface
aarshkshah1992 Apr 26, 2024
18fd140
run make jen
aarshkshah1992 Apr 26, 2024
ad2ec8f
dont duplicate signature
aarshkshah1992 Apr 26, 2024
07d248f
go mod tidy and remove prints
aarshkshah1992 Apr 26, 2024
2e66b80
clean up tests
aarshkshah1992 Apr 26, 2024
4be21ff
test for conversion
aarshkshah1992 Apr 26, 2024
f867359
changes as per review
aarshkshah1992 Apr 29, 2024
9265211
more unit tests for legacy txns
aarshkshah1992 Apr 29, 2024
af4c2cd
Apply suggestions from code review
aarshkshah1992 May 1, 2024
8807aed
address review comments from Rodd
aarshkshah1992 May 1, 2024
c62a67d
changes as per zen's 2nd review
aarshkshah1992 May 1, 2024
cd9d63e
Merge branch 'master' into feat/add-support-legacy-eth-tx
aarshkshah1992 May 1, 2024
a0e1801
go mod tidy
aarshkshah1992 May 1, 2024
b2a10b4
feat: ETH compatibility in Filecoin : Support EIP-155 Ethereum transa…
aarshkshah1992 May 10, 2024
7d04a26
gate tx by Network Version
aarshkshah1992 May 23, 2024
dfb7b2f
Merge remote-tracking branch 'origin/master' into feat/legacy-homeste…
aarshkshah1992 May 23, 2024
c6ab108
handle arajsek review
aarshkshah1992 May 23, 2024
edf1402
fix imports order
aarshkshah1992 May 23, 2024
d759a72
fix lint
aarshkshah1992 May 23, 2024
c9cdd59
dont lock in mpool for network gating ETH messages
aarshkshah1992 May 27, 2024
270d8ea
sender can be an ID address
aarshkshah1992 May 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,12 @@ workflows:
- build
suite: itest-eth_hash_lookup
target: "./itests/eth_hash_lookup_test.go"
- test:
name: test-itest-eth_legacy_transactions
requires:
- build
suite: itest-eth_legacy_transactions
target: "./itests/eth_legacy_transactions_test.go"
- test:
name: test-itest-eth_transactions
requires:
Expand Down
20 changes: 20 additions & 0 deletions build/openrpc/full.json
Original file line number Diff line number Diff line change
Expand Up @@ -6543,6 +6543,7 @@
"gas": "0x5",
"maxFeePerGas": "0x0",
"maxPriorityFeePerGas": "0x0",
"gasPrice": "0x0",
"accessList": [
"0x37690cfec6c1bf4c3b9288c7a5d783e98731e90b0a4c177c2a374c7a9427355e"
],
Expand Down Expand Up @@ -6598,6 +6599,10 @@
"title": "number",
"type": "number"
},
"gasPrice": {
"additionalProperties": false,
"type": "object"
},
"hash": {
"items": {
"description": "Number is a number",
Expand Down Expand Up @@ -6738,6 +6743,7 @@
"gas": "0x5",
"maxFeePerGas": "0x0",
"maxPriorityFeePerGas": "0x0",
"gasPrice": "0x0",
"accessList": [
"0x37690cfec6c1bf4c3b9288c7a5d783e98731e90b0a4c177c2a374c7a9427355e"
],
Expand Down Expand Up @@ -6793,6 +6799,10 @@
"title": "number",
"type": "number"
},
"gasPrice": {
"additionalProperties": false,
"type": "object"
},
"hash": {
"items": {
"description": "Number is a number",
Expand Down Expand Up @@ -6925,6 +6935,7 @@
"gas": "0x5",
"maxFeePerGas": "0x0",
"maxPriorityFeePerGas": "0x0",
"gasPrice": "0x0",
"accessList": [
"0x37690cfec6c1bf4c3b9288c7a5d783e98731e90b0a4c177c2a374c7a9427355e"
],
Expand Down Expand Up @@ -6980,6 +6991,10 @@
"title": "number",
"type": "number"
},
"gasPrice": {
"additionalProperties": false,
"type": "object"
},
"hash": {
"items": {
"description": "Number is a number",
Expand Down Expand Up @@ -7129,6 +7144,7 @@
"gas": "0x5",
"maxFeePerGas": "0x0",
"maxPriorityFeePerGas": "0x0",
"gasPrice": "0x0",
"accessList": [
"0x37690cfec6c1bf4c3b9288c7a5d783e98731e90b0a4c177c2a374c7a9427355e"
],
Expand Down Expand Up @@ -7184,6 +7200,10 @@
"title": "number",
"type": "number"
},
"gasPrice": {
"additionalProperties": false,
"type": "object"
},
"hash": {
"items": {
"description": "Number is a number",
Expand Down
10 changes: 10 additions & 0 deletions build/openrpc/gateway.json
Original file line number Diff line number Diff line change
Expand Up @@ -3077,6 +3077,7 @@
"gas": "0x5",
"maxFeePerGas": "0x0",
"maxPriorityFeePerGas": "0x0",
"gasPrice": "0x0",
"accessList": [
"0x37690cfec6c1bf4c3b9288c7a5d783e98731e90b0a4c177c2a374c7a9427355e"
],
Expand Down Expand Up @@ -3132,6 +3133,10 @@
"title": "number",
"type": "number"
},
"gasPrice": {
"additionalProperties": false,
"type": "object"
},
"hash": {
"items": {
"description": "Number is a number",
Expand Down Expand Up @@ -3281,6 +3286,7 @@
"gas": "0x5",
"maxFeePerGas": "0x0",
"maxPriorityFeePerGas": "0x0",
"gasPrice": "0x0",
"accessList": [
"0x37690cfec6c1bf4c3b9288c7a5d783e98731e90b0a4c177c2a374c7a9427355e"
],
Expand Down Expand Up @@ -3336,6 +3342,10 @@
"title": "number",
"type": "number"
},
"gasPrice": {
"additionalProperties": false,
"type": "object"
},
"hash": {
"items": {
"description": "Number is a number",
Expand Down
2 changes: 1 addition & 1 deletion chain/consensus/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func checkBlockMessages(ctx context.Context, sm *stmgr.StateManager, cs *store.C
return xerrors.Errorf("failed to resolve key addr: %w", err)
}

if err := AuthenticateMessage(m, kaddr); err != nil {
if err := AuthenticateMessage(m, kaddr, nv); err != nil {
return xerrors.Errorf("failed to validate signature: %w", err)
}

Expand Down
41 changes: 28 additions & 13 deletions chain/consensus/signatures.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,51 @@ import (
// SignedMessage was signed by the indicated Address, computing the correct
// signature payload depending on the signature type. The supplied Address type
// must be recognized by the registered verifier for the signature type.
func AuthenticateMessage(msg *types.SignedMessage, signer address.Address) error {
func AuthenticateMessage(msg *types.SignedMessage, signer address.Address, nv network.Version) error {
aarshkshah1992 marked this conversation as resolved.
Show resolved Hide resolved
var digest []byte
signatureType := msg.Signature.Type
signatureCopy := msg.Signature

typ := msg.Signature.Type
switch typ {
switch signatureType {
case crypto.SigTypeDelegated:
txArgs, err := ethtypes.EthTxArgsFromUnsignedEthMessage(&msg.Message)
signatureCopy.Data = make([]byte, len(msg.Signature.Data))
copy(signatureCopy.Data, msg.Signature.Data)
ethTx, err := ethtypes.EthTransactionFromSignedFilecoinMessage(msg)
aarshkshah1992 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return xerrors.Errorf("failed to reconstruct eth transaction: %w", err)
return xerrors.Errorf("failed to reconstruct Ethereum transaction: %w", err)
}
roundTripMsg, err := txArgs.ToUnsignedMessage(msg.Message.From)

if ethTx.Type() != ethtypes.EIP1559TxType {
aarshkshah1992 marked this conversation as resolved.
Show resolved Hide resolved
if nv < network.Version23 {
return xerrors.Errorf("Legacy ETH tx message not supported in network version %d,"+
"need version %d", nv, network.Version23)
}
}

filecoinMsg, err := ethTx.ToUnsignedFilecoinMessage(msg.Message.From)
if err != nil {
return xerrors.Errorf("failed to reconstruct filecoin msg: %w", err)
return xerrors.Errorf("failed to reconstruct Filecoin message: %w", err)
}

if !msg.Message.Equals(roundTripMsg) {
return xerrors.New("ethereum tx failed to roundtrip")
if !msg.Message.Equals(filecoinMsg) {
return xerrors.New("Ethereum transaction roundtrip mismatch")
}

rlpEncodedMsg, err := txArgs.ToRlpUnsignedMsg()
rlpEncodedMsg, err := ethTx.ToRlpUnsignedMsg()
if err != nil {
return xerrors.Errorf("failed to repack eth rlp message: %w", err)
return xerrors.Errorf("failed to encode RLP message: %w", err)
}
digest = rlpEncodedMsg
signatureCopy.Data, err = ethTx.ToVerifiableSignature(signatureCopy.Data)
if err != nil {
return xerrors.Errorf("failed to verify signature: %w", err)
}
default:
digest = msg.Message.Cid().Bytes()
}

if err := sigs.Verify(&msg.Signature, signer, digest); err != nil {
return xerrors.Errorf("message %s has invalid signature (type %d): %w", msg.Cid(), typ, err)
if err := sigs.Verify(&signatureCopy, signer, digest); err != nil {
return xerrors.Errorf("invalid signature for message %s (type %d): %w", msg.Cid(), signatureType, err)
}
return nil
}
Expand Down
11 changes: 10 additions & 1 deletion chain/messagepool/messagepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,16 @@ func (mp *MessagePool) VerifyMsgSig(m *types.SignedMessage) error {
return nil
}

if err := consensus.AuthenticateMessage(m, m.Message.From); err != nil {
mp.curTsLk.RLock()
aarshkshah1992 marked this conversation as resolved.
Show resolved Hide resolved
curTs := mp.curTs
mp.curTsLk.RUnlock()
epoch := curTs.Height() + 1
nv, err := mp.getNtwkVersion(epoch)
if err != nil {
return xerrors.Errorf("failed to get network version: %w", err)
}

if err := consensus.AuthenticateMessage(m, m.Message.From, nv); err != nil {
return xerrors.Errorf("failed to validate signature: %w", err)
}

Expand Down
2 changes: 1 addition & 1 deletion chain/messagesigner/messagesigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (ms *MessageSigner) dstoreKey(addr address.Address) datastore.Key {

func SigningBytes(msg *types.Message, sigType address.Protocol) ([]byte, error) {
if sigType == address.Delegated {
txArgs, err := ethtypes.EthTxArgsFromUnsignedEthMessage(msg)
txArgs, err := ethtypes.Eth1559TxArgsFromUnsignedFilecoinMessage(msg)
if err != nil {
return nil, xerrors.Errorf("failed to reconstruct eth transaction: %w", err)
}
Expand Down
Loading