-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathsinglesig.masm
More file actions
55 lines (45 loc) · 2.01 KB
/
Copy pathsinglesig.masm
File metadata and controls
55 lines (45 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# The MASM code of the BasicSignature Authentication Account Component.
#
# See the `AuthBasicSignature` Rust type's documentation for more details.
use miden::standards::auth::signature
use miden::protocol::active_account
# CONSTANTS
# =================================================================================================
# The slot in this component's storage layout where the public key is stored.
const PUBLIC_KEY_SLOT = word("miden::standards::auth::singlesig::pub_key")
# The slot in this component's storage layout where the corresponding signature scheme id is stored.
const SCHEME_ID_SLOT = word("miden::standards::auth::singlesig::scheme")
#! Authenticate a transaction using the signature scheme specified by scheme_id.
#!
#! Supported schemes:
#! - 1 => ecdsa_k256_keccak
#! - 2 => falcon512_poseidon2
#!
#! It first increments the nonce of the account, independent of whether the account's state has
#! changed or not. Then it computes and signs the following message (in memory order):
#! [ACCOUNT_DELTA_COMMITMENT, INPUT_NOTES_COMMITMENT,
#! OUTPUT_NOTES_COMMITMENT, [0, 0, ref_block_num, final_nonce]]
#!
#! Including the final_nonce is necessary for replay protection. The reference block number is
#! included to commit to the transaction creator's intended reference block of the transaction
#! which determines the fee parameters and therefore the fee amount that is deducted.
#!
#! Inputs: [AUTH_ARGS, pad(12)]
#! Outputs: [pad(16)]
#!
#! Invocation: call
@auth_script
pub proc auth_tx(auth_args: word)
dropw
# => [pad(16)]
# Fetch public key from storage.
# ---------------------------------------------------------------------------------------------
push.PUBLIC_KEY_SLOT[0..2] exec.active_account::get_initial_item
# => [PUB_KEY, pad(16)]
push.SCHEME_ID_SLOT[0..2] exec.active_account::get_initial_item
# => [scheme_id, 0, 0, 0, PUB_KEY, pad(16)]
movdn.7 drop drop drop
# => [PUB_KEY, scheme_id, pad(16)]
exec.signature::authenticate_transaction
# => [pad(16)]
end