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

Commit ee2fd0b

Browse files
authored
ZK-818: remove trapdoor (#91)
1 parent 956e129 commit ee2fd0b

File tree

10 files changed

+8
-56
lines changed

10 files changed

+8
-56
lines changed

crates/shielder-circuits/src/chips/note.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ pub struct Note<T> {
2424
pub version: NoteVersion,
2525
pub id: T,
2626
pub nullifier: T,
27-
pub trapdoor: T,
2827
pub account_balance: T,
2928
pub token_address: T,
3029
}
@@ -43,7 +42,6 @@ impl Embed for Note<Value> {
4342
version: self.version,
4443
id: self.id.embed(synthesizer, annotation.clone())?,
4544
nullifier: self.nullifier.embed(synthesizer, annotation.clone())?,
46-
trapdoor: self.trapdoor.embed(synthesizer, annotation.clone())?,
4745
account_balance: self
4846
.account_balance
4947
.embed(synthesizer, annotation.clone())?,
@@ -72,7 +70,6 @@ pub mod off_circuit {
7270
note.version.as_field(),
7371
note.id,
7472
note.nullifier,
75-
note.trapdoor,
7673
balance_hash,
7774
];
7875

@@ -101,7 +98,7 @@ impl NoteChip {
10198

10299
/// Calculates the note_hash as follows:
103100
///
104-
/// `note_hash = poseidon2(NOTE_VERSION, note.id, note.nullifier, note.trapdoor,
101+
/// `note_hash = poseidon2(NOTE_VERSION, note.id, note.nullifier,
105102
/// poseidon2(note.balance, note.token_address, 0, 0, 0, 0, 0))`
106103
///
107104
/// The reason for the double nesting and for the padding is historical: we keep this hash shape
@@ -126,7 +123,6 @@ impl NoteChip {
126123
note_version,
127124
note.id.clone(),
128125
note.nullifier.clone(),
129-
note.trapdoor.clone(),
130126
h_balance,
131127
];
132128

@@ -223,7 +219,6 @@ mod tests {
223219
version: note.version,
224220
id: Value::known(note.id.into()),
225221
nullifier: Value::known(note.nullifier.into()),
226-
trapdoor: Value::known(note.trapdoor.into()),
227222
account_balance: Value::known(note.account_balance.into()),
228223
token_address: Value::known(note.token_address.into()),
229224
})
@@ -281,7 +276,6 @@ mod tests {
281276
version: NoteVersion::new(0),
282277
id: Value::unknown(),
283278
nullifier: Value::unknown(),
284-
trapdoor: Value::unknown(),
285279
account_balance: Value::unknown(),
286280
token_address: Value::unknown(),
287281
}),
@@ -350,17 +344,15 @@ mod tests {
350344
version: NoteVersion::new(0),
351345
id: Fr::from(1),
352346
nullifier: Fr::from(2),
353-
trapdoor: Fr::from(3),
354-
account_balance: Fr::from(4),
347+
account_balance: Fr::from(3),
355348
token_address,
356349
});
357350
let expected_output = hash(&[
358351
Fr::from(0),
359352
Fr::from(1),
360353
Fr::from(2),
361-
Fr::from(3),
362354
hash(&[
363-
Fr::from(4),
355+
Fr::from(3),
364356
token_address,
365357
Fr::ZERO,
366358
Fr::ZERO,
@@ -380,11 +372,10 @@ mod tests {
380372
version: NoteVersion::new(0),
381373
id: Fr::from(1),
382374
nullifier: Fr::from(2),
383-
trapdoor: Fr::from(3),
384-
account_balance: Fr::from(4),
385-
token_address: Fr::from(5),
375+
account_balance: Fr::from(3),
376+
token_address: Fr::from(4),
386377
});
387-
let pub_input = [Fr::from(5), Fr::from(999999)];
378+
let pub_input = [Fr::from(4), Fr::from(999999)];
388379

389380
let failures = expect_prover_success_and_run_verification(circuit, &pub_input)
390381
.expect_err("Verification must fail");
@@ -402,9 +393,8 @@ mod tests {
402393
version: NoteVersion::new(0),
403394
id: Fr::from(1),
404395
nullifier: Fr::from(2),
405-
trapdoor: Fr::from(3),
406-
account_balance: Fr::from(4),
407-
token_address: Fr::from(5),
396+
account_balance: Fr::from(3),
397+
token_address: Fr::from(4),
408398
};
409399
let circuit = TestCircuit::note_hash_test(note);
410400
let pub_input = [Fr::from(999999), super::off_circuit::note_hash(&note)];

crates/shielder-circuits/src/circuits/deposit/chip.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ impl DepositChip {
4040
version: NOTE_VERSION,
4141
id: knowledge.id.clone(),
4242
nullifier: knowledge.nullifier_old.clone(),
43-
trapdoor: knowledge.trapdoor_old.clone(),
4443
account_balance: knowledge.account_old_balance.clone(),
4544
token_address: knowledge.token_address.clone(),
4645
},
@@ -89,7 +88,6 @@ impl DepositChip {
8988
version: NOTE_VERSION,
9089
id: knowledge.id.clone(),
9190
nullifier: knowledge.nullifier_new.clone(),
92-
trapdoor: knowledge.trapdoor_new.clone(),
9391
account_balance: account_balance_new,
9492
token_address: knowledge.token_address.clone(),
9593
},

crates/shielder-circuits/src/circuits/deposit/circuit.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ mod tests {
160160
version: NOTE_VERSION,
161161
id: pk.id,
162162
nullifier: pk.nullifier_old,
163-
trapdoor: pk.trapdoor_old,
164163
account_balance: pk.account_old_balance,
165164
token_address: pk.token_address,
166165
}) + modification /* Modification here! */;
@@ -178,7 +177,6 @@ mod tests {
178177
version: NOTE_VERSION,
179178
id: pk.id,
180179
nullifier: pk.nullifier_new,
181-
trapdoor: pk.trapdoor_new,
182180
account_balance: account_balance_new,
183181
token_address: pk.token_address,
184182
});
@@ -219,7 +217,6 @@ mod tests {
219217
version: NoteVersion::new(0),
220218
id: pk.id,
221219
nullifier: pk.nullifier_old,
222-
trapdoor: pk.trapdoor_old,
223220
account_balance: pk.account_old_balance,
224221
token_address: pk.token_address,
225222
});
@@ -242,7 +239,6 @@ mod tests {
242239
Fr::ZERO, // Note version.
243240
pk.id,
244241
pk.nullifier_new,
245-
pk.trapdoor_new,
246242
new_balance_hash,
247243
]);
248244
assert_eq!(new_note_hash, pub_input[2]);

