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 legacy Homestead Ethereum transactions and legacy EIP-155 transactions in Filecoin #11930

Closed
wants to merge 28 commits into from

Conversation

aarshkshah1992
Copy link
Contributor

@aarshkshah1992 aarshkshah1992 commented Apr 25, 2024

Related Issues

Closes #11859

Proposed Changes

Additional Info

Checklist

Before you mark the PR ready for review, please make sure that:

  • Commits have a clear commit message.
  • PR title is in the form of of <PR type>: <area>: <change being made>
    • example: fix: mempool: Introduce a cache for valid signatures
    • PR type: fix, feat, build, chore, ci, docs, perf, refactor, revert, style, test
    • area, e.g. api, chain, state, market, mempool, multisig, networking, paych, proving, sealing, wallet, deps
  • If the PR affects users (e.g., new feature, bug fix, system requirements change), update the CHANGELOG.md and add details to the UNRELEASED section.
  • New features have usage guidelines and / or documentation updates in
  • Tests exist for new functionality or change in behavior
  • CI is green

@aarshkshah1992 aarshkshah1992 changed the title [WIP]poc for eth legacy tx [WIP] POC for ETH legacy TX Apr 25, 2024
@aarshkshah1992 aarshkshah1992 marked this pull request as draft April 25, 2024 08:56
@aarshkshah1992 aarshkshah1992 changed the title [WIP] POC for ETH legacy TX ETH legacy TX Apr 26, 2024
@aarshkshah1992 aarshkshah1992 changed the title ETH legacy TX [WIP] Support legacy Homestead Ethereum transactions in Filecoin Apr 26, 2024
@aarshkshah1992 aarshkshah1992 changed the title [WIP] Support legacy Homestead Ethereum transactions in Filecoin feat: ETH compatibility in Filecoin : Support legacy Homestead Ethereum transactions in Filecoin Apr 26, 2024
@aarshkshah1992 aarshkshah1992 self-assigned this Apr 26, 2024
@aarshkshah1992 aarshkshah1992 marked this pull request as ready for review April 26, 2024 15:10
@aarshkshah1992
Copy link
Contributor Author

Should we just make all ETH RPC APIs return all three of GasPrice, MaxFeePerGas and MaxPriorityFeePerGas as non-nil ? For legacy transactions, we can just set the latter two to the value of GasPrice.

Users can always detect that a transaction is a legacy transaction if the ChainID and TxType fields are both set to 0.

@ZenGround0
Copy link
Contributor

Should we just make all ETH RPC APIs return all three of GasPrice, MaxFeePerGas and MaxPriorityFeePerGas as non-nil ? For legacy transactions, we can just set the latter two to the value of GasPrice.

This sounds like a good approach to me.

build/openrpc/gateway.json Show resolved Hide resolved
chain/consensus/signatures.go Outdated Show resolved Hide resolved
chain/messagesigner/messagesigner.go Show resolved Hide resolved
return nil, fmt.Errorf("signature should be %d bytes long, but got %d bytes", legacyHomesteadTxSignatureLen, len(sig))
}
if sig[0] != LegacyHomesteadEthTxSignaturePrefix {
return nil, fmt.Errorf("expected signature prefix 0x01, but got 0x%x", sig[0])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: 0x01 => 0x%x and add LegacyHomesteadEthTxSignaturePrefix as argument

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


func (tx *EthLegacyHomesteadTxArgs) ToVerifiableSignature(sig []byte) ([]byte, error) {
if len(sig) != legacyHomesteadTxSignatureLen {
return nil, fmt.Errorf("signature should be %d bytes long, but got %d bytes", legacyHomesteadTxSignatureLen, len(sig))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure but might be instructive to add a little more information to avoid confusion with the literal length of eth homestead signatures being 1 byte less.

Suggested change
return nil, fmt.Errorf("signature should be %d bytes long, but got %d bytes", legacyHomesteadTxSignatureLen, len(sig))
return nil, fmt.Errorf("signature should be %d bytes long (1 byte metadata, %d bytes sig data), but got %d bytes", legacyHomesteadTxSignatureLen, legacyHomesteadTxSignatureLen - 1, len(sig))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

chain/types/ethtypes/eth_transactions.go Outdated Show resolved Hide resolved
require.NoError(t, err)
}

func prepareTxTestcases() ([]TxTestcase, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any idea where these came from and if it would be easy to compile a similar list for legacy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rvagg I am not sure where this came from. Maybe they pulled these up from etherscan. But it's a bit hard and time consuming to put these together for legacy txns as etherscan does not have a "filter by date" functionality. I was able to find some which I've used here.

I am also going to test this on a butterfly node using legacy txns generated by Metamask so we should be fine.

@rvagg
Copy link
Member

rvagg commented Apr 30, 2024

This looks pretty good, as far as my knowledge of such things go. It would be nice to add a corpus of legacy transactions to decode for the tests like the existing eip1559 ones, but if we don't have a ready source of that I don't think spending time collecting them is going to add enough value for the effort.

It'd also be nice to have a label that we could mark PRs like this as "API breaking" to make sure we don't slip it into a semver-patch.

@jennijuju
Copy link
Member

@raulk @fridrik01 could you please help take a quick look on this PR by any chance?

@aarshkshah1992
Copy link
Contributor Author

@rvagg @ZenGround0 Have addressed all your review comments so far. Testing this on a local node now.

Copy link
Member

@rvagg rvagg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm as far as my review is worth it, pending more functional testing; also a shame we don't have more legacy bytes to run through this but I understand the difficulty

@aarshkshah1992
Copy link
Contributor Author

Tested and works with Metamask Legacy Transactions

image

@aarshkshah1992
Copy link
Contributor Author

Works with Coinbase Wallet as well

image

@aarshkshah1992 aarshkshah1992 changed the title feat: ETH compatibility in Filecoin : Support legacy Homestead Ethereum transactions in Filecoin feat: ETH compatibility in Filecoin : Support legacy Homestead Ethereum transactions and legacy EIP-155 transactions in Filecoin May 6, 2024
@aarshkshah1992
Copy link
Contributor Author

aarshkshah1992 commented May 6, 2024

We need EIP-155 transactions to enable support for Glif, Coinbase Wallet, Phantom Wallet etc with EVM based Filecoin transactions as they use EIP-155 transactions under the hood. This is a big unlock for the ecosystem:

The code difference with Homestead transactions entails two things:
a) Enabling chain replay protection by extracting the ChainID from the V value in the signature and making sure it matches the ChainID of the node.

b) There is a difference in how we construct the digest for signature verification for EIP-155 transactions namely that we include the ChainID in the digest but not in the serialised transaction that is broadcast among nodes (as the digest can be reconstructed by extracting the ChainID from the V value of the signature)

@aarshkshah1992
Copy link
Contributor Author

@rvagg @ZenGround0 @rjan90

Broke this down into two PRs.

  1. feat: ETH compatibility in Filecoin : Support Homestead and EIP-155 Ethereum transactions("legacy" transactions) in Filecoin #11969 -> Enable support for legacy Homestead transactions in Filecoin. This PR contains the reviewed portion of this PR which has everything we need to enable legacy Homestead transactions.

  2. feat: ETH compatibility in Filecoin : Support EIP-155 Ethereum transactions in Filecoin #11970 -> Implements EIP-155 transactions in Filecoin.

We will merge both of these to an integration and then merge the integration branch to master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filecoin should support legacy Homstead and legacy EIP-155 Ethereum transactions
4 participants