@openzeppelin/miden-multisig-client 0.13.4 → 0.14.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/README.md +10 -13
  2. package/dist/account/builder.d.ts +3 -3
  3. package/dist/account/builder.d.ts.map +1 -1
  4. package/dist/account/builder.js +10 -10
  5. package/dist/account/builder.js.map +1 -1
  6. package/dist/account/builder.test.js +16 -14
  7. package/dist/account/builder.test.js.map +1 -1
  8. package/dist/account/masm/account-components/auth.d.ts +4 -4
  9. package/dist/account/masm/account-components/auth.d.ts.map +1 -1
  10. package/dist/account/masm/account-components/auth.js +8 -12
  11. package/dist/account/masm/account-components/auth.js.map +1 -1
  12. package/dist/account/masm/auth.d.ts +4 -4
  13. package/dist/account/masm/auth.d.ts.map +1 -1
  14. package/dist/account/masm/auth.js +226 -124
  15. package/dist/account/masm/auth.js.map +1 -1
  16. package/dist/account/storage.d.ts.map +1 -1
  17. package/dist/account/storage.js +24 -6
  18. package/dist/account/storage.js.map +1 -1
  19. package/dist/account/storage.test.d.ts +2 -0
  20. package/dist/account/storage.test.d.ts.map +1 -0
  21. package/dist/account/storage.test.js +73 -0
  22. package/dist/account/storage.test.js.map +1 -0
  23. package/dist/client.d.ts +9 -9
  24. package/dist/client.d.ts.map +1 -1
  25. package/dist/client.js +24 -14
  26. package/dist/client.js.map +1 -1
  27. package/dist/client.test.js +45 -8
  28. package/dist/client.test.js.map +1 -1
  29. package/dist/index.d.ts +6 -12
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +6 -12
  32. package/dist/index.js.map +1 -1
  33. package/dist/multisig/proposal/execution.d.ts +3 -2
  34. package/dist/multisig/proposal/execution.d.ts.map +1 -1
  35. package/dist/multisig/proposal/execution.js +8 -12
  36. package/dist/multisig/proposal/execution.js.map +1 -1
  37. package/dist/multisig.d.ts +7 -4
  38. package/dist/multisig.d.ts.map +1 -1
  39. package/dist/multisig.js +53 -35
  40. package/dist/multisig.js.map +1 -1
  41. package/dist/multisig.test.js +17 -29
  42. package/dist/multisig.test.js.map +1 -1
  43. package/dist/procedures.d.ts +8 -8
  44. package/dist/procedures.js +8 -8
  45. package/dist/raw-client.d.ts +13 -0
  46. package/dist/raw-client.d.ts.map +1 -0
  47. package/dist/raw-client.js +42 -0
  48. package/dist/raw-client.js.map +1 -0
  49. package/dist/raw-client.test.d.ts +2 -0
  50. package/dist/raw-client.test.d.ts.map +1 -0
  51. package/dist/raw-client.test.js +89 -0
  52. package/dist/raw-client.test.js.map +1 -0
  53. package/dist/signers/ecdsa.d.ts +3 -1
  54. package/dist/signers/ecdsa.d.ts.map +1 -1
  55. package/dist/signers/ecdsa.js +15 -1
  56. package/dist/signers/ecdsa.js.map +1 -1
  57. package/dist/signers/ecdsa.test.js +27 -4
  58. package/dist/signers/ecdsa.test.js.map +1 -1
  59. package/dist/signers/falcon.d.ts +3 -1
  60. package/dist/signers/falcon.d.ts.map +1 -1
  61. package/dist/signers/falcon.js +15 -1
  62. package/dist/signers/falcon.js.map +1 -1
  63. package/dist/signers/falcon.test.js +39 -3
  64. package/dist/signers/falcon.test.js.map +1 -1
  65. package/dist/transaction/consumeNotes.d.ts +2 -2
  66. package/dist/transaction/consumeNotes.d.ts.map +1 -1
  67. package/dist/transaction/consumeNotes.js +5 -4
  68. package/dist/transaction/consumeNotes.js.map +1 -1
  69. package/dist/transaction/options.d.ts +1 -0
  70. package/dist/transaction/options.d.ts.map +1 -1
  71. package/dist/transaction/p2id.d.ts.map +1 -1
  72. package/dist/transaction/p2id.js +7 -10
  73. package/dist/transaction/p2id.js.map +1 -1
  74. package/dist/transaction/p2id.test.js +19 -9
  75. package/dist/transaction/p2id.test.js.map +1 -1
  76. package/dist/transaction/summary.d.ts +2 -2
  77. package/dist/transaction/summary.d.ts.map +1 -1
  78. package/dist/transaction/summary.js +4 -2
  79. package/dist/transaction/summary.js.map +1 -1
  80. package/dist/transaction/updateGuardian.d.ts +2 -2
  81. package/dist/transaction/updateGuardian.d.ts.map +1 -1
  82. package/dist/transaction/updateGuardian.js +8 -11
  83. package/dist/transaction/updateGuardian.js.map +1 -1
  84. package/dist/transaction/updateProcedureThreshold.d.ts +2 -2
  85. package/dist/transaction/updateProcedureThreshold.d.ts.map +1 -1
  86. package/dist/transaction/updateProcedureThreshold.js +8 -10
  87. package/dist/transaction/updateProcedureThreshold.js.map +1 -1
  88. package/dist/transaction/updateSigners.d.ts +2 -2
  89. package/dist/transaction/updateSigners.d.ts.map +1 -1
  90. package/dist/transaction/updateSigners.js +8 -10
  91. package/dist/transaction/updateSigners.js.map +1 -1
  92. package/dist/transaction.test.js +6 -6
  93. package/dist/transaction.test.js.map +1 -1
  94. package/dist/utils/key.d.ts.map +1 -1
  95. package/dist/utils/key.js +3 -3
  96. package/dist/utils/key.js.map +1 -1
  97. package/dist/utils/key.test.js +4 -2
  98. package/dist/utils/key.test.js.map +1 -1
  99. package/dist/utils/signature.d.ts +2 -0
  100. package/dist/utils/signature.d.ts.map +1 -1
  101. package/dist/utils/signature.js +10 -5
  102. package/dist/utils/signature.js.map +1 -1
  103. package/dist/utils/signature.test.js +9 -9
  104. package/dist/utils/signature.test.js.map +1 -1
  105. package/masm/account_components/auth/multisig.masm +2 -3
  106. package/masm/account_components/auth/multisig_ecdsa.masm +2 -3
  107. package/masm/account_components/auth/multisig_guardian.masm +2 -3
  108. package/masm/account_components/auth/multisig_guardian_ecdsa.masm +2 -3
  109. package/masm/auth/guardian.masm +30 -8
  110. package/masm/auth/guardian_ecdsa.masm +24 -7
  111. package/masm/auth/multisig.masm +86 -55
  112. package/masm/auth/multisig_ecdsa.masm +86 -54
  113. package/package.json +3 -3
  114. package/src/account/builder.test.ts +16 -14
  115. package/src/account/builder.ts +13 -12
  116. package/src/account/masm/account-components/auth.ts +8 -12
  117. package/src/account/masm/auth.ts +226 -124
  118. package/src/account/storage.test.ts +90 -0
  119. package/src/account/storage.ts +27 -6
  120. package/src/client.test.ts +52 -8
  121. package/src/client.ts +39 -16
  122. package/src/index.ts +6 -12
  123. package/src/multisig/proposal/execution.ts +18 -14
  124. package/src/multisig.test.ts +17 -29
  125. package/src/multisig.ts +61 -36
  126. package/src/procedures.ts +8 -8
  127. package/src/raw-client.test.ts +133 -0
  128. package/src/raw-client.ts +75 -0
  129. package/src/signers/ecdsa.test.ts +35 -4
  130. package/src/signers/ecdsa.ts +18 -2
  131. package/src/signers/falcon.test.ts +50 -3
  132. package/src/signers/falcon.ts +18 -2
  133. package/src/transaction/consumeNotes.ts +16 -5
  134. package/src/transaction/options.ts +1 -0
  135. package/src/transaction/p2id.test.ts +19 -9
  136. package/src/transaction/p2id.ts +8 -13
  137. package/src/transaction/summary.ts +11 -4
  138. package/src/transaction/updateGuardian.ts +22 -14
  139. package/src/transaction/updateProcedureThreshold.ts +20 -15
  140. package/src/transaction/updateSigners.ts +22 -14
  141. package/src/transaction.test.ts +6 -6
  142. package/src/utils/key.test.ts +4 -2
  143. package/src/utils/key.ts +7 -3
  144. package/src/utils/signature.test.ts +10 -10
  145. package/src/utils/signature.ts +12 -5
