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

Proper Precompile Gas Consumption #337

Merged

Conversation

notlesh
Copy link
Contributor

@notlesh notlesh commented Mar 31, 2021

This PR modifies our precompiles to charge for gas in the same manner as mainnet Ethereum does. This means adopting the same case-by-case calculations for gas.

In addition, it also pulls in some test vectors I found for various precompiles. These test vectors (I refer to them as "Ethereum Consensus tests" sometimes, perhaps incorrectly) test expected input and output for a given precompile as well as expected gas costs in some cases. There are many more similar test vectors out there (example).

There are also numerous fixes for logic errors in some of the precompiles. If this PR is unwelcome, I suggest we still pull in these fixes.

Copy link
Contributor Author

@notlesh notlesh left a comment

Choose a reason for hiding this comment

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

This test failure seems intermittent:

  Frontier RPC (EthFilterApi)
web3-shh package will be deprecated in version 1.3.5 and will no longer be supported.
web3-bzz package will be deprecated in version 1.3.5 and will no longer be supported.
    1) should return response for raw Log filter request.


  0 passing (3s)
  1 failing

  1) Frontier RPC (EthFilterApi)
       should return response for raw Log filter request.:
     TypeError: Cannot read property 'logs' of null
      at Context.<anonymous> (tests/test-filter-api.ts:124:18)
      at step (tests/test-filter-api.ts:33:23)
      at Object.next (tests/test-filter-api.ts:14:53)
      at fulfilled (tests/test-filter-api.ts:5:58)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

On my own local machine, I ran this test in a loop and it took about 20 runs before it failed. I suspect that it is unrelated to this PR.

@notlesh notlesh marked this pull request as ready for review April 9, 2021 16:47
@notlesh notlesh requested a review from sorpaas as a code owner April 9, 2021 16:47
@@ -23,7 +23,7 @@ sp-core = { version = "3.0.0", default-features = false, git = "https://github.c
sp-runtime = { version = "3.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "frontier" }
sp-std = { version = "3.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "frontier" }
sp-io = { version = "3.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "frontier" }
fp-evm = { version = "1.0.0", default-features = false, path = "../../primitives/evm" }
fp-evm = { version = "1.0.1-dev", default-features = false, path = "../../primitives/evm" }
Copy link
Member

Choose a reason for hiding this comment

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

Please also update pallet-evm to 3.0.1-dev

description = "SHA3 FIPS202 precompile for EVM pallet."

[dependencies]
sp-core = { version = "3.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "frontier" }
sp-io = { version = "3.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "frontier" }
fp-evm = { version = "1.0.0", default-features = false, path = "../../../../primitives/evm" }
fp-evm = { version = "1.0.1-dev", default-features = false, path = "../../../../primitives/evm" }
Copy link
Member

Choose a reason for hiding this comment

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

Update pallet-evm-precompile-sha3fips to 1.0.1-dev

@@ -0,0 +1,26 @@
[package]
name = "pallet-evm-test-vector-support"
version = "1.0.1-dev"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
version = "1.0.1-dev"
version = "1.0.0-dev"

Copy link
Member

Choose a reason for hiding this comment

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

Because this crate has not yet been released at all!

@sorpaas
Copy link
Member

sorpaas commented Apr 20, 2021

The majority of the required version bumps remaining comes from the fact that fp-evm is updated from 1.0.0 to 1.0.1-dev. That is okay. But alternatively, since there's no noticeable changes at all to fp-evm, you can also keep it at 1.0.0.

@notlesh
Copy link
Contributor Author

notlesh commented Apr 21, 2021

@sorpaas I believe I took care of the version changes you requested, but feel free to be pedantic if not.

Also, I read up on https://github.com/paritytech/frontier/#versioning for next time 👍

@@ -17,7 +17,7 @@ sc-client-api = { version = "3.0.0", git = "https://github.com/paritytech/substr
sp-block-builder = { version = "3.0.0", git = "https://github.com/paritytech/substrate.git", branch = "frontier" }
sp-inherents = { version = "3.0.0", git = "https://github.com/paritytech/substrate.git", branch = "frontier" }
fp-consensus = { version = "1.0.0", path = "../../primitives/consensus" }
fp-rpc = { version = "1.0.0", path = "../../primitives/rpc" }
fp-rpc = { version = "1.0.1-dev", path = "../../primitives/rpc" }
Copy link
Member

Choose a reason for hiding this comment

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

All bumps should be recursive so fc-consensus needs to be bumped!

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 in 565ea71. And I think that should cover it: every crate that was modified got a bump with -dev unless it was already at -dev. The exception is the node template and runtime, which appear to not be versioned. Hope I got it right this time.

@sorpaas
Copy link
Member

sorpaas commented Apr 22, 2021

Please pull master!

@sorpaas
Copy link
Member

sorpaas commented Apr 22, 2021

@notlesh Still has conflict with master!

@notlesh
Copy link
Contributor Author

notlesh commented Apr 22, 2021

@notlesh Still has conflict with master!

Odd, I pushed a new commit (which merges master), but this PR doesn't seem to update. You can see it on PureStake's repo: https://github.com/PureStake/frontier/commits/notlesh-precompile-gas . Commit is b29dd13.

@notlesh notlesh changed the base branch from master to legacy April 22, 2021 21:53
@sorpaas
Copy link
Member

sorpaas commented Apr 22, 2021

Hmm let me try reopen this PR.

@sorpaas sorpaas closed this Apr 22, 2021
@sorpaas sorpaas reopened this Apr 22, 2021
@notlesh notlesh changed the base branch from legacy to master April 22, 2021 21:54
@notlesh
Copy link
Contributor Author

notlesh commented Apr 22, 2021

I see the commit now

Copy link
Member

@sorpaas sorpaas left a comment

Choose a reason for hiding this comment

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

Thank you!

@sorpaas sorpaas merged commit 961e992 into polkadot-evm:master Apr 22, 2021
abhijeetbhagat pushed a commit to web3labs/frontier that referenced this pull request Jan 11, 2023
* First pass at Modexp precompile gas calculation

* Incremental WIP adding modexp-eip2565.json tests

* Include Modexp in precompile set

* Working impl for ethereum test cases

* Cleanup

* Add Ethereum consensus tests in Modexp unit tests

* Return gas cost from Modexp::execute()

* Add (not very DRY) ethereum tests for Blake2 precompile

* Fixes for Blake2F precompile

* Implement EIP1108 gas costs for bn128 precompiles

* Make precompile consensus test generic

* Move test_precompile_consensus_tests to fp_evm

* Clean up precompile testdata

* Improve test_precompile_consensus_tests error handling

* Change ECRecover to return "" on error; add related tests

* Add clarifying comment

* Add sha256 and ripem160 precompile test vectors

* Add bn128 test vectors

* Remove non-existent mod declaration

* Implement Blake2 gas cost

* Remove ecrecover tests that expect bytes 33-63 to matter

* editorconfig

* Remove version specification from local crate references

* Remove modexp_eip2565 ts-tests (now redundant)

* Use 'core::cmp::max'

* Resolve compilation warnings

* Handle target_gas properly

* Revert from_ne_bytes -> from_le_bytes with comment about the logic

* Bump precompile versions

* Use 1.1.0 instead of 1.0.1 for new precompile versions

Co-authored-by: Wei Tang <[email protected]>

* Bump fp-evm to 1.0.1-dev

* Reflect new fp-evm version in crates which depend on it

* Remove unused log dependency in modexp precompile

* Move eth "consensus tests" utility to its own crate

* Modify remaining precompile tests to use pallet_evm_test_vector_support

* Leave primitives/evm/src/precompile.r untouched

* Add missing files

* Use 1.0.1-dev as version for pallet-evm-test-vector-support

* Chain 'std' for 'fp-evm'

* Specify paritytech/frontier as the repo in all Cargo.toml files

* Bump versions

* Bump fp-storage to 1.0.1-dev

* Bump fp-rpc to 1.0.1-dev

* Bump fc-consensus to 1.0.1-dev

Co-authored-by: Wei Tang <[email protected]>
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.

2 participants