spacemeshos / SMIPS

Spacemesh Improvement Proposals
https://spacemesh.io
Creative Commons Zero v1.0 Universal
7 stars 1 forks source link

SVM Self-Spawn #64

Closed YaronWittenstein closed 1 year ago

YaronWittenstein commented 2 years ago

SVM Self-Spawn

Overview

This SMIP details the Self Spawn functionality from SVM's perspective, along with the required changes for its implementation.

Goals and Motivation

We want to spawn new accounts in the Self Spawn manner. In that case, a newly spawned account will have an initial balance pending him for usage. Spawned accounts will also use it for paying for their spawning. This feature will ease the onboarding of new real-users on the Spacemesh platform.

High-level design

Create Stub Account

In the beginning, an existing account is executing a transaction. While the transaction is running, the current account calls transfer to a non-existing account at some point.

The side-effects of this call will be creating a new account detached from any Template. We'll call such an account a Stub Account or Inactive Account. It will have an initial balance (the amount transferred upon creation), but it won't be eligible for running transactions.

The reason for that is obvious - since there is no Template associated with it. Also, note that transferring coins to a Stub Account should be completely valid.

The Global State component should upgrade to support Stub Accounts. One option is to make the Template an optional attribute and keep things as today. We can also add an explicit mode attribute. It'll serve as a flag for active/inactive.

The Runtime will have to be aware of the possibility of a Stub Account. Therefore, before running a Call transaction, it will have to assert that the target account is active.

Activate Account (a.k.a Self-Spawn)

The way to turn a Stub Account into being active is by executing a Self Spawn transaction. This Self Spawn differs from the currently existing Spawn one by the source of the Principal account. On the current Spawn, the Principal address is associated with an existing account - and it'll pay for the Gas cost of the transaction.

In the Self Spawn case, the Principal address is the address of an inactive account - the one to be spawned. This requirement implies that we should compute the Self Spawned's address ahead of time deterministically.

The formula used should be known and deterministic. It should be independent of the layer that will run the Self Spawn transaction. It's critical since we can't guarantee what layer the Self Spawn will execute.

The steps for executing a Self Spawn are as follows:

Questions/concerns

Dependencies and interactions

Stakeholders and reviewers

@noamnelke @lrettig @neysofu @avive @moshababo

countvonzero commented 1 year ago

implemented as prebuilt https://github.com/spacemeshos/go-spacemesh/issues/3220