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

eth_api: Implement get_storage method #45

Closed
3 tasks
Tracked by #51
dutterbutter opened this issue Aug 10, 2023 · 2 comments · Fixed by #134
Closed
3 tasks
Tracked by #51

eth_api: Implement get_storage method #45

dutterbutter opened this issue Aug 10, 2023 · 2 comments · Fixed by #134
Labels
challenging 🏴‍☠️ Indicates a difficult item eth_api ♢ Indicates eth namespace api tasks p2 🟡 Indicates moderately high priority item

Comments

@dutterbutter
Copy link
Collaborator

Description:

We need to implement the get_storage method, which will be responsible for fetching the storage value from a position in a contract.

/// Retrieves the storage value from a position in a contract.
fn get_storage(&self, address: H160, position: U256, block: Option<BlockIdentifier>) -> jsonrpc_core::BoxFuture<jsonrpc_core::Result<Option<H256>>> {
    not_implemented("get_storage")
}

Expected response

Command:

# Note: Using mainnet URL for demonstration purposes
curl -X POST https://mainnet.era.zksync.io \
     -H "Content-Type: application/json" \
     --data '{
       "jsonrpc": "2.0",
       "id": 1,
       "method": "eth_getStorageAt",
       "params": ["0x123456789abcdef123456789abcdef1234567890", "0x0", "latest"]
     }'

Response:

{"jsonrpc":"2.0","result":"0x0000000000000000000000000000000000000000000000000000000000000000","id":1}

