filecoin-project / devgrants

👟 Apply for a Filecoin devgrant. Help build the Filecoin ecosystem!
Other
371 stars 308 forks source link

RFP Proposal: Tool for applying test vectors from Ethereum on FEVM #1202

Closed wenxinnnnn closed 2 months ago

wenxinnnnn commented 1 year ago

RFP Proposal: Tool for applying test vectors from Ethereum on FEVM

Name of Project: Tool for applying test vectors from Ethereum on FEVM

Link to RFP: fvm-ethereum-test-vectors

RFP Category: devtools-libraries

Proposer: FroghubMan

Do you agree to open source all work you do on behalf of this RFP and dual-license under MIT and APACHE2 licenses?: Yes

Project Description

FVM 2.1 which introduces support for Ethereum smart contracts in the Filecoin network (FEVM) will be the biggest network upgrade since mainnet launch. At the same time, it immensely widens the area of possible problems. That’s why it must be tested thoroughly. One of possibilities to test FEVM is to run already existing and proven smart contracts from Ethereum and compare the state it produces on Ethereum vs Filecoin.

We are seeking proposals from teams that can build such a testing tool. This tool is expected to be in the form of a CLI. It should be able to:

  1. Fetch and store on the order of hundreds of contracts from Ethereum mainnet. These should be widely used contracts covering various use-cases.
  2. Deploy these contracts to a Filecoin testnet (Butterflynet).
  3. Fetch thousands of transactions sent to these contracts on Ethereum in the past.
  4. Replay these transactions to contracts deployed on Filecoin.
  5. Compare the Ethereum state before and after these transactions with the results on Filecoin. We expect the team to research the ideas of how to do state comparison reliably.

We want to run this tool a few times if needed and fix encountered errors every time. This tool can be written in either Go or Rust.

Development Roadmap

Milestone1:

  1. Fetch and store thousands of transactions sent to constracts on Ethereum in the past. And through EVM Tracing, Intercept and store data for opcodes of the following types:

    • context: BLOCKHASH, COINBASE, GASPRICE, GAS, TIMESTAMP, NUMBER, DIFFICULTY, GASLIMIT, CHAINID, BASEFEE
    • ext: EXTCODESIZE, EXTCODECOPY, EXTCODEHASH, BALANCE
    • call: CALLDATALOAD, CALLDATASIZE, CALLDATACOPY, CODESIZE, CODECOPY, CALL
    • storage: SLOAD, SSTORE
    • state: SELFBALANCE
  2. With the help of ref-fvm and the opcode data of call, state and storage types, correctly simulate the data (address, balance, bytecode, slot data) of the account on the state tree. Write the opcode data of context and ext types to blockstore, for reading by related opcode functions in testing phase. Finally intercept blockstore writing and generate tvx test vector file.

Milestone2:

  1. Expand the function implementation of context and ext type opcodes under ref-fvm, allowing data to be read from blockstore directly.
  2. Expand the tvx function so that the test vector of the evm type can be replayed.

Documentation, Education, and Community

The code repository will contain detailed instructions for using the CLI tool

Milestone Summary

Milestone No. Milestone Summary & Staffing Funding Estimated Timeframe
1 Generate tvx test vectors from transactions on Ethereum & 2 people $16000 2 weeks
2 Tvx tools comsume test vectors of type evm & 2 people $12000 1.5 weeks

Total Budget Requested

$28000

Maintenance and Upgrade Plans

We are willing to maintain this test vector tool for a long time

Team

Contact Info

wenxin@froghub.io

Team Members

Team Website

https://www.froghub.io/

Relevant Experience

Please describe (in words) your team's relevant experience, and why you think would do a great job with this RFP. You can cite your team's prior experience in similar domains, doing similar dev work, individual team members' backgrounds, etc.

  1. We are familiar with the implementation of EVM. By using the source code of the public contract, we can output the StateChanges caused by Transaction on Ethereum in a human-readable form
  2. We are familiar with the implementation of FVM \ FEVM, and understand the underlying data structure (eg. HAMT AMT BitField)
  3. We are familiar with the implementation of tvx and the design of its Test Vector

Team code repositories

https://github.com/froghub-io

jennijuju commented 1 year ago

@wenxinnnnn could you please provide the funding breakdowns? i.e: work hours, $ hr/dev ?

wenxinnnnn commented 1 year ago

Funding for this M1:

1 Software engineer lead resource: 1 120 $/h 40 h/week 2 week = $9600 1 Software engineer resource: 3 80 $/h 40 h/week 2 week = $6400

Total = $16000

Funding for this M2:

1 Software engineer lead resource: 1 120 $/h 40 h/week 1.5 week = $7200 1 Software engineer resource: 3 80 $/h 40 h/week 1.5 week = $4800

Total = $12000

jennijuju commented 1 year ago

capturing slack conversation

