Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic kernel procedure invocation #701

Closed
bobbinth opened this issue May 23, 2024 · 1 comment
Closed

Dynamic kernel procedure invocation #701

bobbinth opened this issue May 23, 2024 · 1 comment
Assignees
Labels
kernels Related to transaction, batch, or block kernels
Milestone

Comments

@bobbinth
Copy link
Contributor

Currently, when making calls to kernel procedures we invoke them statically (i.e., via their MAST roots). This approach has a significant downside: any time kernel procedures are modified, any procedure invoking them would also have their MAST changed.

For example, receive_asset procedure from the BasicWallet interface relies on the account_vault_add_asset procedure in the kernel. If we were to modify anything about this procedure (i.e., make an optimization or fix a bug), MAST root of receive_asset would change rendering all P2ID and other notes which rely on receive_asset useless.

What we need is the ability to update the underlying kernel without changing procedures that rely on it. One way to do this is to make all kernel calls dynamic. Specifically, this could work as follows:

  1. Instead of individual kernel procedures we'd have a single procedure - e.g., exec_kernel_proc.
  2. This procedure would take an index of the actual procedure to call and a set of parameters to call the procedure with.
  3. Internally, this procedure would look up the MAST root of the procedure to be called based on the specified index and use dynexec instruction to execute it.

To give a concrete example of how this would work for the receive_asset procedure:

  1. receive_asset procedure would remain exactly as it is now - i.e., it would still call account::add_asset procedure.
  2. account::add_asset procedure would now look something like this:
    export.add_asset
        # push the index of the account_vault_add_asset procedure onto the stack
        push.ACCOUNT_VAULT_ADD_ASSET_IDX
    
        # call the generic procedure executor
        syscall.exec_kernel_proc
    end
    
  3. Inside exec_kernel_proc procedure we'd first look up the root of account_vault_add_asset procedure and then call it via dynexec.

For point 3 above to work, we need to have the map from procedure index to MAST root somewhere in the kernel memory. This map can be built during transaction prologue. Basically, transaction prologue would take hash of the transaction kernel as an input and "unhash" it unto some well known location in memory. Then, the lookup would be as simple as adding the relevant offset to the provided procedure index and reading MAST root from the resulting memory address.

One open question is how kernel hash should be provided to the prologue. A couple of options:

  1. It could be provided as an independent transaction input (i.e., via the stack).
  2. It could be implied by the block reference used when executing a procedure.
@bobbinth bobbinth added the kernels Related to transaction, batch, or block kernels label May 23, 2024
@bobbinth bobbinth added this to the v0.4 milestone May 23, 2024
@bobbinth bobbinth modified the milestones: v0.4, v0.5 Jul 1, 2024
@Dominik1999 Dominik1999 moved this to Todo in User's testnet Aug 12, 2024
@Dominik1999 Dominik1999 moved this from Todo to In Progress in User's testnet Aug 26, 2024
@bobbinth bobbinth modified the milestones: v0.5, v0.6 Aug 27, 2024
@Dominik1999 Dominik1999 moved this from In Progress to In Review in User's testnet Sep 9, 2024
@bobbinth
Copy link
Contributor Author

Closed by #803.

@github-project-automation github-project-automation bot moved this from In Review to Done in User's testnet Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kernels Related to transaction, batch, or block kernels
Projects
Status: Done
Development

No branches or pull requests

3 participants