You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Write the asset in note to memory address ASSET_PTR
92
+
push.ASSET_PTR exec.note::get_assets
79
93
# => [num_assets, dest_ptr]
80
94
81
95
drop
@@ -93,14 +107,16 @@ end
93
107
94
108
### How the assembly code works:
95
109
96
-
1.**Passing the Secret:**
110
+
1.**Constants and Error Handling:**
111
+
The code defines memory pointers (`EXPECTED_DIGEST_PTR` and `ASSET_PTR`) for better code organization and an error message for digest mismatches.
112
+
2.**Passing the Secret:**
97
113
The secret number is passed as `Note Arguments` into the note.
98
-
2.**Hashing the Secret:**
99
-
The `hperm` instruction applies a hash permutation to the secret number, resulting in a hash that takes up four stack elements.
100
-
3.**Stack Cleanup and Comparison:**
101
-
The assembly code extracts the digest, loads the note inputs from memory and checks if the computed hash matches the note’s stored hash.
102
-
4.**Asset Transfer:**
103
-
If the hash of the number passed in as `Note Arguments` matches the hash stored in the note inputs, the script continues, and the asset stored in the note is loaded from memory and passed to Bob’s wallet via the `wallet::receive_asset` function.
114
+
3.**Hashing the Secret:**
115
+
The `hash` instruction applies a hash permutation to the secret number, resulting in a digest that takes up four stack elements.
116
+
4.**Digest Comparison:**
117
+
The assembly code loads the expected digest from the note inputs stored in memory and compares it with the computed hash. If they don't match, the transaction fails with a clear error message.
118
+
5.**Asset Transfer:**
119
+
If the hash of the number passed in as `Note Arguments` matches the hash stored in the note inputs, the script continues, and the asset stored in the note is loaded from memory and passed to Bob's wallet via the `wallet::receive_asset` function.
0 commit comments