Skip to content

Commit 96de49a

Browse files
authored
Merge pull request #24 from casper-devrel/feat/upgrade/v2.0.0
Feat/upgrade/v2.0.0
2 parents ddb9572 + 99afaa9 commit 96de49a

File tree

818 files changed

+31965
-591
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

818 files changed

+31965
-591
lines changed

analyse-docs.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
docs_folder=./cspr-docs/docs;
2+
regex="\/image\/"
3+
regex="import useBaseUrl from \'@docusaurus\/useBaseUrl\';"
4+
grep -r -i "$regex" $docs_folder;
5+

analyse-img.sh

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
image_folder=./cspr-docs/static/image;
2+
docs_folder=./cspr-docs/docs;
3+
image_count=0
4+
image_names=()
5+
images_list=./images_list.csv
6+
images_notused=./images_notused.csv
7+
images_grep=./images_grep_out.csv
8+
9+
echo "" > $images_list
10+
echo "" > $images_notused
11+
echo "" > $images_grep
12+
for entry in $(find $image_folder -iname "*.jpeg" -o -iname "*.jpg" -o -iname "*.gif" -o -iname "*.png" -o -iname "*.bmp")
13+
do
14+
# extract just the filename
15+
filename="${entry##*/}"
16+
printf "$entry\n" >> $images_list
17+
image_names[$image_count]=$filename
18+
image_count=$((image_count+1))
19+
done
20+
21+
for image_name in ${image_names[@]}; do
22+
grep_result=$(grep -r -i "$image_name" $docs_folder);
23+
24+
if [ -z "$grep_result" ];
25+
then
26+
printf "$image_name\n" >> $images_notused
27+
else
28+
printf "$grep_result\n" >> $images_grep
29+
fi
30+
done

cspr-docs/blog/2024-07-16-fee-elimination.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Fee Elimination in Condor
33
description: A discussion of the Fee Elimination feature in Casper 2.0
44
slug: condor-fee-elimination
55
date: 2024-07-16T22:00
6-
authors: [ dylanireland, alexanderlimonov ]
6+
authors: [ dylanireland, melpadden ]
77
tags: [condor, features, tokenomics]
88
hide_table_of_contents: false
99
---
@@ -13,10 +13,12 @@ The Casper 2.0 (aka Condor) network upgrade introduces new options to the way a
1313

1414
<!-- truncate -->
1515

16-
## Gas
17-
Public distributed blockchain networks that support smart contracts generally use a concept commonly known as "[gas](https://docs.casper.network/concepts/glossary/G/#gas)", which can be thought of as "the ability to do work on-chain". Gas is acquired in finite quantities and used to meter and limit resource consumption by individual transactors. A transactor's available gas is consumed by their on-chain usage of computation, data storage, and possibly other chain-specific resources. The public Casper Network and its testnet have used such a gas model since their geneses.
16+
## Concepts
17+
Public distributed blockchain networks that support smart contracts generally employ a concept known as "[gas](https://docs.casper.network/concepts/glossary/G/#gas)", which can be thought of as "the ability to do work on-chain". The problem addressed by this mechanism is that **any finite resource on a publicly accessible computer network must be rate-limited**, because a resource made available without limit is a denial of service attack vector.
1818

