Skip to content
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(contracts): specify gas cost in SemaphoreVerifier precompile calls #883

Merged
merged 3 commits into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions packages/contracts/contracts/base/SemaphoreVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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))
}
Expand Down
Loading