Skip to content
This repository was archived by the owner on Aug 5, 2025. It is now read-only.

Rename caller_address to commitment #96

Merged
merged 1 commit into from
Jul 1, 2025
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
12 changes: 4 additions & 8 deletions crates/shielder-circuits/src/circuits/deposit/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ use crate::{
deposit::knowledge::DepositProverKnowledge,
merkle::{MerkleChip, MerkleProverKnowledge},
},
deposit::DepositInstance::{
self, CallerAddress, DepositValue, HashedNewNote, HashedOldNullifier,
},
deposit::DepositInstance::{self, Commitment, DepositValue, HashedNewNote, HashedOldNullifier},
instance_wrapper::InstanceWrapper,
poseidon::circuit::{hash, PoseidonChip},
synthesizer::Synthesizer,
Expand Down Expand Up @@ -115,14 +113,12 @@ impl DepositChip {
Ok(())
}

pub fn check_caller_address(
pub fn check_commitment(
&self,
synthesizer: &mut impl Synthesizer,
knowledge: &DepositProverKnowledge<AssignedCell>,
) -> Result<(), Error> {
self.public_inputs.constrain_cells(
synthesizer,
[(knowledge.caller_address.clone(), CallerAddress)],
)
self.public_inputs
.constrain_cells(synthesizer, [(knowledge.commitment.clone(), Commitment)])
}
}
8 changes: 4 additions & 4 deletions crates/shielder-circuits/src/circuits/deposit/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Circuit<Fr> for DepositCircuit {
main_chip.check_old_nullifier(&mut synthesizer, &knowledge)?;
main_chip.check_new_note(&mut synthesizer, &knowledge)?;
main_chip.check_mac(&mut synthesizer, &knowledge)?;
main_chip.check_caller_address(&mut synthesizer, &knowledge)
main_chip.check_commitment(&mut synthesizer, &knowledge)
}
}