Requirements:

  1. Implement the Method:

    • This method should take in three parameters: an H160 address, a U256 position, and an optional BlockIdentifier to specify the block from which the storage should be retrieved.
    • It should return an Option<H256> value representing the storage at the specified position.
  2. Unit Tests:

    • Write unit tests to ensure that the get_storage method is functioning correctly.
    • Ensure that any potential exceptions and errors, like an invalid address or position, are correctly handled.
  3. Inline Documentation:

    • Add inline Rust documentation (/// comments) detailing the purpose and usage of the get_storage method.
    • Include any relevant information about the return values and potential errors/exceptions.

Task Checklist:

  • Implement the get_storage method.
  • Write unit tests for the get_storage method.
  • Add inline documentation for the get_storage method.

Additional Notes:

If you're an external contributor looking to take on this issue, please comment below to let us know you're working on it. If you need further clarification on the requirements or need assistance with anything related to the implementation, feel free to ask!

@dutterbutter dutterbutter added p2 🟡 Indicates moderately high priority item challenging 🏴‍☠️ Indicates a difficult item eth_api ♢ Indicates eth namespace api tasks labels Aug 10, 2023
@nbaztec
Copy link
Contributor

nbaztec commented Sep 14, 2023

@MexicanAce I see that currently we do not have a storage (root) per block and only a 1-tier storage. For implementing eth_getStorageAt we also have the additional block parameter to get storage at a height. Do we have an intention of supporting a per height storage?

@georgewhewell
Copy link

@MexicanAce I see that currently we do not have a storage (root) per block and only a 1-tier storage. For implementing eth_getStorageAt we also have the additional block parameter to get storage at a height. Do we have an intention of supporting a per height storage?

imo yes, it's quite important- it would be very confusing for people debug issues that arise when using tooling which expects this parameter to be respected and it is not. other dev nodes (e.g anvil) do implement this

IAvecilla added a commit to lambdaclass/era-test-node that referenced this issue Feb 29, 2024
* ecadd tests

* ecmul tests

* Add test utils

* Add test suit generator

* Remove old tests

* Update tests

* Fix ecadd

* Fix ecmul

* Handle modexp tests

* Add modexp tests

* Update call helper function

* Fix helper function

* Fix test utils

* Improve ecmul precompile

* Add test helper

* Add python script to test double and add algorithm (matter-labs#13)

* Add montgomery reduction algorithm

* Add Rust playground crate

* Update montgomery reduction script

* Add Montgomery reduction precompile

* ecAdd refactor

* Montgomery fix

* Add montgomery inv & modexp

* Fix N'

* Fix REDC

* Fix Montgomery modular inverse

* Remove comments

* Fix prints

* Change to bytes comparison instead of decoded output

* Patch tests with extra check for errors in ecadd and ecmul

* Add EOL

* Update modexp precompile

* Finish optimizing ecAdd & ecMul

* Implement optimized montgomery invmod

* modexpGasCost

* Cleanup

* Last version of ecAdd, ecMul & modexp

* Fix modexp tests calldata

* Fix modexp tests to pass with actual vm state

* Update Montgomery precompile

* Rename montgomery lib

* Add alt_bn128 projective point lib

* Add quadratic extension field arithmetic lib

* Add alt_bn128 pairing script

* Finish quadratic extension field arithmetics

Co-authored-by: Nacho Avecilla <nachoavecilla@gmail.com>

* Fix Montgomery lib

Co-authored-by: Nacho Avecilla <nachoavecilla@gmail.com>

* Implement double and addition steps

Co-authored-by: Nacho Avecilla <nachoavecilla@gmail.com>

* Arithmetics over Fp2 in Python (matter-labs#14)

* Finish fp2 arithmetic

* Add more precomputed values

* Fix fp2 inv

* Add EOF

* Rename module

* Fix point at infinity

* Rename lib

* Arithmetics over Fp6 in Python (matter-labs#15)

* Finish fp2 arithmetic

* Add more precomputed values

* Add arithmetic operations for fp6

* Update constant name

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Replace epsilon for XI

* Change script name

* Add multiplication by xi in fp2 and fp6

* Add alternative inverse method

* Fix inverse operation

---------

Co-authored-by: Iván Litteri <ilitteri@fi.uba.ar>
Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Fp12 arithmetic (matter-labs#21)

* WIP

* add fp12 arithmetics

* fix typo

* add addition tests

* add sub test

* rename gamma function

* add mul tests

* fix function call

* fix typo

* mul fixes

* fix mul by 1

* fix square

* fix fp12 inverse

* add multiply by 2 asserts

* add EOF

---------

Co-authored-by: Iván Litteri <ilitteri@fi.uba.ar>

* Add jacobian coordinates in Python (matter-labs#22)

* Rename file

* Add implementation for jacobian projective coordinates

* Fix fp12 merge error

* Fix addition

* Rename function to check inifinity and add extra comments

* Fp2, Fp6 and Fp12 arithmetics in Yul (matter-labs#23)

* Add fp2 arithmetics

* Add fp6 arithmetics

* Rename funcs

* Fix compilation errors in fp6 operations

* Add tests for inverse and sub for fp2

* Fix square and multiplication for fp6

* Add tests for add, mul, sub and square in fp6

* add fp12 arithmetic

* Fix inverse in fp6

* Add tests for inverse in fp6

* add fp12 tests

* add inverse test for fp12

* changes mul for sub

---------

Co-authored-by: Iván Litteri <ilitteri@fi.uba.ar>
Co-authored-by: Joaquin Carletti <joaquin.carletti@lambdaclass.com>

* Add point addition and line evaluation algorithm (matter-labs#24)

* Point doubling and line evaluation (matter-labs#25)

* Refactor for line evaluation functions (matter-labs#29)

* Move point doubling and line evaluation to pairing file

* Change return type in point adding and line evaluation to match with doubling

* Remove incorrect parameter

* Change name to match with other pairing function

* add mul by gamma functions (matter-labs#31)

* Improve fp6 and fp12 arithmetics return type (matter-labs#35)

* Change fp6 return type to single tuple

* change return to single tuple

---------

Co-authored-by: Joaquin Carletti <joaquin.carletti@lambdaclass.com>

* add millers loop (matter-labs#30)

* add millers loop basics

* add PI functions to loop

* add neg of a G2 point

* add loop counter

* fix return of negate funciton

* fix loop_counter values

* rename utils file

* fix imports

* change constants to fp6 file

* fix miller loop set up

* add comment

* fix comment

* fix typo

* Add Final exponentiation (matter-labs#32)

* Add ten in montgomery form as constant

* Add frobenius operations

* Add negate operation for fp6

* Add conjugate operation for fp2

* Add operations in fp2 used in final exponentiation

* Add final exponentiation function

* Fix return types to match with new changes

* Add corrections to n_square function

* Use montgomery for gamma factors and add frobenius tests

* Add test for cyclotomic square

* Add another final exponentiation implementation and test

* fix fp6 arithmetic (matter-labs#42)

* Precompute Frobenius constants (matter-labs#44)

* Add pairing tests for python implementation (matter-labs#36)

* Add function utils to check elements in curve and twisted curve

* Add conditional for g2 from affine

* Add tests for conjugate in fp12 and fp2

* Fix miller loop errors

* Add pair function

* Add pairing test from eth tests

* Correct NAF representation

* Change exponentiation impl to be able to test it correctly

* Correct point doubling and miller loop

* Add test for point doubling and line evaluation

* add addition tests

* Add tests for frobenius

* Add line evaluation test after point addition

* Add point doubling and adding functions for projective coordinates

* Fix in miller loop function

* Add test refactors with new functions

* Fix constant for fp12

* Add functions for g2 in projective and affine

* Fix NAF representation

* add eth tests

* add tests names

* add expt

* change final_exp

* fix fp6 square

* Delete test generator for pairing in python

* Delete unnecesary comments

* Delete unused exponentiation function

* Delete unused import and old todo

* Improve naming of doubling and addition steps in miller loop

---------

Co-authored-by: Joaquin Carletti <joaquin.carletti@lambdaclass.com>

* Frobenius Operator in Yul (matter-labs#43)

* Implement Frobenius operator in Yul

* Fix Frobenius functions returns

* Fix Frobenius functions returns

* Add tests

* Update comment

* add mix addition in yul (matter-labs#45)

* Add function utils to check elements in curve and twisted curve

* Add conditional for g2 from affine

* Add tests for conjugate in fp12 and fp2

* Fix miller loop errors

* Add pair function

* Add pairing test from eth tests

* Correct NAF representation

* Change exponentiation impl to be able to test it correctly

* Correct point doubling and miller loop

* Add test for point doubling and line evaluation

* add addition tests

* Add tests for frobenius

* Add line evaluation test after point addition

* Add point doubling and adding functions for projective coordinates

* Fix in miller loop function

* Add test refactors with new functions

* Fix constant for fp12

* Add functions for g2 in projective and affine

* Fix NAF representation

* add eth tests

* add tests names

* add expt

* change final_exp

* fix fp6 square

* Delete test generator for pairing in python

* Delete unnecesary comments

* Delete unused exponentiation function

* Delete unused import and old todo

* Improve naming of doubling and addition steps in miller loop

* add mix addition in yul

* fix function

* Update precompiles/Playground.yul

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

---------

Co-authored-by: IAvecilla <iavecilla@fi.uba.ar>
Co-authored-by: Iván Litteri <ilitteri@fi.uba.ar>
Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Add cyclotomicSquare and nSquare (matter-labs#47)

* Add function utils to check elements in curve and twisted curve

* Add conditional for g2 from affine

* Add tests for conjugate in fp12 and fp2

* Fix miller loop errors

* Add pair function

* Add pairing test from eth tests

* Correct NAF representation

* Change exponentiation impl to be able to test it correctly

* Correct point doubling and miller loop

* Add test for point doubling and line evaluation

* add addition tests

* Add tests for frobenius

* Add line evaluation test after point addition

* Add point doubling and adding functions for projective coordinates

* Fix in miller loop function

* Add test refactors with new functions

* Fix constant for fp12

* Add functions for g2 in projective and affine

* Fix NAF representation

* add eth tests

* add tests names

* add expt

* change final_exp

* fix fp6 square

* Delete test generator for pairing in python

* Delete unnecesary comments

* Delete unused exponentiation function

* Delete unused import and old todo

* Improve naming of doubling and addition steps in miller loop

* add cyclotomic square

* fix assignments

* add nSquare

---------

Co-authored-by: IAvecilla <iavecilla@fi.uba.ar>
Co-authored-by: Iván Litteri <ilitteri@fi.uba.ar>

* Add `t` exponentiation for fp12 in Yul (matter-labs#48)

* Add function utils to check elements in curve and twisted curve

* Add conditional for g2 from affine

* Add tests for conjugate in fp12 and fp2

* Fix miller loop errors

* Add pair function

* Add pairing test from eth tests

* Correct NAF representation

* Change exponentiation impl to be able to test it correctly

* Correct point doubling and miller loop

* Add test for point doubling and line evaluation

* add addition tests

* Add tests for frobenius

* Add line evaluation test after point addition

* Add point doubling and adding functions for projective coordinates

* Fix in miller loop function

* Add test refactors with new functions

* Fix constant for fp12

* Add functions for g2 in projective and affine

* Fix NAF representation

* add eth tests

* add tests names

* add expt

* change final_exp

* fix fp6 square

* Delete test generator for pairing in python

* Delete unnecesary comments

* Delete unused exponentiation function

* Delete unused import and old todo

* Improve naming of doubling and addition steps in miller loop

* Add implementation for exponentiation by t for fp12

---------

Co-authored-by: Joaquin Carletti <joaquin.carletti@lambdaclass.com>
Co-authored-by: Iván Litteri <ilitteri@fi.uba.ar>

* Add final exp in yul (matter-labs#49)

* Add function utils to check elements in curve and twisted curve

* Add conditional for g2 from affine

* Add tests for conjugate in fp12 and fp2

* Fix miller loop errors

* Add pair function

* Add pairing test from eth tests

* Correct NAF representation

* Change exponentiation impl to be able to test it correctly

* Correct point doubling and miller loop

* Add test for point doubling and line evaluation

* add addition tests

* Add tests for frobenius

* Add line evaluation test after point addition

* Add point doubling and adding functions for projective coordinates

* Fix in miller loop function

* Add test refactors with new functions

* Fix constant for fp12

* Add functions for g2 in projective and affine

* Fix NAF representation

* add eth tests

* add tests names

* add expt

* change final_exp

* fix fp6 square

* Delete test generator for pairing in python

* Delete unnecesary comments

* Delete unused exponentiation function

* Delete unused import and old todo

* Improve naming of doubling and addition steps in miller loop

* add final exponentiation

* Update precompiles/Playground.yul

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

---------

Co-authored-by: IAvecilla <iavecilla@fi.uba.ar>
Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Point doubling step of the miller loop in Yul (matter-labs#46)

* Add function utils to check elements in curve and twisted curve

* Add conditional for g2 from affine

* Add tests for conjugate in fp12 and fp2

* Fix miller loop errors

* Add pair function

* Add pairing test from eth tests

* Correct NAF representation

* Change exponentiation impl to be able to test it correctly

* Correct point doubling and miller loop

* Add test for point doubling and line evaluation

* add addition tests

* Add tests for frobenius

* Add line evaluation test after point addition

* Add point doubling and adding functions for projective coordinates

* Fix in miller loop function

* Add test refactors with new functions

* Fix constant for fp12

* Add functions for g2 in projective and affine

* Fix NAF representation

* add eth tests

* add tests names

* add expt

* change final_exp

* fix fp6 square

* Delete test generator for pairing in python

* Delete unnecesary comments

* Delete unused exponentiation function

* Delete unused import and old todo

* Improve naming of doubling and addition steps in miller loop

* Add implementation for point doubling step of the miller loop

* Fix fp2 neg function parameters

* Fix typo in parameters to return

* Add precomputation for inverse of two

---------

Co-authored-by: Joaquin Carletti <joaquin.carletti@lambdaclass.com>

* G2 Twist in Yul (matter-labs#50)

* Add basic functionality for G2 Twist

* Rename neg to g2Neg

* Rename functions and fix compilation errors

* Miller loop in yul (matter-labs#52)

* Clean playground code for pairing migration

* ecPairing common tests for all Ethereum implementations (matter-labs#51)

* Add ecpairing official tests

* Change tests path for test generator script

---------

Co-authored-by: IAvecilla <iavecilla@fi.uba.ar>
Co-authored-by: Joaquin Carletti <56092489+ColoCarletti@users.noreply.github.com>
Co-authored-by: Joaquin Carletti <joaquin.carletti@lambdaclass.com>
IAvecilla added a commit to lambdaclass/era-test-node that referenced this issue Feb 29, 2024
* ecadd tests

* ecmul tests

* Add test utils

* Add test suit generator

* Remove old tests

* Update tests

* Fix ecadd

* Fix ecmul

* Handle modexp tests

* Add modexp tests

* Update call helper function

* Fix helper function

* Fix test utils

* Improve ecmul precompile

* Add test helper

* Add python script to test double and add algorithm (matter-labs#13)

* Add montgomery reduction algorithm

* Add Rust playground crate

* Update montgomery reduction script

* Add Montgomery reduction precompile

* ecAdd refactor

* Montgomery fix

* Add montgomery inv & modexp

* Fix N'

* Fix REDC

* Fix Montgomery modular inverse

* Remove comments

* Fix prints

* Change to bytes comparison instead of decoded output

* Patch tests with extra check for errors in ecadd and ecmul

* Add EOL

* Update modexp precompile

* Finish optimizing ecAdd & ecMul

* Implement optimized montgomery invmod

* modexpGasCost

* Cleanup

* Last version of ecAdd, ecMul & modexp

* Fix modexp tests calldata

* Fix modexp tests to pass with actual vm state

* Update Montgomery precompile

* Rename montgomery lib

* Add alt_bn128 projective point lib

* Add quadratic extension field arithmetic lib

* Add alt_bn128 pairing script

* Finish quadratic extension field arithmetics

Co-authored-by: Nacho Avecilla <nachoavecilla@gmail.com>

* Fix Montgomery lib

Co-authored-by: Nacho Avecilla <nachoavecilla@gmail.com>

* Implement double and addition steps

Co-authored-by: Nacho Avecilla <nachoavecilla@gmail.com>

* Arithmetics over Fp2 in Python (matter-labs#14)

* Finish fp2 arithmetic

* Add more precomputed values

* Fix fp2 inv

* Add EOF

* Rename module

* Fix point at infinity

* Rename lib

* Arithmetics over Fp6 in Python (matter-labs#15)

* Finish fp2 arithmetic

* Add more precomputed values

* Add arithmetic operations for fp6

* Update constant name

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Replace epsilon for XI

* Change script name

* Add multiplication by xi in fp2 and fp6

* Add alternative inverse method

* Fix inverse operation

---------

Co-authored-by: Iván Litteri <ilitteri@fi.uba.ar>
Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Fp12 arithmetic (matter-labs#21)

* WIP

* add fp12 arithmetics

* fix typo

* add addition tests

* add sub test

* rename gamma function

* add mul tests

* fix function call

* fix typo

* mul fixes

* fix mul by 1

* fix square

* fix fp12 inverse

* add multiply by 2 asserts

* add EOF

---------

Co-authored-by: Iván Litteri <ilitteri@fi.uba.ar>

* Add jacobian coordinates in Python (matter-labs#22)

* Rename file

* Add implementation for jacobian projective coordinates

* Fix fp12 merge error

* Fix addition

* Rename function to check inifinity and add extra comments

* Fp2, Fp6 and Fp12 arithmetics in Yul (matter-labs#23)

* Add fp2 arithmetics

* Add fp6 arithmetics

* Rename funcs

* Fix compilation errors in fp6 operations

* Add tests for inverse and sub for fp2

* Fix square and multiplication for fp6

* Add tests for add, mul, sub and square in fp6

* add fp12 arithmetic

* Fix inverse in fp6

* Add tests for inverse in fp6

* add fp12 tests

* add inverse test for fp12

* changes mul for sub

---------

Co-authored-by: Iván Litteri <ilitteri@fi.uba.ar>
Co-authored-by: Joaquin Carletti <joaquin.carletti@lambdaclass.com>

* Add point addition and line evaluation algorithm (matter-labs#24)

* Point doubling and line evaluation (matter-labs#25)

* Refactor for line evaluation functions (matter-labs#29)

* Move point doubling and line evaluation to pairing file

* Change return type in point adding and line evaluation to match with doubling

* Remove incorrect parameter

* Change name to match with other pairing function

* add mul by gamma functions (matter-labs#31)

* Improve fp6 and fp12 arithmetics return type (matter-labs#35)

* Change fp6 return type to single tuple

* change return to single tuple

---------

Co-authored-by: Joaquin Carletti <joaquin.carletti@lambdaclass.com>

* add millers loop (matter-labs#30)

* add millers loop basics

* add PI functions to loop

* add neg of a G2 point

* add loop counter

* fix return of negate funciton

* fix loop_counter values

* rename utils file

* fix imports

* change constants to fp6 file

* fix miller loop set up

* add comment

* fix comment

* fix typo

* Add Final exponentiation (matter-labs#32)

* Add ten in montgomery form as constant

* Add frobenius operations

* Add negate operation for fp6

* Add conjugate operation for fp2

* Add operations in fp2 used in final exponentiation

* Add final exponentiation function

* Fix return types to match with new changes

* Add corrections to n_square function

* Use montgomery for gamma factors and add frobenius tests

* Add test for cyclotomic square

* Add another final exponentiation implementation and test

* fix fp6 arithmetic (matter-labs#42)

* Precompute Frobenius constants (matter-labs#44)

* Add pairing tests for python implementation (matter-labs#36)

* Add function utils to check elements in curve and twisted curve

* Add conditional for g2 from affine

* Add tests for conjugate in fp12 and fp2

* Fix miller loop errors

* Add pair function

* Add pairing test from eth tests

* Correct NAF representation

* Change exponentiation impl to be able to test it correctly

* Correct point doubling and miller loop

* Add test for point doubling and line evaluation

* add addition tests

* Add tests for frobenius

* Add line evaluation test after point addition

* Add point doubling and adding functions for projective coordinates

* Fix in miller loop function

* Add test refactors with new functions

* Fix constant for fp12

* Add functions for g2 in projective and affine

* Fix NAF representation

* add eth tests

* add tests names

* add expt

* change final_exp

* fix fp6 square

* Delete test generator for pairing in python

* Delete unnecesary comments

* Delete unused exponentiation function

* Delete unused import and old todo

* Improve naming of doubling and addition steps in miller loop

---------

Co-authored-by: Joaquin Carletti <joaquin.carletti@lambdaclass.com>

* Frobenius Operator in Yul (matter-labs#43)

* Implement Frobenius operator in Yul

* Fix Frobenius functions returns

* Fix Frobenius functions returns

* Add tests

* Update comment

* add mix addition in yul (matter-labs#45)

* Add function utils to check elements in curve and twisted curve

* Add conditional for g2 from affine

* Add tests for conjugate in fp12 and fp2

* Fix miller loop errors

* Add pair function

* Add pairing test from eth tests

* Correct NAF representation

* Change exponentiation impl to be able to test it correctly

* Correct point doubling and miller loop

* Add test for point doubling and line evaluation

* add addition tests

* Add tests for frobenius

* Add line evaluation test after point addition

* Add point doubling and adding functions for projective coordinates

* Fix in miller loop function

* Add test refactors with new functions

* Fix constant for fp12

* Add functions for g2 in projective and affine

* Fix NAF representation

* add eth tests

* add tests names

* add expt

* change final_exp

* fix fp6 square

* Delete test generator for pairing in python

* Delete unnecesary comments

* Delete unused exponentiation function

* Delete unused import and old todo

* Improve naming of doubling and addition steps in miller loop

* add mix addition in yul

* fix function

* Update precompiles/Playground.yul

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

---------

Co-authored-by: IAvecilla <iavecilla@fi.uba.ar>
Co-authored-by: Iván Litteri <ilitteri@fi.uba.ar>
Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Add cyclotomicSquare and nSquare (matter-labs#47)

* Add function utils to check elements in curve and twisted curve

* Add conditional for g2 from affine

* Add tests for conjugate in fp12 and fp2

* Fix miller loop errors

* Add pair function

* Add pairing test from eth tests

* Correct NAF representation

* Change exponentiation impl to be able to test it correctly

* Correct point doubling and miller loop

* Add test for point doubling and line evaluation

* add addition tests

* Add tests for frobenius

* Add line evaluation test after point addition

* Add point doubling and adding functions for projective coordinates

* Fix in miller loop function

* Add test refactors with new functions

* Fix constant for fp12

* Add functions for g2 in projective and affine

* Fix NAF representation

* add eth tests

* add tests names

* add expt

* change final_exp

* fix fp6 square

* Delete test generator for pairing in python

* Delete unnecesary comments

* Delete unused exponentiation function

* Delete unused import and old todo

* Improve naming of doubling and addition steps in miller loop

* add cyclotomic square

* fix assignments

* add nSquare

---------

Co-authored-by: IAvecilla <iavecilla@fi.uba.ar>
Co-authored-by: Iván Litteri <ilitteri@fi.uba.ar>

* Add `t` exponentiation for fp12 in Yul (matter-labs#48)

* Add function utils to check elements in curve and twisted curve

* Add conditional for g2 from affine

* Add tests for conjugate in fp12 and fp2

* Fix miller loop errors

* Add pair function

* Add pairing test from eth tests

* Correct NAF representation

* Change exponentiation impl to be able to test it correctly

* Correct point doubling and miller loop

* Add test for point doubling and line evaluation

* add addition tests

* Add tests for frobenius

* Add line evaluation test after point addition

* Add point doubling and adding functions for projective coordinates

* Fix in miller loop function

* Add test refactors with new functions

* Fix constant for fp12

* Add functions for g2 in projective and affine

* Fix NAF representation

* add eth tests

* add tests names

* add expt

* change final_exp

* fix fp6 square

* Delete test generator for pairing in python

* Delete unnecesary comments

* Delete unused exponentiation function

* Delete unused import and old todo

* Improve naming of doubling and addition steps in miller loop

* Add implementation for exponentiation by t for fp12

---------

Co-authored-by: Joaquin Carletti <joaquin.carletti@lambdaclass.com>
Co-authored-by: Iván Litteri <ilitteri@fi.uba.ar>

* Add final exp in yul (matter-labs#49)

* Add function utils to check elements in curve and twisted curve

* Add conditional for g2 from affine

* Add tests for conjugate in fp12 and fp2

* Fix miller loop errors

* Add pair function

* Add pairing test from eth tests

* Correct NAF representation

* Change exponentiation impl to be able to test it correctly

* Correct point doubling and miller loop

* Add test for point doubling and line evaluation

* add addition tests

* Add tests for frobenius

* Add line evaluation test after point addition

* Add point doubling and adding functions for projective coordinates

* Fix in miller loop function

* Add test refactors with new functions

* Fix constant for fp12

* Add functions for g2 in projective and affine

* Fix NAF representation

* add eth tests

* add tests names

* add expt

* change final_exp

* fix fp6 square

* Delete test generator for pairing in python

* Delete unnecesary comments

* Delete unused exponentiation function

* Delete unused import and old todo

* Improve naming of doubling and addition steps in miller loop

* add final exponentiation

* Update precompiles/Playground.yul

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

---------

Co-authored-by: IAvecilla <iavecilla@fi.uba.ar>
Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Point doubling step of the miller loop in Yul (matter-labs#46)

* Add function utils to check elements in curve and twisted curve

* Add conditional for g2 from affine

* Add tests for conjugate in fp12 and fp2

* Fix miller loop errors

* Add pair function

* Add pairing test from eth tests

* Correct NAF representation

* Change exponentiation impl to be able to test it correctly

* Correct point doubling and miller loop

* Add test for point doubling and line evaluation

* add addition tests

* Add tests for frobenius

* Add line evaluation test after point addition

* Add point doubling and adding functions for projective coordinates

* Fix in miller loop function

* Add test refactors with new functions

* Fix constant for fp12

* Add functions for g2 in projective and affine

* Fix NAF representation

* add eth tests

* add tests names

* add expt

* change final_exp

* fix fp6 square

* Delete test generator for pairing in python

* Delete unnecesary comments

* Delete unused exponentiation function

* Delete unused import and old todo

* Improve naming of doubling and addition steps in miller loop

* Add implementation for point doubling step of the miller loop

* Fix fp2 neg function parameters

* Fix typo in parameters to return

* Add precomputation for inverse of two

---------

Co-authored-by: Joaquin Carletti <joaquin.carletti@lambdaclass.com>

* G2 Twist in Yul (matter-labs#50)

* Add basic functionality for G2 Twist

* Rename neg to g2Neg

* Rename functions and fix compilation errors

* Miller loop in yul (matter-labs#52)

* move from playground to ecPairing

* add pair function

* Fix pair check

* Transform calldata into Montgomery form

* Remove console logs

* Add check for points in twisted curve

* Checks for points in group order

* Fix pairing tests to match with L1 response

* Update README.md

* Some refactor

* Start g2 scalar mul implementation

* Fix compilation errors from new g2 operations

* Correct some test assertions

* Clean pairing precompile

* Ec pairing documentation (matter-labs#68)

* document constant functions

* add documentation

* removeunused functions (#72)

* remove_unnecessary_mod (matter-labs#71)

* implement suggested optimization (matter-labs#70)

* remove constant funcitons (matter-labs#73)

* fix point comparison (matter-labs#74)

* Fix field order naming (matter-labs#75)

* fix field order naming

* replace GROUP_ORDER for FIELD_ORDER

* Removes_unnecessary_checking_in_ecMul (matter-labs#78)

* Add tests for points outside the field (matter-labs#79)

* improves overflowAdd (matter-labs#80)

* fix typos

* Removes unnecessary handling of a special case on addition. (matter-labs#77)

* removes unecesary check

* resolve confilct

* improves_binaryExtendedEuclideanAlgorithm (matter-labs#81)

* Revert "Merge branch 'ecPairing' into ecPairing_documentation"

This reverts commit 86a6e52a5aa31ac2f33139ad9030952ce8d53f8e, reversing
changes made to 5684c153e8990272f09ab2cc922d0c257c9508bc.

* Fix documentation with no utf8 characters

* Delete unused g2 function

* Add TODO comment

---------

Co-authored-by: Nacho Avecilla <nachoavecilla@gmail.com>
Co-authored-by: IAvecilla <iavecilla@fi.uba.ar>
Co-authored-by: Iván Litteri <ilitteri@fi.uba.ar>

* Apply previous audit fixes (matter-labs#97)

* Add missing docs (matter-labs#96)

* Fix ecPairing (matter-labs#103)

* Add missing docs (matter-labs#96)

* Apply previous audit fixes (matter-labs#97)

* Fix `ecPairing` tests (matter-labs#107)

* Fix tests

* Fix clippy lint

* `ecPairing` refactors & cleanup (matter-labs#98)

* Refactor g2AffinePointIsOnCurve

* Refactor `g1AffinePointIsOnCurve`

* Refactor `g1AffinePointIsOnCurve`

Use Montgomery Form

* Refactor `g1AffinePointIsInfinity`

Reduce one operation

* Reorder & refactor checks

- g1AffinePointIsInfinity now uses the point coordinates in Montgomery Form
- g1AffinePointIsOnCurve assumes that the point is not the point at infinity

* Remove 8 ops in pair check

* Remove useless constant functions

* Rename snake case function to camel case

* Rename function calls

* Add an explanatory comment

---------

Co-authored-by: Iván Litteri <ilitteri@fi.uba.ar>
Co-authored-by: IAvecilla <iavecilla@fi.uba.ar>
Co-authored-by: Nacho Avecilla <nachoavecilla@gmail.com>
Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>
IAvecilla added a commit to lambdaclass/era-test-node that referenced this issue Feb 29, 2024
* ecadd tests

* ecmul tests

* Add test utils

* Add test suit generator

* Remove old tests

* Update tests

* Fix ecadd

* Fix ecmul

* Handle modexp tests

* Add modexp tests

* Update call helper function

* Fix helper function

* Fix test utils

* Improve ecmul precompile

* Add test helper

* Add python script to test double and add algorithm (matter-labs#13)

* Add montgomery reduction algorithm

* Add Rust playground crate

* Update montgomery reduction script

* Add Montgomery reduction precompile

* ecAdd refactor

* Montgomery fix

* Add montgomery inv & modexp

* Fix N'

* Fix REDC

* Fix Montgomery modular inverse

* Remove comments

* Fix prints

* Change to bytes comparison instead of decoded output

* Patch tests with extra check for errors in ecadd and ecmul

* Add EOL

* Update modexp precompile

* Finish optimizing ecAdd & ecMul

* Implement optimized montgomery invmod

* modexpGasCost

* Cleanup

* Last version of ecAdd, ecMul & modexp

* Fix modexp tests calldata

* Fix modexp tests to pass with actual vm state

* Update Montgomery precompile

* Rename montgomery lib

* Add alt_bn128 projective point lib

* Add quadratic extension field arithmetic lib

* Add alt_bn128 pairing script

* Finish quadratic extension field arithmetics

Co-authored-by: Nacho Avecilla <nachoavecilla@gmail.com>

* Fix Montgomery lib

Co-authored-by: Nacho Avecilla <nachoavecilla@gmail.com>

* Implement double and addition steps

Co-authored-by: Nacho Avecilla <nachoavecilla@gmail.com>

* Arithmetics over Fp2 in Python (matter-labs#14)

* Finish fp2 arithmetic

* Add more precomputed values

* Fix fp2 inv

* Add EOF

* Rename module

* Fix point at infinity

* Rename lib

* Arithmetics over Fp6 in Python (matter-labs#15)

* Finish fp2 arithmetic

* Add more precomputed values

* Add arithmetic operations for fp6

* Update constant name

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Replace epsilon for XI

* Change script name

* Add multiplication by xi in fp2 and fp6

* Add alternative inverse method

* Fix inverse operation

---------

Co-authored-by: Iván Litteri <ilitteri@fi.uba.ar>
Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Fp12 arithmetic (matter-labs#21)

* WIP

* add fp12 arithmetics

* fix typo

* add addition tests

* add sub test

* rename gamma function

* add mul tests

* fix function call

* fix typo

* mul fixes

* fix mul by 1

* fix square

* fix fp12 inverse

* add multiply by 2 asserts

* add EOF

---------

Co-authored-by: Iván Litteri <ilitteri@fi.uba.ar>

* Add jacobian coordinates in Python (matter-labs#22)

* Rename file

* Add implementation for jacobian projective coordinates

* Fix fp12 merge error

* Fix addition

* Rename function to check inifinity and add extra comments

* Fp2, Fp6 and Fp12 arithmetics in Yul (matter-labs#23)

* Add fp2 arithmetics

* Add fp6 arithmetics

* Rename funcs

* Fix compilation errors in fp6 operations

* Add tests for inverse and sub for fp2

* Fix square and multiplication for fp6

* Add tests for add, mul, sub and square in fp6

* add fp12 arithmetic

* Fix inverse in fp6

* Add tests for inverse in fp6

* add fp12 tests

* add inverse test for fp12

* changes mul for sub

---------

Co-authored-by: Iván Litteri <ilitteri@fi.uba.ar>
Co-authored-by: Joaquin Carletti <joaquin.carletti@lambdaclass.com>

* Add point addition and line evaluation algorithm (matter-labs#24)

* Point doubling and line evaluation (matter-labs#25)

* Refactor for line evaluation functions (matter-labs#29)

* Move point doubling and line evaluation to pairing file

* Change return type in point adding and line evaluation to match with doubling

* Remove incorrect parameter

* Change name to match with other pairing function

* add mul by gamma functions (matter-labs#31)

* Improve fp6 and fp12 arithmetics return type (matter-labs#35)

* Change fp6 return type to single tuple

* change return to single tuple

---------

Co-authored-by: Joaquin Carletti <joaquin.carletti@lambdaclass.com>

* add millers loop (matter-labs#30)

* add millers loop basics

* add PI functions to loop

* add neg of a G2 point

* add loop counter

* fix return of negate funciton

* fix loop_counter values

* rename utils file

* fix imports

* change constants to fp6 file

* fix miller loop set up

* add comment

* fix comment

* fix typo

* Add Final exponentiation (matter-labs#32)

* Add ten in montgomery form as constant

* Add frobenius operations

* Add negate operation for fp6

* Add conjugate operation for fp2

* Add operations in fp2 used in final exponentiation

* Add final exponentiation function

* Fix return types to match with new changes

* Add corrections to n_square function

* Use montgomery for gamma factors and add frobenius tests

* Add test for cyclotomic square

* Add another final exponentiation implementation and test

* fix fp6 arithmetic (matter-labs#42)

* Precompute Frobenius constants (matter-labs#44)

* Add pairing tests for python implementation (matter-labs#36)

* Add function utils to check elements in curve and twisted curve

* Add conditional for g2 from affine

* Add tests for conjugate in fp12 and fp2

* Fix miller loop errors

* Add pair function

* Add pairing test from eth tests

* Correct NAF representation

* Change exponentiation impl to be able to test it correctly

* Correct point doubling and miller loop

* Add test for point doubling and line evaluation

* add addition tests

* Add tests for frobenius

* Add line evaluation test after point addition

* Add point doubling and adding functions for projective coordinates

* Fix in miller loop function

* Add test refactors with new functions

* Fix constant for fp12

* Add functions for g2 in projective and affine

* Fix NAF representation

* add eth tests

* add tests names

* add expt

* change final_exp

* fix fp6 square

* Delete test generator for pairing in python

* Delete unnecesary comments

* Delete unused exponentiation function

* Delete unused import and old todo

* Improve naming of doubling and addition steps in miller loop

---------

Co-authored-by: Joaquin Carletti <joaquin.carletti@lambdaclass.com>

* Frobenius Operator in Yul (matter-labs#43)

* Implement Frobenius operator in Yul

* Fix Frobenius functions returns

* Fix Frobenius functions returns

* Add tests

* Update comment

* add mix addition in yul (matter-labs#45)

* Add function utils to check elements in curve and twisted curve

* Add conditional for g2 from affine

* Add tests for conjugate in fp12 and fp2

* Fix miller loop errors

* Add pair function

* Add pairing test from eth tests

* Correct NAF representation

* Change exponentiation impl to be able to test it correctly

* Correct point doubling and miller loop

* Add test for point doubling and line evaluation

* add addition tests

* Add tests for frobenius

* Add line evaluation test after point addition

* Add point doubling and adding functions for projective coordinates

* Fix in miller loop function

* Add test refactors with new functions

* Fix constant for fp12

* Add functions for g2 in projective and affine

* Fix NAF representation

* add eth tests

* add tests names

* add expt

* change final_exp

* fix fp6 square

* Delete test generator for pairing in python

* Delete unnecesary comments

* Delete unused exponentiation function

* Delete unused import and old todo

* Improve naming of doubling and addition steps in miller loop

* add mix addition in yul

* fix function

* Update precompiles/Playground.yul

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

---------

Co-authored-by: IAvecilla <iavecilla@fi.uba.ar>
Co-authored-by: Iván Litteri <ilitteri@fi.uba.ar>
Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Add cyclotomicSquare and nSquare (matter-labs#47)

* Add function utils to check elements in curve and twisted curve

* Add conditional for g2 from affine

* Add tests for conjugate in fp12 and fp2

* Fix miller loop errors

* Add pair function

* Add pairing test from eth tests

* Correct NAF representation

* Change exponentiation impl to be able to test it correctly

* Correct point doubling and miller loop

* Add test for point doubling and line evaluation

* add addition tests

* Add tests for frobenius

* Add line evaluation test after point addition

* Add point doubling and adding functions for projective coordinates

* Fix in miller loop function

* Add test refactors with new functions

* Fix constant for fp12

* Add functions for g2 in projective and affine

* Fix NAF representation

* add eth tests

* add tests names

* add expt

* change final_exp

* fix fp6 square

* Delete test generator for pairing in python

* Delete unnecesary comments

* Delete unused exponentiation function

* Delete unused import and old todo

* Improve naming of doubling and addition steps in miller loop

* add cyclotomic square

* fix assignments

* add nSquare

---------

Co-authored-by: IAvecilla <iavecilla@fi.uba.ar>
Co-authored-by: Iván Litteri <ilitteri@fi.uba.ar>

* Add `t` exponentiation for fp12 in Yul (matter-labs#48)

* Add function utils to check elements in curve and twisted curve

* Add conditional for g2 from affine

* Add tests for conjugate in fp12 and fp2

* Fix miller loop errors

* Add pair function

* Add pairing test from eth tests

* Correct NAF representation

* Change exponentiation impl to be able to test it correctly

* Correct point doubling and miller loop

* Add test for point doubling and line evaluation

* add addition tests

* Add tests for frobenius

* Add line evaluation test after point addition

* Add point doubling and adding functions for projective coordinates

* Fix in miller loop function

* Add test refactors with new functions

* Fix constant for fp12

* Add functions for g2 in projective and affine

* Fix NAF representation

* add eth tests

* add tests names

* add expt

* change final_exp

* fix fp6 square

* Delete test generator for pairing in python

* Delete unnecesary comments

* Delete unused exponentiation function

* Delete unused import and old todo

* Improve naming of doubling and addition steps in miller loop

* Add implementation for exponentiation by t for fp12

---------

Co-authored-by: Joaquin Carletti <joaquin.carletti@lambdaclass.com>
Co-authored-by: Iván Litteri <ilitteri@fi.uba.ar>

* Add final exp in yul (matter-labs#49)

* Add function utils to check elements in curve and twisted curve

* Add conditional for g2 from affine

* Add tests for conjugate in fp12 and fp2

* Fix miller loop errors

* Add pair function

* Add pairing test from eth tests

* Correct NAF representation

* Change exponentiation impl to be able to test it correctly

* Correct point doubling and miller loop

* Add test for point doubling and line evaluation

* add addition tests

* Add tests for frobenius

* Add line evaluation test after point addition

* Add point doubling and adding functions for projective coordinates

* Fix in miller loop function

* Add test refactors with new functions

* Fix constant for fp12

* Add functions for g2 in projective and affine

* Fix NAF representation

* add eth tests

* add tests names

* add expt

* change final_exp

* fix fp6 square

* Delete test generator for pairing in python

* Delete unnecesary comments

* Delete unused exponentiation function

* Delete unused import and old todo

* Improve naming of doubling and addition steps in miller loop

* add final exponentiation

* Update precompiles/Playground.yul

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

---------

Co-authored-by: IAvecilla <iavecilla@fi.uba.ar>
Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Point doubling step of the miller loop in Yul (matter-labs#46)

* Add function utils to check elements in curve and twisted curve

* Add conditional for g2 from affine

* Add tests for conjugate in fp12 and fp2

* Fix miller loop errors

* Add pair function

* Add pairing test from eth tests

* Correct NAF representation

* Change exponentiation impl to be able to test it correctly

* Correct point doubling and miller loop

* Add test for point doubling and line evaluation

* add addition tests

* Add tests for frobenius

* Add line evaluation test after point addition

* Add point doubling and adding functions for projective coordinates

* Fix in miller loop function

* Add test refactors with new functions

* Fix constant for fp12

* Add functions for g2 in projective and affine

* Fix NAF representation

* add eth tests

* add tests names

* add expt

* change final_exp

* fix fp6 square

* Delete test generator for pairing in python

* Delete unnecesary comments

* Delete unused exponentiation function

* Delete unused import and old todo

* Improve naming of doubling and addition steps in miller loop

* Add implementation for point doubling step of the miller loop

* Fix fp2 neg function parameters

* Fix typo in parameters to return

* Add precomputation for inverse of two

---------

Co-authored-by: Joaquin Carletti <joaquin.carletti@lambdaclass.com>

* G2 Twist in Yul (matter-labs#50)

* Add basic functionality for G2 Twist

* Rename neg to g2Neg

* Rename functions and fix compilation errors

* Miller loop in yul (matter-labs#52)

* move from playground to ecPairing

* add pair function

* Fix pair check

* Transform calldata into Montgomery form

* Remove console logs

* Add check for points in twisted curve

* Checks for points in group order

* Fix pairing tests to match with L1 response

* Update README.md

* Some refactor

* Start g2 scalar mul implementation

* Fix compilation errors from new g2 operations

* Correct some test assertions

* Clean pairing precompile

* Ec pairing documentation (matter-labs#68)

* document constant functions

* add documentation

* removeunused functions (#72)

* remove_unnecessary_mod (matter-labs#71)

* implement suggested optimization (matter-labs#70)

* remove constant funcitons (matter-labs#73)

* fix point comparison (matter-labs#74)

* Fix field order naming (matter-labs#75)

* fix field order naming

* replace GROUP_ORDER for FIELD_ORDER

* Removes_unnecessary_checking_in_ecMul (matter-labs#78)

* Add tests for points outside the field (matter-labs#79)

* improves overflowAdd (matter-labs#80)

* fix typos

* Removes unnecessary handling of a special case on addition. (matter-labs#77)

* removes unecesary check

* resolve confilct

* improves_binaryExtendedEuclideanAlgorithm (matter-labs#81)

* Revert "Merge branch 'ecPairing' into ecPairing_documentation"

This reverts commit 86a6e52a5aa31ac2f33139ad9030952ce8d53f8e, reversing
changes made to 5684c153e8990272f09ab2cc922d0c257c9508bc.

* Fix documentation with no utf8 characters

* Delete unused g2 function

* Add TODO comment

---------

Co-authored-by: Nacho Avecilla <nachoavecilla@gmail.com>
Co-authored-by: IAvecilla <iavecilla@fi.uba.ar>
Co-authored-by: Iván Litteri <ilitteri@fi.uba.ar>

* Add subgroup check for G2 points

* Fix merge errors

* Revert "Merge branch 'main' into ecpairing_subgroup_check"
- For some reason merging main breaks the console_log functionality

This reverts commit b6823fc25c85f1352405255edcc62ac81cad4904, reversing
changes made to 93d66fd8ca8ec665ffb270aadb8499e3fad334c4.

* Fix precompiles with incorrect merge

* Add playground file to test subgroup check

* fix g2Add

* wip

* Clean scalar mul function for g2 points

* wip

* Update add function for g2 points

* Update pairing with new algorithms for g2 operations

* Update docs for new g2 function to check subgroup inclusion

* Update pairing tests with new output from test node

* Fix tests format

* Delete playground file

* Update precompiles with main

* Add docs for helper functions

* Fix typos in docs

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Delete unnecesary checks in g2 addition

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Delete unnecesary infinity check

---------

Co-authored-by: Iván Litteri <ilitteri@fi.uba.ar>
Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>
Co-authored-by: Joaquin Carletti <56092489+ColoCarletti@users.noreply.github.com>
Co-authored-by: Joaquin Carletti <joaquin.carletti@lambdaclass.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
challenging 🏴‍☠️ Indicates a difficult item eth_api ♢ Indicates eth namespace api tasks p2 🟡 Indicates moderately high priority item
Projects
Status: Done 🏁
Development

Successfully merging a pull request may close this issue.

3 participants