diff --git a/packages/contracts/contracts/base/SemaphoreVerifier.sol b/packages/contracts/contracts/base/SemaphoreVerifier.sol index 36da1140a..e454c2e79 100644 --- a/packages/contracts/contracts/base/SemaphoreVerifier.sol +++ b/packages/contracts/contracts/base/SemaphoreVerifier.sol @@ -59,7 +59,10 @@ contract SemaphoreVerifier { mstore(add(mIn, 32), y) mstore(add(mIn, 64), s) - success := staticcall(sub(gas(), 2000), 7, mIn, 96, mIn, 64) + // ecMul gas cost is fixed at 6000. Add 33.3% gas for safety buffer. + // Last checked in 2024 Oct, evm codename Cancun + // ref: https://www.evm.codes/precompiled?fork=cancun#0x07 + success := staticcall(8000, 7, mIn, 96, mIn, 64) if iszero(success) { mstore(0, 0) @@ -69,7 +72,10 @@ contract SemaphoreVerifier { mstore(add(mIn, 64), mload(pR)) mstore(add(mIn, 96), mload(add(pR, 32))) - success := staticcall(sub(gas(), 2000), 6, mIn, 128, pR, 64) + // ecAdd gas cost is fixed at 150. Add 33.3% gas for safety buffer. + // Last checked in 2024 Oct, evm codename Cancun + // ref: https://www.evm.codes/precompiled?fork=cancun#0x06 + success := staticcall(200, 6, mIn, 128, pR, 64) if iszero(success) { mstore(0, 0) @@ -149,7 +155,10 @@ contract SemaphoreVerifier { mstore(add(_pPairing, 704), mload(add(vkPoints, 64))) mstore(add(_pPairing, 736), mload(add(vkPoints, 96))) - let success := staticcall(sub(gas(), 2000), 8, _pPairing, 768, _pPairing, 0x20) + // ecPairing gas cost at 181000 given 768 bytes input. Add 33.3% gas for safety buffer. + // Last checked in 2024 Oct, evm codename Cancun + // ref: https://www.evm.codes/precompiled?fork=cancun#0x08 + let success := staticcall(241333, 8, _pPairing, 768, _pPairing, 0x20) isOk := and(success, mload(_pPairing)) }