Expand Down Expand Up @@ -188,7 +188,7 @@ mod tests {
// Important note: there is no range check in the circuit for DepositValue, however there is an external constraint
// (in the smart contract) guaranteeing that this never exceeds MAX_CONTRACT_BALANCE = 2^{112} - 1.
DepositValue => pk.deposit_value,
CallerAddress => pk.caller_address,
Commitment => pk.commitment,
TokenAddress => pk.token_address,
MacSalt => pk.mac_salt,
MacCommitment => hash(&[pk.mac_salt, off_circuit::derive_viewing_key(pk.id)]),
Expand Down Expand Up @@ -266,9 +266,9 @@ mod tests {
}

#[test]
fn fails_if_caller_address_is_incorrect() {
fn fails_if_commitment_is_incorrect() {
let pk = DepositProverKnowledge::random_correct_example(&mut OsRng);
let pub_input = pk.with_substitution(CallerAddress, |s| s + Fr::ONE);
let pub_input = pk.with_substitution(Commitment, |s| s + Fr::ONE);

assert!(
expect_prover_success_and_run_verification(pk.create_circuit(), &pub_input).is_err()
Expand Down
8 changes: 4 additions & 4 deletions crates/shielder-circuits/src/circuits/deposit/knowledge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct DepositProverKnowledge<T> {
pub mac_salt: T,

pub deposit_value: T,
pub caller_address: T,
pub commitment: T,
}

impl ProverKnowledge for DepositProverKnowledge<Fr> {
Expand Down Expand Up @@ -73,7 +73,7 @@ impl ProverKnowledge for DepositProverKnowledge<Fr> {
nullifier_new: Fr::random(&mut *rng),
deposit_value: Fr::ONE,
mac_salt: Fr::random(&mut *rng),
caller_address: Fr::random(rng),
commitment: Fr::random(rng),
}
}

Expand All @@ -87,7 +87,7 @@ impl ProverKnowledge for DepositProverKnowledge<Fr> {
path: self.path.map(|level| level.map(Value::known)),
deposit_value: Value::known(self.deposit_value),
mac_salt: Value::known(self.mac_salt),
caller_address: Value::known(self.caller_address),
commitment: Value::known(self.commitment),
})
}
}
Expand All @@ -107,7 +107,7 @@ impl PublicInputProvider<DepositInstance> for DepositProverKnowledge<Fr> {
token_address: self.token_address,
}),
DepositInstance::DepositValue => self.deposit_value,
DepositInstance::CallerAddress => self.caller_address,
DepositInstance::Commitment => self.commitment,
DepositInstance::TokenAddress => self.token_address,
DepositInstance::MacSalt => self.mac_salt,
DepositInstance::MacCommitment => hash(&[self.mac_salt, viewing_key]),
Expand Down
4 changes: 2 additions & 2 deletions crates/shielder-circuits/src/circuits/deposit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub enum DepositInstance {
HashedOldNullifier,
HashedNewNote,
DepositValue,
CallerAddress,
Commitment,
TokenAddress,
MacSalt,
MacCommitment,
Expand Down Expand Up @@ -73,7 +73,7 @@ mod tests {
HashedOldNullifier,
HashedNewNote,
DepositValue,
CallerAddress,
Commitment,
TokenAddress,
MacSalt,
MacCommitment,
Expand Down
8 changes: 3 additions & 5 deletions crates/shielder-circuits/src/circuits/new_account/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,12 @@ impl NewAccountChip {
Ok(())
}

pub fn check_caller_address(
pub fn check_commitment(
&self,
synthesizer: &mut impl Synthesizer,
knowledge: &NewAccountProverKnowledge<AssignedCell>,
) -> Result<(), Error> {
self.public_inputs.constrain_cells(
synthesizer,
[(knowledge.caller_address.clone(), CallerAddress)],
)
self.public_inputs
.constrain_cells(synthesizer, [(knowledge.commitment.clone(), Commitment)])
}
}
6 changes: 3 additions & 3 deletions crates/shielder-circuits/src/circuits/new_account/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl Circuit<Fr> for NewAccountCircuit {
main_chip.constrain_prenullifier(&mut synthesizer, &knowledge)?;
main_chip.constrain_encrypting_viewing_key(&mut synthesizer, &knowledge)?;
main_chip.check_mac(&mut synthesizer, &knowledge)?;
main_chip.check_caller_address(&mut synthesizer, &knowledge)
main_chip.check_commitment(&mut synthesizer, &knowledge)
}
}

Expand Down Expand Up @@ -173,9 +173,9 @@ mod tests {
}

#[test]
fn fails_if_caller_address_is_incorrect() {
fn fails_if_commitment_is_incorrect() {
let pk = NewAccountProverKnowledge::random_correct_example(&mut OsRng);
let pub_input = pk.with_substitution(CallerAddress, |s| s + Fr::ONE);
let pub_input = pk.with_substitution(Commitment, |s| s + Fr::ONE);

assert!(
expect_prover_success_and_run_verification(pk.create_circuit(), &pub_input).is_err()
Expand Down
10 changes: 5 additions & 5 deletions crates/shielder-circuits/src/circuits/new_account/knowledge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct NewAccountProverKnowledge<T> {
pub id: T,
pub nullifier: T,
pub initial_deposit: T,
pub caller_address: T,
pub commitment: T,
pub token_address: T,
pub encryption_salt: [T; FIELD_BITS],
pub anonymity_revoker_public_key: GrumpkinPointAffine<T>,
Expand All @@ -40,7 +40,7 @@ impl<T: Default + Copy> Default for NewAccountProverKnowledge<T> {
id: T::default(),
nullifier: T::default(),
initial_deposit: T::default(),
caller_address: T::default(),
commitment: T::default(),
token_address: T::default(),
encryption_salt: [T::default(); FIELD_BITS],
anonymity_revoker_public_key: GrumpkinPointAffine::default(),
Expand All @@ -58,7 +58,7 @@ impl ProverKnowledge for NewAccountProverKnowledge<Fr> {
id: curve_arithmetic::generate_user_id(Fr::random(&mut *rng).to_bytes()),
nullifier: Fr::random(&mut *rng),
initial_deposit: Fr::ONE,
caller_address: Fr::random(&mut *rng),
commitment: Fr::random(&mut *rng),
token_address: Fr::ZERO,
encryption_salt: field_element_to_le_bits(grumpkin::Fr::ONE),
anonymity_revoker_public_key: GrumpkinPointAffine::random(rng),
Expand All @@ -71,7 +71,7 @@ impl ProverKnowledge for NewAccountProverKnowledge<Fr> {
id: Value::known(self.id),
nullifier: Value::known(self.nullifier),
initial_deposit: Value::known(self.initial_deposit),
caller_address: Value::known(self.caller_address),
commitment: Value::known(self.commitment),
token_address: Value::known(self.token_address),
encryption_salt: self.encryption_salt.map(Value::known),
anonymity_revoker_public_key: GrumpkinPointAffine::new(
Expand Down Expand Up @@ -111,7 +111,7 @@ impl PublicInputProvider<NewAccountInstance> for NewAccountProverKnowledge<Fr> {
}),
NewAccountInstance::Prenullifier => hash(&[self.id]),
NewAccountInstance::InitialDeposit => self.initial_deposit,
NewAccountInstance::CallerAddress => self.caller_address,
NewAccountInstance::Commitment => self.commitment,
NewAccountInstance::TokenAddress => self.token_address,
NewAccountInstance::AnonymityRevokerPublicKeyX => self.anonymity_revoker_public_key.x,
NewAccountInstance::AnonymityRevokerPublicKeyY => self.anonymity_revoker_public_key.y,
Expand Down
4 changes: 2 additions & 2 deletions crates/shielder-circuits/src/circuits/new_account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub enum NewAccountInstance {
HashedNote,
Prenullifier,
InitialDeposit,
CallerAddress,
Commitment,
TokenAddress,
AnonymityRevokerPublicKeyX,
AnonymityRevokerPublicKeyY,
Expand Down Expand Up @@ -64,7 +64,7 @@ mod tests {
HashedNote,
Prenullifier,
InitialDeposit,
CallerAddress,
Commitment,
TokenAddress,
AnonymityRevokerPublicKeyX,
AnonymityRevokerPublicKeyY,
Expand Down