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

Commit 804c057

Browse files
PoW gone. (#83)
* PoW gone. * fixed tests and removed range check chip * a shot at fixing WF * my bad * ffs * show me * another CI try * yaml format * rollback changes * review comment --------- Co-authored-by: filip <fbielejec@gmail.com>
1 parent f72371e commit 804c057

File tree

15 files changed

+21
-112
lines changed

15 files changed

+21
-112
lines changed

.github/actions/prepare-rust-env/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ inputs:
66
ssh-private-key:
77
description: "SSH private key to authenticate with"
88
required: true
9+
910
runs:
1011
using: composite
1112
steps:

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

Lines changed: 0 additions & 41 deletions
This file was deleted.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
pub mod el_gamal;
2-
pub mod id_hiding;
32
pub mod mac;
43
pub mod note;
54
pub mod points_add;

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@ use DepositInstance::DepositValue;
33

44
use crate::{
55
chips::{
6-
id_hiding::IdHidingChip,
76
mac::{MacChip, MacInput},
87
note::{Note, NoteChip},
9-
range_check::RangeCheckChip,
108
sym_key::SymKeyChip,
119
},
1210
circuits::{
1311
deposit::knowledge::DepositProverKnowledge,
1412
merkle::{MerkleChip, MerkleProverKnowledge},
1513
},
16-
deposit::DepositInstance::{self, HashedNewNote, HashedOldNullifier, *},
14+
deposit::DepositInstance::{self, HashedNewNote, HashedOldNullifier},
1715
instance_wrapper::InstanceWrapper,
1816
poseidon::circuit::{hash, PoseidonChip},
1917
synthesizer::Synthesizer,
@@ -25,7 +23,6 @@ use crate::{
2523
pub struct DepositChip {
2624
pub public_inputs: InstanceWrapper<DepositInstance>,
2725
pub poseidon: PoseidonChip,
28-
pub range_check: RangeCheckChip,
2926
pub merkle: MerkleChip,
3027
pub note: NoteChip,
3128
}
@@ -69,17 +66,6 @@ impl DepositChip {
6966
.constrain_cells(synthesizer, [(hashed_old_nullifier, HashedOldNullifier)])
7067
}
7168

72-
pub fn check_id_hiding(
73-
&self,
74-
synthesizer: &mut impl Synthesizer,
75-
knowledge: &DepositProverKnowledge<AssignedCell>,
76-
) -> Result<(), Error> {
77-
let id_hiding = IdHidingChip::new(self.poseidon.clone(), self.range_check.clone())
78-
.id_hiding(synthesizer, knowledge.id.clone(), knowledge.nonce.clone())?;
79-
self.public_inputs
80-
.constrain_cells(synthesizer, [(id_hiding, IdHiding)])
81-
}
82-
8369
pub fn check_new_note(
8470
&self,
8571
synthesizer: &mut impl Synthesizer,

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@ impl Circuit<Fr> for DepositCircuit {
3131
let configs_builder = ConfigsBuilder::new(meta)
3232
.with_poseidon()
3333
.with_merkle(public_inputs.narrow())
34-
.with_range_check()
3534
.with_note(public_inputs.narrow());
3635

3736
(
3837
DepositChip {
3938
public_inputs,
4039
poseidon: configs_builder.poseidon_chip(),
4140
merkle: configs_builder.merkle_chip(),
42-
range_check: configs_builder.range_check_chip(),
4341
note: configs_builder.note_chip(),
4442
},
4543
configs_builder.finish(),
@@ -58,7 +56,6 @@ impl Circuit<Fr> for DepositCircuit {
5856
main_chip.check_old_note(&mut synthesizer, &knowledge)?;
5957
main_chip.check_old_nullifier(&mut synthesizer, &knowledge)?;
6058
main_chip.check_new_note(&mut synthesizer, &knowledge)?;
61-
main_chip.check_id_hiding(&mut synthesizer, &knowledge)?;
6259
main_chip.check_mac(&mut synthesizer, &knowledge)
6360
}
6461
}
@@ -186,10 +183,11 @@ mod tests {
186183
});
187184

188185
let pub_input = |instance: DepositInstance| match instance {
189-
IdHiding => hash(&[hash(&[pk.id]), pk.nonce]),
190186
MerkleRoot => merkle_root,
191187
HashedOldNullifier => h_nullifier_old,
192188
HashedNewNote => h_note_new,
189+
// Important note: there is no range check in the circuit for DepositValue, however there is an external constraint
190+
// (in the smart contract) guaranteeing that this never exceeds MAX_CONTRACT_BALANCE = 2^{112} - 1.
193191
DepositValue => pk.deposit_value,
194192
TokenAddress => pk.token_address,
195193
MacSalt => pk.mac_salt,
@@ -245,10 +243,10 @@ mod tests {
245243
pk.trapdoor_new,
246244
new_balance_hash,
247245
]);
248-
assert_eq!(new_note_hash, pub_input[3]);
246+
assert_eq!(new_note_hash, pub_input[2]);
249247

250248
// Verify the token address.
251-
assert_eq!(Fr::from(123), pub_input[5]);
249+
assert_eq!(Fr::from(123), pub_input[4]);
252250
}
253251

254252
#[test]
@@ -265,7 +263,7 @@ mod tests {
265263
// The returned failure location happens to be in
266264
// a `poseidon-gadget` region the token address was copied to.
267265
"add input for domain ConstantLength<7>",
268-
5,
266+
4,
269267
);
270268
}
271269

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
use macros::embeddable;
2-
use rand::Rng;
32
use rand_core::RngCore;
43

54
use crate::{
65
chips::sym_key,
7-
consts::{
8-
merkle_constants::{ARITY, NOTE_TREE_HEIGHT},
9-
NONCE_UPPER_LIMIT,
10-
},
6+
consts::merkle_constants::{ARITY, NOTE_TREE_HEIGHT},
117
curve_arithmetic,
128
deposit::{circuit::DepositCircuit, DepositInstance},
139
embed::Embed,
@@ -43,8 +39,6 @@ pub struct DepositProverKnowledge<T> {
4339
pub nullifier_new: T,
4440
pub trapdoor_new: T,
4541

46-
// Nonce for id_hiding
47-
pub nonce: T,
4842
// Salt for MAC.
4943
pub mac_salt: T,
5044

@@ -59,7 +53,6 @@ impl ProverKnowledge for DepositProverKnowledge<Fr> {
5953
/// amount and the old account balances.
6054
fn random_correct_example(rng: &mut impl RngCore) -> Self {
6155
let id = curve_arithmetic::generate_user_id(Fr::random(&mut *rng).to_bytes());
62-
let nonce = Fr::from(rng.gen_range(0..NONCE_UPPER_LIMIT) as u64);
6356

6457
let nullifier_old = Fr::random(&mut *rng);
6558
let trapdoor_old = Fr::random(&mut *rng);
@@ -76,7 +69,6 @@ impl ProverKnowledge for DepositProverKnowledge<Fr> {
7669
let (_, path) = generate_example_path_with_given_leaf(h_note_old, &mut *rng);
7770
Self {
7871
id,
79-
nonce,
8072
nullifier_old,
8173
trapdoor_old,
8274
account_old_balance,
@@ -98,7 +90,6 @@ impl ProverKnowledge for DepositProverKnowledge<Fr> {
9890
account_old_balance: Value::known(self.account_old_balance),
9991
token_address: Value::known(self.token_address),
10092
id: Value::known(self.id),
101-
nonce: Value::known(self.nonce),
10293
path: self.path.map(|level| level.map(Value::known)),
10394
deposit_value: Value::known(self.deposit_value),
10495
mac_salt: Value::known(self.mac_salt),
@@ -111,7 +102,6 @@ impl PublicInputProvider<DepositInstance> for DepositProverKnowledge<Fr> {
111102
let sym_key = sym_key::off_circuit::derive(self.id);
112103

113104
match instance_id {
114-
DepositInstance::IdHiding => hash(&[hash(&[self.id]), self.nonce]),
115105
DepositInstance::MerkleRoot => hash(&self.path[NOTE_TREE_HEIGHT - 1]),
116106
DepositInstance::HashedOldNullifier => hash(&[self.nullifier_old]),
117107
DepositInstance::HashedNewNote => note_hash(&Note {

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use crate::chips::mac::MacInstance;
1313

1414
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, EnumIter, EnumCount)]
1515
pub enum DepositInstance {
16-
IdHiding,
1716
MerkleRoot,
1817
HashedOldNullifier,
1918
HashedNewNote,
@@ -69,7 +68,6 @@ mod tests {
6968
fn instance_order() {
7069
// This is the order used in other parts of the codebase (e.g., in contracts).
7170
let expected_order = vec![
72-
IdHiding,
7371
MerkleRoot,
7472
HashedOldNullifier,
7573
HashedNewNote,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ impl NewAccountChip {
5858
)
5959
}
6060

61-
pub fn constrain_hashed_id(
61+
pub fn constrain_prenullifier(
6262
&self,
6363
synthesizer: &mut impl Synthesizer,
6464
knowledge: &NewAccountProverKnowledge<AssignedCell>,
6565
) -> Result<(), Error> {
6666
let h_id = hash(synthesizer, self.poseidon.clone(), [knowledge.id.clone()])?;
6767
self.public_inputs
68-
.constrain_cells(synthesizer, [(h_id, HashedId)])
68+
.constrain_cells(synthesizer, [(h_id, Prenullifier)])
6969
}
7070

7171
/// check whether symmetric key is such that it forms a quadratic reside on the Grumpkin curve

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ impl Circuit<Fr> for NewAccountCircuit {
6161
.embed(&mut synthesizer, "NewAccountProverKnowledge")?;
6262

6363
main_chip.check_note(&mut synthesizer, &knowledge)?;
64-
main_chip.constrain_hashed_id(&mut synthesizer, &knowledge)?;
64+
// Instead of a nullifier we emit here the hashed id. Think of it as the "public key".
65+
// Since it is deterministic it can be used as a nullifier to prevent creating a second account with the same id.
66+
main_chip.constrain_prenullifier(&mut synthesizer, &knowledge)?;
6567
main_chip.constrain_sym_key_encryption(&mut synthesizer, &knowledge)
6668
}
6769
}
@@ -130,7 +132,7 @@ mod tests {
130132
#[test]
131133
fn fails_if_incorrect_h_id_is_published() {
132134
let pk = NewAccountProverKnowledge::random_correct_example(&mut OsRng);
133-
let pub_input = pk.with_substitution(HashedId, |v| v + Fr::ONE);
135+
let pub_input = pk.with_substitution(Prenullifier, |v| v + Fr::ONE);
134136

135137
assert!(
136138
expect_prover_success_and_run_verification(pk.create_circuit(), &pub_input).is_err()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl PublicInputProvider<NewAccountInstance> for NewAccountProverKnowledge<Fr> {
102102
account_balance: self.initial_deposit,
103103
token_address: self.token_address,
104104
}),
105-
NewAccountInstance::HashedId => hash(&[self.id]),
105+
NewAccountInstance::Prenullifier => hash(&[self.id]),
106106
NewAccountInstance::InitialDeposit => self.initial_deposit,
107107
NewAccountInstance::TokenAddress => self.token_address,
108108
NewAccountInstance::AnonymityRevokerPublicKeyX => self.anonymity_revoker_public_key.x,

0 commit comments

Comments
 (0)