From e8bbb0b3b216640b9183509d32afb3c8036f9cde Mon Sep 17 00:00:00 2001 From: smtmfft Date: Wed, 10 Jul 2024 07:33:06 +0000 Subject: [PATCH 1/3] update risc0 verifier contract to release-1.0 --- .../risczero/IRiscZeroReceiptVerifier.sol | 17 +++-------------- .../contracts/verifiers/RiscZeroVerifier.sol | 12 ++++++++---- .../test/verifiers/RiscZeroVerifier.t.sol | 7 ++----- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/packages/protocol/contracts/thirdparty/risczero/IRiscZeroReceiptVerifier.sol b/packages/protocol/contracts/thirdparty/risczero/IRiscZeroReceiptVerifier.sol index 841b1c99423..77fb3626133 100644 --- a/packages/protocol/contracts/thirdparty/risczero/IRiscZeroReceiptVerifier.sol +++ b/packages/protocol/contracts/thirdparty/risczero/IRiscZeroReceiptVerifier.sol @@ -2,26 +2,15 @@ pragma solidity 0.8.24; /// @notice Verifier interface for RISC Zero receipts of execution. -/// https://github.com/risc0/risc0-ethereum/blob/release-0.7/contracts/src/IRiscZeroVerifier.sol +/// https://github.com/risc0/risc0-ethereum/blob/release-1.0/contracts/src/IRiscZeroVerifier.sol interface IRiscZeroReceiptVerifier { /// @notice Verify that the given seal is a valid RISC Zero proof of execution with the - /// given image ID, post-state digest, and journal digest. + /// given image ID and journal digest. Reverts on failure. /// @dev This method additionally ensures that the input hash is all-zeros (i.e. no /// committed input), the exit code is (Halted, 0), and there are no assumptions (i.e. the /// receipt is unconditional). /// @param seal The encoded cryptographic proof (i.e. SNARK). /// @param imageId The identifier for the guest program. - /// @param postStateDigest A hash of the final memory state. Required to run the verifier, but - /// otherwise can be left unconstrained for most use cases. /// @param journalDigest The SHA-256 digest of the journal bytes. - /// @return true if the receipt passes the verification checks. The return code must be checked. - function verify( - bytes calldata seal, - bytes32 imageId, - bytes32 postStateDigest, - bytes32 journalDigest - ) - external - view - returns (bool); + function verify(bytes calldata seal, bytes32 imageId, bytes32 journalDigest) external view; } diff --git a/packages/protocol/contracts/verifiers/RiscZeroVerifier.sol b/packages/protocol/contracts/verifiers/RiscZeroVerifier.sol index 5e299802122..eedde409006 100644 --- a/packages/protocol/contracts/verifiers/RiscZeroVerifier.sol +++ b/packages/protocol/contracts/verifiers/RiscZeroVerifier.sol @@ -12,7 +12,7 @@ import "./libs/LibPublicInput.sol"; /// @custom:security-contact security@taiko.xyz contract RiscZeroVerifier is EssentialContract, IVerifier { /// @notice RISC Zero remote verifier contract address, e.g.: - /// https://sepolia.etherscan.io/address/0x83c2e9cd64b2a16d3908e94c7654f3864212e2f8 + /// https://sepolia.etherscan.io/address/0x3d24C84FC1A2B26f9229e58ddDf11A8dfba802d0 IRiscZeroReceiptVerifier public receiptVerifier; /// @notice Trusted imageId mapping mapping(bytes32 imageId => bool trusted) public isImageTrusted; @@ -65,8 +65,7 @@ contract RiscZeroVerifier is EssentialContract, IVerifier { if (_ctx.isContesting) return; // Decode will throw if not proper length/encoding - (bytes memory seal, bytes32 imageId, bytes32 postStateDigest) = - abi.decode(_proof.data, (bytes, bytes32, bytes32)); + (bytes memory seal, bytes32 imageId) = abi.decode(_proof.data, (bytes, bytes32)); if (!isImageTrusted[imageId]) { revert RISC_ZERO_INVALID_IMAGE_ID(); @@ -80,7 +79,12 @@ contract RiscZeroVerifier is EssentialContract, IVerifier { // journalDigest is the sha256 hash of the hashed public input bytes32 journalDigest = sha256(bytes.concat(hash)); - if (!receiptVerifier.verify(seal, imageId, postStateDigest, journalDigest)) { + // call risc0 groth16 verifier contract + (bool success,) = address(receiptVerifier).staticcall( + abi.encodeWithSignature("verify(bytes,bytes32,bytes32)", seal, imageId, journalDigest) + ); + + if (!success) { revert RISC_ZERO_INVALID_PROOF(); } } diff --git a/packages/protocol/test/verifiers/RiscZeroVerifier.t.sol b/packages/protocol/test/verifiers/RiscZeroVerifier.t.sol index 75eb16dd2d0..205fd989bc6 100644 --- a/packages/protocol/test/verifiers/RiscZeroVerifier.t.sol +++ b/packages/protocol/test/verifiers/RiscZeroVerifier.t.sol @@ -14,14 +14,12 @@ contract MockRiscZeroRemoteVerifier is IRiscZeroReceiptVerifier { function verify( bytes calldata, /*seal*/ bytes32, /*imageId*/ - bytes32, /*postStateDigest*/ bytes32 /*journalDigest*/ ) external view - returns (bool) { - return verifying; + require(verifying, "RiscZeroRemoteVerifier: invalid proof"); } } @@ -120,11 +118,10 @@ contract TestRiscZeroVerifier is TaikoL1TestBase { bytes memory seal = hex"00"; bytes32 imageId = bytes32("11"); - bytes32 postStateDigest = bytes32("22"); // TierProof TaikoData.TierProof memory proof = - TaikoData.TierProof({ tier: 100, data: abi.encode(seal, imageId, postStateDigest) }); + TaikoData.TierProof({ tier: 100, data: abi.encode(seal, imageId) }); vm.warp(block.timestamp + 5); From 5e5315acb490a49e917192301488dc1f4f87502e Mon Sep 17 00:00:00 2001 From: smtmfft Date: Thu, 11 Jul 2024 03:21:02 +0000 Subject: [PATCH 2/3] fix CI --- packages/protocol/contracts/verifiers/RiscZeroVerifier.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/contracts/verifiers/RiscZeroVerifier.sol b/packages/protocol/contracts/verifiers/RiscZeroVerifier.sol index eedde409006..9ced5ee6a73 100644 --- a/packages/protocol/contracts/verifiers/RiscZeroVerifier.sol +++ b/packages/protocol/contracts/verifiers/RiscZeroVerifier.sol @@ -79,7 +79,7 @@ contract RiscZeroVerifier is EssentialContract, IVerifier { // journalDigest is the sha256 hash of the hashed public input bytes32 journalDigest = sha256(bytes.concat(hash)); - // call risc0 groth16 verifier contract + // call risc0 verifier contract (bool success,) = address(receiptVerifier).staticcall( abi.encodeWithSignature("verify(bytes,bytes32,bytes32)", seal, imageId, journalDigest) ); From 7c01595c3af6fa04788907d910aa7f4b6940dc5c Mon Sep 17 00:00:00 2001 From: smtmfft Date: Thu, 11 Jul 2024 10:01:40 +0000 Subject: [PATCH 3/3] use abi.encodeCall --- packages/protocol/contracts/verifiers/RiscZeroVerifier.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/contracts/verifiers/RiscZeroVerifier.sol b/packages/protocol/contracts/verifiers/RiscZeroVerifier.sol index 9ced5ee6a73..794253a1fb6 100644 --- a/packages/protocol/contracts/verifiers/RiscZeroVerifier.sol +++ b/packages/protocol/contracts/verifiers/RiscZeroVerifier.sol @@ -81,7 +81,7 @@ contract RiscZeroVerifier is EssentialContract, IVerifier { // call risc0 verifier contract (bool success,) = address(receiptVerifier).staticcall( - abi.encodeWithSignature("verify(bytes,bytes32,bytes32)", seal, imageId, journalDigest) + abi.encodeCall(IRiscZeroReceiptVerifier.verify, (seal, imageId, journalDigest)) ); if (!success) {