@@ -6,27 +6,23 @@ export const MULTISIG_MASM = `# Multi-Signature RPO Falcon 512 Authentication Co
6
6
  # This library provides the reusable multisig procedures used by account wrappers.
7
7
 
8
8
  use miden::protocol::active_account
9
+ use miden::protocol::auth::AUTH_UNAUTHORIZED_EVENT
9
10
  use miden::protocol::native_account
10
11
  use miden::standards::auth
11
12
 
12
- type BeWord = struct @bigendian { a: felt, b: felt, c: felt, d: felt }
13
-
14
13
  # CONSTANTS
15
14
  # =================================================================================================
16
15
 
17
16
  # Auth Request Constants
18
17
 
19
- # The event emitted when a signature is not found for a required signer.
20
- const AUTH_UNAUTHORIZED_EVENT=event("miden::auth::unauthorized")
21
-
22
18
  # Storage Layout Constants
23
19
  #
24
- # +-------------------------------+----------+--------------+-------------------+
25
- # | THRESHOLD & APPROVERS CONFIG | PUB KEYS | EXECUTED TXS | PROC THRESHOLDS |
26
- # | (slot) | (map) | (map) | (map) |
27
- # +-------------------------------+----------+--------------+-------------------+
28
- # | 0 | 1 | 2 | 3 |
29
- # +-------------------------------+----------+--------------+-------------------+
20
+ # +-------------------------------+----------+------------+--------------+-------------------+
21
+ # | THRESHOLD & APPROVERS CONFIG | PUB KEYS | SCHEME IDS | EXECUTED TXS | PROC THRESHOLDS |
22
+ # | (slot) | (map) | (map) | (map) | (map) |
23
+ # +-------------------------------+----------+------------+--------------+-------------------+
24
+ # | 0 | 1 | 2 | 3 | 4 |
25
+ # +-------------------------------+----------+------------+--------------+-------------------+
30
26
 
31
27
  # The slot in this component's storage layout where the default signature threshold and
32
28
  # number of approvers are stored as:
@@ -38,6 +34,10 @@ const THRESHOLD_CONFIG_SLOT=word("openzeppelin::multisig::threshold_config")
38
34
  # Map entries: [key_index, 0, 0, 0] => APPROVER_PUBLIC_KEY
39
35
  const PUBLIC_KEYS_MAP_SLOT=word("openzeppelin::multisig::signer_public_keys")
40
36
 
37
+ # The slot in this component's storage layout where signer scheme IDs are stored.
38
+ # Map entries: [key_index, 0, 0, 0] => [scheme_id, 0, 0, 0]
39
+ const APPROVER_SCHEME_ID_SLOT=word("openzeppelin::multisig::signer_scheme_ids")
40
+
41
41
  # The slot in this component's storage layout where executed transactions are stored.
42
42
  # Map entries: transaction_message => [is_executed, 0, 0, 0]
43
43
  const EXECUTED_TXS_SLOT=word("openzeppelin::multisig::executed_transactions")
@@ -48,6 +48,7 @@ const PROC_THRESHOLD_ROOTS_SLOT=word("openzeppelin::multisig::procedure_threshol
48
48
 
49
49
  # Executed Transaction Flag Constant
50
50
  const IS_EXECUTED_FLAG=[1, 0, 0, 0]
51
+ const FALCON_512_POSEIDON2_SCHEME_WORD=[2, 0, 0, 0]
51
52
 
52
53
  # ERRORS
53
54
  const ERR_TX_ALREADY_EXECUTED="failed to approve multisig transaction as it was already executed"
@@ -72,7 +73,7 @@ const ERR_PROC_THRESHOLD_EXCEEDS_NUM_APPROVERS="procedure threshold exceeds numb
72
73
  #!
73
74
  #! Panics if:
74
75
  #! - the same transaction has already been executed
75
- pub proc assert_new_tx(msg: BeWord)
76
+ pub proc assert_new_tx(msg: word)
76
77
  push.IS_EXECUTED_FLAG
77
78
  # => [[0, 0, 0, is_executed], MSG]
78
79
 
@@ -116,17 +117,29 @@ proc cleanup_pubkey_mapping(init_num_of_approvers: u32, new_num_of_approvers: u3
116
117
  sub.1
117
118
  # => [i-1, new_num_of_approvers]
118
119
 
119
- dup
120
- # => [i-1, i-1, new_num_of_approvers]
121
-
122
- push.0.0.0
123
- # => [[0, 0, 0, i-1], i-1, new_num_of_approvers]
120
+ dup exec.create_approver_map_key
121
+ # => [APPROVER_MAP_KEY, i-1, new_num_of_approvers]
124
122
 
125
123
  padw swapw
126
- # => [[0, 0, 0, i-1], EMPTY_WORD, i-1, new_num_of_approvers]
124
+ # => [APPROVER_MAP_KEY, EMPTY_WORD, i-1, new_num_of_approvers]
127
125
 
128
126
  push.PUBLIC_KEYS_MAP_SLOT[0..2]
129
- # => [pub_key_slot_prefix, pub_key_slot_suffix, [0, 0, 0, i-1], EMPTY_WORD, i-1, new_num_of_approvers]
127
+ # => [pub_key_slot_prefix, pub_key_slot_suffix, APPROVER_MAP_KEY, EMPTY_WORD, i-1, new_num_of_approvers]
128
+
129
+ exec.native_account::set_map_item
130
+ # => [OLD_MAP_VALUE, i-1, new_num_of_approvers]
131
+
132
+ dropw
133
+ # => [i-1, new_num_of_approvers]
134
+
135
+ dup exec.create_approver_map_key
136
+ # => [APPROVER_MAP_KEY, i-1, new_num_of_approvers]
137
+
138
+ padw swapw
139
+ # => [APPROVER_MAP_KEY, EMPTY_WORD, i-1, new_num_of_approvers]
140
+
141
+ push.APPROVER_SCHEME_ID_SLOT[0..2]
142
+ # => [scheme_slot_prefix, scheme_slot_suffix, APPROVER_MAP_KEY, EMPTY_WORD, i-1, new_num_of_approvers]
130
143
 
131
144
  exec.native_account::set_map_item
132
145
  # => [OLD_MAP_VALUE, i-1, new_num_of_approvers]
@@ -143,15 +156,17 @@ proc cleanup_pubkey_mapping(init_num_of_approvers: u32, new_num_of_approvers: u3
143
156
  # => []
144
157
  end
145
158
 
159
+ proc create_approver_map_key
160
+ push.0.0.0 movup.3
161
+ # => [APPROVER_MAP_KEY]
162
+ end
163
+
146
164
  proc get_threshold_and_num_approvers
147
165
  push.THRESHOLD_CONFIG_SLOT[0..2]
148
166
  exec.active_account::get_initial_item
149
- # => [0, 0, num_approvers, threshold]
150
-
151
- drop drop
152
- # => [num_approvers, threshold]
167
+ # => [threshold, num_approvers]
153
168
 
154
- swap
169
+ movup.2 drop movup.2 drop
155
170
  # => [threshold, num_approvers]
156
171
  end
157
172
 
@@ -171,10 +186,10 @@ proc assert_proc_thresholds_lte_num_approvers(num_approvers: u32)
171
186
  push.PROC_THRESHOLD_ROOTS_SLOT[0..2]
172
187
  # => [proc_roots_slot_prefix, proc_roots_slot_suffix, PROC_ROOT, proc_index, num_approvers]
173
188
 
174
- exec.active_account::get_initial_map_item
175
- # => [[0, 0, 0, proc_threshold], proc_index, num_approvers]
189
+ exec.active_account::get_map_item
190
+ # => [[proc_threshold, 0, 0, 0], proc_index, num_approvers]
176
191
 
177
- drop drop drop
192
+ movdn.3 drop drop drop
178
193
  # => [proc_threshold, proc_index, num_approvers]
179
194
 
180
195
  dup.2
@@ -194,7 +209,7 @@ end
194
209
 
195
210
  # Internal storage helper used by the public \`update_procedure_threshold\`
196
211
  # entrypoint after it receives direct stack arguments.
197
- proc set_procedure_threshold(proc_threshold: u32, proc_root: BeWord)
212
+ proc set_procedure_threshold(proc_threshold: u32, proc_root: word)
198
213
  exec.get_threshold_and_num_approvers
199
214
  # => [threshold, num_approvers, proc_threshold, PROC_ROOT]
200
215
 
@@ -209,6 +224,7 @@ proc set_procedure_threshold(proc_threshold: u32, proc_root: BeWord)
209
224
  # => [proc_threshold, PROC_ROOT]
210
225
 
211
226
  push.0.0.0
227
+ movup.3
212
228
  swapw
213
229
  # => [PROC_ROOT, PROC_THRESHOLD_WORD]
214
230
 
@@ -241,7 +257,7 @@ end
241
257
  #! 0: new_num_of_approvers
242
258
  #! 1: init_num_of_approvers
243
259
  @locals(2)
244
- pub proc update_signers_and_threshold(multisig_config_hash: BeWord)
260
+ pub proc update_signers_and_threshold(multisig_config_hash: word)
245
261
  adv.push_mapval
246
262
  # => [MULTISIG_CONFIG_HASH, pad(12)]
247
263
 
@@ -249,10 +265,10 @@ pub proc update_signers_and_threshold(multisig_config_hash: BeWord)
249
265
  # => [MULTISIG_CONFIG, pad(12)]
250
266
 
251
267
  # store new_num_of_approvers for later
252
- dup.2 loc_store.0
268
+ dup.1 loc_store.0
253
269
  # => [MULTISIG_CONFIG, pad(12)]
254
270
 
255
- dup.3 dup.3
271
+ dup dup.2
256
272
  # => [num_approvers, threshold, MULTISIG_CONFIG, pad(12)]
257
273
 
258
274
  # make sure that the threshold is smaller than the number of approvers
@@ -260,7 +276,7 @@ pub proc update_signers_and_threshold(multisig_config_hash: BeWord)
260
276
  u32gt assertz.err=ERR_MALFORMED_MULTISIG_CONFIG
261
277
  # => [MULTISIG_CONFIG, pad(12)]
262
278
 
263
- dup.3 dup.3
279
+ dup dup.2
264
280
  # => [num_approvers, threshold, MULTISIG_CONFIG, pad(12)]
265
281
 
266
282
  # make sure that threshold or num_approvers are not zero
@@ -281,7 +297,7 @@ pub proc update_signers_and_threshold(multisig_config_hash: BeWord)
281
297
  # => [OLD_THRESHOLD_CONFIG, pad(12)]
282
298
 
283
299
  # store init_num_of_approvers for later
284
- drop drop loc_store.1 drop
300
+ drop loc_store.1 drop drop
285
301
  # => [pad(12)]
286
302
 
287
303
  loc_load.0
@@ -292,17 +308,35 @@ pub proc update_signers_and_threshold(multisig_config_hash: BeWord)
292
308
  sub.1
293
309
  # => [i-1, pad(12)]
294
310
 
295
- dup push.0.0.0
296
- # => [[0, 0, 0, i-1], i-1, pad(12)]
311
+ dup exec.create_approver_map_key
312
+ # => [APPROVER_MAP_KEY, i-1, pad(12)]
297
313
 
298
314
  padw adv_loadw
299
- # => [PUB_KEY, [0, 0, 0, i-1], i-1, pad(12)]
315
+ # => [PUB_KEY, APPROVER_MAP_KEY, i-1, pad(12)]
300
316
 
301
317
  swapw
302
- # => [[0, 0, 0, i-1], PUB_KEY, i-1, pad(12)]
318
+ # => [APPROVER_MAP_KEY, PUB_KEY, i-1, pad(12)]
303
319
 
304
320
  push.PUBLIC_KEYS_MAP_SLOT[0..2]
305
- # => [pub_key_slot_prefix, pub_key_slot_suffix, [0, 0, 0, i-1], PUB_KEY, i-1, pad(12)]
321
+ # => [pub_key_slot_prefix, pub_key_slot_suffix, APPROVER_MAP_KEY, PUB_KEY, i-1, pad(12)]
322
+
323
+ exec.native_account::set_map_item
324
+ # => [OLD_VALUE, i-1, pad(12)]
325
+
326
+ dropw
327
+ # => [i-1, pad(12)]
328
+
329
+ dup exec.create_approver_map_key
330
+ # => [APPROVER_MAP_KEY, i-1, pad(12)]
331
+
332
+ push.FALCON_512_POSEIDON2_SCHEME_WORD
333
+ # => [SCHEME_ID_WORD, APPROVER_MAP_KEY, i-1, pad(12)]
334
+
335
+ swapw
336
+ # => [APPROVER_MAP_KEY, [2, 0, 0, 0], i-1, pad(12)]
337
+
338
+ push.APPROVER_SCHEME_ID_SLOT[0..2]
339
+ # => [scheme_slot_prefix, scheme_slot_suffix, APPROVER_MAP_KEY, [2, 0, 0, 0], i-1, pad(12)]
306
340
 
307
341
  exec.native_account::set_map_item
308
342
  # => [OLD_VALUE, i-1, pad(12)]
@@ -335,7 +369,7 @@ end
335
369
  #! Outputs:
336
370
  #! Operand stack: []
337
371
  #! Invocation: call
338
- pub proc update_procedure_threshold(proc_threshold: u32, proc_root: BeWord)
372
+ pub proc update_procedure_threshold(proc_threshold: u32, proc_root: word)
339
373
  exec.set_procedure_threshold
340
374
  end
341
375
 
@@ -391,9 +425,9 @@ proc compute_transaction_threshold(default_threshold: u32) -> u32
391
425
  # 2b. get the override proc_threshold of that procedure
392
426
  # if the procedure has no override threshold, the returned map item will be [0, 0, 0, 0]
393
427
  exec.active_account::get_initial_map_item
394
- # => [[0, 0, 0, proc_threshold], num_procedures-1, transaction_threshold]
428
+ # => [[proc_threshold, 0, 0, 0], num_procedures-1, transaction_threshold]
395
429
 
396
- drop drop drop dup dup.3
430
+ movdn.3 drop drop drop dup dup.3
397
431
  # => [transaction_threshold, proc_threshold, proc_threshold, num_procedures-1, transaction_threshold]
398
432
 
399
433
  u32assert2.err="transaction threshold or procedure threshold are not u32"
@@ -462,18 +496,18 @@ end
462
496
  #!
463
497
  #! Invocation: exec
464
498
  @locals(1)
465
- pub proc auth_tx(salt: BeWord) -> BeWord
499
+ pub proc auth_tx(salt: word)
466
500
  exec.native_account::incr_nonce drop
467
501
  # => [SALT]
468
502
 
469
503
  # ------ Computing transaction summary ------
470
504
 
471
505
  exec.auth::create_tx_summary
472
- # => [SALT, OUTPUT_NOTES_COMMITMENT, INPUT_NOTES_COMMITMENT, ACCOUNT_DELTA_COMMITMENT]
506
+ # => [ACCOUNT_DELTA_COMMITMENT, INPUT_NOTES_COMMITMENT, OUTPUT_NOTES_COMMITMENT, SALT]
473
507
 
474
508
  # to build a tx_summary in the host, we need these four words in the advice provider
475
- exec.auth::adv_insert_hqword
476
- # => [SALT, OUTPUT_NOTES_COMMITMENT, INPUT_NOTES_COMMITMENT, ACCOUNT_DELTA_COMMITMENT]
509
+ adv.insert_hqword
510
+ # => [ACCOUNT_DELTA_COMMITMENT, INPUT_NOTES_COMMITMENT, OUTPUT_NOTES_COMMITMENT, SALT]
477
511
 
478
512
  # the commitment to the tx summary is the message that is signed
479
513
  exec.auth::hash_tx_summary
@@ -481,22 +515,19 @@ pub proc auth_tx(salt: BeWord) -> BeWord
481
515
 
482
516
  # ------ Verifying approver signatures ------
483
517
 
484
- push.THRESHOLD_CONFIG_SLOT[0..2]
485
- # => [config_slot_prefix, config_slot_suffix, TX_SUMMARY_COMMITMENT]
486
-
487
- exec.active_account::get_initial_item
488
- # => [0, 0, num_of_approvers, default_threshold, TX_SUMMARY_COMMITMENT]
489
-
490
- drop drop
491
- # => [num_of_approvers, default_threshold, TX_SUMMARY_COMMITMENT]
518
+ exec.get_threshold_and_num_approvers
519
+ # => [default_threshold, num_of_approvers, TX_SUMMARY_COMMITMENT]
492
520
 
493
- swap movdn.5
521
+ movdn.5
494
522
  # => [num_of_approvers, TX_SUMMARY_COMMITMENT, default_threshold]
495
523
 
496
524
  push.PUBLIC_KEYS_MAP_SLOT[0..2]
497
525
  # => [pub_key_slot_prefix, pub_key_slot_suffix, num_of_approvers, TX_SUMMARY_COMMITMENT, default_threshold]
498
526
 
499
- exec.::miden::standards::auth::falcon512_rpo::verify_signatures
527
+ push.APPROVER_SCHEME_ID_SLOT[0..2]
528
+ # => [scheme_id_slot_prefix, scheme_id_slot_suffix, pub_key_slot_prefix, pub_key_slot_suffix, num_of_approvers, TX_SUMMARY_COMMITMENT, default_threshold]
529
+
530
+ exec.::miden::standards::auth::signature::verify_signatures
500
531
  # => [num_verified_signatures, TX_SUMMARY_COMMITMENT, default_threshold]
501
532
 
502
533
  # ------ Checking threshold is >= num_verified_signatures ------
@@ -525,26 +556,23 @@ export const MULTISIG_ECDSA_MASM = `# Multi-Signature ECDSA secp256k1 Authentica
525
556
  # This library provides the reusable multisig procedures used by account wrappers.
