Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ enum CLType {
String, // e.g. "Hello, World!"
URef, // unforgeable reference (see above)
Key, // global state key (see above)
PublicKey // A Casper system PublicKey type
PublicKey, // A Casper system PublicKey type
Option(CLType), // optional value of the given type
List(CLType), // list of values of the given type (e.g. Vec in rust)
ByteArray(CLType, u32), // same as `List` above, but number of elements
Expand Down
125 changes: 82 additions & 43 deletions versioned_docs/version-2.0.0/concepts/serialization/structures.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Account {#serialization-standard-account}

An Account is a structure that represented a user on a legacy Casper network. Alongside the Condor protocol release, `Accounts` were replaced with `AddressableEntities` of the type `Account`. The account structure consists of the following fields:
An Account is a structure that represented a user on a legacy Casper network. Alongside the Casper 2.0 protocol release, `Accounts` were replaced with `AddressableEntities` of the type `Account`. The account structure consists of the following fields:

- [`account_hash`](./types.md#account-hash)

Expand All @@ -17,53 +17,50 @@ An Account is a structure that represented a user on a legacy Casper network. Al
## AddressableEntity {#addressable-entity}

An Addressable Entity is a structure that represents an entity on a Casper network. The addressable entity consists of the following fields:

- [`package_hash`](./types.md#package-hash)

- [`byte_code_hash`](./types.md#byte-code-hash)

- [`entry_points`](./types.md#entrypoints)

- [`protocol_version`](./types.md#protocolversion)

- `main_purse`: The entity's main purse `URef`. You may find information on `URef` serialization [here](./primitives.md#clvalue-uref).
- [`main_purse`]: The entity's main purse `URef`. You may find information on `URef` serialization [here](./primitives.md#clvalue-uref).

- [`associated_keys`](./types.md#associatedkey)

- [`action_thresholds`](./types.md#entity-action-thresholds)

- [`message_topics`](./types.md#message-topics)

- [`entity_kind`](./types.md#entity-kind)


## Block {#serialization-standard-block}

A block is the core component of the Casper linear blockchain, used in two contexts:

1. A data structure containing a collection of transactions. Blocks form the primary structure of the blockchain.
2. A message that is exchanged between nodes containing the data structure as explained in (1).

Each block has a globally unique ID, achieved by hashing the contents of the block.

Each block points to its parent. An exception is the first block, which has no parent.

A block is structurally defined as follows:

- `hash`: A hash over the header of the block.
- `header`: The header of the block that contains information about the contents of the block with additional metadata.
- `body`: The block's body contains the proposer of the block and hashes of deploys and transfers contained within it.
The block is a polymorphic structure that assumes one of the well-defined variants:
* `V1` which type is `BlockV1` (it has a binary `prefix` of 0)
* `V2` which type is `BlockV2` (it has a binary `prefix` of 1)

Further, a block may consist of one of the following types:
To byte-serialize a `Block` you first need to serialize it's binary prefix and then write the bytes of the byte-serialized representation of it's variant.

- `Version1`: A legacy block created prior to the Condor upgrade.
## BlockV1 {#block-v1}

- `Version2`: A modern block.
This type:
* encapsulates block data that used to be produced in versions of the nodes prior to 2.0.
* represents a historical block that was produced prior to 2.0
Each block:
* has a globally unique ID, achieved by hashing the contents of the block.
* points to its parent. An exception is the first block, which has no parent.

### BlockHash {#block-hash}
A block is structurally defined as follows:

The block hash is a `Digest` over the contents of the block Header. The `BlockHash` serializes as the byte representation of the hash itself.
- `hash`: A hash over the header of the block. It's type is `BlockHash`
- `header`: The header of the block that contains information about the contents of the block with additional metadata. It's type is `BlockHeaderV1`.
- `body`: The block's body contains the proposer of the block and hashes of deploys and transfers contained within it. It's type is `BlockBodyV1`.

### BlockHeader {#block-header}
### BlockHeaderV1 {#block-header-v1}

The header portion of a block, structurally, is defined as follows:

Expand All @@ -72,15 +69,13 @@ The header portion of a block, structurally, is defined as follows:
- `body_hash` the hash of the block body. It serializes to the byte representation of the body hash. The serialized buffer of the `body_hash` is 32 bytes long.
- `random_bit` is a boolean needed for initializing a future era. It is serialized as a single byte; true maps to 1, while false maps to 0.
- `accumulated_seed` is a seed needed for initializing a future era. It serializes to the byte representation of the parent Hash. The serialized buffer of the `accumulated_hash` is 32 bytes long.
- `era_end` contains equivocation and reward information to be included in the terminal finalized block. It is an optional field. Thus if the field is set as `None`, it serializes to _0_. The serialization of the other case is described in the EraEnd.
- `era_end` contains equivocation and reward information to be included in the terminal finalized block. It is an optional field. Thus if the field is set as `None`, it serializes to _0_. The serialization of the other case is described in the `EraEndV1`.
- `timestamp` The timestamp from when the block was proposed. It serializes as a single `u64` value. The serialization of a `u64` value is described in the CLValues section.
- `era_id` Era ID in which this block was created. It serializes as a single `u64` value.
- `height` The height of this block, i.e., the number of ancestors. It serializes as a single `u64` value.
- `protocol_version` The version of the Casper network when this block was proposed. It is 3-element tuple containing `u32` values. It serializes as a buffer containing the three `u32` serialized values. Refer to the CLValues section on how `u32` values are serialized.

Both `BlockHeaderV1` and `BlockHeaderV2` serialize in the same way.

### EraEndV1 {#eraendV1}
#### EraEndV1 {#eraendV1}

`EraEndV1` as represented within the block header, is a struct containing two fields.

Expand All @@ -102,21 +97,9 @@ When serializing the overarching struct of `EraEndV1`, we first allocate a buffe

Note that `EraEndV1` is an optional field. Thus the above scheme only applies if there is an `EraEndV1`; if there is no era end, the field simply serializes to _0_.

### EraEndV2 {#eraendV2}

`EraEndV1` as represented within the block header, is a struct containing four fields.

- `equivocators`: A vector of `PublicKey` listing equivocators for the era.
- `inactive_validators`: A list of inactive validators for the era.
- `next_era_validator_weights`: A map of validators and their weights for the era to follow.
- `rewards`: A Binary Tree Map of `PublicKey` and `u64`.
- `next_era_gas_price`: The next era's gas price as a `u8`.

Note that `EraEndV2` is an optional field. Thus the above scheme only applies if there is an `EraEndV2`; if there is no era end, the field simply serializes to _0_.

### BlockBodyV1 {#blockbodyV1}

The body portion of a block, prior to the Condor upgrade, is structurally defined as:
The body portion of a block, prior to the Casper 2.0 upgrade, is structurally defined as:

- `proposer`: The PublicKey which proposed this block.
- `deploy_hashes`: Is a vector of hex-encoded hashes identifying Deploys included in this block.
Expand All @@ -128,6 +111,52 @@ When we serialize the `BlockBodyV1`, we create a buffer that contains the serial
- `deploy_hashes` serializes to the byte representation of all the deploy_hashes within the block header. Its length is `32 * n`, where n denotes the number of deploy hashes present within the body.
- `transfer_hashes` serializes to the byte representation of all the deploy_hashes within the block header. Its length is `32 * n`, where n denotes the number of transfers present within the body.

## BlockV2 {#block-v2}

This type represents a contemporary block that is produced by the network. A block is the core component of the Casper linear blockchain, used in two contexts:
1. A data structure containing a collection of transactions. Blocks form the primary structure of the blockchain.
2. A message that is exchanged between nodes containing the data structure as explained in (1).

Each block has a globally unique ID, achieved by hashing the contents of the block.

Each block points to its parent. An exception is the first block, which has no parent.

A block is structurally defined as follows:

- `hash`: A hash over the header of the block. It's type is `BlockHash`
- `header`: The header of the block that contains information about the contents of the block with additional metadata. It's type is `BlockHeaderV2`.
- `body`: The block's body contains the proposer of the block and hashes of deploys and transfers contained within it. It's type is `BlockBodyV2`.

### BlockHeaderV2 {#block-header-v2}

The header portion of a block, structurally, is defined as follows:

- `parent_hash` is the hash of the parent block. It serializes to the byte representation of the parent hash. The serialized buffer of the `parent_hash` is 32 bytes long.
- `state_root_hash` is the global state root hash produced by executing this block's body. It serializes to the byte representation of the `state root hash`. The serialized buffer of the `state_root_hash` is 32 bytes long.
- `body_hash` the hash of the block body. It serializes to the byte representation of the body hash. The serialized buffer of the `body_hash` is 32 bytes long.
- `random_bit` is a boolean needed for initializing a future era. It is serialized as a single byte; true maps to 1, while false maps to 0.
- `accumulated_seed` is a seed needed for initializing a future era. It serializes to the byte representation of the parent Hash. The serialized buffer of the `accumulated_hash` is 32 bytes long.
- `era_end` contains equivocation and reward information to be included in the terminal finalized block. It is an optional field. Thus if the field is set as `None`, it serializes to _0_. The serialization of the other case is described in the `EraEndV2`.
- `timestamp` The timestamp from when the block was proposed. It serializes as a single `u64` value. The serialization of a `u64` value is described in the CLValues section.
- `era_id` Era ID in which this block was created. It serializes as a single `u64` value.
- `height` The height of this block, i.e., the number of ancestors. It serializes as a single `u64` value.
- `protocol_version` The version of the Casper network when this block was proposed. It is 3-element tuple containing `u32` values. It serializes as a buffer containing the three `u32` serialized values. Refer to the CLValues section on how `u32` values are serialized.
- `proposer` public key of the proposer of the block. It's type is `PublicKey`
- `current_gas_price` gas price of the block. It is an unsigned 8 bit number.
- `last_switch_block_hash` it is an optional block hash pointing to the last switch block. It's type is `BlockHash`, but since it's optional, rules of serializing (optional fields)[./primitives.md#clvalue-option] apply.

### EraEndV2 {#eraendV2}

`EraEndV2` as represented within the block header, is a struct containing four fields.

- `equivocators`: A vector of `PublicKey` listing equivocators for the era.
- `inactive_validators`: A list of inactive validators for the era.
- `next_era_validator_weights`: A map of validators and their weights for the era to follow.
- `rewards`: A Binary Tree Map of `PublicKey` and `u64`.
- `next_era_gas_price`: The next era's gas price as a `u8`.

Note that `EraEndV2` is an optional field. Thus the above scheme only applies if there is an `EraEndV2`; if there is no era end, the field simply serializes to _0_.

### BlockBodyV2 {blockbodyv2}

A modern block is structurally defined as:
Expand All @@ -136,6 +165,20 @@ A modern block is structurally defined as:

- [`rewarded_signatures`](./types.md#rewarded-signatures): A list of identifiers for finality signatures for a particular past block. It serializes as a vector of `SingleBlockRewardedSignatures` which describes signatures for a single ancestor block. The first entry represents the signatures for the parent block, the second for the parent of the parent, and so on.


## BlockHash {#block-hash}

The block hash is a `Digest` over the contents of the block Header. The `BlockHash` serializes as the byte representation of the hash itself.


## ByteCodeAddr {#byte-code-addr}

An address for ByteCode records stored in global state. Comes in one of three variants:
- `Empty`. It serializes as a `u8` tag of `0`.
- `V1CasperWasm`. It serializes as a `u8` tag of `1` followed by 32 bytes interpreted as hex-encoded address.
- `V2CasperWasm`. It serializes as a `u8` tag of `2` followed by 32 bytes interpreted as hex-encoded address.


## Contract {#contract}

A contract struct containing the following fields:
Expand Down Expand Up @@ -406,10 +449,6 @@ The scheduling mode of a transaction, serialized as a [`u8`](./primitives.md#clv

- `Standard` serializes as a `0`.

- `FutureEra` serializes as a `1` followed by a future [`era_id`](./types.md#eraid).

- `FutureTimestamp` serializes as a `2` followed by a future [`timestamp`](./types.md#timestamp).

### TransactionInvocationTarget {#transactioninvocationtarget}

The identifier of a `stored` transaction target, serialized as one of the following:
Expand Down
15 changes: 9 additions & 6 deletions versioned_docs/version-2.0.0/concepts/serialization/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Hex-encoded bytes serialized as a `u32` value describing the length of the bytes

## ByteCodeKind

The type of byte code, serialized as a single `u8` value. A `0` indicates empty byte code, while a `1` indicates a `V1CasperWasm` to be executed with the first version of the Casper execution engine.
The type of byte code, serialized as a single `u8` value. A `0` indicates empty byte code. `1` indicates a `V1CasperWasm` to be executed with the first version of the Casper execution engine. `2` indicates a `V2CasperWasm` to be executed with the first version of the Casper execution engine

## Caller {#caller}

Expand Down Expand Up @@ -252,6 +252,9 @@ ChainspecRegistry is a unique key variant which contains a mapping of file names

The checksum registry. It serializes as a `BTreeMap` where the first 4 bytes represent a `u32` value describing the number of checksum names as strings and [digests](#digest) held within. The remainder consists of a repeating pattern of serialized strings and then digests of the length dictated by the first four bytes.

## ContractRuntimeTag {#contract-runtime-tag}
A tag for the contracts runtime tag, serialized as a single `u8` tag of 0 for `VmCasperV1`, 1 for `VmCasperV2`.

## Delegator {#delegator}

Represents a party delegating their stake to a validator (or "delegatee"). The structure consists of the following fields:
Expand Down Expand Up @@ -368,7 +371,7 @@ An `enum` specifying who pays for the invocation and execution of an entry point

- `Caller`: Serializes as a 0 and indicates that the caller must cover the cost.

- `SelfOnly`: Serializes as a 1 and indicates that the contract will pay the cost to execute itself, but no subsequent invoked contracts.
- `DirectInvocationOnly`: Serializes as a 1 and indicates that the contract will pay the cost to execute itself, but no subsequent invoked contracts.

- `SelfOnward`: Serializes as a 2 and indicates that the contract will pay for executing itself and any subsequent invocations.

Expand All @@ -378,9 +381,9 @@ The context of method execution. It serializes as one of the following:

- `Caller`: Serializes as a single `u8`, `0b00000000`

- `Called`: Serializes as a single `u8`, `0b00000001`
- `DirectInvocationOnly`: Serializes as a single `u8`, `0b00000001`

- `Factory`: Serializes as a single `u8`, `0b10000000`
- `SelfOnward`: Serializes as a single `u8`, `0b10000000`

## EntrypointV2

Expand Down Expand Up @@ -770,9 +773,9 @@ Entity types for system contracts, serialized as a single `u8` tag identifying t
| Tag | System Contract |
| --- | --------------- |
| 0 | `Mint` |
| 1 | `Auction` |
| 1 | `HandlePayment` |
| 2 | `StandardPayment` |
| 3 | `HandlePayment` |
| 3 | `Auction` |

## TimeDiff {#timediff}

Expand Down
6 changes: 3 additions & 3 deletions versioned_docs/version-2.0.0/developers/cli/opcode-costs.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ All costs in this table are in [motes](/concepts/glossary/M/#motes), not CSPR, a
<!--TODO update the link when 2.0 ships to Testnet/Mainnet. -->
:::

## Storage Costs
## StorageCosts

|Attribute |Description | Cost |
|----------------- |-----------------------------------------------|-----------------|
|gas_per_byte | Gas charged per byte stored in global state. | 1_117_587|

## OpCode Costs
## OpCodeCosts

|Attribute |Description | Cost |
|----------------- |-----------------------------------------------|-----------------|
Expand All @@ -40,7 +40,7 @@ All costs in this table are in [motes](/concepts/glossary/M/#motes), not CSPR, a
|current_memory | Get the current memory operation multiplier. | 290|
|grow_memory | Grow memory cost per page (64 kB). | 240_000|

## Control Flow Operation Costs
## ControlFlowCost

|Attribute |Description | Cost |
|----------------- |-----------------------------------------------|-----------------|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ Required Parameters:

## ByteCodeHash

The hex-encoded address of a smart contract [`AddressableEntity`](#addressableentity).
A type wrapping a `HashAddr` which is the raw bytes of the ByteCodeHash. Serializes as `HashAddr`

## ByteCodeKind

Expand Down
Loading