-
Notifications
You must be signed in to change notification settings - Fork 19
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
Refactor modexp
reimplementation
#156
Merged
ColoCarletti
merged 12 commits into
modexp_reimplementation
from
refactor_modexp_reimplementation
Oct 3, 2023
Merged
Refactor modexp
reimplementation
#156
ColoCarletti
merged 12 commits into
modexp_reimplementation
from
refactor_modexp_reimplementation
Oct 3, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Made it consistent with the rest of the code convention and naming
Made it consistent with the rest of the code convention and naming
ilitteri
requested review from
jpcenteno,
ColoCarletti,
fkrause98 and
IAvecilla
October 2, 2023 14:49
How to test
// BIG UINT OR TESTS
// 1 Limb
let lhsPtr := 0x00
let rhsPtr := 0x20
let orPtr := 0x40
let nLimbs := 1
// 0000 | 0000 = 0000
mstore(lhsPtr, 0x00)
mstore(rhsPtr, 0x00)
bigUIntBitOr(lhsPtr, rhsPtr, nLimbs, orPtr)
console_log(mload(orPtr)) // 0x00
// 1111 | 0000 = 1111
mstore(lhsPtr, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
mstore(rhsPtr, 0x00)
bigUIntBitOr(lhsPtr, rhsPtr, nLimbs, orPtr)
console_log(mload(orPtr)) // 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// 0000 | 1111 = 1111
mstore(lhsPtr, 0x00)
mstore(rhsPtr, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
bigUIntBitOr(lhsPtr, rhsPtr, nLimbs, orPtr)
console_log(mload(orPtr)) // 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// 1111 | 1111 = 1111
mstore(lhsPtr, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
mstore(rhsPtr, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
bigUIntBitOr(lhsPtr, rhsPtr, nLimbs, orPtr)
console_log(mload(orPtr)) // 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// 1010 | 0101 = 1111
mstore(lhsPtr, 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
mstore(rhsPtr, 0x5555555555555555555555555555555555555555555555555555555555555555)
bigUIntBitOr(lhsPtr, rhsPtr, nLimbs, orPtr)
console_log(mload(orPtr)) // 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// 0101 | 1010 = 1111 (needed?)
mstore(lhsPtr, 0x5555555555555555555555555555555555555555555555555555555555555555)
mstore(rhsPtr, 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
bigUIntBitOr(lhsPtr, rhsPtr, nLimbs, orPtr)
console_log(mload(orPtr)) // 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// 2 Limbs
let lhsPtr := 0x00
let rhsPtr := 0x40
let orPtr := 0x80
let nLimbs := 2
// 0000 0000 | 0000 0000 = 0000 0000
mstore(lhsPtr, 0x00)
mstore(add(lhsPtr, 0x20), 0x00)
mstore(rhsPtr, 0x00)
mstore(add(rhsPtr, 0x20), 0x00)
bigUIntBitOr(lhsPtr, rhsPtr, nLimbs, orPtr)
console_log(mload(orPtr)) // 0x00
console_log(mload(add(orPtr, 0x20))) // 0x00
// 1111 1111 | 0000 0000 = 1111 1111
mstore(lhsPtr, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
mstore(add(lhsPtr, 0x20), 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
mstore(rhsPtr, 0x00)
mstore(add(rhsPtr, 0x20), 0x00)
bigUIntBitOr(lhsPtr, rhsPtr, nLimbs, orPtr)
console_log(mload(orPtr)) // 0xff
console_log(mload(add(orPtr, 0x20))) // 0xff
// 0000 0000 | 1111 1111 = 1111 1111
mstore(lhsPtr, 0x00)
mstore(add(lhsPtr, 0x20), 0x00)
mstore(rhsPtr, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
mstore(add(rhsPtr, 0x20), 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
bigUIntBitOr(lhsPtr, rhsPtr, nLimbs, orPtr)
console_log(mload(orPtr)) // 0xff
console_log(mload(add(orPtr, 0x20))) // 0xff
// 1111 1111 | 1111 1111 = 1111 1111
mstore(lhsPtr, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
mstore(add(lhsPtr, 0x20), 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
mstore(rhsPtr, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
mstore(add(rhsPtr, 0x20), 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
bigUIntBitOr(lhsPtr, rhsPtr, nLimbs, orPtr)
console_log(mload(orPtr)) // 0xff
console_log(mload(add(orPtr, 0x20))) // 0xff
// 1010 1010 | 0101 0101 = 1111 1111
mstore(lhsPtr, 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
mstore(add(lhsPtr, 0x20), 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
mstore(rhsPtr, 0x5555555555555555555555555555555555555555555555555555555555555555)
mstore(add(rhsPtr, 0x20), 0x5555555555555555555555555555555555555555555555555555555555555555)
bigUIntBitOr(lhsPtr, rhsPtr, nLimbs, orPtr)
console_log(mload(orPtr)) // 0xff
console_log(mload(add(orPtr, 0x20))) // 0xff
// 0101 0101 | 1010 1010 = 1111 1111 (needed?)
mstore(lhsPtr, 0x5555555555555555555555555555555555555555555555555555555555555555)
mstore(add(lhsPtr, 0x20), 0x5555555555555555555555555555555555555555555555555555555555555555)
mstore(rhsPtr, 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
mstore(add(rhsPtr, 0x20), 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
bigUIntBitOr(lhsPtr, rhsPtr, nLimbs, orPtr)
console_log(mload(orPtr)) // 0xff
console_log(mload(add(orPtr, 0x20))) // 0xff
// 0000 1111 | 0000 1111 = 0000 1111
mstore(lhsPtr, 0x00)
mstore(add(lhsPtr, 0x20), 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
mstore(rhsPtr, 0x00)
mstore(add(rhsPtr, 0x20), 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
bigUIntBitOr(lhsPtr, rhsPtr, nLimbs, orPtr)
console_log(mload(orPtr)) // 0x00
console_log(mload(add(orPtr, 0x20))) // 0xff
// 1111 0000 | 1111 0000 = 1111 0000
mstore(lhsPtr, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
mstore(add(lhsPtr, 0x20), 0x00)
mstore(rhsPtr, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
mstore(add(rhsPtr, 0x20), 0x00)
bigUIntBitOr(lhsPtr, rhsPtr, nLimbs, orPtr)
console_log(mload(orPtr)) // 0xff
console_log(mload(add(orPtr, 0x20))) // 0x00
// 0000 1111 | 1111 0000 = 1111 1111
mstore(lhsPtr, 0x00)
mstore(add(lhsPtr, 0x20), 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
mstore(rhsPtr, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
mstore(add(rhsPtr, 0x20), 0x00)
bigUIntBitOr(lhsPtr, rhsPtr, nLimbs, orPtr)
console_log(mload(orPtr)) // 0xff
console_log(mload(add(orPtr, 0x20))) // 0xff
// BIG UINT COND SELECT TESTS
let borrow1 := 0x00
let borrow2 := 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// 1 Limb
let lhsPtr := 0x00
let rhsPtr := 0x20
let orPtr := 0x40
let nLimbs := 1
mstore(lhsPtr, 0x00)
mstore(rhsPtr, 0x00)
bigUIntCondSelect(lhsPtr, rhsPtr, orPtr, nLimbs, borrow1)
console_log(mload(orPtr)) // 0x00
mstore(lhsPtr, 0x00)
mstore(rhsPtr, 0x00)
bigUIntCondSelect(lhsPtr, rhsPtr, orPtr, nLimbs, borrow2)
console_log(mload(orPtr)) // 0x00
// Selects lhs
mstore(lhsPtr, 0x01)
mstore(rhsPtr, 0x00)
bigUIntCondSelect(lhsPtr, rhsPtr, orPtr, nLimbs, borrow1)
console_log(mload(orPtr)) // 0x01 = lhs
// Selects rhs
mstore(lhsPtr, 0x01)
mstore(rhsPtr, 0x00)
bigUIntCondSelect(lhsPtr, rhsPtr, orPtr, nLimbs, borrow2)
console_log(mload(orPtr)) // 0x00 = rhs
// 2 Limbs
let lhsPtr := 0x00
let rhsPtr := 0x40
let orPtr := 0x80
let nLimbs := 2
mstore(lhsPtr, 0x00)
mstore(add(lhsPtr, 0x20), 0x00)
mstore(rhsPtr, 0x00)
mstore(add(rhsPtr, 0x20), 0x00)
bigUIntCondSelect(lhsPtr, rhsPtr, orPtr, nLimbs, borrow1)
console_log(mload(orPtr)) // 0x00
console_log(mload(add(orPtr, 0x20))) // 0x00
mstore(lhsPtr, 0x00)
mstore(add(lhsPtr, 0x20), 0x00)
mstore(rhsPtr, 0x00)
mstore(add(rhsPtr, 0x20), 0x00)
bigUIntCondSelect(lhsPtr, rhsPtr, orPtr, nLimbs, borrow2)
console_log(mload(orPtr)) // 0x00
console_log(mload(add(orPtr, 0x20))) // 0x00
// Selects lhs
mstore(lhsPtr, 0x01)
mstore(add(lhsPtr, 0x20), 0x00)
mstore(rhsPtr, 0x00)
mstore(add(rhsPtr, 0x20), 0x00)
bigUIntCondSelect(lhsPtr, rhsPtr, orPtr, nLimbs, borrow1)
console_log(mload(orPtr)) // 0x01
console_log(mload(add(orPtr, 0x20))) // 0x00
// Selects rhs
mstore(lhsPtr, 0x01)
mstore(add(lhsPtr, 0x20), 0x00)
mstore(rhsPtr, 0x00)
mstore(add(rhsPtr, 0x20), 0x00)
bigUIntCondSelect(lhsPtr, rhsPtr, orPtr, nLimbs, borrow2)
console_log(mload(orPtr)) // 0x00
console_log(mload(add(orPtr, 0x20))) // 0x00
// Test1: Simple 2 limbs
// First Number:
// - First Limb: 0x0...0
// - Second Limb: 0x0...F
// Second Number:
// - First Limb: 0x0...0
// - Second Limb: 0x0...A
// [0x0...0, 0x0...F]
// -
// [0x0...0, 0x0...A]
// ------------------
// [0x0...0, 0x0...5]
// Should print:
// 0 (first limb)
// 5 (second limb)
mstore(0x00, 0x0)
mstore(0x20, 0xF)
mstore(0x40, 0x0)
mstore(0x60, 0xA)
let retStart := 0x80
let _, borrow := bigUintSubstractionWithBorrow(0x00, 0x40, 2, retStart)
let res := mload(retStart)
let res2 := mload(add(retStart, 0x20))
let res3 := mload(add(retStart, 0x40))
let res4 := mload(add(retStart, 0x60))
console_log(res)
console_log(res2)
// Test2: Borrow works as expected
// First Number:
// - First Limb: 0xFF
// - Second Limb: 0xAA
// Second Number:
// - First Limb: 0xAA
// - Second Limb: 0xFF
// Should print:
// 54 (first limb)
// ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffab (second limb)
mstore(0x00, 0xFF)
mstore(0x20, 0xAA)
mstore(0x40, 0xAA)
mstore(0x60, 0xFF)
let retStart := 0x80
let _, borrow := bigUintSubstractionWithBorrow(0x00, 0x40, 2, retStart)
let res := mload(retStart)
let res2 := mload(add(retStart, 0x20))
let res3 := mload(add(retStart, 0x40))
let res4 := mload(add(retStart, 0x60))
console_log(res)
console_log(res2)
// Test3: Big number 2 limb substraction
// I've tested this againts our reference (Lambdaworks) and gives the same result.
// First Number:
mstore(0x20, 0xffffaaaaaaaaaaaaaaaaffffffffffffffffaaaaaaaaaaaaaaaa)
mstore(0x40, 0xffffffffffffffffaaaaaaaaaaaaaaaaffffffffffffffffaaaaaaaaaaaaaaaa)
// Second Number:
mstore(0x60, 0xaaaaffffffffffffffffaaaaaaaaaaaaaaaaffffffffffffffff)
mstore(0x80, 0xaaaaaaaaaaaaaaaaffffffffffffffffaaaaaaaaaaaaaaaaffffffffffffffff)
let retStart := 0x100
let _, borrow := bigUintSubstractionWithBorrow(0x20, 0x60, 2, retStart)
// Should print:
// 5554aaaaaaaaaaaaaaab5555555555555554aaaaaaaaaaaaaaab
// 5555555555555554aaaaaaaaaaaaaaab5555555555555554aaaaaaaaaaaaaaab
let res := mload(retStart)
let res2 := mload(add(retStart, 0x20))
console_log(res)
console_log(res2)
// BIG UINT MUL TESTS
// 1 limb
let lhs := 100
let rhs := 500
mstore(0x00, lhs)
mstore(0x20, rhs)
let retStart := 0x40
bigUIntMultiplication(0x00, 0x20, 1, retStart)
let res1 := mload(retStart)
let res2 := mload(add(retStart, 0x20))
console_log(res1) // 0
console_log(res2) // C350
// 2 limbs
let lhs1 := 0x5e2d939b602a50911232731d04fe6f4
let lhs2 := 0x0c05f97da0602307099fb991f9b414e2d52bef130349ec18db1a0215ea6caf76
let rhs1 := 0x3f3ad1611ab58212f92a2484e956093
let rhs2 := 0x5b9ac4615fe61cfed1a4861e193a74d20c94f9f88d8b2cc089543c3f699969d9
mstore(0x00, lhs1)
mstore(0x20, lhs2)
mstore(0x40, rhs1)
mstore(0x60, rhs2)
let retStart := 0x80
bigUIntMultiplication(0x00, 0x40, 2, retStart)
let res1 := mload(retStart)
let res2 := mload(add(retStart, 0x20))
let res3 := mload(add(retStart, 0x40))
let res4 := mload(add(retStart, 0x60))
console_log(res1) // 0
console_log(res2) // 1742daad9c7861dd3499e7ece65467e337937b27e20d641b225bfe00323d33
console_log(res3) // ed62715654eadc092b057a5f19f2ad6c9969c0417b9304d9c16b046c860447d3
console_log(res4) // 533999e16710d2e90a44959a168816c015ffb44b987e8cbb82bd46b08d9e2106
// 3 limbs
let lhs1 := 0x5e2d939b602a50911232731d04fe6f4
let lhs2 := 0x0c05f97da0602307099fb991f9b414e2d52bef130349ec18db1a0215ea6caf76
let lhs3 := 0x0c05f97da0602307099fb991f9b414e2d52bef130349ec18db1a0215ea6caf76
let rhs1 := 0x3f3ad1611ab58212f92a2484e956093
let rhs2 := 0x5b9ac4615fe61cfed1a4861e193a74d20c94f9f88d8b2cc089543c3f699969d9
let rhs3 := 0x5b9ac4615fe61cfed1a4861e193a74d20c94f9f88d8b2cc089543c3f699969d9
mstore(0x00, lhs1)
mstore(0x20, lhs2)
mstore(0x40, lhs3)
mstore(0x60, rhs1)
mstore(0x80, rhs2)
mstore(0xa0, rhs3)
let retStart := 0x120
bigUIntMultiplication(0x00, 0x60, 3, retStart)
let res := mload(retStart)
let res2 := mload(add(retStart, 0x20))
let res3 := mload(add(retStart, 0x40))
let res4 := mload(add(retStart, 0x60))
let res5 := mload(add(retStart, 0x80))
let res6 := mload(add(retStart, 0xa0))
console_log(res) // 0
console_log(res2) // 1742daad9c7861dd3499e7ece65467e337937b27e20d641b225bfe00323d33
console_log(res3) // ed62715654eadc092b057a5f19f2ad6c9bb4762cf5888df32f6d3d322db566eb
console_log(res4) // 44e96fb89f5912ee8ba1f06d4ca70fe0f316164f98f81a9bf8d65df1b27ad716
console_log(res5) // aac09843b17f09ce6ae10ba8493c79346fac0a59b5e3a27dba28a035ba14b049
console_log(res6) // 533999e16710d2e90a44959a168816c015ffb44b987e8cbb82bd46b08d9e2106
zksync-era-cli --host localhost --port 8011 call --contract 0x000000000000000000000000000000000000FFFF --function "" --data 00 --private-key 0x850683b40d4a740aa6e745f889a6fdc8327be76e122f5aba645a5b02d0248db8 |
IAvecilla
reviewed
Oct 2, 2023
IAvecilla
approved these changes
Oct 2, 2023
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.
LGTM!
ColoCarletti
approved these changes
Oct 3, 2023
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.
LGTM!
jrchatruc
added a commit
that referenced
this pull request
Oct 30, 2023
* Initial new implementation * Fix compilation error * Implementation of add operation for big integers (#136) * Implement Big UInt Left Shift (#139) * Add `bigUIntShl` implementation * Add constants * Fix compilation * Implement Big UInt Right Shift (#137) * Add `bigUIntShr` implementation * Add constants * Implement Big UInt Bitwise Or for modexp (#135) * Implement bigUIntBitOr * Fix bigUIntBitOr * Fix bigUIntBitOr Co-authored-by: Ivan Litteri <[email protected]> * Fix missing closing brackets --------- Co-authored-by: Ivan Litteri <[email protected]> * Implement big uint conditional select for modexp (#148) * Implement bigUIntCondSelect * Fix missing curly braces Co-authored-by: Ivan Litteri <[email protected]> * Implement Big UInt Right Shift (#137) * Add `bigUIntShr` implementation * Add constants * Implement Big UInt Bitwise Or for modexp (#135) * Implement bigUIntBitOr * Fix bigUIntBitOr * Fix bigUIntBitOr Co-authored-by: Ivan Litteri <[email protected]> * Fix missing closing brackets --------- Co-authored-by: Ivan Litteri <[email protected]> --------- Co-authored-by: Ivan Litteri <[email protected]> * Implement mul operation for big UInts (#151) * First implementation of mul operation for bigints * Fix multiplication for big integers * Fix some merge issues * Improve comments and function docs * Delete whitespaces * Substraction with borrow (#149) * First substraction draft * Fix compile problems * Working implementation * Updated code * Updated code * Update subtract implementation * Remove console_log * Add docs for function * Update function docs * Remove tests from from ModExp.yul * Fix typo * Restore horrible whitespaces to avoid an ugly merge conflict * Update precompiles/Modexp.yul Co-authored-by: Ivan Litteri <[email protected]> * Revert "Update precompiles/Modexp.yul" This reverts commit 582bc41. --------- Co-authored-by: Joaquín P. Centeno <[email protected]> Co-authored-by: Ivan Litteri <[email protected]> * Refactor `modexp` reimplementation (#156) * Make Big UInt API functions naming consistent * Refactor `bigUIntAdd` variable names * Refactor `bigUIntMul` variable names * Refactor `subLimbsWithBorrow` * Refactor `bigUintSubtractionWithBorrow` * Refactor `bigUIntAdd` * Fix `bigUIntSubWithBorrow` * Format `storeLimbValueAtOffset` * Refactor `bigUIntBitOr` Made it consistent with the rest of the code convention and naming * Refactor `bigUIntCondSelect` Made it consistent with the rest of the code convention and naming * Reorder `overflowingSubWithBorrow` * Move comment to modexp API Docs section * Biguint division (#159) * Division draft * Non working draft * Fix compile errors * Use proper pointers for quotient and remainder * Add fix note, some more changes * Add comment * Implement `big_uint_bit_size` * Increase pointer to prevent it from steping over console_log * WIP divrem * Fix loop and zero initializer * Push test cases * Add other test case * Add docs and tests for `big_uint_inplace_or_1` * Fix bug related to bit shifting * Fix borrow return in big uint sub function * Delete playground file used for debugging * Fix sub with borrow function * Add playground again to check more big integer division tests * Remove playground used for testing * Write documentation for new shift functions * Improve naming and documentation for new helper functions * Rename bigUIntOrWith1 to bigUintInPlaceOrWith1 * Add tmp buffer parameters to bigUIntDivRem. Improve docs. * Simplify subLimbsWithBorrow Co-authored-by: Ivan Litteri <[email protected]> * Remove `mul` call from `bigUIntInPlaceOrWith1` Co-authored-by: Ivan Litteri <[email protected]> * Remove multiplications from copyBigUint Co-authored-by: Ivan Litteri <[email protected]> * Optimize bigUIntBitSize loop Co-authored-by: Ivan Litteri <[email protected]> * Simplify zeroWithLimbSizeAt --------- Co-authored-by: Francisco Krause Arnim <[email protected]> Co-authored-by: IAvecilla <[email protected]> Co-authored-by: Ivan Litteri <[email protected]> * Implement mul mod operation for big UInts (#161) * Division draft * Non working draft * Fix compile errors * Use proper pointers for quotient and remainder * Add fix note, some more changes * Add comment * Implement `big_uint_bit_size` * Increase pointer to prevent it from steping over console_log * WIP divrem * Fix loop and zero initializer * Push test cases * Add other test case * Add docs and tests for `big_uint_inplace_or_1` * Fix bug related to bit shifting * Fix borrow return in big uint sub function * Delete playground file used for debugging * Fix sub with borrow function * Add playground again to check more big integer division tests * Remove playground used for testing * Write documentation for new shift functions * Improve naming and documentation for new helper functions * Rename bigUIntOrWith1 to bigUintInPlaceOrWith1 * Add tmp buffer parameters to bigUIntDivRem. Improve docs. * Add big uint mul mod skeleton * Remove wrong comment * Update algorithm comment * Add limb size doubling and divide by two for mul mod operation * Functions to duplicate and halve limb size work in place * Use camelCase * Remove console_log * Add docs * Update doc --------- Co-authored-by: Francisco Krause Arnim <[email protected]> Co-authored-by: Joaquín P. Centeno <[email protected]> * Add parseCallData function * Add function to left-pad big uints * Remove console log function * Change left padding functions for big uints to not work in place * Add `parseCalldata` function (#168) * Remove redundant parse call data declaration * Free memory pointer (#169) * Add free memory pointer function * Update precompiles/Modexp.yul Co-authored-by: Ivan Litteri <[email protected]> * Update precompiles/Modexp.yul Co-authored-by: Ivan Litteri <[email protected]> --------- Co-authored-by: Ivan Litteri <[email protected]> * Start parsing the input calldata * Correctly parse call data * Add left pad steps for modexp inputs * Add pad if needed function * Modexp for big UInts skeleton (#164) * WIP: modexp skeleton * Use of mul mod function for big integers * imlement aux function to check if big uint is larger than 1 * minor fix * Restore modexp from target branch * Fix mul mod * Finish modexp implementation * Remove playground used for debugging * Update modexp with final state of modular exponentiation function * Fix merge issue * Change all names to camel case * fix typo Co-authored-by: Francisco Krause Arnim <[email protected]> --------- Co-authored-by: IAvecilla <[email protected]> Co-authored-by: Ivan Litteri <[email protected]> Co-authored-by: Francisco Krause Arnim <[email protected]> * Add simple integration * Fix calldata buffer in zero check * Uncomment checks for base cases * Fix result length to match with mod length * Fix condition in parse call data * Update test assertions with new test node updates * Add comment for tests with a temp patch * Fix modexp result length * Fix limb amount for modexp operands * Clean sratch buffers in each iteration * Clean sratch buffers for every operation * Remove unused functions * Delete free memory pointer usage and calculate pointers manually * Replace all mul operations for shifts to improve gas usage * Include basic optimizations * Add optimizations for reminder calculations * Add small improvement for main loop in modular exp * Add temporary fix for modexp test * Add modex reference script * Remove unnecesary memory stores * Reduce iterations in rem function * Compilation fix * Print gas used on tests * Add build script to create gas reports * Save gas used for each test of the precompiles * Add aux functions to write lines in each report * Merge main * Fix tests lint * Fix lint in test utils * Change L1 url --------- Co-authored-by: Nacho Avecilla <[email protected]> Co-authored-by: Joaquín Centeno <[email protected]> Co-authored-by: Francisco Krause Arnim <[email protected]> Co-authored-by: Francisco Krause Arnim <[email protected]> Co-authored-by: IAvecilla <[email protected]> Co-authored-by: Javier Chatruc <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
overflowingSubWithBorrow
documentation.bigUIntSubWithBorrow
.