Skip to content

Commit 91c954c

Browse files
feat: add proving system to vk or program code commitment (#939)
Co-authored-by: MauroFab <[email protected]>
1 parent 19af490 commit 91c954c

File tree

7 files changed

+56
-37
lines changed

7 files changed

+56
-37
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ batcher_send_plonk_bn254_burst: batcher/target/release/aligned
296296
--vk ../../scripts/test_files/gnark_plonk_bn254_script/plonk.vk \
297297
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
298298
--rpc_url $(RPC_URL) \
299+
--repetitions 4 \
299300
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
300301

301302
batcher_send_plonk_bls12_381_task: batcher/target/release/aligned

batcher/aligned-sdk/src/core/types.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,32 +91,40 @@ impl From<VerificationData> for VerificationDataCommitment {
9191
fn from(verification_data: VerificationData) -> Self {
9292
let mut hasher = Keccak256::new();
9393

94-
// compute proof commitment
94+
// Compute proof commitment
95+
9596
hasher.update(verification_data.proof.as_slice());
9697
let proof_commitment = hasher.finalize_reset().into();
9798

98-
// compute public input commitment
99+
// Compute public input commitment
100+
99101
let mut pub_input_commitment = [0u8; 32];
100102
if let Some(pub_input) = &verification_data.pub_input {
101103
hasher.update(pub_input);
102104
pub_input_commitment = hasher.finalize_reset().into();
103105
}
104106

105-
// compute proving system auxiliary data commitment
106-
let mut proving_system_aux_data_commitment = [0u8; 32];
107+
// Compute proving system auxiliary data commitment
108+
107109
// FIXME(marian): This should probably be reworked, for the moment when the proving
108-
// system is SP1, `proving_system_aux_data` stands for the compiled ELF, while in the case
109-
// of Groth16 and PLONK, stands for the verification key.
110-
111-
if let Some(vm_program_code) = &verification_data.vm_program_code {
112-
hasher.update(vm_program_code);
113-
proving_system_aux_data_commitment = hasher.finalize_reset().into();
114-
} else if let Some(verification_key) = &verification_data.verification_key {
115-
hasher.update(verification_key);
116-
proving_system_aux_data_commitment = hasher.finalize_reset().into();
117-
}
110+
// system is SP1 or Risc0, `proving_system_aux_data` stands for information related to the
111+
// compiled ELF, while in the rest of the proving systems, stands for the verification key.
112+
let proving_system_byte = verification_data.proving_system as u8;
113+
let proving_system_aux_data_commitment =
114+
if let Some(vm_program_code) = &verification_data.vm_program_code {
115+
hasher.update(vm_program_code);
116+
hasher.update([proving_system_byte]);
117+
hasher.finalize_reset().into()
118+
} else if let Some(verification_key) = &verification_data.verification_key {
119+
hasher.update(verification_key);
120+
hasher.update([proving_system_byte]);
121+
hasher.finalize_reset().into()
122+
} else {
123+
[0u8; 32]
124+
};
125+
126+
// Serialize proof generator address to bytes
118127

119-
// serialize proof generator address to bytes
120128
let proof_generator_addr = verification_data.proof_generator_addr.into();
121129

122130
VerificationDataCommitment {

batcher/aligned-sdk/src/sdk.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use crate::{
66
},
77
core::{
88
errors,
9-
types::{AlignedVerificationData, Chain, VerificationData, VerificationDataCommitment},
9+
types::{
10+
AlignedVerificationData, Chain, ProvingSystemId, VerificationData,
11+
VerificationDataCommitment,
12+
},
1013
},
1114
eth::{
1215
aligned_service_manager::aligned_service_manager,
@@ -415,16 +418,22 @@ async fn _is_proof_verified(
415418
Ok(result)
416419
}
417420

418-
/// Returns the commitment for a given input. Input can be verification key, public input, etc.
421+
/// Returns the commitment for the verification key, taking into account the corresponding proving system.
419422
/// # Arguments
420-
/// * `content` - The content for which the commitment will be calculated.
423+
/// * `verification_key_bytes` - The serialized contents of the verification key.
424+
/// * `proving_system` - The corresponding proving system ID.
421425
/// # Returns
422426
/// * The commitment.
423427
/// # Errors
424428
/// * None.
425-
pub fn get_commitment(content: &[u8]) -> [u8; 32] {
429+
pub fn get_vk_commitment(
430+
verification_key_bytes: &[u8],
431+
proving_system: ProvingSystemId,
432+
) -> [u8; 32] {
433+
let proving_system_id_byte = proving_system.clone() as u8;
426434
let mut hasher = Keccak256::new();
427-
hasher.update(content);
435+
hasher.update(verification_key_bytes);
436+
hasher.update([proving_system_id_byte]);
428437
hasher.finalize().into()
429438
}
430439

batcher/aligned/src/main.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use aligned_sdk::core::{
1414
};
1515
use aligned_sdk::sdk::get_chain_id;
1616
use aligned_sdk::sdk::get_next_nonce;
17-
use aligned_sdk::sdk::{get_commitment, is_proof_verified, submit_multiple};
17+
use aligned_sdk::sdk::{get_vk_commitment, is_proof_verified, submit_multiple};
1818
use clap::Parser;
1919
use clap::Subcommand;
2020
use clap::ValueEnum;
@@ -28,8 +28,8 @@ use log::{error, info};
2828
use transaction::eip2718::TypedTransaction;
2929

3030
use crate::AlignedCommands::DepositToBatcher;
31-
use crate::AlignedCommands::GetCommitment;
3231
use crate::AlignedCommands::GetUserBalance;
32+
use crate::AlignedCommands::GetVkCommitment;
3333
use crate::AlignedCommands::Submit;
3434
use crate::AlignedCommands::VerifyProofOnchain;
3535

@@ -47,10 +47,8 @@ pub enum AlignedCommands {
4747
Submit(SubmitArgs),
4848
#[clap(about = "Verify the proof was included in a verified batch on Ethereum")]
4949
VerifyProofOnchain(VerifyProofOnchainArgs),
50-
51-
// Get commitment for file, command name is get-commitment
52-
#[clap(about = "Get commitment for file", name = "get-commitment")]
53-
GetCommitment(GetCommitmentArgs),
50+
#[clap(about = "Get commitment for file", name = "get-vk-commitment")]
51+
GetVkCommitment(GetVkCommitmentArgs),
5452
#[clap(
5553
about = "Deposits Ethereum in the batcher to pay for proofs",
5654
name = "deposit-to-batcher"
@@ -187,9 +185,11 @@ pub struct VerifyProofOnchainArgs {
187185

188186
#[derive(Parser, Debug)]
189187
#[command(version, about, long_about = None)]
190-
pub struct GetCommitmentArgs {
191-
#[arg(name = "File name", long = "input")]
192-
input_file: PathBuf,
188+
pub struct GetVkCommitmentArgs {
189+
#[arg(name = "Verification key file path", long = "verification_key_file")]
190+
verification_key_file: PathBuf,
191+
#[arg(name = "Proving system", long = "proving_system")]
192+
proving_system: ProvingSystemArg,
193193
#[arg(name = "Output file", long = "output")]
194194
output_file: Option<PathBuf>,
195195
}
@@ -409,17 +409,18 @@ async fn main() -> Result<(), AlignedError> {
409409
info!("Your proof was not included in the batch.");
410410
}
411411
}
412-
GetCommitment(args) => {
413-
let content = read_file(args.input_file)?;
412+
GetVkCommitment(args) => {
413+
let verification_key_bytes = read_file(args.verification_key_file)?;
414+
let proving_system = args.proving_system.into();
414415

415-
let hash = get_commitment(&content);
416+
let vk_commitment = get_vk_commitment(&verification_key_bytes, proving_system);
416417

417-
info!("Commitment: {}", hex::encode(hash));
418+
info!("Commitment: {}", hex::encode(vk_commitment));
418419
if let Some(output_file) = args.output_file {
419420
let mut file = File::create(output_file.clone())
420421
.map_err(|e| SubmitError::IoError(output_file.clone(), e))?;
421422

422-
file.write_all(hex::encode(hash).as_bytes())
423+
file.write_all(hex::encode(vk_commitment).as_bytes())
423424
.map_err(|e| SubmitError::IoError(output_file.clone(), e))?;
424425
}
425426
}

docs/2_architecture/1_fast_mode.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ The root of the Merkle tree is posted to Ethereum together with a pointer to whe
6565
Each leaf contains the following information:
6666

6767
- A commitment to the public input of the proof.
68-
- A commitment to the proof and information about the proof system.
69-
- A commitment to the program or a commitment to the verification key (depending on the proof system used).
68+
- A commitment to the proof
69+
- A commitment to the program or a commitment to the verification key, plus the Proving System/verifier used.
7070
- The address of the proof’s generator/submitter (optional).
7171

7272
A diagram for the batch is shown on the figure below:

docs/3_guides/2_integrating_aligned_into_your_application.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The Aligned CLI provides a way for you to get the verification key commitment wi
2525
You can do this by running the following command:
2626

2727
```bash
28-
aligned get-commitment --input <path_to_input_file>
28+
aligned get-vk-commitment --verification_key_file <path_to_input_file> --proving_system <proving_system_id>
2929
```
3030

3131
The following is an example of how to call the `verifyBatchInclusionMethod` from the `AlignedServiceManager` contract in your smart contract.

docs/images/batch.png

-101 KB
Loading

0 commit comments

Comments
 (0)