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: cad/002_values/README.md
+50-44Lines changed: 50 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,15 @@
1
1
# CVM Values
2
2
3
-
Convex depends on a consistent representation of information values that are used within the CVM and Convergent Proof Of Stake Consensus. This document describes the values used and key design requirements that specify the available data types in the CVM and Convex Peers / Clients.
3
+
Convex uses a special representation of information values within the CVM, across the data lattice and to support the Convergent Proof Of Stake Consensus.
4
+
5
+
Values in Convex are special for a number of reasons:
6
+
- They are **pure immutable values** well suited for use in **functional programming**
7
+
- They are designed for **efficient encoding** and network transmission
8
+
- They form **Merkle trees** supporting cryptographic verification
9
+
- They implement **orthogonal persistence**: automatically migrate between stem main memory and disk as required
10
+
- They support **structural sharing**, making operations such as taking snapshots or the entire CVM state possible in O(1) time
11
+
12
+
It is fair to say that Convex wouldn't be possible without this powerful and flexible implementation of data values. This document describes the values used and key design requirements that specify the available data types in the CVM and Convex Peers / Clients.
4
13
5
14
## Motivation
6
15
@@ -68,23 +77,31 @@ This also ensures that Peers can safely store multiple versions of large data st
68
77
69
78
### Canonical Encoding
70
79
71
-
All CVM values MUST have a unique canonical **Encoding** as a fixed length sequence of bytes. See [Encoding CAD](/cad/003_encoding/README.md) for full specification.
80
+
All CVM values MUST have a unique canonical **encoding** as a fixed length sequence of bytes. See [Encoding CAD](/cad/003_encoding/README.md) for full specification.
72
81
73
82
CVM values are **defined to be equal** if and only if their Encoding is identical.
74
83
75
84
### Value ID
76
85
77
-
Each unique CVM value is defined to have a **Value ID** that is equal to the SHA3-256 hash of the value's Encoding.
86
+
Each unique CVM value is defined to have a **Value ID** that is equal to the SHA3-256 hash of the value's encoding.
78
87
79
-
The Value ID is important, since it makes it possible to refer to Values using a relatively small fixed-length reference type.
88
+
The Value ID is extremely important, because:
89
+
- It makes it possible to refer to values using a small fixed-length reference suitable for content-addressable storage
90
+
- The Value ID makes it possible to cryptographically verify that content is correct in an efficient way (since it acts as the Merkle root of the value when seen as Merkle tree).
80
91
81
92
## Types
82
93
83
94
### Primitive Types
84
95
96
+
#### Integers
97
+
98
+
An integer is a a whole number (positive or negative) as commonly defined in arithmetic.
99
+
100
+
Convex allows big integers up to the size of 32768 bits, i.e. around `1.4*10^9864`. This may be extended in the future, though we haven't found a sensible use case that is likely to require integers this large.
101
+
85
102
#### Long
86
103
87
-
A Long is a 64-bit, signed integer.
104
+
A Long is a 64-bit, signed integer. Longs are the subset of integers within this 64-bit range. For efficiently reasons, Convex automatically uses longs in place of big integers where possible: from a developer perspective, there is usually no need to distinguish between the two.
88
105
89
106
Examples:
90
107
@@ -98,6 +115,12 @@ Longs are the natural representation of small integer values within a fixed rang
98
115
99
116
Longs are also used to represent quantities of native Convex Coins (which by the definition of the 10^18 max supply cap, are guaranteed to fit in 64 bits and not overflow when value quantities are added or subtracted).
100
117
118
+
#### Byte
119
+
120
+
A Byte is an 8-bit, unsigned integer. From a developer perspective, they can be generally be considered simply as longs in the in the range 0-255.
121
+
122
+
Bytes are useful for representing small integer values efficiently, such as a small set of flags or short codes. They are also important as the individual elements of Blob data (equivalent to immutable byte arrays). They are encoded as just 1-2 bytes of data, therefore recommended for very memory conscious applications.
123
+
101
124
#### Double
102
125
103
126
A Double is a 64-bit double precision floating point value as defined in the IEEE 754 standard.
@@ -111,17 +134,13 @@ Examples:
111
134
##Inf
112
135
```
113
136
114
-
Doubles are suitable for many applications that need to represent numerical values that can be very large or very small, but do not need to maintain absolute precision beyond a certain number of decimal places.
137
+
Doubles are suitable for many applications that need to represent numerical values that can be very large or very small, but do not need to maintain precision beyond a certain number of decimal places.
115
138
116
-
While the lowest bits of precision may be lost, Double computations are still deterministic.
117
-
118
-
Doubles support some special values as per the IEEE 754 standard: Positive infinity, negative infinity, negative zero and NaN (not a number).
119
-
120
-
#### Byte
139
+
The maximum IEEEE 754 double value is around `1.7976931348623157*10^308`.
121
140
122
-
A Byte is an 8-bit, unsigned integer.
141
+
While the lowest bits of precision may be lost, double computations are still deterministic.
123
142
124
-
Bytes are suitable for representing small integer values efficiently, such as a small set of flags or short codes. They are also important as the individual elements of Blob data (equivalent to immutable byte arrays)
143
+
Doubles also support some special values as per the IEEE 754 standard: Positive infinity, negative infinity, negative zero and NaN (not a number).
125
144
126
145
#### Character
127
146
@@ -131,7 +150,7 @@ A Character can map to 1-4 bytes in UTF-8 encoding. For maximum efficiency, char
131
150
132
151
#### Boolean
133
152
134
-
A Boolean type contains only two values `true` and `false`.
153
+
A Boolean value is one of the two values `true` and `false`.
135
154
136
155
In addition to their utility in general purpose programming, `true` and `false` are particularly efficient in the CVM, requiring only 1 byte of Encoding.
137
156
@@ -153,11 +172,11 @@ Examples:
153
172
#666
154
173
```
155
174
156
-
Addresses are logically equivalent 63-bit positive integers, though they are not intended for use in calculation. Note that Longs could have been used for this purpose, however a specialised Address value type has some additional advantages:
175
+
Addresses can be considered equivalent to 63-bit positive integers, though they are not intended for use in calculation. Note that Longs could have been used for this purpose, however a specialised Address value type has some additional advantages:
157
176
158
177
- A separate notation for Addresses makes them more clearly visible in code.
159
178
- We can apply additional security validation and prevent some user errors (e.g. getting argument orders wrong and passing an asset quantity instead of an address which might produce unexpected results...)
160
-
- The implementation can be made slightly more optimised
179
+
- The implementation can be made more optimised
161
180
162
181
#### Blob
163
182
@@ -171,11 +190,11 @@ Examples
171
190
0x ;; The empty Blob (0 bytes)
172
191
```
173
192
174
-
Blobs are especially useful for storing opaque units of data that may be important to external systems (e.g. client data encodings) as well as cryptographic values such as keys, hashes or verification proofs. While is is possible to manipulate Blobs in CVM code, this is not usually recommended: such handling should normally be done off-chain.
193
+
Blobs are especially useful for storing opaque units of data that may be important to external systems (e.g. client data encodings) as well as cryptographic values such as keys, hashes (including value IDs) or verification proofs. While is is possible to manipulate Blobs in CVM code, this is not usually recommended: such handling should normally be done off-chain.
175
194
176
195
#### String
177
196
178
-
A String is a sequence of bytes intended to represent the UTF-8 character encoding of text.
197
+
A String is a sequence of bytes intended to represent the UTF-8 character encoding of text.
179
198
180
199
Examples:
181
200
@@ -184,6 +203,8 @@ Examples:
184
203
"" ;; The empty string
185
204
```
186
205
206
+
Internally, storage and management of Strings is very similar to Blobs.
207
+
187
208
#### Symbol
188
209
189
210
A Symbol is a identifier used to name things: values stored in an Account environment, or meaningful symbolic values in code.
@@ -196,7 +217,7 @@ count
196
217
hello
197
218
```
198
219
199
-
Symbols are 1-128 byes long, expressed in UTF-8 encoding.
220
+
Symbols are 1-128 bytes long, expressed in UTF-8 encoding.
200
221
201
222
Symbols have special behaviour when evaluated: they perform a lookup of the value named by the symbol in the current environment. If this behaviour is not desired, they should be **quoted** with `'` to specify that the actual symbol is required, not the referenced value. An example of this usage:
202
223
@@ -211,7 +232,7 @@ a
211
232
=> a ;; No lookup is performed for quoted symbol
212
233
```
213
234
214
-
Internally Symbols *may* contain arbitrary characters (including badly formed UTF-8), but some of these may not read correctly in an off-chain Parser - therefore it is up to users to ensure that the Symbols they define are readable if this is a requirement.
235
+
Internally, Symbols *may* contain arbitrary characters (including badly formed UTF-8), but some of these may not read correctly in an off-chain Parser - therefore it is up to users to ensure that the Symbols they define are readable if this is a requirement.
215
236
216
237
#### Keyword
217
238
@@ -303,8 +324,6 @@ Indexes can be created using the core function `index`
303
324
(index)
304
325
```
305
326
306
-
307
-
308
327
#### Set
309
328
310
329
A Set is a data structure that contains zero or more values as **members** of the set.
@@ -327,13 +346,15 @@ Records behave like Maps when accessed using their field names as keys mapped to
327
346
328
347
#### Block
329
348
349
+
A block is a group of transactions submitted by a peer to the network.
350
+
351
+
Unlike blockchains, Convex does not require blocks to be chained to the previous block via a hash - which allows them to be created and submitted in parallel. They are best thought of as groups of contiguous transactions submitted by the same peer in the ordering.
352
+
330
353
#### Account
331
354
332
-
An Account record represents information regarding the current state of an Account. This includes:
355
+
An Account record represents information regarding the current state of an Account.
333
356
334
-
| Key | Type | Description |
335
-
| --- | ---- | ---- |
336
-
|:sequence| Long | The current sequence number. Next transaction must have this value plus one |
357
+
See CAD004 for more details of the specification and contents of Accounts
337
358
338
359
339
360
#### Peer
@@ -359,28 +380,13 @@ The State represents a total global State of the CVM. This includes
359
380
- Global settings and status flags
360
381
- The Schedule
361
382
362
-
### Transaction Types
363
-
364
-
Transaction types represent instructions to Convex that can be submitted by external Clients.
365
-
366
-
#### Invoke
367
-
368
-
An `Invoke` transaction is a request to execute some CVM code by a User Account. This is the most general type of transaction: any CVM code may be executed.
369
-
370
-
#### Call
371
-
372
-
A `Call` is a transaction requesting the execution of a callable function (typically a smart contract entry point) from a user Account.
373
-
374
-
Semantically, this is roughly equivalent to using an `Invoke` transaction to do the following:
Copy file name to clipboardExpand all lines: cad/010_transactions/README.md
+34-14Lines changed: 34 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,14 +15,13 @@ The general lifecycle of a transaction is as follows:
15
15
16
16
1. Client constructs a transaction containing the desired instruction to the network
17
17
2. Client signs the transaction using a private Ed25519 key
18
-
3. The signed transaction is submitted to a Peer
19
-
4. The Peer incorporates the transaction into a Belief, which is propagated to the network
18
+
3. The signed transaction is submitted to a peer of the client's choosing
19
+
4. The peer incorporates the transaction into a Belief, which is propagated to the network
20
20
5. The transaction is confirmed in consensus according to the CPoS algorithm
21
-
6. The Peer computes the effect of the transaction on the CVM state, and any result(s)
22
-
7. Peer returns a confirmed transaction result to the Client
21
+
6. The peer computes the effect of the transaction on the CVM state, and any result(s)
22
+
7. Peer returns a confirmed transaction result to the client
23
23
24
24
25
-
26
25
## Transaction Types
27
26
28
27
All signed transactions MUST contain at least the following fields:
@@ -32,28 +31,30 @@ All signed transactions MUST contain at least the following fields:
32
31
33
32
### Transfer
34
33
35
-
A Transfer Transaction causes a transfer of Convex Coins from the origin account to a destination account
34
+
A `Transfer` is a transaction requesting the transfer of Convex Coins from a user (origin) account to some other (target) account.
36
35
37
-
A Transfer Transaction MUST specify an amount to transfer, as an integer.
36
+
A transfer transaction MUST specify an amount to transfer, as an integer.
38
37
39
-
The Source Account MUST be the Origin Account for the Transaction, i.e. transfers can only occur from the Account which has the correct Digital Signature
38
+
The Source Account MUST be the origin account for the transaction, i.e. transfers can only occur from the account which has the correct digital signature
40
39
41
-
Both Accounts MUST be valid, otherwise the Transaction MUST fail
40
+
Both accounts MUST be valid, otherwise the transaction MUST fail
42
41
43
-
The Transaction MUST fail if any of the following are true:
42
+
The transaction MUST fail if any of the following are true:
44
43
- The source Account has insufficient balance to pay for Transfer Transaction fees.
45
44
- The transferred Amount is negative
46
45
- The transferred Amount is greater than the Convex Coin Balance of the source Account (after subtracting any Transfer Transaction Fees)
47
46
48
-
If the Transfer Transaction does not fail for any reason, then:
47
+
If the transfer transaction does not fail for any reason, then:
49
48
- The Amount MUST be subtracted from the Source Account's Balance
50
49
- The Amount MUST be added to the Destination Account's balance
51
50
52
-
A transfer amount of zero will succeed, though this is relatively pointless. Users SHOULD avoid submitting such transfers, unless they are willing to pay transaction fees simply to have this recorded in consensus.
51
+
A transfer amount of zero will succeed, though this is relatively pointless. Users SHOULD avoid submitting such transfers, unless there is a good reason (e.g. public proving the ability to transact with a given account).
53
52
54
53
### Invoke
55
54
56
-
An Invoke Transaction causes the execution of CVM Code
55
+
An `Invoke` transaction is a request to execute some CVM code by a user account. This is the most general type of transaction: any CVM code may be executed.
56
+
57
+
An Invoke transaction causes the execution of CVM Code when successfully signed and submitted to the Convex network
57
58
58
59
An Invoke Transaction MUST include a payload of CVM Code. This may be either:
59
60
- A pre-compiled CVM Op
@@ -70,6 +71,14 @@ Otherwise, the CVM State MUST be updated by the result of executing the CVM Code
70
71
71
72
### Call
72
73
74
+
A `Call` is a transaction requesting the execution of a callable function (typically a smart contract entry point) from a user account.
75
+
76
+
Semantically, this is broadly equivalent to using an `Invoke` transaction to do the following:
`Call` transaction types are mainly intended as an efficient way for user applications to invoke smart contract calls on behalf of the User.
81
+
73
82
A Call Transaction causes the invocation of an Actor function.
74
83
75
84
Apart from lower transaction fees, the Call instruction MUST be functionally equivalent to invoking CVM Code of the form:
@@ -107,6 +116,17 @@ Transaction results MUST be returned in a `Result` record which contains the fol
107
116
108
117
An an optimisation, peers MAY avoid creating `Result` records if they have no requirement to report results back to clients.
109
118
119
+
### Verification
120
+
121
+
If the client trusts the peer, the returned result may be assumed as evidence that the transaction has succeeded.
122
+
123
+
If there are doubts about the integrity of the peer, further verification may be performed in several ways:
124
+
- Checking the consensus ordering to ensure that the transaction occurred when the peer claimed
125
+
- Querying the CVM state to ensure transaction effects have been carried out
126
+
- Confirming the result with one or more independent peers
127
+
128
+
It is generally the responsibility of the user / app developer to choose an appropriate level of verification and ensure connection to trusted peers.
129
+
110
130
## Peer Responsibilities
111
131
112
132
Peers are generally expected to be responsible for validating and submitting legitimate transactions for consensus on behalf of their clients.
@@ -117,7 +137,7 @@ Peers SHOULD submit legitimate transaction for consensus, unless they have a rea
117
137
118
138
Peers SHOULD submit transactions in the order that they are received from any single client. Failure to do so is likely to result in sequence errors and potential economic cost for the peers.
119
139
120
-
Peers SHOULD validate the digital signature of transactions they include in a block. Failure to do so is likely to result in penalities (at a minimum, paying the fees for the invalid transaction)
140
+
Peers SHOULD validate the digital signature of transactions they include in a block. Failure to do so is likely to result in penalties (at a minimum, paying the fees for the invalid transaction)
121
141
122
142
Peers MAY reject transactions that do not appear to be legitimate, in which case the Peer SHOULD return a Result to the Client submitting the transaction indicating the reason for rejection. Some examples where this may be appropriate:
123
143
- Any transaction that has an obviously invalid sequence number (less than that required for the current Consensus State)
0 commit comments