-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* precompile/results: add readme for predicate results serialization * minor improvements --------- Co-authored-by: Ceyhun Onur <ceyhun.onur@avalabs.org>
- Loading branch information
1 parent
40d1217
commit 510fa08
Showing
1 changed file
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# Results | ||
|
||
The results package defines how to encode `PredicateResults` within the block header's `Extra` data field. | ||
|
||
For more information on the motivation for encoding the results of predicate verification within a block, see [here](../../x/warp/README.md#re-processing-historical-blocks). | ||
|
||
## Serialization | ||
|
||
Note: PredicateResults are encoded using the AvalancheGo codec, which serializes a map by serializing the length of the map as a uint32 and then serializes each key-value pair sequentially. | ||
|
||
PredicateResults: | ||
``` | ||
+---------------------+----------------------------------+-------------------+ | ||
| codecID : uint16 | 2 bytes | | ||
+---------------------+----------------------------------+-------------------+ | ||
| results : map[[32]byte]TxPredicateResults | 4 + size(results) | | ||
+---------------------+----------------------------------+-------------------+ | ||
| 6 + size(results) | | ||
+-------------------+ | ||
``` | ||
|
||
- `codecID` is the codec version used to serialize the payload and is hardcoded to `0x0000` | ||
- `results` is a map of transaction hashes to the corresponding `TxPredicateResults` | ||
|
||
TxPredicateResults | ||
``` | ||
+--------------------+---------------------+------------------------------------+ | ||
| txPredicateResults : map[[20]byte][]byte | 4 + size(txPredicateResults) bytes | | ||
+--------------------+---------------------+------------------------------------+ | ||
| 4 + size(txPredicateResults) bytes | | ||
+------------------------------------+ | ||
``` | ||
|
||
- `txPredicateResults` is a map of precompile addresses to the corresponding byte array returned by the predicate | ||
|
||
### Examples | ||
|
||
#### Empty Predicate Results Map | ||
|
||
``` | ||
// codecID | ||
0x00, 0x00, | ||
// results length | ||
0x00, 0x00, 0x00, 0x00 | ||
``` | ||
|
||
#### Predicate Map with a Single Transaction Result | ||
|
||
``` | ||
// codecID | ||
0x00, 0x00, | ||
// Results length | ||
0x00, 0x00, 0x00, 0x01, | ||
// txHash (key in results map) | ||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
// TxPredicateResults (value in results map) | ||
// TxPredicateResults length | ||
0x00, 0x00, 0x00, 0x01, | ||
// precompile address (key in TxPredicateResults map) | ||
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
0x00, 0x00, 0x00, 0x00, | ||
// Byte array results (value in TxPredicateResults map) | ||
// Length of bytes result | ||
0x00, 0x00, 0x00, 0x03, | ||
// bytes | ||
0x01, 0x02, 0x03 | ||
``` | ||
|
||
#### Predicate Map with Two Transaction Results | ||
|
||
``` | ||
// codecID | ||
0x00, 0x00, | ||
// Results length | ||
0x00, 0x00, 0x00, 0x02, | ||
// txHash (key in results map) | ||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
// TxPredicateResults (value in results map) | ||
// TxPredicateResults length | ||
0x00, 0x00, 0x00, 0x01, | ||
// precompile address (key in TxPredicateResults map) | ||
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
0x00, 0x00, 0x00, 0x00, | ||
// Byte array results (value in TxPredicateResults map) | ||
// Length of bytes result | ||
0x00, 0x00, 0x00, 0x03, | ||
// bytes | ||
0x01, 0x02, 0x03 | ||
// txHash2 (key in results map) | ||
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
// TxPredicateResults (value in results map) | ||
// TxPredicateResults length | ||
0x00, 0x00, 0x00, 0x01, | ||
// precompile address (key in TxPredicateResults map) | ||
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
0x00, 0x00, 0x00, 0x00, | ||
// Byte array results (value in TxPredicateResults map) | ||
// Length of bytes result | ||
0x00, 0x00, 0x00, 0x03, | ||
// bytes | ||
0x01, 0x02, 0x03 | ||
``` |