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

Add ECRecover support to the Math API #3921

Closed
artob opened this issue Feb 5, 2021 · 0 comments
Closed

Add ECRecover support to the Math API #3921

artob opened this issue Feb 5, 2021 · 0 comments
Assignees
Labels
A-cryptography Area: Cryptography A-EVM Area: Native EVM implementation and support A-transaction-runtime Area: transaction runtime (transaction and receipts processing, state transition, etc) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-Aurora Team: issues relevant to the Aurora team

Comments

@artob
Copy link
Contributor

artob commented Feb 5, 2021

As discussed with @ilblackdragon, @djsatok, and @frankbraun on 2021-02-04, to speed up and lower the cost of the EVM-as-a-contract implementation, we will need to add ecrecover() as a Math API primitive so that the EVM contract itself will not need to implement this function. More broadly, this function will also be useful to any contracts dealing with Eth1/EVM interoperability.

References:

@artob artob added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-transaction-runtime Area: transaction runtime (transaction and receipts processing, state transition, etc) A-cryptography Area: Cryptography A-EVM Area: Native EVM implementation and support labels Feb 5, 2021
@artob artob added the T-public-interfaces Team: issues relevant to the public interfaces team label Feb 5, 2021
@artob artob self-assigned this Feb 12, 2021
@bowenwang1996 bowenwang1996 added T-Aurora Team: issues relevant to the Aurora team and removed T-public-interfaces Team: issues relevant to the public interfaces team labels Jun 28, 2021
bowenwang1996 added a commit that referenced this issue Jun 30, 2021
* feat: Extend the Math API with EVM precompiles.

