Skip to content

Commit 458c31f

Browse files
committed
CAD minor edits and clarifications
1 parent 0ddb76f commit 458c31f

File tree

2 files changed

+84
-58
lines changed

2 files changed

+84
-58
lines changed

cad/002_values/README.md

Lines changed: 50 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# CVM Values
22

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.
413

514
## Motivation
615

@@ -68,23 +77,31 @@ This also ensures that Peers can safely store multiple versions of large data st
6877

6978
### Canonical Encoding
7079

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.
7281

7382
CVM values are **defined to be equal** if and only if their Encoding is identical.
7483

7584
### Value ID
7685

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.
7887

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).
8091

8192
## Types
8293

8394
### Primitive Types
8495

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+
85102
#### Long
86103

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.
88105

89106
Examples:
90107

@@ -98,6 +115,12 @@ Longs are the natural representation of small integer values within a fixed rang
98115

99116
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).
100117

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+
101124
#### Double
102125

103126
A Double is a 64-bit double precision floating point value as defined in the IEEE 754 standard.
@@ -111,17 +134,13 @@ Examples:
111134
##Inf
112135
```
113136

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.
115138

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`.
121140

122-
A Byte is an 8-bit, unsigned integer.
141+
While the lowest bits of precision may be lost, double computations are still deterministic.
123142

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).
125144

126145
#### Character
127146

@@ -131,7 +150,7 @@ A Character can map to 1-4 bytes in UTF-8 encoding. For maximum efficiency, char
131150

132151
#### Boolean
133152

134-
A Boolean type contains only two values `true` and `false`.
153+
A Boolean value is one of the two values `true` and `false`.
135154

136155
In addition to their utility in general purpose programming, `true` and `false` are particularly efficient in the CVM, requiring only 1 byte of Encoding.
137156

@@ -153,11 +172,11 @@ Examples:
153172
#666
154173
```
155174

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:
157176

158177
- A separate notation for Addresses makes them more clearly visible in code.
159178
- 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
161180

162181
#### Blob
163182

@@ -171,11 +190,11 @@ Examples
171190
0x ;; The empty Blob (0 bytes)
172191
```
173192

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.
175194

176195
#### String
177196

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.
179198

180199
Examples:
181200

@@ -184,6 +203,8 @@ Examples:
184203
"" ;; The empty string
185204
```
186205

206+
Internally, storage and management of Strings is very similar to Blobs.
207+
187208
#### Symbol
188209

189210
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
196217
hello
197218
```
198219

199-
Symbols are 1-128 byes long, expressed in UTF-8 encoding.
220+
Symbols are 1-128 bytes long, expressed in UTF-8 encoding.
200221

201222
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:
202223

@@ -211,7 +232,7 @@ a
211232
=> a ;; No lookup is performed for quoted symbol
212233
```
213234

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.
215236

216237
#### Keyword
217238

@@ -303,8 +324,6 @@ Indexes can be created using the core function `index`
303324
(index)
304325
```
305326

306-
307-
308327
#### Set
309328

310329
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
327346

328347
#### Block
329348

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+
330353
#### Account
331354

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.
333356

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
337358

338359

339360
#### Peer
@@ -359,28 +380,13 @@ The State represents a total global State of the CVM. This includes
359380
- Global settings and status flags
360381
- The Schedule
361382

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:
375-
376-
`(call target-address (function-name arg1 arg2 .... argN)`
383+
#### Transaction Types
377384

378-
`Call` transaction types are mainly intended as an efficient way for user applications to invoke smart contract calls on behalf of the User.
385+
Transaction types represent instructions to Convex that can be submitted by external Clients. Transactions are specialised record types.
379386

387+
For more details see CAD010.
380388

381-
#### Transfer
382389

383-
A `Transfer` is a transaction requesting the transfer of Convex Coins from a User Account to some other Account.
384390

385391
## Implementation notes
386392

cad/010_transactions/README.md

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ The general lifecycle of a transaction is as follows:
1515

1616
1. Client constructs a transaction containing the desired instruction to the network
1717
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
2020
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
2323

2424

25-
2625
## Transaction Types
2726

2827
All signed transactions MUST contain at least the following fields:
@@ -32,28 +31,30 @@ All signed transactions MUST contain at least the following fields:
3231

3332
### Transfer
3433

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.
3635

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.
3837

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
4039

41-
Both Accounts MUST be valid, otherwise the Transaction MUST fail
40+
Both accounts MUST be valid, otherwise the transaction MUST fail
4241

43-
The Transaction MUST fail if any of the following are true:
42+
The transaction MUST fail if any of the following are true:
4443
- The source Account has insufficient balance to pay for Transfer Transaction fees.
4544
- The transferred Amount is negative
4645
- The transferred Amount is greater than the Convex Coin Balance of the source Account (after subtracting any Transfer Transaction Fees)
4746

48-
If the Transfer Transaction does not fail for any reason, then:
47+
If the transfer transaction does not fail for any reason, then:
4948
- The Amount MUST be subtracted from the Source Account's Balance
5049
- The Amount MUST be added to the Destination Account's balance
5150

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).
5352

5453
### Invoke
5554

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
5758

5859
An Invoke Transaction MUST include a payload of CVM Code. This may be either:
5960
- A pre-compiled CVM Op
@@ -70,6 +71,14 @@ Otherwise, the CVM State MUST be updated by the result of executing the CVM Code
7071

7172
### Call
7273

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:
77+
78+
`(call target-address (function-name arg1 arg2 .... argN)`
79+
80+
`Call` transaction types are mainly intended as an efficient way for user applications to invoke smart contract calls on behalf of the User.
81+
7382
A Call Transaction causes the invocation of an Actor function.
7483

7584
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
107116

108117
An an optimisation, peers MAY avoid creating `Result` records if they have no requirement to report results back to clients.
109118

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+
110130
## Peer Responsibilities
111131

112132
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
117137

118138
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.
119139

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)
121141

122142
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:
123143
- Any transaction that has an obviously invalid sequence number (less than that required for the current Consensus State)

0 commit comments

Comments
 (0)