Skip to content

Commit

Permalink
feat(protocol): update risc0 verifier contract to release-1.0 (#17776)
Browse files Browse the repository at this point in the history
  • Loading branch information
smtmfft authored Jul 12, 2024
1 parent c190bcf commit 2dd30ab
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
12 changes: 8 additions & 4 deletions packages/protocol/contracts/verifiers/RiscZeroVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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 verifier contract
(bool success,) = address(receiptVerifier).staticcall(
abi.encodeCall(IRiscZeroReceiptVerifier.verify, (seal, imageId, journalDigest))
);

if (!success) {
revert RISC_ZERO_INVALID_PROOF();
}
}
Expand Down
7 changes: 2 additions & 5 deletions packages/protocol/test/verifiers/RiscZeroVerifier.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 2dd30ab

Please sign in to comment.