From 9e179f739ca87739575df2cd9ad8b7fbe602d317 Mon Sep 17 00:00:00 2001 From: Francisco Krause Arnim Date: Tue, 10 Oct 2023 13:10:25 -0300 Subject: [PATCH 1/3] Add free memory pointer function --- precompiles/Modexp.yul | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/precompiles/Modexp.yul b/precompiles/Modexp.yul index 6aba607d..4e7760a6 100644 --- a/precompiles/Modexp.yul +++ b/precompiles/Modexp.yul @@ -3,6 +3,7 @@ object "ModExp" { object "ModExp_deployed" { code { + // CONSTANTS function LIMB_SIZE_IN_BYTES() -> limbSize { limbSize := 0x20 @@ -13,6 +14,14 @@ object "ModExp" { } // HELPER FUNCTIONS + /// @notice Returns an address for a free memory region, + /// which will be startPtr...(startPtr+(howManyAdresses*32)) + /// @param howManyAdresses The number of addresses needed. + function freeMemoryPointer(howManyAdresses) -> startPtr { + startPtr := mload(0x0) + mstore(0x0, add(startPtr, mul(howManyAdresses, 32))) + } + /// @notice Stores a one in big unsigned integer form in memory. /// @param nLimbs The number of limbs needed to represent the operand. /// @param toAddress The pointer to the MSB of the destination. From a7aede67423bb3a6cd3307408a6c24d2279eb0eb Mon Sep 17 00:00:00 2001 From: Francisco Krause Arnim <56402156+fkrause98@users.noreply.github.com> Date: Tue, 10 Oct 2023 14:06:39 -0300 Subject: [PATCH 2/3] Update precompiles/Modexp.yul Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com> --- precompiles/Modexp.yul | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/precompiles/Modexp.yul b/precompiles/Modexp.yul index 4e7760a6..ca0324e1 100644 --- a/precompiles/Modexp.yul +++ b/precompiles/Modexp.yul @@ -19,7 +19,7 @@ object "ModExp" { /// @param howManyAdresses The number of addresses needed. function freeMemoryPointer(howManyAdresses) -> startPtr { startPtr := mload(0x0) - mstore(0x0, add(startPtr, mul(howManyAdresses, 32))) + mstore(0x0, add(startPtr, shl(5, howManyAdresses))) } /// @notice Stores a one in big unsigned integer form in memory. From 5173fff75981f31c68fa7ea151ddf219d264d959 Mon Sep 17 00:00:00 2001 From: Francisco Krause Arnim <56402156+fkrause98@users.noreply.github.com> Date: Tue, 10 Oct 2023 14:09:45 -0300 Subject: [PATCH 3/3] Update precompiles/Modexp.yul Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com> --- precompiles/Modexp.yul | 1 - 1 file changed, 1 deletion(-) diff --git a/precompiles/Modexp.yul b/precompiles/Modexp.yul index ca0324e1..0d46e390 100644 --- a/precompiles/Modexp.yul +++ b/precompiles/Modexp.yul @@ -3,7 +3,6 @@ object "ModExp" { object "ModExp_deployed" { code { - // CONSTANTS function LIMB_SIZE_IN_BYTES() -> limbSize { limbSize := 0x20