526
557
 
527
558
  use miden::protocol::active_account
559
+ use miden::protocol::auth::AUTH_UNAUTHORIZED_EVENT
528
560
  use miden::protocol::native_account
529
561
  use miden::standards::auth
530
- type BeWord = struct @bigendian { a: felt, b: felt, c: felt, d: felt }
531
562
 
532
563
  # CONSTANTS
533
564
  # =================================================================================================
534
565
 
535
566
  # Auth Request Constants
536
567
 
537
- # The event emitted when a signature is not found for a required signer.
538
- const AUTH_UNAUTHORIZED_EVENT=event("miden::auth::unauthorized")
539
-
540
568
  # Storage Layout Constants
541
569
  #
542
- # +-------------------------------+----------+--------------+-------------------+
543
- # | THRESHOLD & APPROVERS CONFIG | PUB KEYS | EXECUTED TXS | PROC THRESHOLDS |
544
- # | (slot) | (map) | (map) | (map) |
545
- # +-------------------------------+----------+--------------+-------------------+
546
- # | 0 | 1 | 2 | 3 |
547
- # +-------------------------------+----------+--------------+-------------------+
570
+ # +-------------------------------+----------+------------+--------------+-------------------+
571
+ # | THRESHOLD & APPROVERS CONFIG | PUB KEYS | SCHEME IDS | EXECUTED TXS | PROC THRESHOLDS |
572
+ # | (slot) | (map) | (map) | (map) | (map) |
573
+ # +-------------------------------+----------+------------+--------------+-------------------+
574
+ # | 0 | 1 | 2 | 3 | 4 |
575
+ # +-------------------------------+----------+------------+--------------+-------------------+
548
576
 
