spacemeshos / SMIPS

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

Generalized Nonces (WIP) #79

Open lrettig opened 2 years ago

lrettig commented 2 years ago

Overview

This proposal outlines our design for generalized nonces. A nonce is a unique value included in a transaction that serves three purposes:

  1. To prevent the same transaction from being replayed multiple times (replay protection)
  2. To allow transactions to be replaced by higher-fee transactions (replace by fee)
  3. To ensure transactions for a given account are executed in a specific order (transaction ordering)

Hand-in-hand with account unification and the abstraction and generalization of many of the core concepts and functions of the account model "into the VM" in specialized smart contracts (dubbed "principal accounts" in Spacemesh), this proposal presents a scheme whereby principal accounts can implement nonce schemes in a variety of fashions.

Background: https://community.spacemesh.io/t/nonce-schemes-and-account-unification/202

Goals and motivation

High-level design

Each account has a nonce value stored in its state. The account can choose to interpret this value any way it likes through the use of new handler methods used to sort new transactions, check transaction validity, and perform state updates. Miners use these handler methods to filter and sort new transactions as they enter the mempool.

Prior art

Proposed implementation

We add a 32 byte nonce value to the state of each principal account. Each principal account also implements four handler methods:

A nonce scheme needs to specify:

Miners apply the new transaction filter to every new transaction they receive in gossip, and ignore transactions that don’t pass the filter (the filter can specify that an existing mempool transaction should be replaced by the new one).

Once transactions are collected into a unified transaction block, transactions from the same account are sorted using the sorting algorithm (e.g., if the block contains the transactions A1,B1,A2,A3,B2, from accounts A and B, and the sorting algorithm specified that A1,A2,A3 should be in the order A2,A3,A1, then the sorted transactions would be A2,B1,A3,A1,B2).

After sorting, transactions are executed in order:

Implementation plan

tbd

Questions

Dependencies and interactions

tbd

Stakeholders and reviewers

tbd

Testing and performance

tbd