-
Notifications
You must be signed in to change notification settings - Fork 632
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
Extend the Math API with EVM precompiles #3954
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good. This is considered as a protocol version change, so we need to introduce a new protocol feature & protocol version and import it with guard:
// #["protocol_feature_evm", EVM] test_api<[a: u64] -> []>, |
e5afcb9
to
f03aca2
Compare
@ailisp Please re-review, this is substantially closer to graduating from draft status. The top open question I still have is how, concretely, I should go about measuring and assigning the gas costs for the new functions. (Also, the runtime-params-estimator exits with a failure, so I may still be missing something in that regard.)
Thanks. I've guarded everything new behind the EVM feature for now. |
I also think this should be a separate feature from EVM, so that it can be released separately from the full precompiled EVM. This can be (and probably should be) batched with bn128 host functions. |
Looks like runtime param estimator tests failed because it isn't compiled with protocol-feature-evm enabled, so those new functions isn't exported: https://buildkite.com/nearprotocol/nearcore/builds/5739#17b95e82-bc41-4b95-b620-44d8c5b42c89 I suggest:
Use this to build a docker image: once in docker, disregard above steps, simply run |
There is a problem with the BLAKE2b function added here. While this PR adds the whole BLAKE2b function, what EVM should provide to smart contracts is the compression function F (see EIP 152), and you can't use the whole BLAKE2b function to implement just the compression function. While we can add just the function F as a host function, it would be preferred that the function is usable not just for the EVM but also for other contracts that may want to compute BLAKE2 hashes. So, I think that a better idea is to add a function that evaluates a sequence of calls to the compression function in a way similar to how the BLAKE2 function itself does it. Such function could be used to perform a single compression function call (as needed by the EVM), and it can also compute the BLAKE2 hash itself in a single call. Another thing that I would have changed is to charge gas proportional to the number of blocks, not bytes. |
@joshuajbouw I will not have time to come back to this for a bit, so please take over this task and push it to completion. The subtasks I currently know about include the following:
|
Ok, yes will go through all that today and this weekend. |
Had to import two additional crates |
7b94c67
to
c1eba41
Compare
Closing in favour of a new PR with blake2 descoped as we have to ensure that it is completely correct. Ecrecover is the most important method that we need in the PR for Aurora. |
To speed up performance and lower the cost of EVM-as-a-contract, this adds several functions to the contract runtime Math API in order to support implementing the standard EVM precompiled contracts:
ripemd160()
(RIPEMD-160 hash function)blake2b()
(BLAKE2b hash function)ecrecover()
(ECRecover ECDSA signer recovery)References: