Skip to content

Commit

Permalink
feat: load kernel to memory, exec syscalls with their hash
Browse files Browse the repository at this point in the history
  • Loading branch information
Fumuran committed Aug 7, 2024
1 parent 3e77745 commit 977ec96
Show file tree
Hide file tree
Showing 11 changed files with 591 additions and 39 deletions.
3 changes: 2 additions & 1 deletion docs/architecture/transactions/contexts.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ The [account API](https://github.com/0xPolygonMiden/miden-base/blob/main/miden-l
#! Add the specified asset to the vault.
#! ...
export.add_asset
syscall.account_vault_add_asset
exec.mem::account_vault_add_asset_ptr
syscall.exec_kernel_proc
end
```

Expand Down
19 changes: 19 additions & 0 deletions miden-lib/asm/kernels/transaction/api.masm
Original file line number Diff line number Diff line change
Expand Up @@ -659,3 +659,22 @@ export.get_note_serial_number
swapw dropw
# => [SERIAL_NUMBER]
end

#! Executes a kernel procedure specified by its memory pointer
#!
#! Inputs: [procedure_ptr]
#! Outputs: [*executed_procedure_output*]
#!
#! - procedure_ptr is a pointer to the memory where hash of the desired kernel procedure is stored.
export.exec_kernel_proc
# prepare stack for procedure hash obtaining
padw movup.4
# => [procedure_ptr, 0, 0, 0, 0]

# load kernel procedure hash
mem_loadw
# => [KERNEL_PROCEDURE_HASH]

# execute loaded procedure
dynexec
end
47 changes: 32 additions & 15 deletions miden-lib/asm/miden/account.masm
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use.miden::kernels::tx::memory

#! Returns the account id.
#!
#! Stack: []
Expand All @@ -8,7 +10,8 @@ export.get_id
push.0
# => [0]

syscall.get_account_id
exec.memory::get_account_id_ptr
syscall.exec_kernel_proc
# => [acct_id]
end

Expand All @@ -22,7 +25,8 @@ export.get_nonce
push.0
# => [0]

syscall.get_account_nonce
exec.memory::get_account_nonce_ptr
syscall.exec_kernel_proc
# => [nonce]
end

Expand All @@ -36,7 +40,8 @@ export.get_initial_hash
padw
# => [0, 0, 0, 0]

syscall.get_initial_account_hash
exec.memory::get_initial_account_hash_ptr
syscall.exec_kernel_proc
# => [H]
end

Expand All @@ -50,7 +55,8 @@ export.get_current_hash
padw
# => [0, 0, 0, 0]

syscall.get_current_account_hash
exec.memory::get_current_account_hash_ptr
syscall.exec_kernel_proc
# => [ACCT_HASH]
end

Expand All @@ -62,7 +68,8 @@ end
#! - value is the value to increment the nonce by. value can be at most 2^32 - 1 otherwise this
#! procedure panics.
export.incr_nonce
syscall.incr_account_nonce
exec.memory::incr_account_nonce_ptr
syscall.exec_kernel_proc
# => [0]

drop
Expand All @@ -80,7 +87,8 @@ export.get_item
push.0.0.0 movup.3
# => [index, 0, 0, 0]

syscall.get_account_item
exec.memory::get_account_item_ptr
syscall.exec_kernel_proc
# => [VALUE]
end

Expand All @@ -97,7 +105,8 @@ export.set_item
push.0 movdn.5 push.0 movdn.5 push.0 movdn.5
# => [index, V', 0, 0, 0]

syscall.set_account_item
exec.memory::set_account_item_ptr
syscall.exec_kernel_proc
# => [R', V]
end

Expand All @@ -112,7 +121,8 @@ end
#! - KEY is the key of the item to get.
#! - VALUE is the value of the item.
export.get_map_item
syscall.get_account_map_item
exec.memory::get_account_map_item_ptr
syscall.exec_kernel_proc
# => [VALUE]

# prepare stack for return
Expand All @@ -133,7 +143,8 @@ end
#! - OLD_MAP_ROOT is the old map root.
#! - OLD_MAP_VALUE is the old value at KEY.
export.set_map_item
syscall.set_account_map_item
exec.memory::set_account_map_item_ptr
syscall.exec_kernel_proc
# => [OLD_MAP_ROOT, OLD_MAP_VALUE, 0]

movup.8 drop
Expand All @@ -148,7 +159,8 @@ end
#!
#! - CODE_COMMITMENT is the hash of the code to set.
export.set_code
syscall.set_account_code
exec.memory::set_account_code_ptr
syscall.exec_kernel_proc
# => [0, 0, 0, 0]

dropw
Expand All @@ -164,7 +176,8 @@ end
#! - faucet_id is the faucet id of the fungible asset of interest.
#! - balance is the vault balance of the fungible asset.
export.get_balance
syscall.account_vault_get_balance
exec.memory::account_vault_get_balance_ptr
syscall.exec_kernel_proc
# => [balance]
end

Expand All @@ -177,7 +190,8 @@ end
#! - ASSET is the non-fungible asset of interest
#! - has_asset is a boolean indicating whether the account vault has the asset of interest
export.has_non_fungible_asset
syscall.account_vault_has_non_fungible_asset
exec.memory::account_vault_has_non_fungible_asset_ptr
syscall.exec_kernel_proc
# => [has_asset, 0, 0, 0]

swap drop swap drop swap drop
Expand All @@ -199,7 +213,8 @@ end
#! - If ASSET is a fungible asset, then ASSET' is the total fungible asset in the account vault
#! after ASSET was added to it.
export.add_asset
syscall.account_vault_add_asset
exec.memory::account_vault_add_asset_ptr
syscall.exec_kernel_proc
end

#! Remove the specified asset from the vault.
Expand All @@ -214,7 +229,8 @@ end
#!
#! - ASSET is the asset to remove from the vault.
export.remove_asset
syscall.account_vault_remove_asset
exec.memory::account_vault_remove_asset_ptr
syscall.exec_kernel_proc
end

#! Returns a commitment to the account vault.
Expand All @@ -229,6 +245,7 @@ export.get_vault_commitment
# => [0, 0, 0, 0]

# invoke the syscall
syscall.get_account_vault_commitment
exec.memory::get_account_vault_commitment_ptr
syscall.exec_kernel_proc
# => [COM]
end
11 changes: 8 additions & 3 deletions miden-lib/asm/miden/faucet.masm
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use.miden::kernels::tx::memory

#! Mint an asset from the faucet the transaction is being executed against.
#!
#! Panics:
Expand All @@ -14,7 +16,8 @@
#!
#! - ASSET is the asset that was minted.
export.mint
syscall.mint_asset
exec.memory::mint_asset_ptr
syscall.exec_kernel_proc
# => [ASSET]
end

Expand All @@ -35,7 +38,8 @@ end
#!
#! - ASSET is the asset that was burned.
export.burn
syscall.burn_asset
exec.memory::burn_asset_ptr
syscall.exec_kernel_proc
# => [ASSET]
end

Expand All @@ -55,6 +59,7 @@ export.get_total_issuance
# => [0]

# invoke the `get_fungible_faucet_total_issuance` kernel procedure
syscall.get_fungible_faucet_total_issuance
exec.memory::get_fungible_faucet_total_issuance_ptr
syscall.exec_kernel_proc
# => [total_issuance]
end
Loading

0 comments on commit 977ec96

Please sign in to comment.