You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/src/store_type.md
+32-30Lines changed: 32 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,19 +29,25 @@ creates
29
29
The Act storage corresponds directly to the EVM state variables, but with two important differences:
30
30
1. All storage is immutable by default.
31
31
Storage can only change through explicit updates inside transitions.
32
-
2. Types are explicit and checked. Storage in Act can have the following types:
33
-
-**base types** e.g. line 2 in the snippet above: `uint256 totalSupply`
34
-
- unsigned integers of various sizes: `uint8`, `uint16`, `uint32`, `uint64`, `uint128`, `uint256`,
35
-
- signed integers of various sizes: `int8`, `int16`, `int32`, `int64`, `int128`, `int256`,
36
-
- booleans: `bool`
37
-
- addresses:`address`
38
-
-**mapping types**
39
-
- mappings from one base type to another, e.g. from `address` to `uint256` in line 3 `mapping(address => uint256) balanceOf`
40
-
- nested mappings: from a base type to another mapping, e.g. from `address` to `mapping(address => uint256)` in line 4 `mapping(address => mapping(address => uint256)) allowance`
41
-
-**contract types** referencing the storage of other contracts (details later in <spanstyle="color:red">
42
-
"Advanced Topics: Aliasing and Unique Ownership" (?)
43
-
</span>).
44
-
- Artificial example: Another contract `OtherContract` uses in its storage a reference to an ERC20 `Token` contract: In `OtherContract`'s storage we would have a field of type `Token`, which can be initialized with an address of a specific deployed ERC20 contract.
32
+
2. Types are explicit and checked. Which types storage can have is detailed next.
33
+
34
+
### Storage Types
35
+
Storage in Act can have the following types:
36
+
37
+
-**base types** e.g. line 2 in the snippet above: `uint256 totalSupply`
38
+
- unsigned integers of various sizes: `uint8`, `uint16`, `uint32`, `uint64`, `uint128`, `uint256`,
39
+
- signed integers of various sizes: `int8`, `int16`, `int32`, `int64`, `int128`, `int256`,
40
+
- booleans: `bool`
41
+
- addresses:`address`
42
+
-**mapping types**
43
+
- mappings from one base type to another, e.g. from `address` to `uint256` in line 3 `mapping(address => uint256) balanceOf`
44
+
- nested mappings: from a base type to another mapping, e.g. from `address` to `mapping(address => uint256)` in line 4 `mapping(address => mapping(address => uint256)) allowance`
45
+
-**contract types** referencing the storage of other contracts (details later in
46
+
<spanstyle="color:red">
47
+
"Advanced Topics: Aliasing and Unique Ownership" (?)
48
+
</span>).
49
+
50
+
- Artificial example: Another contract `OtherContract` uses in its storage a reference to an ERC20 `Token` contract: In `OtherContract`'s storage we would have a field of type `Token`, which can be initialized with an address of a specific deployed ERC20 contract.~
45
51
46
52
47
53
## Mapping Types and Defaults
@@ -70,17 +76,12 @@ The **defaults** for the different mapping types are:
70
76
71
77
This matches Solidity’s behavior but is **made explicit** in Act, which is essential for reasoning about invariants.
72
78
73
-
## ABI Types vs Storage Types
74
-
Not all types in Act are allowed everywhere. There is a distinction between:
75
-
1.**ABI types**: used for function parameters and return values.
76
-
2.**Storage types**: used for persistent state (e.g. mappings, contract references
77
-
78
-
### ABI types
79
+
## ABI Types
79
80
80
-
The following types are used for function parameters and return values.
81
+
The following types are used for function parameters and return values, mirroring the Ethereum ABI specification:
81
82
82
83
- All **base types** (`uint*`, `int*`, `bool`, `address`) are allowed here.
83
-
- Additionally, there is another ABI type: specially **annotated address types**. These are addresses which point to contracts.
84
+
- Additionally, there is another ABI type: specially **annotated address types**. These are addresses which point to contracts. Intuitively, an annotated address type `address<ContractType>` can be thought of as a regular address, for which we know that it points to the storage of a contract of type `ContractType`.
84
85
85
86
Consider the following act snippet that declares a transition `foo` which takes an address of an ERC20 contract as parameter:
86
87
@@ -90,14 +91,15 @@ The following types are used for function parameters and return values.
90
91
storage
91
92
erc_token := token_addr as Token
92
93
```
93
-
The parameter `token_addr` has type `address<Token>`, which indicates that the address points to a deployed contract of type `Token` (e.g. in our example an ERC20). This allows Act to reason about calls to this contract now called `erc_token`, which *lives* at address `token_addr` inside the transition body.
94
-
95
-
Intuitively, an annotated address type `address<ContractType>` can be thought of as a regular address, for which we know that it points to the storage of a contract of type `ContractType`.
96
-
97
-
CONTINUE HERE: talk about how this allows reasoning about calls to other contracts, and how act can verify that the called contract conforms to its spec (if provided). Refer to the correctness section (paragraph on Input space equivalence)
94
+
The parameter `token_addr` has type `address<Token>`, which indicates that the address points to a deployed contract of type `Token` (e.g. in our example an ERC20 token).
95
+
96
+
This special type exists to allow Act to reason about calls to this contract now called `erc_token`, which *lives* at address `token_addr` inside the transition body. Ensuring that the spec which includes this annotated address types is equivalent to the implementation which only uses regular addresses is still possible and discussed in the <span style="color:red">
97
+
correctness section (paragraph on Input space equivalence).</span>)
98
98
99
-
### Storage types
100
-
Used for persistent state
101
-
(e.g. mappings, contract references)
102
99
103
-
For ERC20, all parameters and storage fields are ABI-compatible, which simplifies the specification. More complex contracts may involve non-ABI storage types.
100
+
*Note:* Not all types in Act are allowed everywhere. There is a distinction between **ABI types** and **Storage types**:
101
+
1. **ABI types** include **base types** and **annotated address types**. They are used for function parameters and return values.
102
+
2. **Storage types** include **base types**, **mapping types**, and **contract types**. They are
103
+
used for storage.
104
+
105
+
That means in function parameters and return values, mapping types and contract types are not allowed. Whereas in storage, annotated address types are not allowed.
0 commit comments