Skip to content

Commit

Permalink
feat: remove unnecessary sp1 risc0 dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
pbeza committed Dec 11, 2024
1 parent b49a9f2 commit 1168b05
Show file tree
Hide file tree
Showing 30 changed files with 5 additions and 603 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ on:

workflow_dispatch:

env:
DCAP_RISCZERO_IMAGE_ID: "0x83613a8beec226d1f29714530f1df791fa16c2c4dfcf22c50ab7edac59ca637f"

jobs:
check:
strategy:
Expand Down
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/sp1-contracts"]
path = lib/sp1-contracts
url = https://github.com/succinctlabs/sp1-contracts
[submodule "lib/risc0-ethereum"]
path = lib/risc0-ethereum
url = https://github.com/risc0/risc0-ethereum
[submodule "lib/automata-on-chain-pccs"]
path = lib/automata-on-chain-pccs
url = https://github.com/automata-network/automata-on-chain-pccs
22 changes: 0 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,6 @@ contract ExampleDcapContract {
}
}
// SNARK Attestation example
// ZkCoProcessorType can either be RiscZero or Succinct
function attestWithSnark(
bytes calldata output,
ZkCoProcessorType zkvm,
bytes calldata proofBytes
) public
{
(bool success, bytes memory output) = attest.verifyAndAttestWithZKProof(
output,
zkvm,
proofBytes
);
if (success) {
// ... implementation to handle successful attestations
} else {
string memory errorMessage = string(output);
// ... implementation to handle failed attestations
}
}
}
```

Expand Down
95 changes: 0 additions & 95 deletions contracts/AttestationEntrypointBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,11 @@ import "./types/Constants.sol";
import {Header} from "./types/CommonStruct.sol";
import {Ownable} from "solady/auth/Ownable.sol";

// ZK-Coprocessor imports:
import {IRiscZeroVerifier} from "risc0/IRiscZeroVerifier.sol";
import {ISP1Verifier} from "@sp1-contracts/ISP1Verifier.sol";

enum ZkCoProcessorType {
Unknown,
RiscZero,
Succinct
}

/**
* @title ZK Co-Processor Configuration Object
* @param dcapProgramIdentifier - This is the identifier of the ZK Program, required for
* verification
* @param zkVerifier - Points to the address of the ZK Verifier contract. Ideally
* this should be pointing to a universal verifier, that may support multiple proof types and/or versions.
*/
struct ZkCoProcessorConfig {
bytes32 dcapProgramIdentifier;
address zkVerifier;
}

/**
* @title DCAP Attestation Entrypoint Base contract
* @notice Provides full implementation of both on-chain and ZK DCAP Verification
*/
abstract contract AttestationEntrypointBase is Ownable {
// 51abd95c
error Unknown_Zk_Coprocessor();

mapping(ZkCoProcessorType => ZkCoProcessorConfig) _zkConfig;

mapping(uint16 quoteVersion => IQuoteVerifier verifier) public quoteVerifiers;

constructor() {
Expand All @@ -55,32 +28,6 @@ abstract contract AttestationEntrypointBase is Ownable {
quoteVerifiers[quoteVerifier.quoteVersion()] = quoteVerifier;
}

/**
* @notice Sets the ZK Configuration for the given ZK Co-Processor
*/
function setZkConfiguration(ZkCoProcessorType zkCoProcessor, ZkCoProcessorConfig memory config)
external
onlyOwner
{
_zkConfig[zkCoProcessor] = config;
}

/**
* @param zkCoProcessorType 1 - RiscZero, 2 - Succinct... etc.
* @return this is either the IMAGE_ID for RiscZero Guest Program or
* Succiinct Program Verifying Key
*/
function programIdentifier(uint8 zkCoProcessorType) external view returns (bytes32) {
return _zkConfig[ZkCoProcessorType(zkCoProcessorType)].dcapProgramIdentifier;
}

/**
* @notice get the contract verifier for the provided ZK Co-processor
*/
function zkVerifier(uint8 zkCoProcessorType) external view returns (address) {
return _zkConfig[ZkCoProcessorType(zkCoProcessorType)].zkVerifier;
}

/**
* @notice full on-chain verification for an attestation
* @param rawQuote - Intel DCAP Quote serialized in raw bytes
Expand All @@ -107,48 +54,6 @@ abstract contract AttestationEntrypointBase is Ownable {
(success, output) = quoteVerifier.verifyQuote(header, rawQuote);
}

/**
* @notice verifies an attestation using SNARK proofs
*
* @param output - The output of the Guest program, this includes:
* - VerifiedOutput struct
* - RootCA hash
* - TCB Signing CA hash
* - Root CRL hash
* - Platform or Processor CRL hash
* @param zkCoprocessor - Specify ZK Co-Processor
* @param proofBytes - The encoded cryptographic proof (i.e. SNARK)).
*/
function _verifyAndAttestWithZKProof(
bytes calldata output,
ZkCoProcessorType zkCoprocessor,
bytes calldata proofBytes
)
internal
view
returns (bool success, bytes memory verifiedOutput)
{
ZkCoProcessorConfig memory zkConfig = _zkConfig[zkCoprocessor];

if (zkCoprocessor == ZkCoProcessorType.RiscZero) {
IRiscZeroVerifier(zkConfig.zkVerifier).verify(
proofBytes, zkConfig.dcapProgramIdentifier, sha256(output)
);
} else if (zkCoprocessor == ZkCoProcessorType.Succinct) {
ISP1Verifier(zkConfig.zkVerifier).verifyProof(zkConfig.dcapProgramIdentifier, output, proofBytes);
} else {
revert Unknown_Zk_Coprocessor();
}

// verifies the output
uint16 version = uint16(bytes2(output[2:4]));
IQuoteVerifier quoteVerifier = quoteVerifiers[version];
if (address(quoteVerifier) == address(0)) {
return (false, bytes("Unsupported quote version"));
}
(success, verifiedOutput) = quoteVerifier.verifyZkOutput(output);
}

/**
* @notice Parses the header to get basic information about the quote, such as the version, TEE types etc.
*/
Expand Down
13 changes: 0 additions & 13 deletions contracts/AutomataDcapAttestationFee.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,4 @@ contract AutomataDcapAttestationFee is FeeManagerBase, AttestationEntrypointBase
{
(success, output) = _verifyAndAttestOnChain(rawQuote);
}

function verifyAndAttestWithZKProof(
bytes calldata output,
ZkCoProcessorType zkCoprocessor,
bytes calldata proofBytes
)
external
payable
collectFee
returns (bool success, bytes memory verifiedOutput)
{
(success, verifiedOutput) = _verifyAndAttestWithZKProof(output, zkCoprocessor, proofBytes);
}
}
5 changes: 0 additions & 5 deletions contracts/interfaces/IQuoteVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,4 @@ interface IQuoteVerifier {
function quoteVersion() external view returns (uint16);

function verifyQuote(Header calldata, bytes calldata) external view returns (bool, bytes memory);

/**
* @notice additional check on the public output obtained from the ZK Program execution
*/
function verifyZkOutput(bytes calldata) external view returns (bool, bytes memory);
}
15 changes: 0 additions & 15 deletions contracts/verifiers/V3QuoteVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,6 @@ import "../bases/tcb/TCBInfoV2Base.sol";
contract V3QuoteVerifier is QuoteVerifierBase, TCBInfoV2Base {
constructor(address _ecdsaVerifier, address _router) QuoteVerifierBase(_router, 3) P256Verifier(_ecdsaVerifier) {}

function verifyZkOutput(bytes calldata outputBytes)
external
view
override
returns (bool success, bytes memory output)
{
uint256 offset = 2 + uint16(bytes2(outputBytes[0:2]));
success = checkCollateralHashes(offset + 72, outputBytes);
if (success) {
output = outputBytes[2:offset];
} else {
output = bytes("Found one or more collaterals mismatch");
}
}

function verifyQuote(Header calldata header, bytes calldata rawQuote)
external
view
Expand Down
21 changes: 0 additions & 21 deletions contracts/verifiers/V4QuoteVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,6 @@ contract V4QuoteVerifier is QuoteVerifierBase, TCBInfoV3Base, TDXModuleBase {

constructor(address _ecdsaVerifier, address _router) QuoteVerifierBase(_router, 4) P256Verifier(_ecdsaVerifier) {}

function verifyZkOutput(bytes calldata outputBytes)
external
view
override
returns (bool success, bytes memory output)
{
bytes4 teeType = bytes4(outputBytes[4:8]);
if (teeType != SGX_TEE && teeType != TDX_TEE) {
return (false, bytes("Unknown TEE type"));
}

uint256 offset = 2 + uint16(bytes2(outputBytes[0:2]));

success = checkCollateralHashes(offset + 72, outputBytes);
if (success) {
output = outputBytes[2:offset];
} else {
output = bytes("Found one or more collaterals mismatch");
}
}

function verifyQuote(Header calldata header, bytes calldata rawQuote)
external
view
Expand Down
24 changes: 0 additions & 24 deletions env/.arbitrum-one.env.example

This file was deleted.

25 changes: 0 additions & 25 deletions env/.arbitrum-sepolia.env.example

This file was deleted.

24 changes: 0 additions & 24 deletions env/.base-mainnet.env.example

This file was deleted.

24 changes: 0 additions & 24 deletions env/.base-sepolia.env.example

This file was deleted.

5 changes: 0 additions & 5 deletions env/.ethereum-mainnet.env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
RPC_URL="https://1rpc.io/eth"
PRIVATE_KEY=0x
ETHERSCAN_OG_API_KEY=""
DCAP_RISCZERO_IMAGE_ID=0x83613a8beec226d1f29714530f1df791fa16c2c4dfcf22c50ab7edac59ca637f
DCAP_SUCCINCT_VKEY=0x0043e4e0c286cf4a2c03472ca2384f35a008558bc5de4e0f39d1d1bc989badca

ENCLAVE_IDENTITY_HELPER=0x13BECaa512713Ac7C2d7a04ba221aD5E02D43DFE
FMSPC_TCB_HELPER=0xc99bF04C31bF3d026B5B47b2574FC19C1459B732
Expand All @@ -15,9 +13,6 @@ FMSPC_TCB_DAO=0x868c18869f68E0E0b0b7B2B4439f7fDDd0421e6b
PCK_DAO=0xeCc198936FcA3Ca1fDc97B8612B32185908917B0
PCS_DAO=0x86f8865BCe8BE62CB8096b5B94fA3fB3a6ED330c

RISC0_VERIFIER=0x8EaB2D97Dfce405A1692a21b3ff3A172d593D319
SP1_VERIFIER_GATEWAY=0xD3dc607EfDfB758c0dcB47CA7BD6f22a1257606d

PCCS_ROUTER=0x09bBC921be046726bb5b694A49888e4e2e7AA9C3
DCAP_ATTESTATION=0xE26E11B257856B0bEBc4C759aaBDdea72B64351F
V3_VERIFIER=0xF38a49322cAA0Ead71D4B1cF2afBb6d02BE5FC96
Expand Down
5 changes: 0 additions & 5 deletions env/.holesky.env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
RPC_URL="https://1rpc.io/holesky"
PRIVATE_KEY=0x
ETHERSCAN_OG_API_KEY=""
DCAP_RISCZERO_IMAGE_ID=0x83613a8beec226d1f29714530f1df791fa16c2c4dfcf22c50ab7edac59ca637f
DCAP_SUCCINCT_VKEY=0x0043e4e0c286cf4a2c03472ca2384f35a008558bc5de4e0f39d1d1bc989badca

ENCLAVE_IDENTITY_HELPER=0xae27D762EED6958bc34b358bd7C78c7211fe77F8
FMSPC_TCB_HELPER=0x71056B540b4E60D0E8eFb55FAd487C486B09FFF5
Expand All @@ -15,9 +13,6 @@ FMSPC_TCB_DAO=0x9c54C72867b07caF2e6255CE32983c28aFE40F26
PCK_DAO=0x31F18aA7B4cbAD7A726BCBF5AB3e286fC0b02A82
PCS_DAO=0xcf171ACd6c0a776f9d3E1F6Cac8067c982Ac6Ce1

RISC0_VERIFIER=0xf70aBAb028Eb6F4100A24B203E113D94E87DE93C
SP1_VERIFIER_GATEWAY=0xD3dc607EfDfB758c0dcB47CA7BD6f22a1257606d

PCCS_ROUTER=0x729E3e7542E8A6630818E9a14A67e0Cb7008a5E5
DCAP_ATTESTATION=0xaEd8bF5907fC8690b1cb70DFD459Ca5Ed1529246
V3_VERIFIER=0x4613038C93aF8963dc9E5e46c9fb3cbc68724df1
Expand Down
Loading

0 comments on commit 1168b05

Please sign in to comment.