Skip to content

Commit 6b33f80

Browse files
committed
feat: proving system id for proof commitments
1 parent b0d2a13 commit 6b33f80

File tree

10 files changed

+41
-16
lines changed

10 files changed

+41
-16
lines changed

aggregation_mode/aggregation_programs/risc0/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct Risc0ImageIdAndPubInputs {
1111
impl Risc0ImageIdAndPubInputs {
1212
pub fn commitment(&self) -> [u8; 32] {
1313
let mut hasher = Keccak::v256();
14+
hasher.update(&[1u8]);
1415
for &word in &self.image_id {
1516
hasher.update(&word.to_be_bytes());
1617
}

aggregation_mode/aggregation_programs/sp1/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct SP1VkAndPubInputs {
1111
impl SP1VkAndPubInputs {
1212
pub fn commitment(&self) -> [u8; 32] {
1313
let mut hasher = Keccak256::new();
14+
hasher.update(&[0u8]);
1415
for &word in &self.vk {
1516
hasher.update(word.to_be_bytes());
1617
}

aggregation_mode/src/aggregators/risc0_aggregator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub const RISC0_CHUNK_AGGREGATOR_PROGRAM_ID_BYTES: [u8; 32] = {
8080
impl Risc0ProofReceiptAndImageId {
8181
pub fn hash_image_id_and_public_inputs(&self) -> [u8; 32] {
8282
let mut hasher = Keccak256::new();
83+
hasher.update(&[1u8]);
8384
hasher.update(self.image_id);
8485
hasher.update(self.public_inputs());
8586
hasher.finalize().into()

aggregation_mode/src/aggregators/sp1_aggregator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ impl SP1ProofWithPubValuesAndElf {
6363

6464
pub fn hash_vk_and_pub_inputs(&self) -> [u8; 32] {
6565
let mut hasher = Keccak256::new();
66+
hasher.update(&[0u8]);
6667
let vk_bytes = &self.vk.hash_bytes();
6768
hasher.update(vk_bytes);
6869
hasher.update(self.proof_with_pub_values.public_values.as_slice());

contracts/src/core/AlignedProofAggregationService.sol

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,18 @@ contract AlignedProofAggregationService is
111111
/// - The function returns `true` if this Merkle root is known to correspond to a valid aggregated proof.
112112
///
113113
/// @param merklePath The Merkle proof (sibling hashes) needed to reconstruct the Merkle root.
114+
/// @param provingSystemId The id of the proving system (0 for SP1, 1 for RISC0).
114115
/// @param programId The identifier for the ZK program (image_id in RISC0 or vk hash in SP1).
115116
/// @param publicInputs The public inputs bytes of the proof.
116117
///
117118
/// @return bool Returns true if the computed Merkle root is a recognized valid aggregated proof.
118-
function verifyProofInclusion(bytes32[] calldata merklePath, bytes32 programId, bytes calldata publicInputs)
119-
public
120-
view
121-
returns (bool)
122-
{
123-
bytes32 proofCommitment = keccak256(abi.encodePacked(programId, publicInputs));
119+
function verifyProofInclusion(
120+
bytes32[] calldata merklePath,
121+
uint256 provingSystemId,
122+
bytes32 programId,
123+
bytes calldata publicInputs
124+
) public view returns (bool) {
125+
bytes32 proofCommitment = keccak256(abi.encodePacked(provingSystemId, programId, publicInputs));
124126
bytes32 merkleRoot = MerkleProof.processProofCalldata(merklePath, proofCommitment);
125127
return aggregatedProofs[merkleRoot];
126128
}

contracts/src/core/IAlignedProofAggregationService.sol

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ interface IAlignedProofAggregationService {
77

88
/// @notice Event emitted when the Risc0 verifier address is updated
99
event Risc0VerifierAddressUpdated(address indexed newAddress);
10-
10+
1111
/// @notice Event emitted when the SP1 verifier address is updated
1212
event SP1VerifierAddressUpdated(address indexed newAddress);
13-
13+
1414
/// @notice Event emitted when the Risc0 aggregator program image ID is updated
1515
event Risc0AggregatorProgramImageIdUpdated(bytes32 indexed newImageId);
16-
16+
1717
/// @notice Event emitted when the SP1 aggregator program VK hash is updated
1818
event SP1AggregatorProgramVKHashUpdated(bytes32 indexed newVKHash);
1919

@@ -29,10 +29,12 @@ interface IAlignedProofAggregationService {
2929
function verifyRisc0(bytes32 blobVersionedHash, bytes calldata risc0ReceiptSeal, bytes calldata risc0JournalBytes)
3030
external;
3131

32-
function verifyProofInclusion(bytes32[] calldata merklePath, bytes32 programId, bytes calldata publicInputs)
33-
external
34-
view
35-
returns (bool);
32+
function verifyProofInclusion(
33+
bytes32[] calldata merklePath,
34+
uint256 provingSystemId,
35+
bytes32 programId,
36+
bytes calldata publicInputs
37+
) external view returns (bool);
3638

3739
/// @notice Sets the address of the Risc0 verifier contract
3840
/// @param _risc0VerifierAddress The new address for the Risc0 verifier contract

crates/sdk/src/aggregation_layer/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ pub async fn is_proof_verified_on_chain(
128128
let res = contract_provider
129129
.verify_proof_inclusion(
130130
merkle_path,
131+
verification_data.proving_system_id().into(),
131132
verification_data.program_id(),
132133
Bytes::from(verification_data.public_inputs().clone()),
133134
)

crates/sdk/src/aggregation_layer/types.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,18 @@ impl AggregationModeVerificationData {
3030
}
3131
}
3232

33+
pub fn proving_system_id(&self) -> u8 {
34+
match self {
35+
Self::SP1 { .. } => 0u8,
36+
Self::Risc0 { .. } => 1u8,
37+
}
38+
}
39+
3340
pub fn commitment(&self) -> [u8; 32] {
3441
match self {
3542
AggregationModeVerificationData::SP1 { vk, public_inputs } => {
3643
let mut hasher = Keccak256::new();
44+
hasher.update(&[0u8]);
3745
hasher.update(vk);
3846
hasher.update(public_inputs);
3947
hasher.finalize().into()
@@ -43,6 +51,7 @@ impl AggregationModeVerificationData {
4351
public_inputs,
4452
} => {
4553
let mut hasher = Keccak256::new();
54+
hasher.update(&[1u8]);
4655
hasher.update(image_id);
4756
hasher.update(public_inputs);
4857
hasher.finalize().into()

examples/l2/contracts/src/StateTransition.sol

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ contract StateTransition {
2222
stateRoot = initialStateRoot;
2323
}
2424

25-
function updateState(bytes calldata publicInputs, bytes32[] calldata merkleProof) public onlyOwner {
25+
function updateState(uint256 provingSystemId, bytes calldata publicInputs, bytes32[] calldata merkleProof)
26+
public
27+
onlyOwner
28+
{
2629
bytes memory callData = abi.encodeWithSignature(
27-
"verifyProofInclusion(bytes32[],bytes32,bytes)", merkleProof, PROGRAM_ID, publicInputs
30+
"verifyProofInclusion(bytes32[],uint256,bytes32,bytes)",
31+
merkleProof,
32+
provingSystemId,
33+
PROGRAM_ID,
34+
publicInputs
2835
);
2936
(bool callResult, bytes memory response) = alignedProofAggregator.staticcall(callData);
3037
if (!callResult) {

examples/l2/crates/l2/src/eth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub async fn send_state_transition_to_chain(
3636
let merkle_proof = merkle_proof.iter().map(|e| e.into()).collect();
3737

3838
let res = state_transition_contract
39-
.updateState(public_inputs.into(), merkle_proof)
39+
.updateState(0u8.into(), public_inputs.into(), merkle_proof)
4040
.send()
4141
.await
4242
.expect("State transition tx to not revert");

0 commit comments

Comments
 (0)