* feat: Add Math API stubs for ECRecover. (#3921)

* test: Add RIPEMD-160 and BLAKE2b to the params estimator.

* fix: Improve error output from the params estimator.

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>

* test: Add ECRecover stubs to the params estimator.

* fix: Widen ecrecover() parameter type to pass CI checks.

* feat(chain): Bump the protocol version.

* feat(runtime): Implement ECRecover in the Math API. (#3921)

* docs: Document the ecrecover() function.

* fix(chain): Guard protocol upgrade behind EVM feature.

* add crypto feature gates

* fix nightly compile

* cargo fmt

* fix two ripemd160 missing feature gates

* rename crypto_extras feature to protocol_feature equivalents

* change repo to our git

* put everything under protocol_feature_evm

* point to alternative blake2 branch temporarily

* Add blake2b f function

* add blake2b_f to config

* post rebase fixes

* wrap all ext_costs in evm feature

* add blake_2b_f to runtime estimator

* cargo fmt

* add new hash algos to feature

* add vm-logic test for blake2b_f

* fix derive formatting

* use same blake2 library

* change blake F tests to test 1 round

* fix blake f test

* cleanup calls_helper

* add missing feature gated fields from ExtCostsConfig

* add blake2b_f compression docs

* remove unused `blake2b_f_byte` as sizes are fixed

* add missing blake2b_f to imports

* runtime estimator mod docs

* Add near-blake2 lib to near-crypto

* fix test imports

* add more pub methods to blake2

* add blake2 state success tests

* cargo fmt

* Add initial blake2 logic to vm

* Fix ecrecover

* Change blake2 `update` to `update_inner`

* Update params estimator

* Remove duplicate evm feature

* Remove pattern

* Fix some compilation errors

* Fix runtime-params-estimator compile

* Fix tests

* Reduce blake2s param estimator rounds from 12 to 10

* Add protocol_feature_evm feature to standalone runner

* Add estimated gas values

* Update estimated gas value note

* cargo fmt

* Update c2-chacha

* Remove nightly features from lib blake2

* Add blake2 pass tests

* Fix up ecrecover test

* Fix blake2s args

* Remove blake2 lib

* Update documentation for blake2

* Pin comment for blake2 lib

* Fix with_state

* Return a bool for ecrecover, not abort

* Fix VarBlake2b -> VarBlake2s

* Add errors to RPC errors schema

* Add bool return to wrapped imports

* Take t0 and t1 for blake2b

* Charge ripemd160 by blocks, not bytes

* Correctly send both t0 and t1 to blake2

* Remove too many rounds error

* Remove any near-blake2 errors

* Remove hash data overflow error

* Rename Blake2InvalidStateLength -> Blake2StateLengthExceeded

* Small ecrecover clarifications

* Return public key in ecrecover

* Correct blake2 message block math

* Correct ripemd160 message block math

* Read blake2s as u32 not u64

* Remove `state_len` and blake2 len error

* Add `saturating_mul` to blake2 math

* Don't allocate an extra vec on blake2

* Remove unused import

* Fix args in wrapped imports

* Fix blake2s test

* Remove blake2 and added protocol_feature_evm conditional comps

* Remove optional from crypto imports in logic

* Revert from near-blake2 to upstream blake2

* Drop libsecp256k1 crate in favour of near-crypto

* Improve code quality by using U256

* Pass hash_bytes as ref

* Revert "Pass hash_bytes as ref"

This reverts commit 434145b.

* matklad nit

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>

* Fix ecrecover exports arg sig

* Move when malleability check happens

* Remove last check in signature values

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>

* Don't use `v` in a check, now unused

* Update description of ripemd160 with correct cost

* Use u32 for malleability_flag

* Introduce protocol_feature_math_extension

* Use our own div_ceil implementation

* Include protocol_feature_math_extension in runtime-params-estimator/nightly_protocol_features

* Nightly protocol version bump

* Simplify message_blocks computation

* Remove unused div_ceil function

* Ignore first byte of result

* Remove uneeded return at end of function

Co-authored-by: EgorKulikov <egor@egork.net>

* Remove check_v and add in option to skip reject upper range

* Use `get_vec_from_memory_or_register` over `memory_get_into`

* Remove unused

* Separate `v`, change args to `u64`

* Remove redundant check

* 64th byte, not 65

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>

* Fix test

* Update doc cost

* Fix estimator

* Small fixes

* Add missing feature `protocol_feature_math_extension` from neard

* Add near-primitives to math extension params estimator

* Fix byte length

* Fix Cargo.toml

* Nit. Typos

* Nit. param estimator is missing feature dependency

* Add feature support for build.sh of test-contract

* Add consts for SECP256K1 malleability values

* Remove map err, change to unwrap

* Change v check to something more simple

* Always do signature check

* Check one s bound

* Allow for specifying a register

* Remove math extension feature from primitives core

* Nit. Convering byte to bool

* Add measuring support.

* Revert "Remove math extension feature from primitives core"

This reverts commit ac53dcb.

* Const SECP256K1 half + 1

* Revert "Add measuring support."

This reverts commit 210ee55.

* Update gas costs with correct values

* Nit. Method signature typo causing runtime failure

* Fix fee. It seems like a copy-paste typo

* Undo the wrong fix

* Add malleability_flag check as requested in #4380 (comment)

* syntax fix

Co-authored-by: Arto Bendiken <arto@near.org>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Co-authored-by: Michael Birch <michael@near.org>
Co-authored-by: Michael Birch <michael.birch@aurora.dev>
Co-authored-by: EgorKulikov <egor@egork.net>
Co-authored-by: Maksym Zavershynskyi <max@near.org>
Co-authored-by: Nikolay Igotti <igotti@gmail.com>
Co-authored-by: Bowen Wang <bowenwang1996@users.noreply.github.com>
Co-authored-by: Bowen Wang <bowen@near.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cryptography Area: Cryptography A-EVM Area: Native EVM implementation and support A-transaction-runtime Area: transaction runtime (transaction and receipts processing, state transition, etc) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-Aurora Team: issues relevant to the Aurora team
Projects
None yet
Development

No branches or pull requests

3 participants