@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
@@ -5,27 +5,23 @@ export const MULTISIG_MASM = `# Multi-Signature RPO Falcon 512 Authentication Co
5
5
  # This library provides the reusable multisig procedures used by account wrappers.
6
6
 
7
7
  use miden::protocol::active_account
8
+ use miden::protocol::auth::AUTH_UNAUTHORIZED_EVENT
8
9
  use miden::protocol::native_account
9
10
  use miden::standards::auth
10
11
 
11
- type BeWord = struct @bigendian { a: felt, b: felt, c: felt, d: felt }
12
-
13
12
  # CONSTANTS
14
13
  # =================================================================================================
15
14
 
16
15
  # Auth Request Constants
17
16
 
18
- # The event emitted when a signature is not found for a required signer.
19
- const AUTH_UNAUTHORIZED_EVENT=event("miden::auth::unauthorized")
20
-
21
17
  # Storage Layout Constants
22
18
  #
23
- # +-------------------------------+----------+--------------+-------------------+
24
- # | THRESHOLD & APPROVERS CONFIG | PUB KEYS | EXECUTED TXS | PROC THRESHOLDS |
25
- # | (slot) | (map) | (map) | (map) |
26
- # +-------------------------------+----------+--------------+-------------------+
27
- # | 0 | 1 | 2 | 3 |
28
- # +-------------------------------+----------+--------------+-------------------+
19
+ # +-------------------------------+----------+------------+--------------+-------------------+
20
+ # | THRESHOLD & APPROVERS CONFIG | PUB KEYS | SCHEME IDS | EXECUTED TXS | PROC THRESHOLDS |
21
+ # | (slot) | (map) | (map) | (map) | (map) |
22
+ # +-------------------------------+----------+------------+--------------+-------------------+
23
+ # | 0 | 1 | 2 | 3 | 4 |
24
+ # +-------------------------------+----------+------------+--------------+-------------------+
29
25
 
30
26
  # The slot in this component's storage layout where the default signature threshold and
31
27
  # number of approvers are stored as:
@@ -37,6 +33,10 @@ const THRESHOLD_CONFIG_SLOT=word("openzeppelin::multisig::threshold_config")
37
33
  # Map entries: [key_index, 0, 0, 0] => APPROVER_PUBLIC_KEY
38
34
  const PUBLIC_KEYS_MAP_SLOT=word("openzeppelin::multisig::signer_public_keys")
39
35
 
36
+ # The slot in this component's storage layout where signer scheme IDs are stored.
37
+ # Map entries: [key_index, 0, 0, 0] => [scheme_id, 0, 0, 0]
38
+ const APPROVER_SCHEME_ID_SLOT=word("openzeppelin::multisig::signer_scheme_ids")
39
+
40
40
  # The slot in this component's storage layout where executed transactions are stored.
41
41
  # Map entries: transaction_message => [is_executed, 0, 0, 0]
42
42
  const EXECUTED_TXS_SLOT=word("openzeppelin::multisig::executed_transactions")
@@ -47,6 +47,7 @@ const PROC_THRESHOLD_ROOTS_SLOT=word("openzeppelin::multisig::procedure_threshol
47
47
 
48
48
  # Executed Transaction Flag Constant
49
49
  const IS_EXECUTED_FLAG=[1, 0, 0, 0]
50
+ const FALCON_512_POSEIDON2_SCHEME_WORD=[2, 0, 0, 0]
50
51
 
51
52
  # ERRORS
52
53
  const ERR_TX_ALREADY_EXECUTED="failed to approve multisig transaction as it was already executed"
@@ -71,7 +72,7 @@ const ERR_PROC_THRESHOLD_EXCEEDS_NUM_APPROVERS="procedure threshold exceeds numb
71
72
  #!
72
73
  #! Panics if:
73
74
  #! - the same transaction has already been executed
74
- pub proc assert_new_tx(msg: BeWord)
75
+ pub proc assert_new_tx(msg: word)
75
76
  push.IS_EXECUTED_FLAG
76
77
  # => [[0, 0, 0, is_executed], MSG]
77
78
 
@@ -115,17 +116,29 @@ proc cleanup_pubkey_mapping(init_num_of_approvers: u32, new_num_of_approvers: u3
115
116
  sub.1
116
117
  # => [i-1, new_num_of_approvers]
117
118
 
118
- dup
119
- # => [i-1, i-1, new_num_of_approvers]
120
-
121
- push.0.0.0
122
- # => [[0, 0, 0, i-1], i-1, new_num_of_approvers]
119
+ dup exec.create_approver_map_key
120
+ # => [APPROVER_MAP_KEY, i-1, new_num_of_approvers]
123
121
 
124
122
  padw swapw
125
- # => [[0, 0, 0, i-1], EMPTY_WORD, i-1, new_num_of_approvers]
123
+ # => [APPROVER_MAP_KEY, EMPTY_WORD, i-1, new_num_of_approvers]
126
124
 
127
125
  push.PUBLIC_KEYS_MAP_SLOT[0..2]
128
- # => [pub_key_slot_prefix, pub_key_slot_suffix, [0, 0, 0, i-1], EMPTY_WORD, i-1, new_num_of_approvers]
126
+ # => [pub_key_slot_prefix, pub_key_slot_suffix, APPROVER_MAP_KEY, EMPTY_WORD, i-1, new_num_of_approvers]
127
+
128
+ exec.native_account::set_map_item
129
+ # => [OLD_MAP_VALUE, i-1, new_num_of_approvers]
130
+
131
+ dropw
132
+ # => [i-1, new_num_of_approvers]
133
+
134
+ dup exec.create_approver_map_key
135
+ # => [APPROVER_MAP_KEY, i-1, new_num_of_approvers]
136
+
137
+ padw swapw
138
+ # => [APPROVER_MAP_KEY, EMPTY_WORD, i-1, new_num_of_approvers]
139
+
140
+ push.APPROVER_SCHEME_ID_SLOT[0..2]
141
+ # => [scheme_slot_prefix, scheme_slot_suffix, APPROVER_MAP_KEY, EMPTY_WORD, i-1, new_num_of_approvers]
129
142
 
130
143
  exec.native_account::set_map_item
131
144
  # => [OLD_MAP_VALUE, i-1, new_num_of_approvers]
@@ -142,15 +155,17 @@ proc cleanup_pubkey_mapping(init_num_of_approvers: u32, new_num_of_approvers: u3
142
155
  # => []
143
156
  end
144
157
 
158
+ proc create_approver_map_key
159
+ push.0.0.0 movup.3
160
+ # => [APPROVER_MAP_KEY]
161
+ end
162
+
145
163
  proc get_threshold_and_num_approvers
146
164
  push.THRESHOLD_CONFIG_SLOT[0..2]
147
165
  exec.active_account::get_initial_item
148
- # => [0, 0, num_approvers, threshold]
149
-
150
- drop drop
151
- # => [num_approvers, threshold]
166
+ # => [threshold, num_approvers]
152
167
 
153
- swap
168
+ movup.2 drop movup.2 drop
154
169
  # => [threshold, num_approvers]
155
170
  end
156
171
 
@@ -170,10 +185,10 @@ proc assert_proc_thresholds_lte_num_approvers(num_approvers: u32)
170
185
  push.PROC_THRESHOLD_ROOTS_SLOT[0..2]
171
186
  # => [proc_roots_slot_prefix, proc_roots_slot_suffix, PROC_ROOT, proc_index, num_approvers]
172
187
 
173
- exec.active_account::get_initial_map_item
174
- # => [[0, 0, 0, proc_threshold], proc_index, num_approvers]
188
+ exec.active_account::get_map_item
189
+ # => [[proc_threshold, 0, 0, 0], proc_index, num_approvers]
175
190
 
176
- drop drop drop
191
+ movdn.3 drop drop drop
177
192
  # => [proc_threshold, proc_index, num_approvers]
178
193
 
179
194
  dup.2
@@ -193,7 +208,7 @@ end
193
208
 
194
209
  # Internal storage helper used by the public \`update_procedure_threshold\`
195
210
  # entrypoint after it receives direct stack arguments.
196
- proc set_procedure_threshold(proc_threshold: u32, proc_root: BeWord)
211
+ proc set_procedure_threshold(proc_threshold: u32, proc_root: word)
197
212
  exec.get_threshold_and_num_approvers
198
213
  # => [threshold, num_approvers, proc_threshold, PROC_ROOT]
199
214
 
@@ -208,6 +223,7 @@ proc set_procedure_threshold(proc_threshold: u32, proc_root: BeWord)
208
223
  # => [proc_threshold, PROC_ROOT]
209
224
 
210
225
  push.0.0.0
226
+ movup.3
211
227
  swapw
212
228
  # => [PROC_ROOT, PROC_THRESHOLD_WORD]
213
229
 
@@ -240,7 +256,7 @@ end
240
256
  #! 0: new_num_of_approvers
241
257
  #! 1: init_num_of_approvers
242
258
  @locals(2)
243
- pub proc update_signers_and_threshold(multisig_config_hash: BeWord)
259
+ pub proc update_signers_and_threshold(multisig_config_hash: word)
244
260
  adv.push_mapval
245
261
  # => [MULTISIG_CONFIG_HASH, pad(12)]
246
262
 
@@ -248,10 +264,10 @@ pub proc update_signers_and_threshold(multisig_config_hash: BeWord)
248
264
  # => [MULTISIG_CONFIG, pad(12)]
249
265
 
250
266
  # store new_num_of_approvers for later
251
- dup.2 loc_store.0
267
+ dup.1 loc_store.0
252
268
  # => [MULTISIG_CONFIG, pad(12)]
253
269
 
254
- dup.3 dup.3
270
+ dup dup.2
255
271
  # => [num_approvers, threshold, MULTISIG_CONFIG, pad(12)]
256
272
 
257
273
  # make sure that the threshold is smaller than the number of approvers
@@ -259,7 +275,7 @@ pub proc update_signers_and_threshold(multisig_config_hash: BeWord)
259
275
  u32gt assertz.err=ERR_MALFORMED_MULTISIG_CONFIG
260
276
  # => [MULTISIG_CONFIG, pad(12)]
261
277
 
262
- dup.3 dup.3
278
+ dup dup.2
263
279
  # => [num_approvers, threshold, MULTISIG_CONFIG, pad(12)]
264
280
 
265
281
  # make sure that threshold or num_approvers are not zero
@@ -280,7 +296,7 @@ pub proc update_signers_and_threshold(multisig_config_hash: BeWord)
280
296
  # => [OLD_THRESHOLD_CONFIG, pad(12)]
281
297
 
282
298
  # store init_num_of_approvers for later
283
- drop drop loc_store.1 drop
299
+ drop loc_store.1 drop drop
284
300
  # => [pad(12)]
285
301
 
286
302
  loc_load.0
@@ -291,17 +307,35 @@ pub proc update_signers_and_threshold(multisig_config_hash: BeWord)
291
307
  sub.1
292
308
  # => [i-1, pad(12)]
293
309
 
294
- dup push.0.0.0
295
- # => [[0, 0, 0, i-1], i-1, pad(12)]
310
+ dup exec.create_approver_map_key
311
+ # => [APPROVER_MAP_KEY, i-1, pad(12)]
296
312
 
297
313
  padw adv_loadw
298
- # => [PUB_KEY, [0, 0, 0, i-1], i-1, pad(12)]
314
+ # => [PUB_KEY, APPROVER_MAP_KEY, i-1, pad(12)]
299
315
 
300
316
  swapw
301
- # => [[0, 0, 0, i-1], PUB_KEY, i-1, pad(12)]
317
+ # => [APPROVER_MAP_KEY, PUB_KEY, i-1, pad(12)]
302
318
 
303
319
  push.PUBLIC_KEYS_MAP_SLOT[0..2]
304
- # => [pub_key_slot_prefix, pub_key_slot_suffix, [0, 0, 0, i-1], PUB_KEY, i-1, pad(12)]
320
+ # => [pub_key_slot_prefix, pub_key_slot_suffix, APPROVER_MAP_KEY, PUB_KEY, i-1, pad(12)]
321
+
322
+ exec.native_account::set_map_item
323
+ # => [OLD_VALUE, i-1, pad(12)]
324
+
325
+ dropw
326
+ # => [i-1, pad(12)]
327
+
328
+ dup exec.create_approver_map_key
329
+ # => [APPROVER_MAP_KEY, i-1, pad(12)]
330
+
331
+ push.FALCON_512_POSEIDON2_SCHEME_WORD
332
+ # => [SCHEME_ID_WORD, APPROVER_MAP_KEY, i-1, pad(12)]
333
+
334
+ swapw
335
+ # => [APPROVER_MAP_KEY, [2, 0, 0, 0], i-1, pad(12)]
336
+
337
+ push.APPROVER_SCHEME_ID_SLOT[0..2]
338
+ # => [scheme_slot_prefix, scheme_slot_suffix, APPROVER_MAP_KEY, [2, 0, 0, 0], i-1, pad(12)]
305
339
 
306
340
  exec.native_account::set_map_item
307
341
  # => [OLD_VALUE, i-1, pad(12)]
@@ -334,7 +368,7 @@ end
334
368
  #! Outputs:
335
369
  #! Operand stack: []
336
370
  #! Invocation: call
337
- pub proc update_procedure_threshold(proc_threshold: u32, proc_root: BeWord)
371
+ pub proc update_procedure_threshold(proc_threshold: u32, proc_root: word)
338
372
  exec.set_procedure_threshold
339
373
  end
340
374
 
@@ -390,9 +424,9 @@ proc compute_transaction_threshold(default_threshold: u32) -> u32
390
424
  # 2b. get the override proc_threshold of that procedure
391
425
  # if the procedure has no override threshold, the returned map item will be [0, 0, 0, 0]
392
426
  exec.active_account::get_initial_map_item
393
- # => [[0, 0, 0, proc_threshold], num_procedures-1, transaction_threshold]
427
+ # => [[proc_threshold, 0, 0, 0], num_procedures-1, transaction_threshold]
394
428
 
395
- drop drop drop dup dup.3
429
+ movdn.3 drop drop drop dup dup.3
396
430
  # => [transaction_threshold, proc_threshold, proc_threshold, num_procedures-1, transaction_threshold]
397
431
 
398
432
  u32assert2.err="transaction threshold or procedure threshold are not u32"
@@ -461,18 +495,18 @@ end
461
495
  #!
462
496
  #! Invocation: exec
463
497
  @locals(1)
464
- pub proc auth_tx(salt: BeWord) -> BeWord
498
+ pub proc auth_tx(salt: word)
465
499
  exec.native_account::incr_nonce drop
466
500
  # => [SALT]
467
501
 
468
502
  # ------ Computing transaction summary ------
469
503
 
470
504
  exec.auth::create_tx_summary
471
- # => [SALT, OUTPUT_NOTES_COMMITMENT, INPUT_NOTES_COMMITMENT, ACCOUNT_DELTA_COMMITMENT]
505
+ # => [ACCOUNT_DELTA_COMMITMENT, INPUT_NOTES_COMMITMENT, OUTPUT_NOTES_COMMITMENT, SALT]
472
506
 
473
507
  # to build a tx_summary in the host, we need these four words in the advice provider
474
- exec.auth::adv_insert_hqword
475
- # => [SALT, OUTPUT_NOTES_COMMITMENT, INPUT_NOTES_COMMITMENT, ACCOUNT_DELTA_COMMITMENT]
508
+ adv.insert_hqword
509
+ # => [ACCOUNT_DELTA_COMMITMENT, INPUT_NOTES_COMMITMENT, OUTPUT_NOTES_COMMITMENT, SALT]
476
510
 
477
511
  # the commitment to the tx summary is the message that is signed
478
512
  exec.auth::hash_tx_summary
@@ -480,22 +514,19 @@ pub proc auth_tx(salt: BeWord) -> BeWord
480
514
 
481
515
  # ------ Verifying approver signatures ------
482
516
 
483
- push.THRESHOLD_CONFIG_SLOT[0..2]
484
- # => [config_slot_prefix, config_slot_suffix, TX_SUMMARY_COMMITMENT]
485
-
486
- exec.active_account::get_initial_item
487
- # => [0, 0, num_of_approvers, default_threshold, TX_SUMMARY_COMMITMENT]
488
-
489
- drop drop
490
- # => [num_of_approvers, default_threshold, TX_SUMMARY_COMMITMENT]
517
+ exec.get_threshold_and_num_approvers
518
+ # => [default_threshold, num_of_approvers, TX_SUMMARY_COMMITMENT]
491
519
 
492
- swap movdn.5
520
+ movdn.5
493
521
  # => [num_of_approvers, TX_SUMMARY_COMMITMENT, default_threshold]
494
522
 
495
523
  push.PUBLIC_KEYS_MAP_SLOT[0..2]
496
524
  # => [pub_key_slot_prefix, pub_key_slot_suffix, num_of_approvers, TX_SUMMARY_COMMITMENT, default_threshold]
497
525
 
498
- exec.::miden::standards::auth::falcon512_rpo::verify_signatures
526
+ push.APPROVER_SCHEME_ID_SLOT[0..2]
527
+ # => [scheme_id_slot_prefix, scheme_id_slot_suffix, pub_key_slot_prefix, pub_key_slot_suffix, num_of_approvers, TX_SUMMARY_COMMITMENT, default_threshold]
528
+
529
+ exec.::miden::standards::auth::signature::verify_signatures
499
530
  # => [num_verified_signatures, TX_SUMMARY_COMMITMENT, default_threshold]
500
531
 
501
532
  # ------ Checking threshold is >= num_verified_signatures ------
@@ -523,26 +554,23 @@ export const MULTISIG_ECDSA_MASM = `# Multi-Signature ECDSA secp256k1 Authentica
523
554
  # This library provides the reusable multisig procedures used by account wrappers.
