-
Notifications
You must be signed in to change notification settings - Fork 2
Description
author: @dr-orlovsky
layers: consensus
breaking: consensus, api
requires: RCP-241024A
supersedes: RCP-241013A, RCP-240731A
Background
Consensus ordering is a way how we deterministically define a order in which contract operations are validated and added to the contract state. The details of the current procedure and discussion can be found in RCP-241013A and RCP-240731A.
Motivation
Assume a sequence of state transitions StA, StB, StC, with each one following transition spending inputs of the previous one. Let us name the corresponding witness transactions WtxA, WtxB, WtxC. Lets assume these transactions are otherwise unrelated (i.e. they do not spend outputs of each other neither directly or indirectly, i.e. do not belong to the same transaction graph onchain). In this case, a re-org may happen such that WtxC will be included in a block before WtxB, putting StC in a consensus ordering before StB, making StB state either invalid - or requiring a validation algorithm to include state from arbitrary state transition, including unvalidated ones. This is in fact a side-channeling which makes it really hard to formally ensure and audit that all state transitions are validated in the right way.
The problem is doubled by the fact that one contract may operate over multiple chains.
Proposal
- Make contracts chain-specific, excluding cross-chain race conditions (as required by RCP-241024A)
- Use a block height of a witness transaction as a base for the ordering
- For the protection from re-orgs, as well for the operation ordering within the same block, use a PoW, such that the number of zero bits (divided by a chain-specific factor) is added to the block height value and the resulting sum is used for the final consensus ordering of the operations.
- Evaluate state of the contract using consensus ordering, requiring inputs for the operation to come from already validated operations - or fail otherwise.
- Blockchain-specific parameter of the safe number of blocks (amount of PoW units to add) must be a consensus parameter defined at the level of single-use seal type.
Example
Order = height + pow / factor
| Height | PoW | Order | |
|---|---|---|---|
| StA | 1 | 0 | 1 |
| StB | 21 | 0 | 21 |
| StC | 20 | 1 | 22 |
| StD | 30 | 0 | 30 |
Rationale
The proposed approach allows to run all parts of the validation and contract state computation in one go, without an introduction of any side-channel information which may potentially skip the normal validation flow. It is also easy to audit.
The use of PoW value instead of nonce is needed to prevent malicious actors from using high value for the nonce, requiring beneficiaries to wait a long time before being able to use assets in a secure way.
PoW is divided over a blockchain-specific factor since each blockchain has a different block production time, and thus a different amount of work would be needed
Metadata
Metadata
Assignees
Labels
Type
Projects
Status