From 297d174e34c8eaae4bb87f04be379bf7fe6e9958 Mon Sep 17 00:00:00 2001 From: Michael Amadi Date: Wed, 6 Nov 2024 13:16:26 +0100 Subject: [PATCH] fix stack too deep - forge coverage --- contracts/lib/LibKeccak.sol | 51 +++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/contracts/lib/LibKeccak.sol b/contracts/lib/LibKeccak.sol index 86130d7..8b201d4 100644 --- a/contracts/lib/LibKeccak.sol +++ b/contracts/lib/LibKeccak.sol @@ -87,31 +87,32 @@ library LibKeccak { let xs1 := xor(stateElem(ptr, 1), D1) let A1 := xor(shl(1, xs1), shr(63, xs1)) - setStateElem(ptr, 0, xor(stateElem(ptr, 0), D0)) - rhoPi(ptr, 1, 6, 44, D1) - rhoPi(ptr, 6, 9, 20, D4) - rhoPi(ptr, 9, 22, 61, D2) - rhoPi(ptr, 22, 14, 39, D4) - rhoPi(ptr, 14, 20, 18, D0) - rhoPi(ptr, 20, 2, 62, D2) - rhoPi(ptr, 2, 12, 43, D2) - rhoPi(ptr, 12, 13, 25, D3) - rhoPi(ptr, 13, 19, 8, D4) - rhoPi(ptr, 19, 23, 56, D3) - rhoPi(ptr, 23, 15, 41, D0) - rhoPi(ptr, 15, 4, 27, D4) - rhoPi(ptr, 4, 24, 14, D4) - rhoPi(ptr, 24, 21, 2, D1) - rhoPi(ptr, 21, 8, 55, D3) - rhoPi(ptr, 8, 16, 45, D1) - rhoPi(ptr, 16, 5, 36, D0) - rhoPi(ptr, 5, 3, 28, D3) - rhoPi(ptr, 3, 18, 21, D3) - rhoPi(ptr, 18, 17, 15, D2) - rhoPi(ptr, 17, 11, 10, D1) - rhoPi(ptr, 11, 7, 6, D2) - rhoPi(ptr, 7, 10, 3, D0) - setStateElem(ptr, 10, A1) + let _ptr := ptr + setStateElem(_ptr, 0, xor(stateElem(_ptr, 0), D0)) + rhoPi(_ptr, 1, 6, 44, D1) + rhoPi(_ptr, 6, 9, 20, D4) + rhoPi(_ptr, 9, 22, 61, D2) + rhoPi(_ptr, 22, 14, 39, D4) + rhoPi(_ptr, 14, 20, 18, D0) + rhoPi(_ptr, 20, 2, 62, D2) + rhoPi(_ptr, 2, 12, 43, D2) + rhoPi(_ptr, 12, 13, 25, D3) + rhoPi(_ptr, 13, 19, 8, D4) + rhoPi(_ptr, 19, 23, 56, D3) + rhoPi(_ptr, 23, 15, 41, D0) + rhoPi(_ptr, 15, 4, 27, D4) + rhoPi(_ptr, 4, 24, 14, D4) + rhoPi(_ptr, 24, 21, 2, D1) + rhoPi(_ptr, 21, 8, 55, D3) + rhoPi(_ptr, 8, 16, 45, D1) + rhoPi(_ptr, 16, 5, 36, D0) + rhoPi(_ptr, 5, 3, 28, D3) + rhoPi(_ptr, 3, 18, 21, D3) + rhoPi(_ptr, 18, 17, 15, D2) + rhoPi(_ptr, 17, 11, 10, D1) + rhoPi(_ptr, 11, 7, 6, D2) + rhoPi(_ptr, 7, 10, 3, D0) + setStateElem(_ptr, 10, A1) } // Inner `chi` function, unrolled in `chi` for performance.