524
555
 
525
556
  use miden::protocol::active_account
557
+ use miden::protocol::auth::AUTH_UNAUTHORIZED_EVENT
526
558
  use miden::protocol::native_account
527
559
  use miden::standards::auth
528
- type BeWord = struct @bigendian { a: felt, b: felt, c: felt, d: felt }
529
560
 
530
561
  # CONSTANTS
531
562
  # =================================================================================================
532
563
 
533
564
  # Auth Request Constants
534
565
 
535
- # The event emitted when a signature is not found for a required signer.
536
- const AUTH_UNAUTHORIZED_EVENT=event("miden::auth::unauthorized")
537
-
538
566
  # Storage Layout Constants
539
567
  #
540
- # +-------------------------------+----------+--------------+-------------------+
541
- # | THRESHOLD & APPROVERS CONFIG | PUB KEYS | EXECUTED TXS | PROC THRESHOLDS |
542
- # | (slot) | (map) | (map) | (map) |
543
- # +-------------------------------+----------+--------------+-------------------+
544
- # | 0 | 1 | 2 | 3 |
545
- # +-------------------------------+----------+--------------+-------------------+
568
+ # +-------------------------------+----------+------------+--------------+-------------------+
569
+ # | THRESHOLD & APPROVERS CONFIG | PUB KEYS | SCHEME IDS | EXECUTED TXS | PROC THRESHOLDS |
570
+ # | (slot) | (map) | (map) | (map) | (map) |
571
+ # +-------------------------------+----------+------------+--------------+-------------------+
572
+ # | 0 | 1 | 2 | 3 | 4 |
573
+ # +-------------------------------+----------+------------+--------------+-------------------+
546
574
 
