Skip to content

Commit

Permalink
Squashed '.test-node-subtree/' changes from fb635d1..814ae72
Browse files Browse the repository at this point in the history
814ae72 Update subtree with new precompiles
f832eb9 Merge pull request #226 from lambdaclass/fix-subtree
9031cb5 Update subtree
3e5f82a Merge commit '55210e4632566a4f74503d83aed246b7a4e69233' as '.test-node-subtree'
3e386d4 Remove old subtree
16c494e Add ecAddG2 precompile (#211)
787f7fe Add ecAddG2 precompile (#211)
2fdb9d0 Add ecMulG2 precompile (#220)
9469bb6 Add ecMulG2 precompile (#220)
0e8e9e1 Update contracts in subtree (#218)
f5e645b Update contracts in subtree (#218)
5ae9408 Makefile fixes (#217)
d9c5563 Subtree era test node (#215)
73e2469 Subtree era test node (#215)
fc8fe32 Add ignore to test that is stopping the test suite (#213)
9bfb1c3 Improve makefile (#212)
fe92e93 Fix repo setup (#210)
0d6c0f2 update gas_consumption (#206)
52be222 Update docs (#204)
7be1914 Update README.md
80f543f P256verify audit fixes (#200)
d047659 Add verifier integration test (#179)
a7a5ed4 `modexp` big integers arithmetics (#124)
bee001d Add P256Verify tests (#178)
2753d37 Subgroup check for points in `G2` in `ecPairing` (#92)
0e961c2 Update Readme and gas tables (#174)
3067c76 fix projectiveAdd (#173)
9118195 adds shamir´s trick (#172)
710813d Implement strauss shamir trick (#171)
ea7c283 [CI] build precompiles (#165)
23fb8d0 update submodules (#167)
b7d1311 secp256k1VERIFY Precompile (#160)
63f0214 add p256 s input check (#166)
87186ca add r check (#163)
f272068 Update `README.md` (#162)
2da5282 P256VERIFY precompile contract (#55)
228e0e3 Add your own precompiles guide (#152)
b23a364 Replace invalid call to burnGas (#157)
b01b3c1 Optimize first iterations of miller loop (#119)
6347ae1 Add edge case tests for modexp precompile (#109)
dc3a750 Replace addmod/submod with Montgomery counterparts (#145)
a891bb8 Remove unnecessary checks in `ecAdd` (#144)
3044527 Store zero before returning in ecmul trivial cases (#123)
cc25b14 Add documentation for BEE (#120)
6ff795d Add extra checks to fix some edge cases (#118)
062fbcf Document montgomeryAdd and montgomerySub (#116)
f7430f3 Delete precompiles/Montgomery.yul (#101)
f660dca Improve `montgomeryAdd` implementation (#113)
e155896 remove_switch_in_projectiveIntoAffine (#115)
637ea8e Make `modexp` consistent with the other precompiles (#117)
76bef0f ecPairing (#53)
724a49b Replace `burnGas` with `invalid` (#105)
fa1dc58 Apply audit changes to ecAdd (#102)
8173484 Add CI (#18)
95e75d2 improves_binaryExtendedEuclideanAlgorithm (#81)
2c1d38d Removes unnecessary handling of a special case on addition. (#77)
56e342d improves overflowAdd (#80)
f7e551d Add tests for points outside the field (#79)
62cf99f Removes_unnecessary_checking_in_ecMul (#78)
1f1b863 Fix field order naming (#75)
1e2b0e4 fix point comparison (#74)
f203e46 remove constant funcitons (#73)
f376abf implement suggested optimization (#70)
d9bed40 remove_unnecessary_mod (#71)
e9bf3f2 removeunused functions (#72)
cf7fbab Remove Playground.yul (#54)
e2e7e5e Python implementation for bn254 (alt_bn128) pairing (#16)
de71908 Fix format for section separators (#39)
ff93e4d Update precompiles to latest improvements (#38)
b72ee59 Clean code commets and console_log calls on main (#34)
75ac242 Remove playground crate (turned out to be useless) (#28)
8ccbe1d Add basic documentation (#20)
5c2c9f8 Update README.md
e2f7d55 Update README.md (#27)
c52393c Update README.md
281af62 Update README.md
4b90112 Update README.md
fdbcdc3 Update LICENSE (#26)
5d0380a Update README.md
d571657 Setup repo for precompile development (#17)
5b99326 Add Ethereum Execution Tests (#5)
8d1d6ae Update EcAdd.yul
0bff51f Update ModExp.yul
a3b2e1a Update EcMul.yul
87bf237 [Feature] `ecAdd` precompile (#1)
3b1bcfd [Feature] `ecMul` precompile (#2)
f7eae0d [Feature] `modexp` precompile (#3)
bb2b95f update readme
2036029 Update README.md
e50177f Repo cleanup (#4)
aae80c5 cargo init w/ extra steps
fcd4c44 Precompiles scaffolding
fc42e54 Update README.md
50f4b1e Initial commit

git-subtree-dir: .test-node-subtree
git-subtree-split: 814ae72cc5cf1d1842b3ed4ceeb8b78de43baf9c
  • Loading branch information
IAvecilla committed Feb 29, 2024
1 parent 55210e4 commit f16c269
Show file tree
Hide file tree
Showing 24 changed files with 1,271 additions and 40 deletions.
46 changes: 20 additions & 26 deletions etc/system-contracts/contracts/precompiles/EcAdd.yul
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
object "EcAdd" {
code {
return(0, 0)
}
code { }
object "EcAdd_deployed" {
code {
////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -45,18 +43,18 @@ object "EcAdd" {
//////////////////////////////////////////////////////////////////

/// @dev Executes the `precompileCall` opcode.
function precompileCall(precompileParams, gasToBurn) -> ret {
// Compiler simulation for calling `precompileCall` opcode
ret := verbatim_2i_1o("precompile", precompileParams, gasToBurn)
}
function precompileCall(precompileParams, gasToBurn) -> ret {
// Compiler simulation for calling `precompileCall` opcode
ret := verbatim_2i_1o("precompile", precompileParams, gasToBurn)
}

/// @notice Burns remaining gas until revert.
/// @dev This function is used to burn gas in the case of a failed precompile call.
function burnGas() {
// Precompiles that do not have a circuit counterpart
// will burn the provided gas by calling this function.
precompileCall(0, gas())
}
function burnGas() {
// Precompiles that do not have a circuit counterpart
// will burn the provided gas by calling this function.
precompileCall(0, gas())
}

/// @notice Retrieves the highest half of the multiplication result.
/// @param multiplicand The value to multiply.
Expand Down Expand Up @@ -247,7 +245,7 @@ object "EcAdd" {
/// @dev See https://en.wikipedia.org/wiki/Montgomery_modular_multiplication#The_REDC_algorithm for further details on the Montgomery multiplication.
/// @param minuend The minuend in Montgomery form.
/// @param subtrahend The subtrahend in Montgomery form.
/// @return ret The result of the Montgomery subtraction.
/// @return ret The result of the Montgomery addition.
function montgomerySub(minuend, subtrahend) -> ret {
ret := montgomeryAdd(minuend, sub(P(), subtrahend))
}
Expand Down Expand Up @@ -300,7 +298,7 @@ object "EcAdd" {
mstore(32, 0)
return(0, 64)
}
if and(p1IsInfinity, iszero(p2IsInfinity)) {
if p1IsInfinity {
// Infinity + P = P

// Ensure that the coordinates are between 0 and the field order.
Expand All @@ -323,7 +321,7 @@ object "EcAdd" {
mstore(32, y2)
return(0, 64)
}
if and(iszero(p1IsInfinity), p2IsInfinity) {
if p2IsInfinity {
// P + Infinity = P

// Ensure that the coordinates are between 0 and the field order.
Expand Down Expand Up @@ -368,7 +366,7 @@ object "EcAdd" {
let m_y2 := intoMontgomeryForm(y2)

// Ensure that the points are in the curve (Y^2 = X^3 + 3).
if or(iszero(pointIsInCurve(m_x1, m_y1)), iszero(pointIsInCurve(m_x2, m_y2))) {
if iszero(pointIsInCurve(m_x1, m_y1)) {
burnGas()
}

Expand All @@ -380,10 +378,6 @@ object "EcAdd" {
return(0, 64)
}

if and(eq(x1, x2), and(iszero(eq(y1, y2)), iszero(eq(y1, submod(0, y2, P()))))) {
burnGas()
}

if and(eq(x1, x2), eq(y1, y2)) {
// P + P = 2P

Expand All @@ -397,11 +391,11 @@ object "EcAdd" {

// (3 * x1^2 + a) / (2 * y1)
let x1_squared := montgomeryMul(x, x)
let slope := montgomeryDiv(addmod(x1_squared, addmod(x1_squared, x1_squared, P()), P()), addmod(y, y, P()))
let slope := montgomeryDiv(montgomeryAdd(x1_squared, montgomeryAdd(x1_squared, x1_squared)), montgomeryAdd(y, y))
// x3 = slope^2 - 2 * x1
let x3 := submod(montgomeryMul(slope, slope), addmod(x, x, P()), P())
let x3 := montgomerySub(montgomeryMul(slope, slope), montgomeryAdd(x, x))
// y3 = slope * (x1 - x3) - y1
let y3 := submod(montgomeryMul(slope, submod(x, x3, P())), y, P())
let y3 := montgomerySub(montgomeryMul(slope, montgomerySub(x, x3)), y)

x3 := outOfMontgomeryForm(x3)
y3 := outOfMontgomeryForm(y3)
Expand All @@ -424,11 +418,11 @@ object "EcAdd" {
}

// (y2 - y1) / (x2 - x1)
let slope := montgomeryDiv(submod(y2, y1, P()), submod(x2, x1, P()))
let slope := montgomeryDiv(montgomerySub(y2, y1), montgomerySub(x2, x1))
// x3 = slope^2 - x1 - x2
let x3 := submod(montgomeryMul(slope, slope), addmod(x1, x2, P()), P())
let x3 := montgomerySub(montgomeryMul(slope, slope), montgomeryAdd(x1, x2))
// y3 = slope * (x1 - x3) - y1
let y3 := submod(montgomeryMul(slope, submod(x1, x3, P())), y1, P())
let y3 := montgomerySub(montgomeryMul(slope, montgomerySub(x1, x3)), y1)

x3 := outOfMontgomeryForm(x3)
y3 := outOfMontgomeryForm(y3)
Expand Down
Loading

0 comments on commit f16c269

Please sign in to comment.