image
maciejwitowski commented 1 year ago

Hey @wenxinnnnn thanks for updating the team/price info. @raulk will review it.

Can you share any updates on the work so far? IIRC you started last week, right?

wenxinnnnn commented 1 year ago
  1. Mock Blockstore, completed Generate Account, mock_single_actor_blockstore, and then write slot data and opcodes, etc., and finally generate Blockstore to generate car files, which are then used to generate part of the corpus of JSON test vectors. https://github.com/froghub-io/builtin-actors/tree/tvx

  2. Fetching data from Ethereum and generating a corpus of JSON test vectors is also in progress

raulk commented 1 year ago

@wenxinnnnn I think we are broadly aligned here, but there are some details that need to be adjusted.

If you agree on these, I'm happy to approve the submission.

wenxinnnnn commented 1 year ago

We agree with these adjustment details, The tips are greatly appreciated.

raulk commented 1 year ago

@realChainLife this is approved from the FVM team. Can we formalise?

BlocksOnAChain commented 1 year ago

@wenxinnnnn - Hey, Dragan from the core FVM team here, I just wanted to check did you already started some work on this RFP? Would be great if we have something to try in January 2023?

wenxinnnnn commented 1 year ago

I think the progress is very smooth, and we will see results soon.

jennijuju commented 1 year ago

@BlocksOnAChain we are aiming to get MVP by EOW.

jennijuju commented 1 year ago

@wenxinnnnn Can we sync again tonight? I wanna touch point on:

For Milestone 1:

For Milestone 2 Tvx tools consume test vectors Other than the test vector coverage above, we think it would be really useful if we can build:

wenxinnnnn commented 1 year ago

For Milestone 1, repo Generate tvx test vectors from transactions on Ethereum, applicable to all Ethereum transactions, including “Constructor” and “applyTransaction”, but it requires the chain status of Ethereum nodes, so too old transactions are not easily exported. The top evm contract is of course good test case, but the contracts that depend on the evm context are also critical, such as timestamp, chainId, etc.

For Milestone 2, repo Testing with the test vector generated by Milestone 1 is underway.

wenxinnnnn commented 1 year ago

MVP has been met. @raulk Can you help us review whether it meets your expectations? Some transactions can be perfectly replayed, but the actual gasLimit on Ethereum will generally fail. In addition, there are some strange problems, and the reason is still being found.

raulk commented 1 year ago

@wenxinnnnn that is great news! Yes, the gas limit on Ethereum is absolutely not translatable to Filecoin gas. See comment in the respective FIP: https://github.com/filecoin-project/FIPs/pull/569/files#diff-42db5d06aa41036fbab88aef4ad06e69fbfec97dba280a6227f27a1cffbd8f5dR808-R821

wenxinnnnn commented 1 year ago

@raulk https://github.com/froghub-io/builtin-actors/commit/7d39a2ba9f83e67f6e88df4fad34e4f7a790e14f

jennijuju commented 1 year ago

Testing with the test vector generated by Milestone 1 is underway.

how is this going?

wenxinnnnn commented 1 year ago

Found another problem:Simply sending funds to the contract without input_data will not trigger bytecode execution, which is inconsistent with the behavior of evm.

jennijuju commented 1 year ago

@wenxinnnnn i think this is a known behaviour tho could you please create a ticket in ref-fvm repo with each of your discoveries so we can keep track of them? In the ticket, please include the original etherum tx id that triggered behaviour. thank you!

maciejwitowski commented 1 year ago

@wenxinnnnn IIUC this is the issue you're talking about https://github.com/filecoin-project/ref-fvm/issues/835. Feel free to contribute to the discussion, the decision hasn't been reached there yet.

maciejwitowski commented 1 year ago

More generally though, @wenxinnnnn do you have any report after running these test vectors already?

wenxinnnnn commented 1 year ago

The M1 and M2 goals of the current Test Vector Tool have been completed.

By running some test vectors of transactions, we found the following problems:

  1. filecoin-project/ref-fvm#1369
  2. Simply sending funds to the contract without input_data will not trigger bytecode execution, which is inconsistent with the behavior of evm. (related to filecoin-project/ref-fvm#835)

But there are still some problems that have not been found:

  1. Rollbacks occurs when transactions involving complex calls are replayed. (eg. uniswap v2, v3 transactions) The original etherum tx is 0x1e7fafb64440bd4c2e2793544baa613ad81a62edc5ec5918c302847b55627994, 0xd4ff32d2b048dc0bce17b697e68766f218cdf0c81b9e931cab2da83afb9fd7a8.

Due to the lack of fevm tracing, it is still difficult to locate the problem. It may be necessary to consider implementing evm tracing similar to geth format for fevm?

ErinOCon commented 2 months ago

This issue #1202 has been closed. Please reach out to grants@fil.org with any questions.