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

feat(protocol): use SP1 1.2.0-rc with more proof verification tests #18001

Merged
merged 7 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
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
88 changes: 44 additions & 44 deletions packages/protocol/contract_layout.md

Large diffs are not rendered by default.

92 changes: 45 additions & 47 deletions packages/protocol/deployments/gen-layouts.sh
Original file line number Diff line number Diff line change
@@ -1,54 +1,52 @@
#!/bin/bash

# Define the list of contracts to inspect
# Please try not to change the order
contracts=(
# Base contracts
"TaikoL1"
"TaikoL2"
"SignalService"
"Bridge"
"DelegateOwner"
"GuardianProver"
"TaikoToken"
"BridgedTaikoToken"
"ERC20Vault"
"ERC721Vault"
"ERC1155Vault"
"BridgedERC20"
"BridgedERC20V2"
"BridgedERC721"
"BridgedERC1155"
"AutomataDcapV3Attestation"
"SgxVerifier"
"Risc0Verifier"
"SP1Verifier"
"QuotaManager"
"ProverSet"
"TokenUnlock"
"ComposeVerifier"
"TeeAnyVerifier"
"ZkAnyVerifier"
"ZkAndTeeVerifier"
# Hekla contracts
"HeklaTaikoL1"
# Mainnet contracts
"MainnetBridge"
"MainnetERC1155Vault"
"MainnetERC20Vault"
"MainnetERC721Vault"
"MainnetGuardianProver"
"MainnetProverSet"
"MainnetRisc0Verifier"
"MainnetSP1Verifier"
"MainnetRollupAddressManager"
"MainnetSgxVerifier"
"MainnetTeeAnyVerifier"
"MainnetZkAnyVerifier"
"MainnetZkAndTeeVerifier"
"MainnetSharedAddressManager"
"MainnetSignalService"
"MainnetTaikoL1"
"MainnetTierRouter"
"contracts/L1/TaikoL1.sol:TaikoL1"
"contracts/L2/TaikoL2.sol:TaikoL2"
"contracts/signal/SignalService.sol:SignalService"
"contracts/bridge/Bridge.sol:Bridge"
"contracts/L2/DelegateOwner.sol:DelegateOwner"
"contracts/L1/provers/GuardianProver.sol:GuardianProver"
"contracts/tko/TaikoToken.sol:TaikoToken"
"contracts/tko/BridgedTaikoToken.sol:BridgedTaikoToken"
"contracts/tokenvault/ERC20Vault.sol:ERC20Vault"
"contracts/tokenvault/ERC721Vault.sol:ERC721Vault"
"contracts/tokenvault/ERC1155Vault.sol:ERC1155Vault"
"contracts/tokenvault/BridgedERC20.sol:BridgedERC20"
"contracts/tokenvault/BridgedERC20V2.sol:BridgedERC20V2"
"contracts/tokenvault/BridgedERC721.sol:BridgedERC721"
"contracts/tokenvault/BridgedERC1155.sol:BridgedERC1155"
"contracts/automata-attestation/AutomataDcapV3Attestation.sol:AutomataDcapV3Attestation"
"contracts/verifiers/SgxVerifier.sol:SgxVerifier"
"contracts/verifiers/Risc0Verifier.sol:Risc0Verifier"
"contracts/verifiers/SP1Verifier.sol:SP1Verifier"
"contracts/bridge/QuotaManager.sol:QuotaManager"
"contracts/team/proving/ProverSet.sol:ProverSet"
"contracts/team/tokenunlock/TokenUnlock.sol:TokenUnlock"
"contracts/verifiers/compose/ComposeVerifier.sol:ComposeVerifier"
"contracts/verifiers/compose/TeeAnyVerifier.sol:TeeAnyVerifier"
"contracts/verifiers/compose/ZkAnyVerifier.sol:ZkAnyVerifier"
"contracts/verifiers/compose/ZkAndTeeVerifier.sol:ZkAndTeeVerifier"
"contracts/hekla/HeklaTaikoL1.sol:HeklaTaikoL1"
"contracts/mainnet/shared/MainnetBridge.sol:MainnetBridge"
"contracts/mainnet/shared/MainnetERC1155Vault.sol:MainnetERC1155Vault"
"contracts/mainnet/shared/MainnetERC20Vault.sol:MainnetERC20Vault"
"contracts/mainnet/shared/MainnetERC721Vault.sol:MainnetERC721Vault"
"contracts/mainnet/rollup/MainnetGuardianProver.sol:MainnetGuardianProver"
"contracts/mainnet/rollup/MainnetProverSet.sol:MainnetProverSet"
"contracts/mainnet/rollup/verifiers/MainnetRisc0Verifier.sol:MainnetRisc0Verifier"
"contracts/mainnet/rollup/verifiers/MainnetSP1Verifier.sol:MainnetSP1Verifier"
"contracts/mainnet/rollup/MainnetRollupAddressManager.sol:MainnetRollupAddressManager"
"contracts/mainnet/rollup/verifiers/MainnetSgxVerifier.sol:MainnetSgxVerifier"
"contracts/mainnet/rollup/verifiers/MainnetTeeAnyVerifier.sol:MainnetTeeAnyVerifier"
"contracts/mainnet/rollup/verifiers/MainnetZkAnyVerifier.sol:MainnetZkAnyVerifier"
"contracts/mainnet/rollup/verifiers/MainnetZkAndTeeVerifier.sol:MainnetZkAndTeeVerifier"
"contracts/mainnet/shared/MainnetSharedAddressManager.sol:MainnetSharedAddressManager"
"contracts/mainnet/shared/MainnetSignalService.sol:MainnetSignalService"
"contracts/mainnet/rollup/MainnetTaikoL1.sol:MainnetTaikoL1"
"contracts/mainnet/rollup/MainnetTierRouter.sol:MainnetTierRouter"
)