19-
## Casper 1.x: Payment, Gas Price, Fees and Refunds
19+
Gas is acquired in finite quantities and used to meter and limit resource consumption by individual transactors. A transactor's available gas is consumed by their on-chain usage of computation, data storage, and possibly other chain-specific resources. The public Casper Network and its testnet have used such a gas model since their geneses.
20+
21+
## Payment, Gas Price, Fees
2022
On Casper 1.x, every transaction is subject to gas consumption. The transactor must specify an amount of token that is converted to gas and used to pay for execution. All gas consumed in each block is allotted to the [proposer](#proposer) of that block in the form of transaction [fees](#fees). The model also includes tables to allow calculation of gas costs, and support for some portion of unconsumed gas to be refunded to transactors. We refer to these concepts using the following terms:
2123

2224
* **Gas Limit**: An amount of gas, specified by the transactor, at which to cancel a transaction.
@@ -25,7 +27,7 @@ On Casper 1.x, every transaction is subject to gas consumption. The transactor m
2527
* **Payment**: The amount of token specified by the transactor to pay for the execution of a transaction.
2628
* **Refund**: All or a portion of the remaining token after gas is purchased for execution.
2729

28-
> [!NOTE]
30+
>
2931
> The Casper node software supports a number of configurable options which govern how gas may be calculated for a given transaction. A discussion of these is outside the scope of this article. This article is concerned with how these gas costs are dealt with, once calculated. Gas cost options will be the subject of another article.
3032
3133
## Fee Elimination
@@ -42,7 +44,7 @@ A hold may be thought of as a temporary freeze on some portion of the funds in a
4244

4345
The Casper Node 2.0 software currently supports two hold release models: **Accrued** and **Amortized**.
4446

45-
> [!NOTE]
47+
>
4648
> The Condor node architecture allows for any time-based function to be developed and used to calculate hold releases. However, for simplicity, this article will deal with the two currently available options.
4749
4850
#### Accrued
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
title: Addressable Entity in Casper 2.0
3+
description: An introduction to the Addressable Entity concept.
4+
slug: addressable-entity
5+
date: 2024-07-17T18:00
6+
authors: [ sczembor, melpadden ]
7+
tags: [condor]
8+
hide_table_of_contents: false
9+
---
10+
11+
# AddressableEntity in Casper 2.0
12+
13+
Casper 2.0 introduces significant changes in the representation and management of accounts and smart contracts, through the introduction of the `AddressableEntity` type. This new structure replaces the separate `AccountHash` and `ContractHash` used in Casper 1.x, bringing a unified approach to interact with entities on the network. Contracts can now hold and manage funds directly through associated purses, similar to user accounts. They can also manage their own keys, enabling more sophisticated access control.
14+
15+
In this article, we'll dive into the details of `AddressableEntity`, exploring its structure and functionalities.
16+
17+
<!-- truncate -->
18+
19+
## Key Concepts
20+
21+
**AddressableEntity**
22+
23+
At its core, an `AddressableEntity` is a versatile data structure that represents both accounts and smart contracts within the Casper global state. It encapsulates all the necessary information for identifying and managing these entities. An `AddressableEntity` provides a unified interface for various operations, including authorization, access control, and execution of functions.
24+
25+
**EntityAddr**
26+
27+
An `EntityAddr` serves as the address for an `AddressableEntity`. It not only encodes the unique identifier (hash) of the entity but also its type. There are three distinct variants of `EntityAddr`:
28+
29+
1. **System:** Used for built-in, native contracts crucial for the blockchain's operation.
30+
2. **Account:** Represents a user's account.
31+
3. **SmartContract:** Represents a user-deployed smart contract.
32+
33+
**AddressableEntityHash**
34+
35+
The `AddressableEntityHash` is a newtype wrapper around a 32-byte hash (`HashAddr`). This hash functions as a unique identifier for the `AddressableEntity`, typically derived from either the account's public key or the smart contract's hash using hashing algorithm.
36+
37+
## The inner workings of AddressableEntity
38+
39+
Let's dive into the critical components within an `AddressableEntity`:
40+
41+
* **`protocol_version` (ProtocolVersion):** This field indicates the protocol version that the entity is compatible with. It ensures backward compatibility and allows for smooth upgrades as the Casper network evolves.
42+
* **`entity_kind` (EntityKind):** As mentioned earlier, this enum determines the type of entity – System, Account, or SmartContract.
43+
* **`associated_keys` (AssociatedKeys):** This data structure stores a map of public keys authorized to interact with the entity. Each key is associated with a weight that represents its voting power in decision-making processes within the entity.
44+
* **`action_thresholds` (ActionThresholds):** These thresholds define the minimum combined weight of associated keys required to authorize specific actions. The three main action types are `deployment`, `key_management`, and `upgrade_management`. Each action type has its own weight threshold, allowing for fine-grained control over permissions.
45+
* **`entry_points` (EntryPoints):** This component is relevant only for smart contracts. It defines the functions (entry points) that external actors can call on the contract, along with their parameters, return types, and access permissions.
46+
47+
## Obtaining and converting Keys
48+
49+
In Casper 2.0, developers will primarily work with `Key::AddressableEntity` when referring to accounts and smart contracts. Here's how you can create them and convert between different key formats:
50+
51+
### Creating AddressableEntity Keys
52+
53+
**From Account Hash:**
54+
55+
```rust
56+
let addressable_entity_key = Key::AddressableEntity(EntityAddr::Account(account_hash));
57+
```
58+
59+
**From Smart Contract Hash:**
60+
61+
```rust
62+
let addressable_entity_key = Key::AddressableEntity(EntityAddr::SmartContract(contract_hash));
63+
```
64+
65+
### Extracting AccountHash or ContractHash from a Key
66+
You can extract the `AccountHash` or `ContractHash` from a `Key::AddressableEntity` using pattern matching:
67+
68+
```rust
69+
//For Accounts
70+
let account_hash = match addressable_entity_key {
71+
Key::AddressableEntity(EntityAddr::Account(hash)) => hash,
72+
_ => panic!("Not an account key"),
73+
};
74+
//For Contracts
75+
let contract_hash = match addressable_entity_key {
76+
Key::AddressableEntity(EntityAddr::SmartContract(hash)) => hash,
77+
_ => panic!("Not a contract key"),
78+
};
79+
```
80+
81+
## The Address Merge in Condor
82+
83+
The "Address Merge" in the Condor upgrade of Casper is a foundational shift, impacting how accounts and smart contracts are identified and interacted with.
84+
85+
**Global State Transformation:**
86+
87+
Post-Condor, all accounts and smart contract addresses residing within the global state will be automatically migrated to the `AddressableEntity` structure. This means the network itself will recognize and handle these entities using the new format.
88+
89+
**Smart Contract Compatibility Considerations:**
90+
91+
While the global state automatically transitions to `AddressableEntity`, existing contracts are expected to function without any modification.
92+
93+
* **Caller Identification:**
94+
Existing host functions used to identify the caller within your contract will continue to work as before, ensuring no disruption to your contract's functionality. However, new host functions have been introduced that are specifically designed to work with the AddressableEntity format.
95+
96+
* **External Contract Interaction:** Other contracts may have updated their interfaces to accept AddressableEntity arguments. Its worth to verify the argument types to avoid potential errors.
97+
98+
> **Note**
99+
> * Upgrading a contract to a newer version may involve complexities, such as changes to the contract's addressable hash. These changes might require coordination with centralized and decentralized exchanges, as well as communication with your community to ensure a smooth transition.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
title: validator rewards in Casper 2.0
3+
description: A discussion of validator rewards under Casper 2.0
4+
slug: condor-validator-rewards
5+
date: 2024-08-20T18:00
6+
authors: [ melpadden, alexanderlimonov ]
7+
tags: [condor, validators]
8+
hide_table_of_contents: false
9+
---
10+
11+
# Validator rewards with Casper 2.0
12+
13+
## Economics of consensus
14+
15+
Proof of Stake consensus protocols explicitly impose an assumption that a critical portion of the validator set, by weight, remains honest. Normally, just as it is in Highway and will be in Zug, there is a requirement that at least 2/3 of the weight remain honest for the chain to continue to operate normally.
16+
17+
Proof of Stake protocols do not typically describe the particular incentives that should keep validators honest, however, so some incentive scheme must be independently developed to ensure that the assumptions of the safety and liveness theorems actually hold. Such a scheme may directly reward some measure of performance within the protocol model, but an alternative model can choose to reward consensus-independent measures of chain performance, such as chain progress.
18+
19+
Incentive rewards in Casper come from issuance of new token at the end of each era, with quantity derived from an inflation parameter in the chainspec. The minted token are distributed in proportion to weight, assuming nominal performance of the chain.
20+
21+
## Casper 1.X Highway-specific incentives
22+
23+
The 1.0 rewards scheme introduced with Highway on mainnet is directly tied to the details of Highway consensus. Rewards are maximized when all validators regularly send messages necessary to finalize a block within a time limit in a particular round.
24+
25+
Degrading platform performance by delaying block finalization is disadvantageous for all validators, even those not directly responsible for the delay, which is a means of aligning validator incentives with each other by discouraging censorship of consensus messages produced by others.
26+
27+
The weakness of the 1.0 rewards model is that it is difficult to understand and maintain. Additionally, by focusing on a consensus-specific measure of performance, it does not directly incentivize the observable outcome that we actually care about, which is public knowledge of block finality.
28+
29+
## Casper 2.0
30+
31+
### Public knowledge of finality
32+
33+
A necessary outcome of a safe consensus process over possible histories of the chain is that all honest validators should have at least mutual knowledge of the canonical history. That is, each honest validator should believe that a particular history is the correct one, and this history should be the same for all validators.
34+
35+
This mutual knowledge is sufficient for validators to make further progress in building up the canonical history. However, for a user of the blockchain, establishing confidence in the correct operation of the protocol and the identity of the canonical history requires that the validators' knowledge of the canonical history be attested publicly.
36+
37+
In Casper, validators create and distribute finality signatures, which are cryptographically secure witnesses of their belief in the finality of a particular block. Under 1.X, however, these are not easily verifiable by users and play no role in the reward mechanism, despite being a critical tool for building user confidence in the canonical history. In 2.0, we propose to allocate rewards for creation and publication of one's own and other validators' finality signatures.
38+
39+
### Design
40+
41+
Rewards that promote public knowledge of finality naturally suggest rewarding publicly observable behaviors, rather than metrics only readily visible to the consensus component. This, together with the expected transition from Highway to Zug, naturally led to a system that rewards three publicly observable activities
42+
43+
* Block proposal
44+
* Signature creation
45+
* Signature publication
46+
47+
Note that we expect very little, if any, rewards to be allocated for block proposals on mainnet, but the feature remains available.
48+
49+
The rewards apportioned to a block, under nominal operating conditions, are the same as they are under 1.X, that is, they amount to total supply at last era's end multiplied by an inflation factor derived from the chainspec. "Nominal" here means that all rounds result in a finalized block and that all finality signatures are collected and published.
50+
51+
The rewards are apportioned to these three activities based on chainspec settings governing the split between block proposals and signature rewards, and, within signature rewards, between finality signature creation and publication.
52+
53+
Note that this split ensures that validators' incentives are aligned, in the sense that other validators' correct operation is beneficial for each validator. This is because each validator is rewarded for publishing other validators' signature, and because each validator benefits from other publishing its own signatures.
54+
55+
#### Expected rewards & volatility
56+
57+
Under nominal operating conditions, the total rewards for each validator will be proportional to weight in the long run. Depending on the particular values of the parameters governing the split between the three components of the rewards, short-run rewards can be more or less variable.
58+
59+
In the long run, with a stable validator set, each validator eventually produces a number of blocks proportional to its weight. Small validators can do months between producing a block, and will experience variable wait times between such occasions. However, each validator is supposed to produce signatures for each finalized block, so moving the allocation towards signature creation can reduce volatility.
60+
61+
#### Rewards formula
62+
63+
The rewards have three additive components, one for each observable activity we described in the previous section. The era rewards for a particular validator can be described using a simple formula, given below. Note that the formula does not exactly correspond to the actual on-chain calculation, for technical reasons we discuss in a further section.
64+
65+
Let us define some notation first
66+
67+
**N** - expected number of blocks in an era
68+
69+
**N*** - the *set* of observed blocks in an era
70+
71+
**R** - total potential reward pot for the era (i.e., nominal inflation based on chainspec and current supply)
72+
73+
**r** - fraction of reward pot dedicated to block production rewards
74+
75+
**f** - finder's fee for finality signatures
76+
77+
**I** - validator index set
78+
79+
**i**: **N*** -> {0,1} - indicator function for blocks produced by validator i (with abuse of notation)
80+
81+
**w**: **I** -> [0,1] - validator's weight
82+
83+
**W** - total weight of the validator set
84+
85+
**S**: **N*** -> **P(I)** - set of validators associated with finality signatures for a particular observed block
86+
87+
**s_i**: **N*** -> {0,1} - indicator functions for existence of finality signatures associated with validator i for particular observed blocks
88+
89+
Now, we can use our defined symbols to concisely describe era rewards for a particular validator
90+
91+
Era rewards for validator i =
92+
93+
**Σ** (n in **N***) **i(n)** * (**rR/N**) (block production)
94+
95+
&#43; **Σ** (n in **N***) **i(n)** * **Σ** (j in **S(n)**) (**w(j)/W**) * (**f(1-r)R/N**) (finality signature publication)
96+
97+
&#43; **Σ** (n in **N***) **s_i(n)** * (**w(i)/W**) * (**(1-f)(1-r)R/N**) (finality signature contribution)
98+
99+
The meanings of the three additive components in the formula above are, in order
100+
101+
* Sum over blocks, discarding blocks not proposed by this validator
102+
* For each block, add the per-block reward allocation for block proposals from the total pot for the era
103+
* Sum over blocks, discarding blocks not proposed by this validator
104+
* For each block, sum over published signatures
105+
* For each signature, add the per-block reward allocation for signature publication from the total pot for the era, weighing each signature by its creator's proportion of total validator weight
106+
* Sum over blocks, discarding those for which this validator did not create a signature
107+
* For each block, add the per-block reward allocation for signature creation from the total pot for the era, weighing it by the validator's proportion of total validator weight
108+
109+
#### Notes on implementation
110+
111+
In a real network, messages arrive with a delay. This means that we cannot guarantee that all finality signatures for an era will arrive in time to be used by the rewards calculation carried out in the switch block.
112+
113+
We solve this problem by allowing publication of finality signatures for a preceding era. As long as the validator set stays unchanged, in the long run the formula above is a near-exact representation of rewards.
114+
115+
However, entry of new validators means that some of the publication rewards may be distributed among more validators than just those who participated in the era in which the signatures were created.
116+
117+
### Impact on validator revenue
118+
119+
No impact is expected on average validator rewards under nominal operating conditions. Note that shortfall in signature creation, or network issues preventing the propagation of such signatures, can reduce rewards, even for validators who honestly publish all incoming signatures and honestly create signatures for each block. Additionally, allocating more rewards to block proposals or finality publication can make the rewards more volatile.

0 commit comments

Comments
 (0)