From 8f63a44f5988b7846f54f7fc7317ddaeb686e790 Mon Sep 17 00:00:00 2001 From: Preston Ong Date: Mon, 18 Nov 2024 17:13:50 +0800 Subject: [PATCH] env, scripts and forge-test updates --- .env.example | 2 +- .github/workflows/build.yml | 2 +- forge-script/AttestationScript.s.sol | 2 - forge-script/DeployRouter.s.sol | 13 +++ .../AutomataDcapAttestationFeeTest.t.sol | 2 +- forge-test/AutomataDcapAttestationTest.t.sol | 105 ++++++++++-------- forge-test/utils/SuccinctSetup.sol | 25 ----- forge-test/utils/succinct/Groth16Setup.sol | 11 ++ forge-test/utils/succinct/PlonkSetup.sol | 11 ++ 9 files changed, 96 insertions(+), 77 deletions(-) delete mode 100644 forge-test/utils/SuccinctSetup.sol create mode 100644 forge-test/utils/succinct/Groth16Setup.sol create mode 100644 forge-test/utils/succinct/PlonkSetup.sol diff --git a/.env.example b/.env.example index 5e0c8d4..33a75a3 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,7 @@ # Environment Configuration PRIVATE_KEY=0x RPC_URL="" -DCAP_IMAGE_ID=0x4052beb38db7869b15596d53c2d5c02c9307faffca9215e69b0f0d0e1812a6c2 +DCAP_RISCZERO_IMAGE_ID=0x4052beb38db7869b15596d53c2d5c02c9307faffca9215e69b0f0d0e1812a6c2 # On-Chain PCCS Configurations ENCLAVE_IDENTITY_HELPER=0xfd4a34b578B352FE1896CDafaEb0f45f993352Bf diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 46f7955..a270889 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,7 @@ on: workflow_dispatch: env: - DCAP_IMAGE_ID: "0x4052beb38db7869b15596d53c2d5c02c9307faffca9215e69b0f0d0e1812a6c2" + DCAP_RISCZERO_IMAGE_ID: "0x4052beb38db7869b15596d53c2d5c02c9307faffca9215e69b0f0d0e1812a6c2" jobs: check: diff --git a/forge-script/AttestationScript.s.sol b/forge-script/AttestationScript.s.sol index d1698f0..cf9b7e0 100644 --- a/forge-script/AttestationScript.s.sol +++ b/forge-script/AttestationScript.s.sol @@ -8,8 +8,6 @@ import "../contracts/AutomataDcapAttestation.sol"; contract AttestationScript is Script { uint256 deployerKey = uint256(vm.envBytes32("PRIVATE_KEY")); - address riscZeroVerifier = vm.envAddress("RISC0_VERIFIER"); - bytes32 riscZeroImageId = vm.envBytes32("DCAP_IMAGE_ID"); function deployEntrypoint() public { vm.startBroadcast(deployerKey); diff --git a/forge-script/DeployRouter.s.sol b/forge-script/DeployRouter.s.sol index e624362..d07350d 100644 --- a/forge-script/DeployRouter.s.sol +++ b/forge-script/DeployRouter.s.sol @@ -27,8 +27,21 @@ contract DeployRouter is Script { vm.stopBroadcast(); } + function updateConfig() public { + vm.startBroadcast(deployerKey); + + PCCSRouter router = PCCSRouter(vm.envAddress("PCCS_ROUTER")); + router.setConfig(enclaveIdDaoAddr, tcbDaoAddr, pcsDaoAddr, pckDaoAddr, pckHelperAddr, crlHelperAddr); + + vm.stopBroadcast(); + } + function setAuthorizedCaller(address caller, bool authorized) public { + vm.startBroadcast(deployerKey); + PCCSRouter router = PCCSRouter(vm.envAddress("PCCS_ROUTER")); router.setAuthorized(caller, authorized); + + vm.stopBroadcast(); } } diff --git a/forge-test/AutomataDcapAttestationFeeTest.t.sol b/forge-test/AutomataDcapAttestationFeeTest.t.sol index 347a4b0..18fdc15 100644 --- a/forge-test/AutomataDcapAttestationFeeTest.t.sol +++ b/forge-test/AutomataDcapAttestationFeeTest.t.sol @@ -21,7 +21,7 @@ contract AutomataDcapAttestationFeeTest is PCCSSetupBase, RiscZeroSetup { AutomataDcapAttestationFee attestation; PCCSRouter pccsRouter; - bytes32 imageId = vm.envBytes32("DCAP_IMAGE_ID"); + bytes32 imageId = vm.envBytes32("DCAP_RISCZERO_IMAGE_ID"); address user = address(69); function setUp() public override { diff --git a/forge-test/AutomataDcapAttestationTest.t.sol b/forge-test/AutomataDcapAttestationTest.t.sol index 0fe9b5e..2799c6a 100644 --- a/forge-test/AutomataDcapAttestationTest.t.sol +++ b/forge-test/AutomataDcapAttestationTest.t.sol @@ -3,7 +3,8 @@ pragma solidity ^0.8.13; import "./utils/PCCSSetupBase.sol"; import "./utils/RiscZeroSetup.sol"; -import "./utils/SuccinctSetup.sol"; +import {PlonkSetup} from "./utils/succinct/PlonkSetup.sol"; +import {Groth16Setup} from "./utils/succinct/Groth16Setup.sol"; import { AutomataDcapAttestation, ZkCoProcessorConfig, ZkCoProcessorType @@ -11,9 +12,15 @@ import { import {V3QuoteVerifier} from "../contracts/verifiers/V3QuoteVerifier.sol"; import {V4QuoteVerifier} from "../contracts/verifiers/V4QuoteVerifier.sol"; -contract AutomataDcapAttestationTest is PCCSSetupBase, RiscZeroSetup, SuccinctSetup { +import {ISP1Verifier} from "@sp1-contracts/ISP1Verifier.sol"; + +contract AutomataDcapAttestationTest is PCCSSetupBase, RiscZeroSetup { AutomataDcapAttestation attestation; PCCSRouter pccsRouter; + + // Contracts used for testing only + PlonkSetup succinctPlonkSetup; + Groth16Setup succinctGroth16Setup; function setUp() public override { super.setUp(); @@ -94,7 +101,7 @@ contract AutomataDcapAttestationTest is PCCSSetupBase, RiscZeroSetup, SuccinctSe } function testRiscZeroProofAttestation() public { - bytes32 imageId = vm.envBytes32("DCAP_IMAGE_ID"); + bytes32 imageId = vm.envBytes32("DCAP_RISCZERO_IMAGE_ID"); setUpRiscZero(); ZkCoProcessorConfig memory riscZeroConfig = ZkCoProcessorConfig({dcapProgramIdentifier: imageId, zkVerifier: address(riscZeroVerifier)}); @@ -128,56 +135,60 @@ contract AutomataDcapAttestationTest is PCCSSetupBase, RiscZeroSetup, SuccinctSe assertTrue(success); } - // function testSuccintGroth16ProofAttestation() public { - // bytes32 vk = 0x0016d421d8599b43498eee7c30e6eca5e7aa05c02e38e5bf392937c98736fda6; - // ISP1Verifier sp1Verifier = setupSP1Verifier(ProveOpt.Groth16); - // ZkCoProcessorConfig memory riscZeroConfig = - // ZkCoProcessorConfig({dcapProgramIdentifier: vk, zkVerifier: address(sp1Verifier)}); - // vm.prank(admin); - // attestation.setZkConfiguration(ZkCoProcessorType.Succinct, riscZeroConfig); - - // // pinned May 10th, 2024, Midnight GMT - // vm.warp(1715342400); - - // vm.startPrank(admin); - // bytes memory pckCrlUpdate = - // hex"30820a6230820a08020101300a06082a8648ce3d04030230703122302006035504030c19496e74656c205347582050434b20506c6174666f726d204341311a3018060355040a0c11496e74656c20436f72706f726174696f6e3114301206035504070c0b53616e746120436c617261310b300906035504080c024341310b3009060355040613025553170d3234303530393132333735335a170d3234303630383132333735335a30820934303302146fc34e5023e728923435d61aa4b83c618166ad35170d3234303530393132333735335a300c300a0603551d1504030a01013034021500efae6e9715fca13b87e333e8261ed6d990a926ad170d3234303530393132333735335a300c300a0603551d1504030a01013034021500fd608648629cba73078b4d492f4b3ea741ad08cd170d3234303530393132333735335a300c300a0603551d1504030a010130340215008af924184e1d5afddd73c3d63a12f5e8b5737e56170d3234303530393132333735335a300c300a0603551d1504030a01013034021500b1257978cfa9ccdd0759abf8c5ca72fae3a78a9b170d3234303530393132333735335a300c300a0603551d1504030a01013033021474fea614a972be0e2843f2059835811ed872f9b3170d3234303530393132333735335a300c300a0603551d1504030a01013034021500f9c4ef56b3ab48d577e108baedf4bf88014214b9170d3234303530393132333735335a300c300a0603551d1504030a010130330214071de0778f9e5fc4f2878f30d6b07c9a30e6b30b170d3234303530393132333735335a300c300a0603551d1504030a01013034021500cde2424f972cea94ff239937f4d80c25029dd60b170d3234303530393132333735335a300c300a0603551d1504030a0101303302146c3319e5109b64507d3cf1132ce00349ef527319170d3234303530393132333735335a300c300a0603551d1504030a01013034021500df08d756b66a7497f43b5bb58ada04d3f4f7a937170d3234303530393132333735335a300c300a0603551d1504030a01013033021428af485b6cf67e409a39d5cb5aee4598f7a8fa7b170d3234303530393132333735335a300c300a0603551d1504030a01013034021500fb8b2daec092cada8aa9bc4ff2f1c20d0346668c170d3234303530393132333735335a300c300a0603551d1504030a01013034021500cd4850ac52bdcc69a6a6f058c8bc57bbd0b5f864170d3234303530393132333735335a300c300a0603551d1504030a01013034021500994dd3666f5275fb805f95dd02bd50cb2679d8ad170d3234303530393132333735335a300c300a0603551d1504030a0101303302140702136900252274d9035eedf5457462fad0ef4c170d3234303530393132333735335a300c300a0603551d1504030a01013033021461f2bf73e39b4e04aa27d801bd73d24319b5bf80170d3234303530393132333735335a300c300a0603551d1504030a0101303302143992be851b96902eff38959e6c2eff1b0651a4b5170d3234303530393132333735335a300c300a0603551d1504030a010130330214639f139a5040fdcff191e8a4fb1bf086ed603971170d3234303530393132333735335a300c300a0603551d1504030a01013034021500959d533f9249dc1e513544cdc830bf19b7f1f301170d3234303530393132333735335a300c300a0603551d1504030a0101303302140fda43a00b68ea79b7c2deaeac0b498bdfb2af90170d3234303530393132333735335a300c300a0603551d1504030a010130340215009d67753b81e47090aea763fbec4c4549bcdb9933170d3234303530393132333735335a300c300a0603551d1504030a01013033021434bfbb7a1d9c568147e118b614f7b76ed3ef68df170d3234303530393132333735335a300c300a0603551d1504030a0101303402150085d3c9381b77a7e04d119c9e5ad6749ff3ffab87170d3234303530393132333735335a300c300a0603551d1504030a0101303402150093887ca4411e7a923bd1fed2819b2949f201b5b4170d3234303530393132333735335a300c300a0603551d1504030a0101303302142498dc6283930996fd8bf23a37acbe26a3bed457170d3234303530393132333735335a300c300a0603551d1504030a010130340215008a66f1a749488667689cc3903ac54c662b712e73170d3234303530393132333735335a300c300a0603551d1504030a01013034021500afc13610bdd36cb7985d106481a880d3a01fda07170d3234303530393132333735335a300c300a0603551d1504030a01013034021500efe04b2c33d036aac96ca673bf1e9a47b64d5cbb170d3234303530393132333735335a300c300a0603551d1504030a0101303402150083d9ac8d8bb509d1c6c809ad712e8430559ed7f3170d3234303530393132333735335a300c300a0603551d1504030a0101303302147931fd50b5071c1bbfc5b7b6ded8b45b9d8b8529170d3234303530393132333735335a300c300a0603551d1504030a0101303302141fa20e2970bde5d57f7b8ddf8339484e1f1d0823170d3234303530393132333735335a300c300a0603551d1504030a0101303302141e87b2c3b32d8d23e411cef34197b95af0c8adf5170d3234303530393132333735335a300c300a0603551d1504030a010130340215009afd2ee90a473550a167d996911437c7502d1f09170d3234303530393132333735335a300c300a0603551d1504030a0101303302144481b0f11728a13b696d3ea9c770a0b15ec58dda170d3234303530393132333735335a300c300a0603551d1504030a01013034021500a7859f57982ef0e67d37bc8ef2ef5ac835ff1aa9170d3234303530393132333735335a300c300a0603551d1504030a0101303302147ae37748a9f912f4c63ba7ab07c593ce1d1d1181170d3234303530393132333735335a300c300a0603551d1504030a01013033021413884b33269938c195aa170fca75da177538df0b170d3234303530393132333735335a300c300a0603551d1504030a0101303302142c3cc6fe9279db1516d5ce39f2a898cda5a175e1170d3234303530393132333735335a300c300a0603551d1504030a010130330214717948687509234be979e4b7dce6f31bef64b68c170d3234303530393132333735335a300c300a0603551d1504030a010130340215009d76ef2c39c136e8658b6e7396b1d7445a27631f170d3234303530393132333735335a300c300a0603551d1504030a01013034021500c3e025fca995f36f59b48467939e3e34e6361a6f170d3234303530393132333735335a300c300a0603551d1504030a010130340215008c5f6b3257da05b17429e2e61ba965d67330606a170d3234303530393132333735335a300c300a0603551d1504030a01013034021500a17c51722ec1e0c3278fe8bdf052059cbec4e648170d3234303530393132333735335a300c300a0603551d1504030a0101a02f302d300a0603551d140403020101301f0603551d23041830168014956f5dcdbd1be1e94049c9d4f433ce01570bde54300a06082a8648ce3d04030203480030450220556cff7546df52c6c39dae93fd6c0c2c5375fffe28c9b06e702fd8fed06eb4ad022100dfcfc43950839421833147eac23990a3017b9ea2f6cd49a1060363b83246ba2b"; - // pcsDao.upsertPckCrl(CA.PLATFORM, pckCrlUpdate); - // V4QuoteVerifier quoteVerifier = new V4QuoteVerifier(P256_VERIFIER, address(pccsRouter)); - // attestation.setQuoteVerifier(address(quoteVerifier)); - // pccsRouter.setAuthorized(address(quoteVerifier), true); - // assertEq(address(attestation.quoteVerifiers(4)), address(quoteVerifier)); - // vm.stopPrank(); - - // bytes memory output = - // hex"55020004000000810790c06f000000040102000000000000000000000000009790d89a10210ec6968a773cee2ca05b5aa97309f36727a968527be4606fc19e6f73acce350946c9d46a9bf7a63f843000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000080e702060000000000f2dd2696f69b950645832bdc095ffd11247eeff687eeacdb57a58d2ddb9a9f94fea40c961e19460c00ffa31420ecbc180000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000998204508d58dcbfebe5e11c48669f7a921ac2da744dfb7d014ecdff2acdff1c9f665fdad52aadacf296a1df9909eb2383d100224f1716aeb431f7cb3cf028197dbd872487f27b0f6329ab17647dc9953c7014109818634f879e6550bc60f93eecfc42ff4d49278bfdbb0c77e570f4490cff10a2ee1ac11fbd2c2b49fa6cfa3cf1a1cb755c72522dd8a689e9d47906a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000278e753482976c8a7351fe2113609c7350d491cdae3d449eefc202fa41b2ad6840239cc2ba084c2d594b4e6dabeae0fcbf71c96daf0d0c9ecf0e9810c045790000a51167000000009d15153a84fbc62bcf79a13967729408838fc92c0c97eb85d628db3566af265467eebe27bf6dc0aa227bc8ad11c55c22370f4f7e7246c6c65bef5205342142090fa74a3f32c80b978c8ad671395dabf24283eef9091bc3919fd39b9915a87f1adf3061c165c0191e2658256a2855cac9267f179aafb1990c9e918d6452816adf9953f245d005b9d7d8e36a842a60b51e5cf85b2c2072ae397c178535c9985b77607c9c42db9df0b9b1a68b4172b8f2303edbf0a41308850a850bcbfb713318b0"; - // bytes memory proofBytes = - // hex"090690900c2a14e85adb02593ae269bb6a4e0d8098d1939b32d057cf8fe73dcab26603701c1090beae84c08953e144aee41731878b00a5f68a830627ccddb609635f9d91107248fe5ad6d9ade4052829b574c4f124449172bbb0275ba7538bccc791b4b21eec494d2a3df1124de1bb6c10e7b7802364b7c76867af56809c9db027283ed200fbf3b39f1bb34751e7319002d988ab248f1ada5c2443ad4f75732da53412d228618160bb5ab7f6356eb0ca1aa7d6267c71291216217975a1738dae8f4f76d42a72e01519936b19c7ef38d15d1364854a62702abeedab435edc0390c50f542c23ce879c0bf941c2256b58b146731f7d5780a5e45dda5949ce18d27b866bd698"; - - // ZkCoProcessorType zkCoProcessorType = ZkCoProcessorType.Succinct; - // (bool success, bytes memory ret) = attestation.verifyAndAttestWithZKProof( - // output, - // zkCoProcessorType, - // proofBytes - // ); - - // if (!success) { - // console.log(string(ret)); - // } - // assertTrue(success); - // } + function testSuccintGroth16ProofAttestation() public { + succinctGroth16Setup = new Groth16Setup(); + + bytes32 vk = 0x0043e4e0c286cf4a2c03472ca2384f35a008558bc5de4e0f39d1d1bc989badca; + ISP1Verifier sp1Verifier = ISP1Verifier(succinctGroth16Setup.setup()); + ZkCoProcessorConfig memory succinctConfig = + ZkCoProcessorConfig({dcapProgramIdentifier: vk, zkVerifier: address(sp1Verifier)}); + vm.prank(admin); + attestation.setZkConfiguration(ZkCoProcessorType.Succinct, succinctConfig); + + // pinned May 10th, 2024, Midnight GMT + vm.warp(1715342400); + + vm.startPrank(admin); + bytes memory pckCrlUpdate = + hex"30820a6230820a08020101300a06082a8648ce3d04030230703122302006035504030c19496e74656c205347582050434b20506c6174666f726d204341311a3018060355040a0c11496e74656c20436f72706f726174696f6e3114301206035504070c0b53616e746120436c617261310b300906035504080c024341310b3009060355040613025553170d3234303530393132333735335a170d3234303630383132333735335a30820934303302146fc34e5023e728923435d61aa4b83c618166ad35170d3234303530393132333735335a300c300a0603551d1504030a01013034021500efae6e9715fca13b87e333e8261ed6d990a926ad170d3234303530393132333735335a300c300a0603551d1504030a01013034021500fd608648629cba73078b4d492f4b3ea741ad08cd170d3234303530393132333735335a300c300a0603551d1504030a010130340215008af924184e1d5afddd73c3d63a12f5e8b5737e56170d3234303530393132333735335a300c300a0603551d1504030a01013034021500b1257978cfa9ccdd0759abf8c5ca72fae3a78a9b170d3234303530393132333735335a300c300a0603551d1504030a01013033021474fea614a972be0e2843f2059835811ed872f9b3170d3234303530393132333735335a300c300a0603551d1504030a01013034021500f9c4ef56b3ab48d577e108baedf4bf88014214b9170d3234303530393132333735335a300c300a0603551d1504030a010130330214071de0778f9e5fc4f2878f30d6b07c9a30e6b30b170d3234303530393132333735335a300c300a0603551d1504030a01013034021500cde2424f972cea94ff239937f4d80c25029dd60b170d3234303530393132333735335a300c300a0603551d1504030a0101303302146c3319e5109b64507d3cf1132ce00349ef527319170d3234303530393132333735335a300c300a0603551d1504030a01013034021500df08d756b66a7497f43b5bb58ada04d3f4f7a937170d3234303530393132333735335a300c300a0603551d1504030a01013033021428af485b6cf67e409a39d5cb5aee4598f7a8fa7b170d3234303530393132333735335a300c300a0603551d1504030a01013034021500fb8b2daec092cada8aa9bc4ff2f1c20d0346668c170d3234303530393132333735335a300c300a0603551d1504030a01013034021500cd4850ac52bdcc69a6a6f058c8bc57bbd0b5f864170d3234303530393132333735335a300c300a0603551d1504030a01013034021500994dd3666f5275fb805f95dd02bd50cb2679d8ad170d3234303530393132333735335a300c300a0603551d1504030a0101303302140702136900252274d9035eedf5457462fad0ef4c170d3234303530393132333735335a300c300a0603551d1504030a01013033021461f2bf73e39b4e04aa27d801bd73d24319b5bf80170d3234303530393132333735335a300c300a0603551d1504030a0101303302143992be851b96902eff38959e6c2eff1b0651a4b5170d3234303530393132333735335a300c300a0603551d1504030a010130330214639f139a5040fdcff191e8a4fb1bf086ed603971170d3234303530393132333735335a300c300a0603551d1504030a01013034021500959d533f9249dc1e513544cdc830bf19b7f1f301170d3234303530393132333735335a300c300a0603551d1504030a0101303302140fda43a00b68ea79b7c2deaeac0b498bdfb2af90170d3234303530393132333735335a300c300a0603551d1504030a010130340215009d67753b81e47090aea763fbec4c4549bcdb9933170d3234303530393132333735335a300c300a0603551d1504030a01013033021434bfbb7a1d9c568147e118b614f7b76ed3ef68df170d3234303530393132333735335a300c300a0603551d1504030a0101303402150085d3c9381b77a7e04d119c9e5ad6749ff3ffab87170d3234303530393132333735335a300c300a0603551d1504030a0101303402150093887ca4411e7a923bd1fed2819b2949f201b5b4170d3234303530393132333735335a300c300a0603551d1504030a0101303302142498dc6283930996fd8bf23a37acbe26a3bed457170d3234303530393132333735335a300c300a0603551d1504030a010130340215008a66f1a749488667689cc3903ac54c662b712e73170d3234303530393132333735335a300c300a0603551d1504030a01013034021500afc13610bdd36cb7985d106481a880d3a01fda07170d3234303530393132333735335a300c300a0603551d1504030a01013034021500efe04b2c33d036aac96ca673bf1e9a47b64d5cbb170d3234303530393132333735335a300c300a0603551d1504030a0101303402150083d9ac8d8bb509d1c6c809ad712e8430559ed7f3170d3234303530393132333735335a300c300a0603551d1504030a0101303302147931fd50b5071c1bbfc5b7b6ded8b45b9d8b8529170d3234303530393132333735335a300c300a0603551d1504030a0101303302141fa20e2970bde5d57f7b8ddf8339484e1f1d0823170d3234303530393132333735335a300c300a0603551d1504030a0101303302141e87b2c3b32d8d23e411cef34197b95af0c8adf5170d3234303530393132333735335a300c300a0603551d1504030a010130340215009afd2ee90a473550a167d996911437c7502d1f09170d3234303530393132333735335a300c300a0603551d1504030a0101303302144481b0f11728a13b696d3ea9c770a0b15ec58dda170d3234303530393132333735335a300c300a0603551d1504030a01013034021500a7859f57982ef0e67d37bc8ef2ef5ac835ff1aa9170d3234303530393132333735335a300c300a0603551d1504030a0101303302147ae37748a9f912f4c63ba7ab07c593ce1d1d1181170d3234303530393132333735335a300c300a0603551d1504030a01013033021413884b33269938c195aa170fca75da177538df0b170d3234303530393132333735335a300c300a0603551d1504030a0101303302142c3cc6fe9279db1516d5ce39f2a898cda5a175e1170d3234303530393132333735335a300c300a0603551d1504030a010130330214717948687509234be979e4b7dce6f31bef64b68c170d3234303530393132333735335a300c300a0603551d1504030a010130340215009d76ef2c39c136e8658b6e7396b1d7445a27631f170d3234303530393132333735335a300c300a0603551d1504030a01013034021500c3e025fca995f36f59b48467939e3e34e6361a6f170d3234303530393132333735335a300c300a0603551d1504030a010130340215008c5f6b3257da05b17429e2e61ba965d67330606a170d3234303530393132333735335a300c300a0603551d1504030a01013034021500a17c51722ec1e0c3278fe8bdf052059cbec4e648170d3234303530393132333735335a300c300a0603551d1504030a0101a02f302d300a0603551d140403020101301f0603551d23041830168014956f5dcdbd1be1e94049c9d4f433ce01570bde54300a06082a8648ce3d04030203480030450220556cff7546df52c6c39dae93fd6c0c2c5375fffe28c9b06e702fd8fed06eb4ad022100dfcfc43950839421833147eac23990a3017b9ea2f6cd49a1060363b83246ba2b"; + pcsDao.upsertPckCrl(CA.PLATFORM, pckCrlUpdate); + V4QuoteVerifier quoteVerifier = new V4QuoteVerifier(P256_VERIFIER, address(pccsRouter)); + attestation.setQuoteVerifier(address(quoteVerifier)); + pccsRouter.setAuthorized(address(quoteVerifier), true); + assertEq(address(attestation.quoteVerifiers(4)), address(quoteVerifier)); + vm.stopPrank(); + + bytes memory output = + hex"02550004000000810790c06f000000040102000000000000000000000000009790d89a10210ec6968a773cee2ca05b5aa97309f36727a968527be4606fc19e6f73acce350946c9d46a9bf7a63f843000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000080e702060000000000f2dd2696f69b950645832bdc095ffd11247eeff687eeacdb57a58d2ddb9a9f94fea40c961e19460c00ffa31420ecbc180000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000998204508d58dcbfebe5e11c48669f7a921ac2da744dfb7d014ecdff2acdff1c9f665fdad52aadacf296a1df9909eb2383d100224f1716aeb431f7cb3cf028197dbd872487f27b0f6329ab17647dc9953c7014109818634f879e6550bc60f93eecfc42ff4d49278bfdbb0c77e570f4490cff10a2ee1ac11fbd2c2b49fa6cfa3cf1a1cb755c72522dd8a689e9d47906a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000278e753482976c8a7351fe2113609c7350d491cdae3d449eefc202fa41b2ad6840239cc2ba084c2d594b4e6dabeae0fcbf71c96daf0d0c9ecf0e9810c0457900000000006711a5009d15153a84fbc62bcf79a13967729408838fc92c0c97eb85d628db3566af265467eebe27bf6dc0aa227bc8ad11c55c22370f4f7e7246c6c65bef5205342142090fa74a3f32c80b978c8ad671395dabf24283eef9091bc3919fd39b9915a87f1adf3061c165c0191e2658256a2855cac9267f179aafb1990c9e918d6452816adf9953f245d005b9d7d8e36a842a60b51e5cf85b2c2072ae397c178535c9985b77607c9c42db9df0b9b1a68b4172b8f2303edbf0a41308850a850bcbfb713318b0"; + bytes memory proofBytes = + hex"090690902e3b7d041ca4d5f9f3b26f78687c0b6713374e64ecf3dedea472ba9c8520da991f0eab3733f2d32ea127447cea9698981866ba2eb5f945107f5476e5f44fa78b0beff7bc8f171768ce1c2b1e7ca2a9de2cf041bc93d603d0d1dc6fd69eb57f0c2fa84dee5d83f0345efa4d7ec3fff021118fbc7924d1374cc04b5ac4b5d70f8c15939e4c434318ee15e65f5a1ff612571ba93734dc57fc2de4c6a17a6fd28fd60007f59f01c31558a0b7f3e4152a8975b0a39497531d08e0b603ddd24445b2f30e167bfa7be1524e3eb552e031250a76d78aa6f634ada635c82dce0ae667a7af29345d5a84e2f4bcb22c1e06258ab163458cfd0aaeb9577e1d430788d94aadb6"; + + ZkCoProcessorType zkCoProcessorType = ZkCoProcessorType.Succinct; + (bool success, bytes memory ret) = attestation.verifyAndAttestWithZKProof( + output, + zkCoProcessorType, + proofBytes + ); + + if (!success) { + console.log(string(ret)); + } + assertTrue(success); + } function testSuccintPlonkProofAttestation() public { - bytes32 vk = 0x0016d421d8599b43498eee7c30e6eca5e7aa05c02e38e5bf392937c98736fda6; - ISP1Verifier sp1Verifier = setupSP1Verifier(ProveOpt.Plonk); - ZkCoProcessorConfig memory riscZeroConfig = ZkCoProcessorConfig({ + succinctPlonkSetup = new PlonkSetup(); + + bytes32 vk = 0x0043e4e0c286cf4a2c03472ca2384f35a008558bc5de4e0f39d1d1bc989badca; + ISP1Verifier sp1Verifier = ISP1Verifier(succinctPlonkSetup.setup()); + ZkCoProcessorConfig memory succinctConfig = ZkCoProcessorConfig({ dcapProgramIdentifier: vk, zkVerifier: address(sp1Verifier) }); vm.prank(admin); attestation.setZkConfiguration( ZkCoProcessorType.Succinct, - riscZeroConfig + succinctConfig ); // pinned May 10th, 2024, Midnight GMT @@ -192,8 +203,8 @@ contract AutomataDcapAttestationTest is PCCSSetupBase, RiscZeroSetup, SuccinctSe assertEq(address(attestation.quoteVerifiers(4)), address(quoteVerifier)); vm.stopPrank(); - bytes memory output = hex"55020004000000810790c06f000000040102000000000000000000000000009790d89a10210ec6968a773cee2ca05b5aa97309f36727a968527be4606fc19e6f73acce350946c9d46a9bf7a63f843000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000080e702060000000000f2dd2696f69b950645832bdc095ffd11247eeff687eeacdb57a58d2ddb9a9f94fea40c961e19460c00ffa31420ecbc180000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000998204508d58dcbfebe5e11c48669f7a921ac2da744dfb7d014ecdff2acdff1c9f665fdad52aadacf296a1df9909eb2383d100224f1716aeb431f7cb3cf028197dbd872487f27b0f6329ab17647dc9953c7014109818634f879e6550bc60f93eecfc42ff4d49278bfdbb0c77e570f4490cff10a2ee1ac11fbd2c2b49fa6cfa3cf1a1cb755c72522dd8a689e9d47906a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000278e753482976c8a7351fe2113609c7350d491cdae3d449eefc202fa41b2ad6840239cc2ba084c2d594b4e6dabeae0fcbf71c96daf0d0c9ecf0e9810c045790000a51167000000009d15153a84fbc62bcf79a13967729408838fc92c0c97eb85d628db3566af265467eebe27bf6dc0aa227bc8ad11c55c22370f4f7e7246c6c65bef5205342142090fa74a3f32c80b978c8ad671395dabf24283eef9091bc3919fd39b9915a87f1adf3061c165c0191e2658256a2855cac9267f179aafb1990c9e918d6452816adf9953f245d005b9d7d8e36a842a60b51e5cf85b2c2072ae397c178535c9985b77607c9c42db9df0b9b1a68b4172b8f2303edbf0a41308850a850bcbfb713318b0"; - bytes memory proofBytes = hex"54bdcae302c578c28074b9f5ac6a7e1e9d69e05e7bb172edb4eb01713796f79ccb2b6b9b2e568cfe8abcd85e9a17e77bfa229040f66d3fc32050fe311061e3adfc86743f02515ab315c0009061a14b917fd88bc98a466d898527c4b987eac8f1353df6c60cbff6bc50adffc0e087b67f3d75ecf4ed1e502b1ce05743b935d0e79ed6a9770a857a91081bf0bcfd0ed51395fa9ce83f310b903b9d2ff6f137a3c1f4fe0c1d0b886eafdf8027f7b0d6e49354c2f0b6246a5f75f5a031d2140ce2656faa7ab60ab2ee2b0361df8e3b8aef629277d61bc5ab732528e0a74c319c7cacd140d98c2dc54c9e5cb9ae7544ba6fdd4f90191670d50225a37775faa55ec091f7b9301607243d4652182abdd7f74dd0240484aed21291a4250cf04a84fe315bf46f0b310d24ff86efcee8318ee43aeba8df0adca1ffe9f7b19c0b978d324f9d7e34e8cf1ccc6e484de6432b4670b1de5aa994a4c04d50cb5aa506c03a063e70ded3ad480bff382e1da7104c808558107a51a95e1aa5e4426ba3660aa6894a9c45c8cc571b495f4c7f3c5802cbb1322e7683ae8bf9e9b4bcb7c72c4fa5661c215363abf32bbbdcdb69160a1b2e54e3bdd9a643db1551a7be5bee8bc228b001826129b4991782eb98e1ed29c845133be823df7c3425645fde880a683b536e4ed39752e23f01db352b7d70fce79bb667841b03c3782dd02a1d1a08acd09843833ee5e0d78b1c7be7c86e3f83da02862eddd46aaf8c71e652d6daf9bc16c469a6bdf79e2fa229bf14a36c37c3b23b6c6f4ca54e566b715bc749344c0043200aef11755e7ff0161a99d097dd5de337ae52bc5b7524ca8203d8ec5838e320c8fe21eb693c014e27139525e35eef0faa954aa6f7047b35e72a8b186a22245df8ab7b4c25fddad4044a53021931815e8a958e6a2c885bea3064e3202f5cca7f27fa10a207c48309206bc23b51714911511194e1ea0b5ae30dbdfa63c39bb50ec600a71d1b4f94561e479b720036334d248b8f7637aaeadd45bf1a601a67860073fa0704b5a4b7ed1e406d758fc71319a5e52d6590a00694020b16f6b67933c9b1f0490a86185b79205debb05323cac965a159d7e73b4ce292e36d88b6b0f53d30cf5db5e4d26d5412e29ac4a20a780c9e341bcd95eef81bc3ce6970c9797cc5493eaadb5dade98c2a9735c052860ecd31a7d9e27b5f03ee13159ae8aeb0bfcf0dee1071649c6975"; + bytes memory output = hex"02550004000000810790c06f000000040102000000000000000000000000009790d89a10210ec6968a773cee2ca05b5aa97309f36727a968527be4606fc19e6f73acce350946c9d46a9bf7a63f843000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000080e702060000000000f2dd2696f69b950645832bdc095ffd11247eeff687eeacdb57a58d2ddb9a9f94fea40c961e19460c00ffa31420ecbc180000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000998204508d58dcbfebe5e11c48669f7a921ac2da744dfb7d014ecdff2acdff1c9f665fdad52aadacf296a1df9909eb2383d100224f1716aeb431f7cb3cf028197dbd872487f27b0f6329ab17647dc9953c7014109818634f879e6550bc60f93eecfc42ff4d49278bfdbb0c77e570f4490cff10a2ee1ac11fbd2c2b49fa6cfa3cf1a1cb755c72522dd8a689e9d47906a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000278e753482976c8a7351fe2113609c7350d491cdae3d449eefc202fa41b2ad6840239cc2ba084c2d594b4e6dabeae0fcbf71c96daf0d0c9ecf0e9810c0457900000000006711a5009d15153a84fbc62bcf79a13967729408838fc92c0c97eb85d628db3566af265467eebe27bf6dc0aa227bc8ad11c55c22370f4f7e7246c6c65bef5205342142090fa74a3f32c80b978c8ad671395dabf24283eef9091bc3919fd39b9915a87f1adf3061c165c0191e2658256a2855cac9267f179aafb1990c9e918d6452816adf9953f245d005b9d7d8e36a842a60b51e5cf85b2c2072ae397c178535c9985b77607c9c42db9df0b9b1a68b4172b8f2303edbf0a41308850a850bcbfb713318b0"; + bytes memory proofBytes = hex"54bdcae30257b2a6b364ef0ad5d08c1789c5bd33bdae2f6a077108a4287b6c119bfa95e01c52f57b719acfece7405d405a3af1800400e03dabbc12a416aac723de796c550d20db00d614561667a91e5131d399e6ab7187f2ee74ccf892736206462f704226cda97a534276d92dca4332fce7578a97906e74b451e3eca007707db34df26f293ce4413d61a21da49c685b4a4619e0c98ab29a9eec217c9466cc1fdf05b8f30d2987b8d93976805123ffa978c5b830c9abea8921b0c0d7901b0f558a3cd9fc2f31f0568cbfb8df1ce63058992d1f3e921ae4d6a54caba77394429e36f40e6916eaad98e391db1af39829bd4f2b6a16bbf71d9f714ac412042e1febe663927e1fd67bd115e78a370cccca6d53851ecdf6762c705d3bbb63f35d00373eef20561ad93d9e046335a11fa48469850181e80c5944cbfce75447f72ed296f304b4160acdf1ef3858974fbc379aa75efa7eb3aa8e20ad5565045b9288f592a6e17b141f86b4d4c4c5fdec21b113d6e423212f5db56b8a546885b12cc9e379abad7513247d03ebc3964c7b04fe00eaf3adebbb1a59af03de4e21faa0380f50f269925822285195a606c06f4e0d34f7773b1576454e33affeea4b4424175a573a4b21f813432bd4f4081ad49a5e11d3c5bda4db6eeba477e7e1560caccc2d8a120b7646304fef4b3a2d058419a2af9e39e52944c819576db4d77382563e5358c2db02fd09c7e153e9a5d9dd3e29a155ae8841049d1ed0ec88dbf07c051b9b3b69ee9dd41aade969bdc2ee2ee639fa1178e2ea50dbb415d72ea273da05579434a0d2fbf528a61bfd3ed97fdcb13ac1b79206ca950c59328e74a4961c070179455ae0be9d1f22d8414937f676ddecfc28d0af8c8d203cd12c2607cf261f7e5d842622fbbd2f953cf2a3ae123569cea71b1d8d1e3ff5307dfbfba7524d4cf063497acadfd62cae8f0e2292f0c9034401685afedc3b4060fc4a3c984da6e3adf0888bc00fda2d658d77046a032c5c80e2c61f3167d0c0740ea286987e14278aeb109d5a9a230ed0932e114ddc4ba556334322e49ef973532d4bb1fe014fbf5da9b545af71362beb8ce20aa2a34b2f83600ab74de1d5ed7283c294c7cb7a144c90e7d33f8bf3043f7299964fe67fce64ece1665566b6c669025d1008267551563f3d8ed3e42b277efe0627ec0a327c7551258e11410c7f4f3e12ab3536ba7966d954d25891bf"; ZkCoProcessorType zkCoProcessorType = ZkCoProcessorType.Succinct; (bool success, bytes memory ret)= attestation.verifyAndAttestWithZKProof( diff --git a/forge-test/utils/SuccinctSetup.sol b/forge-test/utils/SuccinctSetup.sol deleted file mode 100644 index 87f6372..0000000 --- a/forge-test/utils/SuccinctSetup.sol +++ /dev/null @@ -1,25 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -// import {SP1Verifier} from "@sp1-contracts/v3.0.0/SP1VerifierGroth16.sol"; -import {SP1Verifier} from "@sp1-contracts/v3.0.0/SP1VerifierPlonk.sol"; -import {ISP1Verifier} from "@sp1-contracts/ISP1Verifier.sol"; - -enum ProveOpt { - Groth16, - Plonk -} - -abstract contract SuccinctSetup { - function setupSP1Verifier(ProveOpt opt) internal returns (ISP1Verifier verifier) { - // if (opt == ProveOpt.Groth16) { - // SP1Verifier groth16Verifier = new SP1Verifier(); - // verifier = ISP1Verifier(address(groth16Verifier)); - // } - // } else - if (opt == ProveOpt.Plonk) { - SP1Verifier plonkVerifier = new SP1Verifier(); - verifier = ISP1Verifier(address(plonkVerifier)); - } - } -} diff --git a/forge-test/utils/succinct/Groth16Setup.sol b/forge-test/utils/succinct/Groth16Setup.sol new file mode 100644 index 0000000..bb80722 --- /dev/null +++ b/forge-test/utils/succinct/Groth16Setup.sol @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.13; + +import {SP1Verifier} from "@sp1-contracts/v3.0.0/SP1VerifierGroth16.sol"; + +contract Groth16Setup { + function setup() public returns (address verifier) { + SP1Verifier groth16Verifier = new SP1Verifier(); + verifier = address(groth16Verifier); + } +} diff --git a/forge-test/utils/succinct/PlonkSetup.sol b/forge-test/utils/succinct/PlonkSetup.sol new file mode 100644 index 0000000..d754647 --- /dev/null +++ b/forge-test/utils/succinct/PlonkSetup.sol @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.13; + +import {SP1Verifier} from "@sp1-contracts/v3.0.0/SP1VerifierPlonk.sol"; + +contract PlonkSetup { + function setup() public returns (address verifier) { + SP1Verifier plonkVerifier = new SP1Verifier(); + verifier = address(plonkVerifier); + } +}