Skip to content

Commit d048423

Browse files
committed
chore: rebase goodies
1 parent dc82a70 commit d048423

File tree

6 files changed

+47
-85
lines changed

6 files changed

+47
-85
lines changed

yarn-project/aztec.js/src/abis/ecdsa_account_contract.json

+2-14
Large diffs are not rendered by default.

yarn-project/aztec.js/src/abis/schnorr_account_contract.json

+2-14
Large diffs are not rendered by default.

yarn-project/aztec.js/src/abis/schnorr_auth_witness_account_contract.json

+4-4
Large diffs are not rendered by default.

yarn-project/aztec.js/src/abis/schnorr_single_key_account_contract.json

+1-1
Large diffs are not rendered by default.

yarn-project/noir-contracts/src/contracts/schnorr_auth_witness_account_contract/src/main.nr

+8-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ contract SchnorrAuthWitnessAccount {
1313
oracle::compute_selector::compute_selector,
1414
context::{
1515
PrivateContext,
16-
PublicContext
16+
PublicContext,
17+
Context,
1718
},
1819
state_vars::{
1920
map::Map,
@@ -35,19 +36,14 @@ contract SchnorrAuthWitnessAccount {
3536
}
3637

3738
impl Storage {
38-
fn init(
39-
private_context: Option<&mut PrivateContext>,
40-
public_context: Option<&mut PublicContext>,
41-
) -> pub Self {
39+
fn init(context: Context) -> pub Self {
4240
Storage {
4341
approved_action: Map::new(
44-
private_context,
45-
public_context,
42+
context,
4643
1,
47-
|private_context, public_context, slot| {
44+
|context, slot| {
4845
PublicState::new(
49-
private_context,
50-
public_context,
46+
context,
5147
slot,
5248
FieldSerialisationMethods,
5349
)
@@ -87,7 +83,7 @@ contract SchnorrAuthWitnessAccount {
8783
fn is_valid_public(
8884
message_hash: Field,
8985
) -> Field {
90-
let storage = Storage::init(Option::none(), Option::some(&mut context));
86+
let storage = Storage::init(Context::public(&mut context));
9187
let value = storage.approved_action.at(message_hash).read();
9288
if (value == 1){
9389
0xe86ab4ff
@@ -114,7 +110,7 @@ contract SchnorrAuthWitnessAccount {
114110
message_hash: Field,
115111
value: Field,
116112
) {
117-
let storage = Storage::init(Option::none(), Option::some(&mut context));
113+
let storage = Storage::init(Context::public(&mut context));
118114
storage.approved_action.at(message_hash).write(value);
119115
}
120116

yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr

+30-40
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ contract Token {
2626
note_header::NoteHeader,
2727
utils as note_utils,
2828
},
29-
context::{PrivateContext, PublicContext},
29+
context::{PrivateContext, PublicContext, Context},
3030
state_vars::{map::Map, public_state::PublicState, set::Set},
3131
types::type_serialisation::field_serialisation::{
3232
FieldSerialisationMethods, FIELD_SERIALISED_LEN,
@@ -48,53 +48,43 @@ contract Token {
4848
}
4949

5050
impl Storage {
51-
fn init(
52-
private_context: Option<&mut PrivateContext>,
53-
public_context: Option<&mut PublicContext>,
54-
) -> pub Self {
51+
fn init(context: Context) -> pub Self {
5552
Storage {
5653
admin: PublicState::new(
57-
private_context,
58-
public_context,
54+
context,
5955
1,
6056
FieldSerialisationMethods,
6157
),
6258
minters: Map::new(
63-
private_context,
64-
public_context,
59+
context,
6560
2,
66-
|private_context, public_context, slot| {
61+
|context, slot| {
6762
PublicState::new(
68-
private_context,
69-
public_context,
63+
context,
7064
slot,
7165
FieldSerialisationMethods,
7266
)
7367
},
7468
),
7569
balances: Map::new(
76-
private_context,
77-
public_context,
70+
context,
7871
3,
79-
|private_context, public_context, slot| {
80-
Set::new(private_context, public_context, slot, ValueNoteMethods)
72+
|context, slot| {
73+
Set::new(context, slot, ValueNoteMethods)
8174
},
8275
),
8376
total_supply: PublicState::new(
84-
private_context,
85-
public_context,
77+
context,
8678
4,
8779
FieldSerialisationMethods,
8880
),
89-
pending_shields: Set::new(private_context, public_context, 5, TransparentNoteMethods),
81+
pending_shields: Set::new(context, 5, TransparentNoteMethods),
9082
public_balances: Map::new(
91-
private_context,
92-
public_context,
83+
context,
9384
6,
94-
|private_context, public_context, slot| {
85+
|context, slot| {
9586
PublicState::new(
96-
private_context,
97-
public_context,
87+
context,
9888
slot,
9989
FieldSerialisationMethods,
10090
)
@@ -115,7 +105,7 @@ contract Token {
115105
fn set_admin(
116106
new_admin: AztecAddress,
117107
) {
118-
let storage = Storage::init(Option::none(), Option::some(&mut context));
108+
let storage = Storage::init(Context::public(&mut context));
119109
assert(storage.admin.read() == context.msg_sender(), "caller is not admin");
120110
storage.admin.write(new_admin.address);
121111
}
@@ -126,7 +116,7 @@ contract Token {
126116
approve: Field,
127117
) {
128118
assert((approve == 1) | (approve == 0), "not providing boolean");
129-
let storage = Storage::init(Option::none(), Option::some(&mut context));
119+
let storage = Storage::init(Context::public(&mut context));
130120
assert(storage.admin.read() == context.msg_sender(), "caller is not admin");
131121
storage.minters.at(minter.address).write(approve as Field);
132122
}
@@ -136,7 +126,7 @@ contract Token {
136126
to: AztecAddress,
137127
amount: Field,
138128
) -> Field {
139-
let storage = Storage::init(Option::none(), Option::some(&mut context));
129+
let storage = Storage::init(Context::public(&mut context));
140130
assert(storage.minters.at(context.msg_sender()).read() == 1, "caller is not minter");
141131
let amount = SafeU120::new(amount);
142132
let new_balance = SafeU120::new(storage.public_balances.at(to.address).read()).add(amount);
@@ -152,7 +142,7 @@ contract Token {
152142
amount: Field,
153143
secret_hash: Field,
154144
) -> Field {
155-
let storage = Storage::init(Option::none(), Option::some(&mut context));
145+
let storage = Storage::init(Context::public(&mut context));
156146
assert(storage.minters.at(context.msg_sender()).read() == 1, "caller is not minter");
157147
let pending_shields = storage.pending_shields;
158148
let mut note = TransparentNote::new(amount, secret_hash);
@@ -170,7 +160,7 @@ contract Token {
170160
secret_hash: Field,
171161
nonce: Field,
172162
) -> Field {
173-
let storage = Storage::init(Option::none(), Option::some(&mut context));
163+
let storage = Storage::init(Context::public(&mut context));
174164

175165
if (from.address != context.msg_sender()) {
176166
// The redeem is only spendable once, so we need to ensure that you cannot insert multiple shields from the same message.
@@ -200,7 +190,7 @@ contract Token {
200190
amount: Field,
201191
nonce: Field,
202192
) -> Field {
203-
let storage = Storage::init(Option::none(), Option::some(&mut context));
193+
let storage = Storage::init(Context::public(&mut context));
204194

205195
if (from.address != context.msg_sender()) {
206196
let selector = compute_selector("transfer_public((Field),(Field),Field,Field)");
@@ -226,7 +216,7 @@ contract Token {
226216
secret: Field,
227217
) -> Field {
228218
// @todo @lherskind consider Altering the value note as well to be safemath
229-
let storage = Storage::init(Option::some(&mut context), Option::none());
219+
let storage = Storage::init(Context::private(&mut context));
230220
let pending_shields = storage.pending_shields;
231221
let balance = storage.balances.at(to.address);
232222
let public_note = TransparentNote::new_from_secret(amount, secret);
@@ -242,7 +232,7 @@ contract Token {
242232
amount: Field,
243233
nonce: Field,
244234
) -> Field {
245-
let storage = Storage::init(Option::some(&mut context), Option::none());
235+
let storage = Storage::init(Context::private(&mut context));
246236

247237
if (from.address != context.msg_sender()) {
248238
let selector = compute_selector("unshield((Field),(Field),Field,Field)");
@@ -267,7 +257,7 @@ contract Token {
267257
amount: Field,
268258
nonce: Field,
269259
) -> Field {
270-
let storage = Storage::init(Option::some(&mut context), Option::none());
260+
let storage = Storage::init(Context::private(&mut context));
271261

272262
if (from.address != context.msg_sender()) {
273263
let selector = compute_selector("transfer((Field),(Field),Field,Field)");
@@ -294,7 +284,7 @@ contract Token {
294284
fn _initialize(
295285
new_admin: AztecAddress,
296286
) {
297-
let storage = Storage::init(Option::none(), Option::some(&mut context));
287+
let storage = Storage::init(Context::public(&mut context));
298288
storage.admin.write(new_admin.address);
299289
storage.minters.at(new_admin.address).write(1);
300290
}
@@ -306,34 +296,34 @@ contract Token {
306296
to: AztecAddress,
307297
amount: Field,
308298
) {
309-
let storage = Storage::init(Option::none(), Option::some(&mut context));
299+
let storage = Storage::init(Context::public(&mut context));
310300
let new_balance = SafeU120::new(storage.public_balances.at(to.address).read()).add(SafeU120::new(amount));
311301
storage.public_balances.at(to.address).write(new_balance.value as Field);
312302
}
313303

314304
/// Unconstrained ///
315305

316306
unconstrained fn admin() -> Field {
317-
let storage = Storage::init(Option::none(), Option::none());
307+
let storage = Storage::init(Context::none());
318308
storage.admin.read()
319309
}
320310

321311
unconstrained fn is_minter(
322312
minter: AztecAddress,
323313
) -> bool {
324-
let storage = Storage::init(Option::none(), Option::none());
314+
let storage = Storage::init(Context::none());
325315
storage.minters.at(minter.address).read() as bool
326316
}
327317

328318
unconstrained fn total_supply() -> Field {
329-
let storage = Storage::init(Option::none(), Option::none());
319+
let storage = Storage::init(Context::none());
330320
storage.total_supply.read()
331321
}
332322

333323
unconstrained fn balance_of_private(
334324
owner: AztecAddress,
335325
) -> Field {
336-
let storage = Storage::init(Option::none(), Option::none());
326+
let storage = Storage::init(Context::none());
337327
let owner_balance = storage.balances.at(owner.address);
338328

339329
balance_utils::get_balance(owner_balance)
@@ -342,7 +332,7 @@ contract Token {
342332
unconstrained fn balance_of_public(
343333
owner: AztecAddress,
344334
) -> Field {
345-
let storage = Storage::init(Option::none(), Option::none());
335+
let storage = Storage::init(Context::none());
346336
storage.public_balances.at(owner.address).read()
347337
}
348338

0 commit comments

Comments
 (0)