Fix issue with detection of RIP7212 precompile by Amxx · Pull Request #5620 · OpenZeppelin/openzeppelin-contracts (original) (raw)

Just a little paranoid on the gas estimation part.

// The invalid upon staticcall failure is solely for gas estimation. // When given sufficient gas, the precompile will not revert. if iszero(staticcall(gas(), 0x100, m, 0xa0, 0x00, 0x00)) { invalid() } // The precompile will only return uint256(1) if and only if the signature is valid. // As per latest spec, verified against the op-geth implementation: // See: https://github.com/ethereum-optimism/op-geth/blob/02dfe8692a3c606dbabd83c1ced2037aab9753d7/core/vm/contracts.go#L1342 // Otherwise, it will always return no data. isValid := iszero(iszero(returndatasize()))

More conservative (in case the spec and implementations are somehow edited again):

// The invalid upon staticcall failure is solely for gas estimation. // When given sufficient gas, the precompile will not revert. mstore(0x00, 0) // Zeroize the slot for the returndata. if iszero(staticcall(gas(), 0x100, m, 0xa0, 0x00, 0x20)) { invalid() } // The precompile will only return uint256(1) if and only if the signature is valid. // As per latest spec, verified against the op-geth implementation: // See: https://github.com/ethereum-optimism/op-geth/blob/02dfe8692a3c606dbabd83c1ced2037aab9753d7/core/vm/contracts.go#L1342 // Otherwise, it will always return no data. isValid := mload(0x00)