# Empty the output file initially
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
"p256-verifier": "github:taikoxyz/p256-verifier#v0.1.0",
"risc0-ethereum": "github:risc0/risc0-ethereum#v1.0.0",
"solady": "github:Vectorized/solady#v0.0.231",
"sp1-contracts": "github:succinctlabs/sp1-contracts#v1.1.0"
"sp1-contracts": "github:succinctlabs/sp1-contracts#v1.2.0-rc1"
}
}
19 changes: 19 additions & 0 deletions packages/protocol/script/DeployOnL1.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity 0.8.24;

import "@openzeppelin/contracts/utils/Strings.sol";
import "@risc0/contracts/groth16/RiscZeroGroth16Verifier.sol";
import { SP1Verifier as SP1Verifier120rc } from "@sp1-contracts/src/v1.2.0-rc/SP1VerifierPlonk.sol";

// Actually this one is deployed already on mainnet, but we are now deploying our own (non via-ir)
// version. For mainnet, it is easier to go with one of:
Expand Down Expand Up @@ -36,6 +37,7 @@ import "../test/common/erc20/MayFailFreeMintERC20.sol";
import "../test/L1/TestTierProvider.sol";
import "../test/DeployCapability.sol";
import "../contracts/verifiers/Risc0Verifier.sol";
import "../contracts/verifiers/SP1Verifier.sol";

/// @title DeployOnL1
/// @notice This script deploys the core Taiko protocol smart contract on L1,
Expand Down Expand Up @@ -395,6 +397,12 @@ contract DeployOnL1 is DeployCapability {
)
});

deployZKVerifiers(owner, rollupAddressManager);
}

// deploy both sp1 & risc0 verifiers.
// using function to avoid stack too deep error
function deployZKVerifiers(address owner, address rollupAddressManager) private {
// Deploy r0 groth16 verifier
RiscZeroGroth16Verifier verifier =
new RiscZeroGroth16Verifier(ControlID.CONTROL_ROOT, ControlID.BN254_CONTROL_ID);
Expand All @@ -406,6 +414,17 @@ contract DeployOnL1 is DeployCapability {
data: abi.encodeCall(Risc0Verifier.init, (owner, rollupAddressManager)),
registerTo: rollupAddressManager
});

// Deploy sp1 plonk verifier
SP1Verifier120rc sp1Verifier120rc = new SP1Verifier120rc();
register(rollupAddressManager, "sp1_remote_verifier", address(sp1Verifier120rc));

deployProxy({
name: "tier_zkvm_sp1",
impl: address(new SP1Verifier()),
data: abi.encodeCall(SP1Verifier.init, (owner, rollupAddressManager)),
registerTo: rollupAddressManager
});
}