crates/shielder-circuits/src/circuits/deposit/knowledge.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ pub struct DepositProverKnowledge<T> {
2828
// Old note
2929
pub id: T,
3030
pub nullifier_old: T,
31-
pub trapdoor_old: T,
3231
pub account_old_balance: T,
3332
pub token_address: T,
3433

@@ -37,7 +36,6 @@ pub struct DepositProverKnowledge<T> {
3736

3837
// New note
3938
pub nullifier_new: T,
40-
pub trapdoor_new: T,
4139

4240
// Salt for MAC.
4341
pub mac_salt: T,
@@ -56,27 +54,23 @@ impl ProverKnowledge for DepositProverKnowledge<Fr> {
5654
let id = curve_arithmetic::generate_user_id(Fr::random(&mut *rng).to_bytes());
5755

5856
let nullifier_old = Fr::random(&mut *rng);
59-
let trapdoor_old = Fr::random(&mut *rng);
6057
let account_old_balance = Fr::from(10);
6158
let token_address = Fr::ZERO;
6259
let h_note_old = note_hash(&Note {
6360
version: NOTE_VERSION,
6461
id,
6562
nullifier: nullifier_old,
66-
trapdoor: trapdoor_old,
6763
account_balance: account_old_balance,
6864
token_address,
6965
});
7066
let (_, path) = generate_example_path_with_given_leaf(h_note_old, &mut *rng);
7167
Self {
7268
id,
7369
nullifier_old,
74-
trapdoor_old,
7570
account_old_balance,
7671
token_address,
7772
path,
7873
nullifier_new: Fr::random(&mut *rng),
79-
trapdoor_new: Fr::random(&mut *rng),
8074
deposit_value: Fr::ONE,
8175
mac_salt: Fr::random(&mut *rng),
8276
caller_address: Fr::random(rng),
@@ -85,8 +79,6 @@ impl ProverKnowledge for DepositProverKnowledge<Fr> {
8579

8680
fn create_circuit(&self) -> Self::Circuit {
8781
DepositCircuit(DepositProverKnowledge {
88-
trapdoor_new: Value::known(self.trapdoor_new),
89-
trapdoor_old: Value::known(self.trapdoor_old),
9082
nullifier_new: Value::known(self.nullifier_new),
9183
nullifier_old: Value::known(self.nullifier_old),
9284
account_old_balance: Value::known(self.account_old_balance),
@@ -111,7 +103,6 @@ impl PublicInputProvider<DepositInstance> for DepositProverKnowledge<Fr> {
111103
version: NOTE_VERSION,
112104
id: self.id,
113105
nullifier: self.nullifier_new,
114-
trapdoor: self.trapdoor_new,
115106
account_balance: self.account_old_balance + self.deposit_value,
116107
token_address: self.token_address,
117108
}),

crates/shielder-circuits/src/circuits/new_account/chip.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ impl NewAccountChip {
4444
version: NOTE_VERSION,
4545
id: knowledge.id.clone(),
4646
nullifier: knowledge.nullifier.clone(),
47-
trapdoor: knowledge.trapdoor.clone(),
4847
account_balance: knowledge.initial_deposit.clone(),
4948
token_address: knowledge.token_address.clone(),
5049
},

crates/shielder-circuits/src/circuits/new_account/circuit.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ mod tests {
115115
Fr::ZERO, // Note version.
116116
pk.id,
117117
pk.nullifier,
118-
pk.trapdoor,
119118
balance_hash,
120119
]);
121120
assert_eq!(note_hash, pub_input[0]);

crates/shielder-circuits/src/circuits/new_account/knowledge.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use crate::{
2626
pub struct NewAccountProverKnowledge<T> {
2727
pub id: T,
2828
pub nullifier: T,
29-
pub trapdoor: T,
3029
pub initial_deposit: T,
3130
pub caller_address: T,
3231
pub token_address: T,
@@ -40,7 +39,6 @@ impl<T: Default + Copy> Default for NewAccountProverKnowledge<T> {
4039
Self {
4140
id: T::default(),
4241
nullifier: T::default(),
43-
trapdoor: T::default(),
4442
initial_deposit: T::default(),
4543
caller_address: T::default(),
4644
token_address: T::default(),
@@ -59,7 +57,6 @@ impl ProverKnowledge for NewAccountProverKnowledge<Fr> {
5957
Self {
6058
id: curve_arithmetic::generate_user_id(Fr::random(&mut *rng).to_bytes()),
6159
nullifier: Fr::random(&mut *rng),
62-
trapdoor: Fr::random(&mut *rng),
6360
initial_deposit: Fr::ONE,
6461
caller_address: Fr::random(&mut *rng),
6562
token_address: Fr::ZERO,
@@ -72,7 +69,6 @@ impl ProverKnowledge for NewAccountProverKnowledge<Fr> {
7269
fn create_circuit(&self) -> Self::Circuit {
7370
NewAccountCircuit(NewAccountProverKnowledge {
7471
id: Value::known(self.id),
75-
trapdoor: Value::known(self.trapdoor),
7672
nullifier: Value::known(self.nullifier),
7773
initial_deposit: Value::known(self.initial_deposit),
7874
caller_address: Value::known(self.caller_address),
@@ -110,7 +106,6 @@ impl PublicInputProvider<NewAccountInstance> for NewAccountProverKnowledge<Fr> {
110106
version: NOTE_VERSION,
111107
id: self.id,
112108
nullifier: self.nullifier,
113-
trapdoor: self.trapdoor,
114109
account_balance: self.initial_deposit,
115110
token_address: self.token_address,
116111
}),

crates/shielder-circuits/src/circuits/withdraw/chip.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ impl WithdrawChip {
4343
version: NOTE_VERSION,
4444
id: knowledge.id.clone(),
4545
nullifier: knowledge.nullifier_old.clone(),
46-
trapdoor: knowledge.trapdoor_old.clone(),
4746
account_balance: knowledge.account_old_balance.clone(),
4847
token_address: knowledge.token_address.clone(),
4948
},
@@ -95,7 +94,6 @@ impl WithdrawChip {
9594
version: NOTE_VERSION,
9695
id: knowledge.id.clone(),
9796
nullifier: knowledge.nullifier_new.clone(),
98-
trapdoor: knowledge.trapdoor_new.clone(),
9997
account_balance: new_balance,
10098
token_address: knowledge.token_address.clone(),
10199
},

crates/shielder-circuits/src/circuits/withdraw/circuit.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ mod tests {
106106
version: NoteVersion::new(0),
107107
id: pk.id,
108108
nullifier: pk.nullifier_old,
109-
trapdoor: pk.trapdoor_old,
110109
account_balance: pk.account_old_balance,
111110
token_address: pk.token_address,
112111
});
@@ -129,7 +128,6 @@ mod tests {
129128
Fr::ZERO, // Note version.
130129
pk.id,
131130
pk.nullifier_new,
132-
pk.trapdoor_new,
133131
new_balance_hash,
134132
]);
135133
assert_eq!(new_note_hash, pub_input[2]);
@@ -207,7 +205,6 @@ mod tests {
207205
version: NOTE_VERSION,
208206
id: pk.id,
209207
nullifier: pk.nullifier_old,
210-
trapdoor: pk.trapdoor_old,
211208
account_balance: pk.account_old_balance,
212209
token_address: pk.token_address,
213210
}) + modification /* Modification here! */;
@@ -225,7 +222,6 @@ mod tests {
225222
version: NOTE_VERSION,
226223
id: pk.id,
227224
nullifier: pk.nullifier_new,
228-
trapdoor: pk.trapdoor_new,
229225
account_balance: account_balance_new,
230226
token_address: pk.token_address,
231227
});

crates/shielder-circuits/src/circuits/withdraw/knowledge.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ pub struct WithdrawProverKnowledge<T> {
3232
// Old note
3333
pub id: T,
3434
pub nullifier_old: T,
35-
pub trapdoor_old: T,
3635
pub account_old_balance: T,
3736
pub token_address: T,
3837

@@ -41,7 +40,6 @@ pub struct WithdrawProverKnowledge<T> {
4140

4241
// New note
4342
pub nullifier_new: T,
44-
pub trapdoor_new: T,
4543

4644
// Salt for MAC.
4745
pub mac_salt: T,
@@ -63,15 +61,13 @@ impl ProverKnowledge for WithdrawProverKnowledge<Fr> {
6361
fn random_correct_example(rng: &mut impl RngCore) -> Self {
6462
let id = curve_arithmetic::generate_user_id(Fr::random(&mut *rng).to_bytes());
6563
let nullifier_old = Fr::random(&mut *rng);
66-
let trapdoor_old = Fr::random(&mut *rng);
6764

6865
let account_old_balance = Fr::from_u128(MAX_ACCOUNT_BALANCE_PASSING_RANGE_CHECK);
6966
let token_address = Fr::ZERO;
7067
let h_note_old = note_hash(&Note {
7168
version: NOTE_VERSION,
7269
id,
7370
nullifier: nullifier_old,
74-
trapdoor: trapdoor_old,
7571
account_balance: account_old_balance,
7672
token_address,
7773
});
@@ -83,21 +79,16 @@ impl ProverKnowledge for WithdrawProverKnowledge<Fr> {
8379
commitment: Fr::random(&mut *rng),
8480
id,
8581
nullifier_old,
86-
trapdoor_old,
8782
account_old_balance,
8883
token_address,
8984
path,
9085
nullifier_new: Fr::random(&mut *rng),
91-
trapdoor_new: Fr::random(&mut *rng),
9286
mac_salt: Fr::random(rng),
9387
}
9488
}
9589

9690
fn create_circuit(&self) -> Self::Circuit {
9791
WithdrawCircuit(WithdrawProverKnowledge {
98-
trapdoor_new: Value::known(self.trapdoor_new),
99-
trapdoor_old: Value::known(self.trapdoor_old),
100-
10192
nullifier_new: Value::known(self.nullifier_new),
10293
nullifier_old: Value::known(self.nullifier_old),
10394

@@ -126,7 +117,6 @@ impl PublicInputProvider<WithdrawInstance> for WithdrawProverKnowledge<Fr> {
126117
version: NOTE_VERSION,
127118
id: self.id,
128119
nullifier: self.nullifier_new,
129-
trapdoor: self.trapdoor_new,
130120
account_balance: self.account_old_balance - self.withdrawal_value,
131121
token_address: self.token_address,
132122
}),

0 commit comments

Comments
 (0)