547
575
  # The slot in this component's storage layout where the default signature threshold and
548
576
  # number of approvers are stored as:
@@ -554,6 +582,10 @@ const THRESHOLD_CONFIG_SLOT=word("openzeppelin::multisig::threshold_config")
554
582
  # Map entries: [key_index, 0, 0, 0] => APPROVER_PUBLIC_KEY
555
583
  const PUBLIC_KEYS_MAP_SLOT=word("openzeppelin::multisig::signer_public_keys")
556
584
 
585
+ # The slot in this component's storage layout where signer scheme IDs are stored.
586
+ # Map entries: [key_index, 0, 0, 0] => [scheme_id, 0, 0, 0]
587
+ const APPROVER_SCHEME_ID_SLOT=word("openzeppelin::multisig::signer_scheme_ids")
588
+
557
589
  # The slot in this component's storage layout where executed transactions are stored.
558
590
  # Map entries: transaction_message => [is_executed, 0, 0, 0]
559
591
  const EXECUTED_TXS_SLOT=word("openzeppelin::multisig::executed_transactions")
@@ -564,6 +596,7 @@ const PROC_THRESHOLD_ROOTS_SLOT=word("openzeppelin::multisig::procedure_threshol
564
596
 
565
597
  # Executed Transaction Flag Constant
566
598
  const IS_EXECUTED_FLAG=[1, 0, 0, 0]
599
+ const ECDSA_K256_KECCAK_SCHEME_WORD=[1, 0, 0, 0]
567
600
 
568
601
  # ERRORS
569
602
  const ERR_TX_ALREADY_EXECUTED="failed to approve multisig transaction as it was already executed"
@@ -588,7 +621,7 @@ const ERR_PROC_THRESHOLD_EXCEEDS_NUM_APPROVERS="procedure threshold exceeds numb
588
621
  #!
589
622
  #! Panics if:
590
623
  #! - the same transaction has already been executed
591
- pub proc assert_new_tx(msg: BeWord)
624
+ pub proc assert_new_tx(msg: word)
592
625
  push.IS_EXECUTED_FLAG
593
626
  # => [[0, 0, 0, is_executed], MSG]
594
627
 
@@ -632,17 +665,29 @@ proc cleanup_pubkey_mapping(init_num_of_approvers: u32, new_num_of_approvers: u3
632
665
  sub.1
633
666
  # => [i-1, new_num_of_approvers]
634
667
 
635
- dup
636
- # => [i-1, i-1, new_num_of_approvers]
637
-
638
- push.0.0.0
639
- # => [[0, 0, 0, i-1], i-1, new_num_of_approvers]
668
+ dup exec.create_approver_map_key
669
+ # => [APPROVER_MAP_KEY, i-1, new_num_of_approvers]
640
670
 
641
671
  padw swapw
642
- # => [[0, 0, 0, i-1], EMPTY_WORD, i-1, new_num_of_approvers]
672
+ # => [APPROVER_MAP_KEY, EMPTY_WORD, i-1, new_num_of_approvers]
643
673
 
644
674
  push.PUBLIC_KEYS_MAP_SLOT[0..2]
645
- # => [pub_key_slot_prefix, pub_key_slot_suffix, [0, 0, 0, i-1], EMPTY_WORD, i-1, new_num_of_approvers]
675
+ # => [pub_key_slot_prefix, pub_key_slot_suffix, APPROVER_MAP_KEY, EMPTY_WORD, i-1, new_num_of_approvers]
676
+
677
+ exec.native_account::set_map_item
678
+ # => [OLD_MAP_VALUE, i-1, new_num_of_approvers]
679
+
680
+ dropw
681
+ # => [i-1, new_num_of_approvers]
682
+
683
+ dup exec.create_approver_map_key
684
+ # => [APPROVER_MAP_KEY, i-1, new_num_of_approvers]
685
+
686
+ padw swapw
687
+ # => [APPROVER_MAP_KEY, EMPTY_WORD, i-1, new_num_of_approvers]
688
+
689
+ push.APPROVER_SCHEME_ID_SLOT[0..2]
690
+ # => [scheme_slot_prefix, scheme_slot_suffix, APPROVER_MAP_KEY, EMPTY_WORD, i-1, new_num_of_approvers]
646
691
 
647
692
  exec.native_account::set_map_item
648
693
  # => [OLD_MAP_VALUE, i-1, new_num_of_approvers]
@@ -659,15 +704,17 @@ proc cleanup_pubkey_mapping(init_num_of_approvers: u32, new_num_of_approvers: u3
659
704
  # => []
660
705
  end
661
706
 
707
+ proc create_approver_map_key
708
+ push.0.0.0 movup.3
709
+ # => [APPROVER_MAP_KEY]
710
+ end
711
+
662
712
  proc get_threshold_and_num_approvers
663
713
  push.THRESHOLD_CONFIG_SLOT[0..2]
664
714
  exec.active_account::get_initial_item
665
- # => [0, 0, num_approvers, threshold]
666
-
667
- drop drop
668
- # => [num_approvers, threshold]
715
+ # => [threshold, num_approvers]
669
716
 
670
- swap
717
+ movup.2 drop movup.2 drop
671
718
  # => [threshold, num_approvers]
672
719
  end
673
720
 
@@ -687,10 +734,10 @@ proc assert_proc_thresholds_lte_num_approvers(num_approvers: u32)
687
734
  push.PROC_THRESHOLD_ROOTS_SLOT[0..2]
688
735
  # => [proc_roots_slot_prefix, proc_roots_slot_suffix, PROC_ROOT, proc_index, num_approvers]
689
736
 
690
- exec.active_account::get_initial_map_item
691
- # => [[0, 0, 0, proc_threshold], proc_index, num_approvers]
737
+ exec.active_account::get_map_item
738
+ # => [[proc_threshold, 0, 0, 0], proc_index, num_approvers]
692
739
 
693
- drop drop drop
740
+ movdn.3 drop drop drop
694
741
  # => [proc_threshold, proc_index, num_approvers]
695
742
 
696
743
  dup.2
@@ -710,7 +757,7 @@ end
710
757
 
711
758
  # Internal storage helper used by the public \`update_procedure_threshold\`
712
759
  # entrypoint after it receives direct stack arguments.
713
- proc set_procedure_threshold(proc_threshold: u32, proc_root: BeWord)
760
+ proc set_procedure_threshold(proc_threshold: u32, proc_root: word)
714
761
  exec.get_threshold_and_num_approvers
715
762
  # => [threshold, num_approvers, proc_threshold, PROC_ROOT]
716
763
 
@@ -725,6 +772,7 @@ proc set_procedure_threshold(proc_threshold: u32, proc_root: BeWord)
725
772
  # => [proc_threshold, PROC_ROOT]
726
773
 
727
774
  push.0.0.0
775
+ movup.3
728
776
  swapw
729
777
  # => [PROC_ROOT, PROC_THRESHOLD_WORD]
730
778
 
@@ -757,7 +805,7 @@ end
757
805
  #! 0: new_num_of_approvers
758
806
  #! 1: init_num_of_approvers
759
807
  @locals(2)
760
- pub proc update_signers_and_threshold(multisig_config_hash: BeWord)
808
+ pub proc update_signers_and_threshold(multisig_config_hash: word)
761
809
  adv.push_mapval
762
810
  # => [MULTISIG_CONFIG_HASH, pad(12)]
763
811
 
@@ -765,10 +813,10 @@ pub proc update_signers_and_threshold(multisig_config_hash: BeWord)
765
813
  # => [MULTISIG_CONFIG, pad(12)]
766
814
 
767
815
  # store new_num_of_approvers for later
768
- dup.2 loc_store.0
816
+ dup.1 loc_store.0
769
817
  # => [MULTISIG_CONFIG, pad(12)]
770
818
 
771
- dup.3 dup.3
819
+ dup dup.2
772
820
  # => [num_approvers, threshold, MULTISIG_CONFIG, pad(12)]
773
821
 
774
822
  # make sure that the threshold is smaller than the number of approvers
@@ -776,7 +824,7 @@ pub proc update_signers_and_threshold(multisig_config_hash: BeWord)
776
824
  u32gt assertz.err=ERR_MALFORMED_MULTISIG_CONFIG
777
825
  # => [MULTISIG_CONFIG, pad(12)]
778
826
 
779
- dup.3 dup.3
827
+ dup dup.2
780
828
  # => [num_approvers, threshold, MULTISIG_CONFIG, pad(12)]
781
829
 
782
830
  # make sure that threshold or num_approvers are not zero
@@ -797,7 +845,7 @@ pub proc update_signers_and_threshold(multisig_config_hash: BeWord)
797
845
  # => [OLD_THRESHOLD_CONFIG, pad(12)]
798
846
 
799
847
  # store init_num_of_approvers for later
800
- drop drop loc_store.1 drop
848
+ drop loc_store.1 drop drop
801
849
  # => [pad(12)]
802
850
 
803
851
  loc_load.0
@@ -808,17 +856,35 @@ pub proc update_signers_and_threshold(multisig_config_hash: BeWord)
808
856
  sub.1
809
857
  # => [i-1, pad(12)]
810
858
 
811
- dup push.0.0.0
812
- # => [[0, 0, 0, i-1], i-1, pad(12)]
859
+ dup exec.create_approver_map_key
860
+ # => [APPROVER_MAP_KEY, i-1, pad(12)]
813
861
 
814
862
  padw adv_loadw
815
- # => [PUB_KEY, [0, 0, 0, i-1], i-1, pad(12)]
863
+ # => [PUB_KEY, APPROVER_MAP_KEY, i-1, pad(12)]
816
864
 
817
865
  swapw
818
- # => [[0, 0, 0, i-1], PUB_KEY, i-1, pad(12)]
866
+ # => [APPROVER_MAP_KEY, PUB_KEY, i-1, pad(12)]
819
867
 
820
868
  push.PUBLIC_KEYS_MAP_SLOT[0..2]
821
- # => [pub_key_slot_prefix, pub_key_slot_suffix, [0, 0, 0, i-1], PUB_KEY, i-1, pad(12)]
869
+ # => [pub_key_slot_prefix, pub_key_slot_suffix, APPROVER_MAP_KEY, PUB_KEY, i-1, pad(12)]
870
+
871
+ exec.native_account::set_map_item
872
+ # => [OLD_VALUE, i-1, pad(12)]
873
+
874
+ dropw
875
+ # => [i-1, pad(12)]
876
+
877
+ dup exec.create_approver_map_key
878
+ # => [APPROVER_MAP_KEY, i-1, pad(12)]
879
+
880
+ push.ECDSA_K256_KECCAK_SCHEME_WORD
881
+ # => [SCHEME_ID_WORD, APPROVER_MAP_KEY, i-1, pad(12)]
882
+
883
+ swapw
884
+ # => [APPROVER_MAP_KEY, [1, 0, 0, 0], i-1, pad(12)]
885
+
886
+ push.APPROVER_SCHEME_ID_SLOT[0..2]
887
+ # => [scheme_slot_prefix, scheme_slot_suffix, APPROVER_MAP_KEY, [1, 0, 0, 0], i-1, pad(12)]
822
888
 
823
889
  exec.native_account::set_map_item
824
890
  # => [OLD_VALUE, i-1, pad(12)]
@@ -851,7 +917,7 @@ end
851
917
  #! Outputs:
852
918
  #! Operand stack: []
853
919
  #! Invocation: call
854
- pub proc update_procedure_threshold(proc_threshold: u32, proc_root: BeWord)
920
+ pub proc update_procedure_threshold(proc_threshold: u32, proc_root: word)
855
921
  exec.set_procedure_threshold
856
922
  end
857
923
 
@@ -907,9 +973,9 @@ proc compute_transaction_threshold(default_threshold: u32) -> u32
907
973
  # 2b. get the override proc_threshold of that procedure
908
974
  # if the procedure has no override threshold, the returned map item will be [0, 0, 0, 0]
909
975
  exec.active_account::get_initial_map_item
910
- # => [[0, 0, 0, proc_threshold], num_procedures-1, transaction_threshold]
976
+ # => [[proc_threshold, 0, 0, 0], num_procedures-1, transaction_threshold]
911
977
 
912
- drop drop drop dup dup.3
978
+ movdn.3 drop drop drop dup dup.3
913
979
  # => [transaction_threshold, proc_threshold, proc_threshold, num_procedures-1, transaction_threshold]
914
980
 
915
981
  u32assert2.err="transaction threshold or procedure threshold are not u32"
@@ -978,18 +1044,18 @@ end
978
1044
  #!
979
1045
  #! Invocation: exec
980
1046
  @locals(1)
981
- pub proc auth_tx(salt: BeWord) -> BeWord
1047
+ pub proc auth_tx(salt: word)
982
1048
  exec.native_account::incr_nonce drop
983
1049
  # => [SALT]
984
1050
 
985
1051
  # ------ Computing transaction summary ------
986
1052
 
987
1053
  exec.auth::create_tx_summary
988
- # => [SALT, OUTPUT_NOTES_COMMITMENT, INPUT_NOTES_COMMITMENT, ACCOUNT_DELTA_COMMITMENT]
1054
+ # => [ACCOUNT_DELTA_COMMITMENT, INPUT_NOTES_COMMITMENT, OUTPUT_NOTES_COMMITMENT, SALT]
989
1055
 
990
1056
  # to build a tx_summary in the host, we need these four words in the advice provider
991
- exec.auth::adv_insert_hqword
992
- # => [SALT, OUTPUT_NOTES_COMMITMENT, INPUT_NOTES_COMMITMENT, ACCOUNT_DELTA_COMMITMENT]
1057
+ adv.insert_hqword
1058
+ # => [ACCOUNT_DELTA_COMMITMENT, INPUT_NOTES_COMMITMENT, OUTPUT_NOTES_COMMITMENT, SALT]
993
1059
 
994
1060
  # the commitment to the tx summary is the message that is signed
995
1061
  exec.auth::hash_tx_summary
@@ -997,22 +1063,19 @@ pub proc auth_tx(salt: BeWord) -> BeWord
997
1063
 
998
1064
  # ------ Verifying approver signatures ------
999
1065
 
1000
- push.THRESHOLD_CONFIG_SLOT[0..2]
1001
- # => [config_slot_prefix, config_slot_suffix, TX_SUMMARY_COMMITMENT]
1002
-
1003
- exec.active_account::get_initial_item
1004
- # => [0, 0, num_of_approvers, default_threshold, TX_SUMMARY_COMMITMENT]
1005
-
1006
- drop drop
1007
- # => [num_of_approvers, default_threshold, TX_SUMMARY_COMMITMENT]
1066
+ exec.get_threshold_and_num_approvers
1067
+ # => [default_threshold, num_of_approvers, TX_SUMMARY_COMMITMENT]
1008
1068
 
1009
- swap movdn.5
1069
+ movdn.5
1010
1070
  # => [num_of_approvers, TX_SUMMARY_COMMITMENT, default_threshold]
1011
1071
 
1012
1072
  push.PUBLIC_KEYS_MAP_SLOT[0..2]
1013
1073
  # => [pub_key_slot_prefix, pub_key_slot_suffix, num_of_approvers, TX_SUMMARY_COMMITMENT, default_threshold]
1014
1074
 
1015
- exec.::miden::standards::auth::ecdsa_k256_keccak::verify_signatures
1075
+ push.APPROVER_SCHEME_ID_SLOT[0..2]
1076
+ # => [scheme_id_slot_prefix, scheme_id_slot_suffix, pub_key_slot_prefix, pub_key_slot_suffix, num_of_approvers, TX_SUMMARY_COMMITMENT, default_threshold]
1077
+
1078
+ exec.::miden::standards::auth::signature::verify_signatures
1016
1079
  # => [num_verified_signatures, TX_SUMMARY_COMMITMENT, default_threshold]
1017
1080
 
1018
1081
  # ------ Checking threshold is >= num_verified_signatures ------
@@ -1041,10 +1104,9 @@ export const GUARDIAN_MASM = `# Guardian Authentication Component
1041
1104
  # It can be used standalone or in conjunction with other auth components like multisig.
1042
1105
 
1043
1106
  use miden::protocol::active_account
1107
+ use miden::protocol::auth::AUTH_UNAUTHORIZED_EVENT
1044
1108
  use miden::protocol::native_account
1045
1109
 
1046
- type BeWord = struct @bigendian { a: felt, b: felt, c: felt, d: felt }
1047
-
1048
1110
  # IMPORTANT SECURITY NOTES
1049
1111
  # --------------------------------------------------------------------------------
1050
1112
  # - The selector in \`GUARDIAN_SELECTOR_SLOT\` controls whether the extra GUARDIAN signature
@@ -1070,6 +1132,7 @@ type BeWord = struct @bigendian { a: felt, b: felt, c: felt, d: felt }
1070
1132
  # +---------------------+---------------+
1071
1133
  # | GUARDIAN SELECTOR (word) | 0 |
1072
1134
  # | GUARDIAN PUBLIC KEY MAP | 1 |
1135
+ # | GUARDIAN SCHEME ID MAP | 2 |
1073
1136
  # +---------------------+---------------+
1074
1137
  #
1075
1138
  # - GUARDIAN_SELECTOR_SLOT (0):
@@ -1079,7 +1142,7 @@ type BeWord = struct @bigendian { a: felt, b: felt, c: felt, d: felt }
1079
1142
  # - GUARDIAN_PUBLIC_KEY_MAP_SLOT (1):
1080
1143
  # * A map from a fixed key [0, 0, 0, 0] to the single GUARDIAN public key:
1081
1144
  # [0, 0, 0, 0] => GUARDIAN_PUBLIC_KEY
1082
- # * GUARDIAN_PUBLIC_KEY is a RPO Falcon 512 public key represented as a word.
1145
+ # * GUARDIAN_PUBLIC_KEY is a Falcon Poseidon2 public key represented as a word.
1083
1146
 
1084
1147
  # CONSTANTS
1085
1148
  # =================================================================================================
@@ -1094,12 +1157,15 @@ const GUARDIAN_SELECTOR_SLOT=word("openzeppelin::guardian::selector")
1094
1157
  # [0, 0, 0, 0] => GUARDIAN_PUBLIC_KEY
1095
1158
  const GUARDIAN_PUBLIC_KEY_MAP_SLOT=word("openzeppelin::guardian::public_key")
1096
1159
 
1160
+ # Map slot for GUARDIAN signature scheme IDs
1161
+ # Uses exactly one scheme ID entry at index [0, 0, 0, 0]
1162
+ # [0, 0, 0, 0] => [scheme_id, 0, 0, 0]
1163
+ const GUARDIAN_SCHEME_ID_MAP_SLOT=word("openzeppelin::guardian::scheme_id")
1164
+
1097
1165
  # Selector flag values
1098
1166
  const GUARDIAN_ON=[1, 0, 0, 0]
1099
1167
  const GUARDIAN_OFF=[0, 0, 0, 0]
1100
-
1101
- # The event emitted when a signature is not found for a required signer.
1102
- const AUTH_UNAUTHORIZED_EVENT=event("miden::auth::unauthorized")
1168
+ const FALCON_512_POSEIDON2_SCHEME_WORD=[2, 0, 0, 0]
1103
1169
 
1104
1170
  # GUARDIAN PROCEDURES
1105
1171
  # =================================================================================================
@@ -1177,6 +1243,24 @@ pub proc update_guardian_public_key
1177
1243
 
1178
1244
  dropw
1179
1245
  # => []
1246
+
1247
+ push.0.0.0.0
1248
+ # => [MAP_KEY]
1249
+
1250
+ push.FALCON_512_POSEIDON2_SCHEME_WORD
1251
+ # => [SCHEME_ID_WORD, MAP_KEY]
1252
+
1253
+ swapw
1254
+ # => [MAP_KEY, SCHEME_ID_WORD]
1255
+
1256
+ push.GUARDIAN_SCHEME_ID_MAP_SLOT[0..2]
1257
+ # => [scheme_id_slot_prefix, scheme_id_slot_suffix, MAP_KEY, SCHEME_ID_WORD]
1258
+
1259
+ exec.native_account::set_map_item
1260
+ # => [OLD_MAP_VALUE]
1261
+
1262
+ dropw
1263
+ # => []
1180
1264
  end
1181
1265
 
1182
1266
  #! Conditionally verify a "GUARDIAN" signature against a stored public key hash.
@@ -1192,7 +1276,7 @@ end
1192
1276
  #! - MSG is TX_SUMMARY_COMMITMENT provided by auth procedure
1193
1277
  #! - If selector is OFF (0), GUARDIAN verification is skipped
1194
1278
  #! - Selector value is read from initial storage state
1195
- pub proc verify_guardian_signature(msg: BeWord) -> BeWord
1279
+ pub proc verify_guardian_signature(msg: word)
1196
1280
  push.GUARDIAN_SELECTOR_SLOT[0..2]
1197
1281
  exec.active_account::get_item
1198
1282
  drop drop drop
@@ -1202,7 +1286,8 @@ pub proc verify_guardian_signature(msg: BeWord) -> BeWord
1202
1286
  if.true
1203
1287
  push.1
1204
1288
  push.GUARDIAN_PUBLIC_KEY_MAP_SLOT[0..2]
1205
- exec.::miden::standards::auth::falcon512_rpo::verify_signatures
1289
+ push.GUARDIAN_SCHEME_ID_MAP_SLOT[0..2]
1290
+ exec.::miden::standards::auth::signature::verify_signatures
1206
1291
  push.1 neq
1207
1292
  if.true
1208
1293
  emit.AUTH_UNAUTHORIZED_EVENT
@@ -1220,10 +1305,9 @@ export const GUARDIAN_ECDSA_MASM = `# Guardian Authentication Component (ECDSA)
1220
1305
  # It can be used standalone or in conjunction with other auth components like multisig.
1221
1306
 
1222
1307
  use miden::protocol::active_account
1308
+ use miden::protocol::auth::AUTH_UNAUTHORIZED_EVENT
1223
1309
  use miden::protocol::native_account
1224
1310
 
1225
- type BeWord = struct @bigendian { a: felt, b: felt, c: felt, d: felt }
1226
-
1227
1311
  # IMPORTANT SECURITY NOTES
1228
1312
  # --------------------------------------------------------------------------------
1229
1313
  # - The selector in \`GUARDIAN_SELECTOR_SLOT\` controls whether the extra GUARDIAN signature
@@ -1272,13 +1356,12 @@ const GUARDIAN_SELECTOR_SLOT=word("openzeppelin::guardian::selector")
1272
1356
  # Uses exactly one GUARDIAN public key at index [0, 0, 0, 0]
1273
1357
  # [0, 0, 0, 0] => GUARDIAN_PUBLIC_KEY
1274
1358
  const GUARDIAN_PUBLIC_KEY_MAP_SLOT=word("openzeppelin::guardian::public_key")
1359
+ const GUARDIAN_SCHEME_ID_MAP_SLOT=word("openzeppelin::guardian::scheme_id")
1275
1360
 
1276
1361
  # Selector flag values
1277
1362
  const GUARDIAN_ON=[1, 0, 0, 0]
1278
1363
  const GUARDIAN_OFF=[0, 0, 0, 0]
1279
-
1280
- # The event emitted when a signature is not found for a required signer.
1281
- const AUTH_UNAUTHORIZED_EVENT=event("miden::auth::unauthorized")
1364
+ const ECDSA_K256_KECCAK_SCHEME_WORD=[1, 0, 0, 0]
1282
1365
 
1283
1366
  # GUARDIAN PROCEDURES
1284
1367
  # =================================================================================================
@@ -1356,6 +1439,24 @@ pub proc update_guardian_public_key
1356
1439
 
1357
1440
  dropw
1358
1441
  # => []
1442
+
1443
+ push.0.0.0.0
1444
+ # => [MAP_KEY]
1445
+
1446
+ push.ECDSA_K256_KECCAK_SCHEME_WORD
1447
+ # => [SCHEME_ID_WORD, MAP_KEY]
1448
+
1449
+ swapw
1450
+ # => [MAP_KEY, SCHEME_ID_WORD]
1451
+
1452
+ push.GUARDIAN_SCHEME_ID_MAP_SLOT[0..2]
1453
+ # => [scheme_id_slot_prefix, scheme_id_slot_suffix, MAP_KEY, SCHEME_ID_WORD]
1454
+
1455
+ exec.native_account::set_map_item
1456
+ # => [OLD_MAP_VALUE]
1457
+
1458
+ dropw
1459
+ # => []
1359
1460
  end
1360
1461
 
1361
1462
  #! Conditionally verify a "GUARDIAN" signature against a stored public key hash.
@@ -1371,7 +1472,7 @@ end
1371
1472
  #! - MSG is TX_SUMMARY_COMMITMENT provided by auth procedure
1372
1473
  #! - If selector is OFF (0), GUARDIAN verification is skipped
1373
1474
  #! - Selector value is read from initial storage state
1374
- pub proc verify_guardian_signature(msg: BeWord) -> BeWord
1475
+ pub proc verify_guardian_signature(msg: word)
1375
1476
  push.GUARDIAN_SELECTOR_SLOT[0..2]
1376
1477
  exec.active_account::get_item
1377
1478
  drop drop drop
@@ -1381,7 +1482,8 @@ pub proc verify_guardian_signature(msg: BeWord) -> BeWord
1381
1482
  if.true
1382
1483
  push.1
1383
1484
  push.GUARDIAN_PUBLIC_KEY_MAP_SLOT[0..2]
1384
- exec.::miden::standards::auth::ecdsa_k256_keccak::verify_signatures
1485
+ push.GUARDIAN_SCHEME_ID_MAP_SLOT[0..2]
1486
+ exec.::miden::standards::auth::signature::verify_signatures
1385
1487
  push.1 neq
1386
1488
  if.true
1387
1489
  emit.AUTH_UNAUTHORIZED_EVENT