549
577
  # The slot in this component's storage layout where the default signature threshold and
550
578
  # number of approvers are stored as:
@@ -556,6 +584,10 @@ const THRESHOLD_CONFIG_SLOT=word("openzeppelin::multisig::threshold_config")
556
584
  # Map entries: [key_index, 0, 0, 0] => APPROVER_PUBLIC_KEY
557
585
  const PUBLIC_KEYS_MAP_SLOT=word("openzeppelin::multisig::signer_public_keys")
558
586
 
587
+ # The slot in this component's storage layout where signer scheme IDs are stored.
588
+ # Map entries: [key_index, 0, 0, 0] => [scheme_id, 0, 0, 0]
589
+ const APPROVER_SCHEME_ID_SLOT=word("openzeppelin::multisig::signer_scheme_ids")
590
+
559
591
  # The slot in this component's storage layout where executed transactions are stored.
560
592
  # Map entries: transaction_message => [is_executed, 0, 0, 0]
561
593
  const EXECUTED_TXS_SLOT=word("openzeppelin::multisig::executed_transactions")
@@ -566,6 +598,7 @@ const PROC_THRESHOLD_ROOTS_SLOT=word("openzeppelin::multisig::procedure_threshol
566
598
 
567
599
  # Executed Transaction Flag Constant
568
600
  const IS_EXECUTED_FLAG=[1, 0, 0, 0]
601
+ const ECDSA_K256_KECCAK_SCHEME_WORD=[1, 0, 0, 0]
569
602
 
570
603
  # ERRORS
571
604
  const ERR_TX_ALREADY_EXECUTED="failed to approve multisig transaction as it was already executed"
@@ -590,7 +623,7 @@ const ERR_PROC_THRESHOLD_EXCEEDS_NUM_APPROVERS="procedure threshold exceeds numb
590
623
  #!
591
624
  #! Panics if:
592
625
  #! - the same transaction has already been executed
593
- pub proc assert_new_tx(msg: BeWord)
626
+ pub proc assert_new_tx(msg: word)
594
627
  push.IS_EXECUTED_FLAG
595
628
  # => [[0, 0, 0, is_executed], MSG]
596
629
 
@@ -634,17 +667,29 @@ proc cleanup_pubkey_mapping(init_num_of_approvers: u32, new_num_of_approvers: u3
634
667
  sub.1
635
668
  # => [i-1, new_num_of_approvers]
636
669
 
637
- dup
638
- # => [i-1, i-1, new_num_of_approvers]
639
-
640
- push.0.0.0
641
- # => [[0, 0, 0, i-1], i-1, new_num_of_approvers]
670
+ dup exec.create_approver_map_key
671
+ # => [APPROVER_MAP_KEY, i-1, new_num_of_approvers]
642
672
 
643
673
  padw swapw
644
- # => [[0, 0, 0, i-1], EMPTY_WORD, i-1, new_num_of_approvers]
674
+ # => [APPROVER_MAP_KEY, EMPTY_WORD, i-1, new_num_of_approvers]
645
675
 
646
676
  push.PUBLIC_KEYS_MAP_SLOT[0..2]
647
- # => [pub_key_slot_prefix, pub_key_slot_suffix, [0, 0, 0, i-1], EMPTY_WORD, i-1, new_num_of_approvers]
677
+ # => [pub_key_slot_prefix, pub_key_slot_suffix, APPROVER_MAP_KEY, EMPTY_WORD, i-1, new_num_of_approvers]
678
+
679
+ exec.native_account::set_map_item
680
+ # => [OLD_MAP_VALUE, i-1, new_num_of_approvers]
681
+
682
+ dropw
683
+ # => [i-1, new_num_of_approvers]
684
+
685
+ dup exec.create_approver_map_key
686
+ # => [APPROVER_MAP_KEY, i-1, new_num_of_approvers]
687
+
688
+ padw swapw
689
+ # => [APPROVER_MAP_KEY, EMPTY_WORD, i-1, new_num_of_approvers]
690
+
691
+ push.APPROVER_SCHEME_ID_SLOT[0..2]
692
+ # => [scheme_slot_prefix, scheme_slot_suffix, APPROVER_MAP_KEY, EMPTY_WORD, i-1, new_num_of_approvers]
648
693
 
649
694
  exec.native_account::set_map_item
650
695
  # => [OLD_MAP_VALUE, i-1, new_num_of_approvers]
@@ -661,15 +706,17 @@ proc cleanup_pubkey_mapping(init_num_of_approvers: u32, new_num_of_approvers: u3
661
706
  # => []
662
707
  end
663
708
 
709
+ proc create_approver_map_key
710
+ push.0.0.0 movup.3
711
+ # => [APPROVER_MAP_KEY]
712
+ end
713
+
664
714
  proc get_threshold_and_num_approvers
665
715
  push.THRESHOLD_CONFIG_SLOT[0..2]
666
716
  exec.active_account::get_initial_item
667
- # => [0, 0, num_approvers, threshold]
668
-
669
- drop drop
670
- # => [num_approvers, threshold]
717
+ # => [threshold, num_approvers]
671
718
 
672
- swap
719
+ movup.2 drop movup.2 drop
673
720
  # => [threshold, num_approvers]
674
721
  end
675
722
 
@@ -689,10 +736,10 @@ proc assert_proc_thresholds_lte_num_approvers(num_approvers: u32)
689
736
  push.PROC_THRESHOLD_ROOTS_SLOT[0..2]
690
737
  # => [proc_roots_slot_prefix, proc_roots_slot_suffix, PROC_ROOT, proc_index, num_approvers]
691
738
 
692
- exec.active_account::get_initial_map_item
693
- # => [[0, 0, 0, proc_threshold], proc_index, num_approvers]
739
+ exec.active_account::get_map_item
740
+ # => [[proc_threshold, 0, 0, 0], proc_index, num_approvers]
694
741
 
695
- drop drop drop
742
+ movdn.3 drop drop drop
696
743
  # => [proc_threshold, proc_index, num_approvers]
697
744
 
698
745
  dup.2
@@ -712,7 +759,7 @@ end
712
759
 
713
760
  # Internal storage helper used by the public \`update_procedure_threshold\`
714
761
  # entrypoint after it receives direct stack arguments.
715
- proc set_procedure_threshold(proc_threshold: u32, proc_root: BeWord)
762
+ proc set_procedure_threshold(proc_threshold: u32, proc_root: word)
716
763
  exec.get_threshold_and_num_approvers
717
764
  # => [threshold, num_approvers, proc_threshold, PROC_ROOT]
718
765
 
@@ -727,6 +774,7 @@ proc set_procedure_threshold(proc_threshold: u32, proc_root: BeWord)
727
774
  # => [proc_threshold, PROC_ROOT]
728
775
 
729
776
  push.0.0.0
777
+ movup.3
730
778
  swapw
731
779
  # => [PROC_ROOT, PROC_THRESHOLD_WORD]
732
780
 
@@ -759,7 +807,7 @@ end
759
807
  #! 0: new_num_of_approvers
760
808
  #! 1: init_num_of_approvers
761
809
  @locals(2)
762
- pub proc update_signers_and_threshold(multisig_config_hash: BeWord)
810
+ pub proc update_signers_and_threshold(multisig_config_hash: word)
763
811
  adv.push_mapval
764
812
  # => [MULTISIG_CONFIG_HASH, pad(12)]
765
813
 
@@ -767,10 +815,10 @@ pub proc update_signers_and_threshold(multisig_config_hash: BeWord)
767
815
  # => [MULTISIG_CONFIG, pad(12)]
768
816
 
769
817
  # store new_num_of_approvers for later
770
- dup.2 loc_store.0
818
+ dup.1 loc_store.0
771
819
  # => [MULTISIG_CONFIG, pad(12)]
772
820
 
773
- dup.3 dup.3
821
+ dup dup.2
774
822
  # => [num_approvers, threshold, MULTISIG_CONFIG, pad(12)]
775
823
 
776
824
  # make sure that the threshold is smaller than the number of approvers
@@ -778,7 +826,7 @@ pub proc update_signers_and_threshold(multisig_config_hash: BeWord)
778
826
  u32gt assertz.err=ERR_MALFORMED_MULTISIG_CONFIG
779
827
  # => [MULTISIG_CONFIG, pad(12)]
780
828
 
781
- dup.3 dup.3
829
+ dup dup.2
782
830
  # => [num_approvers, threshold, MULTISIG_CONFIG, pad(12)]
783
831
 
784
832
  # make sure that threshold or num_approvers are not zero
@@ -799,7 +847,7 @@ pub proc update_signers_and_threshold(multisig_config_hash: BeWord)
799
847
  # => [OLD_THRESHOLD_CONFIG, pad(12)]
800
848
 
801
849
  # store init_num_of_approvers for later
802
- drop drop loc_store.1 drop
850
+ drop loc_store.1 drop drop
803
851
  # => [pad(12)]
804
852
 
805
853
  loc_load.0
@@ -810,17 +858,35 @@ pub proc update_signers_and_threshold(multisig_config_hash: BeWord)
810
858
  sub.1
811
859
  # => [i-1, pad(12)]
812
860
 
813
- dup push.0.0.0
814
- # => [[0, 0, 0, i-1], i-1, pad(12)]
861
+ dup exec.create_approver_map_key
862
+ # => [APPROVER_MAP_KEY, i-1, pad(12)]
815
863
 
816
864
  padw adv_loadw
817
- # => [PUB_KEY, [0, 0, 0, i-1], i-1, pad(12)]
865
+ # => [PUB_KEY, APPROVER_MAP_KEY, i-1, pad(12)]
818
866
 
819
867
  swapw
820
- # => [[0, 0, 0, i-1], PUB_KEY, i-1, pad(12)]
868
+ # => [APPROVER_MAP_KEY, PUB_KEY, i-1, pad(12)]
821
869
 
822
870
  push.PUBLIC_KEYS_MAP_SLOT[0..2]
823
- # => [pub_key_slot_prefix, pub_key_slot_suffix, [0, 0, 0, i-1], PUB_KEY, i-1, pad(12)]
871
+ # => [pub_key_slot_prefix, pub_key_slot_suffix, APPROVER_MAP_KEY, PUB_KEY, i-1, pad(12)]
872
+
873
+ exec.native_account::set_map_item
874
+ # => [OLD_VALUE, i-1, pad(12)]
875
+
876
+ dropw
877
+ # => [i-1, pad(12)]
878
+
879
+ dup exec.create_approver_map_key
880
+ # => [APPROVER_MAP_KEY, i-1, pad(12)]
881
+
882
+ push.ECDSA_K256_KECCAK_SCHEME_WORD
883
+ # => [SCHEME_ID_WORD, APPROVER_MAP_KEY, i-1, pad(12)]
884
+
885
+ swapw
886
+ # => [APPROVER_MAP_KEY, [1, 0, 0, 0], i-1, pad(12)]
887
+
888
+ push.APPROVER_SCHEME_ID_SLOT[0..2]
889
+ # => [scheme_slot_prefix, scheme_slot_suffix, APPROVER_MAP_KEY, [1, 0, 0, 0], i-1, pad(12)]
824
890
 
825
891
  exec.native_account::set_map_item
826
892
  # => [OLD_VALUE, i-1, pad(12)]
@@ -853,7 +919,7 @@ end
853
919
  #! Outputs:
854
920
  #! Operand stack: []
855
921
  #! Invocation: call
856
- pub proc update_procedure_threshold(proc_threshold: u32, proc_root: BeWord)
922
+ pub proc update_procedure_threshold(proc_threshold: u32, proc_root: word)
857
923
  exec.set_procedure_threshold
858
924
  end
859
925
 
@@ -909,9 +975,9 @@ proc compute_transaction_threshold(default_threshold: u32) -> u32
909
975
  # 2b. get the override proc_threshold of that procedure
910
976
  # if the procedure has no override threshold, the returned map item will be [0, 0, 0, 0]
911
977
  exec.active_account::get_initial_map_item
912
- # => [[0, 0, 0, proc_threshold], num_procedures-1, transaction_threshold]
978
+ # => [[proc_threshold, 0, 0, 0], num_procedures-1, transaction_threshold]
913
979
 
914
- drop drop drop dup dup.3
980
+ movdn.3 drop drop drop dup dup.3
915
981
  # => [transaction_threshold, proc_threshold, proc_threshold, num_procedures-1, transaction_threshold]
916
982
 
917
983
  u32assert2.err="transaction threshold or procedure threshold are not u32"
@@ -980,18 +1046,18 @@ end
980
1046
  #!
981
1047
  #! Invocation: exec
982
1048
  @locals(1)
983
- pub proc auth_tx(salt: BeWord) -> BeWord
1049
+ pub proc auth_tx(salt: word)
984
1050
  exec.native_account::incr_nonce drop
985
1051
  # => [SALT]
986
1052
 
987
1053
  # ------ Computing transaction summary ------
988
1054
 
989
1055
  exec.auth::create_tx_summary
990
- # => [SALT, OUTPUT_NOTES_COMMITMENT, INPUT_NOTES_COMMITMENT, ACCOUNT_DELTA_COMMITMENT]
1056
+ # => [ACCOUNT_DELTA_COMMITMENT, INPUT_NOTES_COMMITMENT, OUTPUT_NOTES_COMMITMENT, SALT]
991
1057
 
992
1058
  # to build a tx_summary in the host, we need these four words in the advice provider
993
- exec.auth::adv_insert_hqword
994
- # => [SALT, OUTPUT_NOTES_COMMITMENT, INPUT_NOTES_COMMITMENT, ACCOUNT_DELTA_COMMITMENT]
1059
+ adv.insert_hqword
1060
+ # => [ACCOUNT_DELTA_COMMITMENT, INPUT_NOTES_COMMITMENT, OUTPUT_NOTES_COMMITMENT, SALT]
995
1061
 
996
1062
  # the commitment to the tx summary is the message that is signed
997
1063
  exec.auth::hash_tx_summary
@@ -999,22 +1065,19 @@ pub proc auth_tx(salt: BeWord) -> BeWord
999
1065
 
1000
1066
  # ------ Verifying approver signatures ------
1001
1067
 
1002
- push.THRESHOLD_CONFIG_SLOT[0..2]
1003
- # => [config_slot_prefix, config_slot_suffix, TX_SUMMARY_COMMITMENT]
1004
-
1005
- exec.active_account::get_initial_item
1006
- # => [0, 0, num_of_approvers, default_threshold, TX_SUMMARY_COMMITMENT]
1007
-
1008
- drop drop
1009
- # => [num_of_approvers, default_threshold, TX_SUMMARY_COMMITMENT]
1068
+ exec.get_threshold_and_num_approvers
1069
+ # => [default_threshold, num_of_approvers, TX_SUMMARY_COMMITMENT]
1010
1070
 
1011
- swap movdn.5
1071
+ movdn.5
1012
1072
  # => [num_of_approvers, TX_SUMMARY_COMMITMENT, default_threshold]
1013
1073
 
1014
1074
  push.PUBLIC_KEYS_MAP_SLOT[0..2]
1015
1075
  # => [pub_key_slot_prefix, pub_key_slot_suffix, num_of_approvers, TX_SUMMARY_COMMITMENT, default_threshold]
1016
1076
 
1017
- exec.::miden::standards::auth::ecdsa_k256_keccak::verify_signatures
1077
+ push.APPROVER_SCHEME_ID_SLOT[0..2]
1078
+ # => [scheme_id_slot_prefix, scheme_id_slot_suffix, pub_key_slot_prefix, pub_key_slot_suffix, num_of_approvers, TX_SUMMARY_COMMITMENT, default_threshold]
1079
+
1080
+ exec.::miden::standards::auth::signature::verify_signatures
1018
1081
  # => [num_verified_signatures, TX_SUMMARY_COMMITMENT, default_threshold]
1019
1082
 
1020
1083
  # ------ Checking threshold is >= num_verified_signatures ------
@@ -1044,10 +1107,9 @@ export const GUARDIAN_MASM = `# Guardian Authentication Component
1044
1107
  # It can be used standalone or in conjunction with other auth components like multisig.
1045
1108
 
1046
1109
  use miden::protocol::active_account
1110
+ use miden::protocol::auth::AUTH_UNAUTHORIZED_EVENT
1047
1111
  use miden::protocol::native_account
1048
1112
 
1049
- type BeWord = struct @bigendian { a: felt, b: felt, c: felt, d: felt }
1050
-
1051
1113
  # IMPORTANT SECURITY NOTES
1052
1114
  # --------------------------------------------------------------------------------
1053
1115
  # - The selector in \`GUARDIAN_SELECTOR_SLOT\` controls whether the extra GUARDIAN signature
@@ -1073,6 +1135,7 @@ type BeWord = struct @bigendian { a: felt, b: felt, c: felt, d: felt }
1073
1135
  # +---------------------+---------------+
1074
1136
  # | GUARDIAN SELECTOR (word) | 0 |
1075
1137
  # | GUARDIAN PUBLIC KEY MAP | 1 |
1138
+ # | GUARDIAN SCHEME ID MAP | 2 |
1076
1139
  # +---------------------+---------------+
1077
1140
  #
1078
1141
  # - GUARDIAN_SELECTOR_SLOT (0):
@@ -1082,7 +1145,7 @@ type BeWord = struct @bigendian { a: felt, b: felt, c: felt, d: felt }
1082
1145
  # - GUARDIAN_PUBLIC_KEY_MAP_SLOT (1):
1083
1146
  # * A map from a fixed key [0, 0, 0, 0] to the single GUARDIAN public key:
1084
1147
  # [0, 0, 0, 0] => GUARDIAN_PUBLIC_KEY
1085
- # * GUARDIAN_PUBLIC_KEY is a RPO Falcon 512 public key represented as a word.
1148
+ # * GUARDIAN_PUBLIC_KEY is a Falcon Poseidon2 public key represented as a word.
1086
1149
 
1087
1150
  # CONSTANTS
1088
1151
  # =================================================================================================
@@ -1097,12 +1160,15 @@ const GUARDIAN_SELECTOR_SLOT=word("openzeppelin::guardian::selector")
1097
1160
  # [0, 0, 0, 0] => GUARDIAN_PUBLIC_KEY
1098
1161
  const GUARDIAN_PUBLIC_KEY_MAP_SLOT=word("openzeppelin::guardian::public_key")
1099
1162
 
1163
+ # Map slot for GUARDIAN signature scheme IDs
1164
+ # Uses exactly one scheme ID entry at index [0, 0, 0, 0]
1165
+ # [0, 0, 0, 0] => [scheme_id, 0, 0, 0]
1166
+ const GUARDIAN_SCHEME_ID_MAP_SLOT=word("openzeppelin::guardian::scheme_id")
1167
+
1100
1168
  # Selector flag values
1101
1169
  const GUARDIAN_ON=[1, 0, 0, 0]
1102
1170
  const GUARDIAN_OFF=[0, 0, 0, 0]
1103
-
1104
- # The event emitted when a signature is not found for a required signer.
1105
- const AUTH_UNAUTHORIZED_EVENT=event("miden::auth::unauthorized")
1171
+ const FALCON_512_POSEIDON2_SCHEME_WORD=[2, 0, 0, 0]
1106
1172
 
1107
1173
  # GUARDIAN PROCEDURES
1108
1174
  # =================================================================================================
@@ -1180,6 +1246,24 @@ pub proc update_guardian_public_key
1180
1246
 
1181
1247
  dropw
1182
1248
  # => []
1249
+
1250
+ push.0.0.0.0
1251
+ # => [MAP_KEY]
1252
+
1253
+ push.FALCON_512_POSEIDON2_SCHEME_WORD
1254
+ # => [SCHEME_ID_WORD, MAP_KEY]
1255
+
1256
+ swapw
1257
+ # => [MAP_KEY, SCHEME_ID_WORD]
1258
+
1259
+ push.GUARDIAN_SCHEME_ID_MAP_SLOT[0..2]
1260
+ # => [scheme_id_slot_prefix, scheme_id_slot_suffix, MAP_KEY, SCHEME_ID_WORD]
1261
+
1262
+ exec.native_account::set_map_item
1263
+ # => [OLD_MAP_VALUE]
1264
+
1265
+ dropw
1266
+ # => []
1183
1267
  end
1184
1268
 
1185
1269
  #! Conditionally verify a "GUARDIAN" signature against a stored public key hash.
@@ -1195,7 +1279,7 @@ end
1195
1279
  #! - MSG is TX_SUMMARY_COMMITMENT provided by auth procedure
1196
1280
  #! - If selector is OFF (0), GUARDIAN verification is skipped
1197
1281
  #! - Selector value is read from initial storage state
1198
- pub proc verify_guardian_signature(msg: BeWord) -> BeWord
1282
+ pub proc verify_guardian_signature(msg: word)
1199
1283
  push.GUARDIAN_SELECTOR_SLOT[0..2]
1200
1284
  exec.active_account::get_item
1201
1285
  drop drop drop
@@ -1205,7 +1289,8 @@ pub proc verify_guardian_signature(msg: BeWord) -> BeWord
1205
1289
  if.true
1206
1290
  push.1
1207
1291
  push.GUARDIAN_PUBLIC_KEY_MAP_SLOT[0..2]
1208
- exec.::miden::standards::auth::falcon512_rpo::verify_signatures
1292
+ push.GUARDIAN_SCHEME_ID_MAP_SLOT[0..2]
1293
+ exec.::miden::standards::auth::signature::verify_signatures
1209
1294
  push.1 neq
1210
1295
  if.true
1211
1296
  emit.AUTH_UNAUTHORIZED_EVENT
@@ -1224,10 +1309,9 @@ export const GUARDIAN_ECDSA_MASM = `# Guardian Authentication Component (ECDSA)
1224
1309
  # It can be used standalone or in conjunction with other auth components like multisig.
1225
1310
 
1226
1311
  use miden::protocol::active_account
1312
+ use miden::protocol::auth::AUTH_UNAUTHORIZED_EVENT
1227
1313
  use miden::protocol::native_account
1228
1314
 
1229
- type BeWord = struct @bigendian { a: felt, b: felt, c: felt, d: felt }
1230
-
1231
1315
  # IMPORTANT SECURITY NOTES
1232
1316
  # --------------------------------------------------------------------------------
1233
1317
  # - The selector in \`GUARDIAN_SELECTOR_SLOT\` controls whether the extra GUARDIAN signature
@@ -1276,13 +1360,12 @@ const GUARDIAN_SELECTOR_SLOT=word("openzeppelin::guardian::selector")
1276
1360
  # Uses exactly one GUARDIAN public key at index [0, 0, 0, 0]
1277
1361
  # [0, 0, 0, 0] => GUARDIAN_PUBLIC_KEY
1278
1362
  const GUARDIAN_PUBLIC_KEY_MAP_SLOT=word("openzeppelin::guardian::public_key")
1363
+ const GUARDIAN_SCHEME_ID_MAP_SLOT=word("openzeppelin::guardian::scheme_id")
1279
1364
 
1280
1365
  # Selector flag values
1281
1366
  const GUARDIAN_ON=[1, 0, 0, 0]
1282
1367
  const GUARDIAN_OFF=[0, 0, 0, 0]
1283
-
1284
- # The event emitted when a signature is not found for a required signer.
1285
- const AUTH_UNAUTHORIZED_EVENT=event("miden::auth::unauthorized")
1368
+ const ECDSA_K256_KECCAK_SCHEME_WORD=[1, 0, 0, 0]
1286
1369
 
1287
1370
  # GUARDIAN PROCEDURES
1288
1371
  # =================================================================================================
@@ -1360,6 +1443,24 @@ pub proc update_guardian_public_key
1360
1443
 
1361
1444
  dropw
1362
1445
  # => []
1446
+
1447
+ push.0.0.0.0
1448
+ # => [MAP_KEY]
1449
+
1450
+ push.ECDSA_K256_KECCAK_SCHEME_WORD
1451
+ # => [SCHEME_ID_WORD, MAP_KEY]
1452
+
1453
+ swapw
1454
+ # => [MAP_KEY, SCHEME_ID_WORD]
1455
+
1456
+ push.GUARDIAN_SCHEME_ID_MAP_SLOT[0..2]
1457
+ # => [scheme_id_slot_prefix, scheme_id_slot_suffix, MAP_KEY, SCHEME_ID_WORD]
1458
+
1459
+ exec.native_account::set_map_item
1460
+ # => [OLD_MAP_VALUE]
1461
+
1462
+ dropw
1463
+ # => []
1363
1464
  end
1364
1465
 
1365
1466
  #! Conditionally verify a "GUARDIAN" signature against a stored public key hash.
@@ -1375,7 +1476,7 @@ end
1375
1476
  #! - MSG is TX_SUMMARY_COMMITMENT provided by auth procedure
1376
1477
  #! - If selector is OFF (0), GUARDIAN verification is skipped
1377
1478
  #! - Selector value is read from initial storage state
1378
- pub proc verify_guardian_signature(msg: BeWord) -> BeWord
1479
+ pub proc verify_guardian_signature(msg: word)
1379
1480
  push.GUARDIAN_SELECTOR_SLOT[0..2]
1380
1481
  exec.active_account::get_item
1381
1482
  drop drop drop
@@ -1385,7 +1486,8 @@ pub proc verify_guardian_signature(msg: BeWord) -> BeWord
1385
1486
  if.true
1386
1487
  push.1
1387
1488
  push.GUARDIAN_PUBLIC_KEY_MAP_SLOT[0..2]
1388
- exec.::miden::standards::auth::ecdsa_k256_keccak::verify_signatures
1489
+ push.GUARDIAN_SCHEME_ID_MAP_SLOT[0..2]
1490
+ exec.::miden::standards::auth::signature::verify_signatures
1389
1491
  push.1 neq
1390
1492
  if.true
1391
1493
  emit.AUTH_UNAUTHORIZED_EVENT