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

VM: Include principal and nonce in ComputePrincipal calculation #6420

Open
lrettig opened this issue Oct 25, 2024 · 0 comments
Open

VM: Include principal and nonce in ComputePrincipal calculation #6420

lrettig opened this issue Oct 25, 2024 · 0 comments
Labels

Comments

@lrettig
Copy link
Member

lrettig commented Oct 25, 2024

Right now, vm.core.hash::ComputePrincipal is extremely simplistic: it just calculates the principal address using the hash of the template and spawn args (pubkey, for wallet). This is more or less the same thing we do on the Spacemesh mainnet, and it's fine for the v1 Athena testnet, where the simple wallet is the only template.

However, we need to do something more sophisticated when we begin allowing other kinds of templates to be deployed (i.e., when we begin allowing spawn that isn't self-spawn). The issue here is that, as things stand today, each and every template can only be spawned once with a given set of params (immutable state). This is fine for a wallet, but it's not fine for many other types of programs: e.g., it would not allow two different people to both spawn an ERC-20-style fungible token with the same params (token name, decimals, etc.).

The correct way to do this is to include both spawning principal account and nonce in the principal computation. This has the added benefit that, if the same principal spawns exactly the same program again (same template, same args), it'll get a new address. This should be permitted.

In other words, the computation should be:

HASH(template || principal || spawnArgs || nonce)

We can't do this today because it doesn't work for self-spawn: computing the principal cannot require the principal! I see a couple of options:

  1. Just use special handling for self-spawn txs: in only this case, calculate principal using the current, simpler method

and/or

  1. Allow a template (such as a wallet) to mark itself as a "singleton", meaning it uses a simpler principal computation, and, as described above, cannot be spawned twice with the same set of args
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant