Skip to content

Commit 4e23fbc

Browse files
committed
Added Condor section in additional docs plugin.
1 parent 7c9a6e1 commit 4e23fbc

File tree

336 files changed

+36666
-15
lines changed

Some content is hidden

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

336 files changed

+36666
-15
lines changed

condor/addressable-entity.md

+99
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: [v2]
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.

0 commit comments

Comments
 (0)