function deployTierProvider(string memory tierProviderName) private returns (address) {
Expand Down
100 changes: 100 additions & 0 deletions packages/protocol/test/verifiers/SP1PlonkVerifier.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import "../L1/TaikoL1TestBase.sol";
import { SP1Verifier as SP1PlonkVerifier } from "@sp1-contracts/src/v1.2.0-rc/SP1VerifierPlonk.sol";

contract SP1PlonkVerifierTest is TaikoL1TestBase {
function deployTaikoL1() internal override returns (TaikoL1) {
return
TaikoL1(payable(deployProxy({ name: "taiko", impl: address(new TaikoL1()), data: "" })));
}

function setUp() public override {
vm.startPrank(Emma);
// Call the TaikoL1TestBase setUp()
super.setUp();

SP1PlonkVerifier verifier = new SP1PlonkVerifier();
console2.log("Deployed SP1PlonkVerifier to", address(verifier));
registerAddress("sp1_remote_verifier", address(verifier));

// Deploy Taiko's SP1 proof verifier
sp1 = SP1Verifier(
deployProxy({
name: "tier_zkvm_sp1",
impl: address(new SP1Verifier()),
data: abi.encodeCall(SP1Verifier.init, (address(0), address(addressManager)))
})
);

sp1.setProgramTrusted(
bytes32(0x008985ad6b5f2bcf7045ae495ae7e36ec0744befcd0881ecf0c3618541f21c9a), true
);
}

// Test `verifyProof()` happy path
function test_sp1_Plonk_verifyProof() external {
vm.stopPrank();

// Caller not necessary has to be TaikoL1 contract because there is no keys (as in SGX keys)
// to be front run.
vm.startPrank(Emma);

bytes memory sp1Proof =
hex"616a42051d0b264598d3ce80b077e8e5d3d6209834817c3d5cc6ae9ef9282129999978a3262175276ff5cb3072fe862a210a50f81e7d8684944202c3a19672ad87bfb4a81699105748fa8516cce7c817e72717cf91cba986e01c82f72cbd3e0a5b18f9540ccde87997b79148c1c19689afa2d67b701b9d3705d93f39912a9e956016d7d027112ae07e51b658a565fde7c21b03d1ebd799f9fb92680cba9ed7903a690fc10b03b6b8bc3f29d487533ca9aecc762ddc297e0f54d2290038bb7673a3867e1217c52471a108298e34cb25ae15082832cf4ddc6ca13e3fe418c391e9ea053738116833c96667052033452ee4e97baf77acabf21673a7d650a84866124122e493256a9f1679db2f46c0722267a16efe6ba1ef6a0bf105f973ef6b5d98e0236a6c1e74c4c7c984fe7a61f89b9dd739c3a43947b44835202afe54bdef012e0945a22569c82f420ebd0e08b3552d1b07e15e7cd81a33c55fb12f3c83ebc114d25a5527b2f9a20ed48a5e8dbaeb000b21a7106f0d2538278d985a619fc2074999e79512adce8bbe362113c965400a8127f85543f909d6f65a909ea0e5bb7a6e867ed3261111ea8b12c041df1d70e02aa42b9fe30be06265d02ff4f0d29545c22339430c5164fd0496b03fb5ce39f4518402251450a2ebca06d1209a570e859702ff552bc7bae5b3118017bea5569dfc6188fe5442236fd0330879076ed37313cc04be11386895c911c06b72b63785656050e9858975a9b5280a89cf3edc109130619718159eeeb77a1b48773a0a0df65170aefdd3a82858ac729ead3aa0918b52a7f101ec6ee3baccbc890bed38622a157541153167dd5f497bf8778c886508bc172a179618294af48fcc69354c93f013e06666fe26b5006729a03728a7ddc319f66600b0bcdece21a82072b2a2036a97246f101138ee19cf39a90d24fb5f12f0c40b1aa9ccd2a70c96da3af9bc9b76cdbd37054291c9ee6974c9d40089bf68d525a612e992cf3de3acf7feb072b928852bfaf50d6c69c7672a08ed15d1bbcfaff22a0277ea85becd001bf9df5589050e71d8ee11e6d13b63365f445377aebcec33140d4b5ff2150633f2d1edddfe100a42f81b25f22fd667180056607c34fb808a7125b16ae2fb907f5629b987eb596377ff1e3e42042b9e14741e258c17d14e1ae91f178226c8b10798b84a7c5a93b282a7b6115f568cebf95c15b47e7e084d031c";
bytes32 vKey = bytes32(0x008985ad6b5f2bcf7045ae495ae7e36ec0744befcd0881ecf0c3618541f21c9a);

console2.logBytes(abi.encodePacked(vKey, sp1Proof));
// TierProof
TaikoData.TierProof memory proof =
TaikoData.TierProof({ tier: 100, data: abi.encodePacked(vKey, sp1Proof) });

vm.warp(block.timestamp + 5);

(IVerifier.Context memory ctx, TaikoData.Transition memory transition) =
_generateTaikoMainnetContextAndTransition();

uint64 chainId = L1.getConfig().chainId;
bytes32 pi = LibPublicInput.hashPublicInputs(
transition, address(sp1), address(0), ctx.prover, ctx.metaHash, chainId
);
console2.log("chainId: ", chainId);
console2.log("Verifier: ", address(sp1));
console2.log("Prover: ", ctx.prover);
console2.log("MetaHash: ");
console2.logBytes32(ctx.metaHash);
console2.log("Public input");
console2.logBytes32(pi);

// `verifyProof()`
sp1.verifyProof(ctx, transition, proof);

vm.stopPrank();
}

function _generateTaikoMainnetContextAndTransition()
internal
pure
returns (IVerifier.Context memory ctx, TaikoData.Transition memory transition)
{
// Context
ctx = IVerifier.Context({
metaHash: bytes32(0xd7efb262f6f25cc817452a622009a22e5868e53e1f934d899d3ec68d8c4f2c5b),
blobHash: bytes32(0x015cc9688f24b8d2195e46829b3f726ce006884d5fd2760b7cf414bab9a1b231),
prover: address(0x70997970C51812dc3A010C7d01b50e0d17dc79C8),
msgSender: address(0),
blockId: 223_248, //from mainnet
isContesting: false,
blobUsed: true
});

// Transition
transition = TaikoData.Transition({
parentHash: 0x317de24b32f09629524133334ad552a14e3de603d71a9cf9e88d722809f101b3,
blockHash: 0x9966d3cf051d3d1e44e2a740169627506a619257c95374e812ca572de91ed885,
stateRoot: 0x3ae3de1afa16b93a5c7ea20a0b36b43357061f5b8ef857053d68b2735c3df860,
graffiti: 0x8008500000000000000000000000000000000000000000000000000000000000
});
}
}
Loading
Loading