Closed YaronWittenstein closed 1 year ago
This SMIP is partially outdated due to replacing our custom encoding with SSZ. Also, the new transaction syntax redefines deploy
transactions as call
's, effectively removing the need to have a custom encoding for them. Similarly, spawn
receipts will most likely be replaced with self-spawn
receipts due to transaction types unification. See also https://github.com/spacemeshos/pm/issues/108.
Overview
This SMIP documents the exact binary encoding of Receipts. It'll also include ASCII charts to make it (hopefully) nicer to read.
Goals and motivation
The primary motivation for the SMIP is to give a full spec to be implemented by
go-svm
. After a transaction has completed, SVM will pass back a blob back (using thesvm_byte_array
) togo-svm
.In order to enable
go-svm
to reason about this blob it must know how to decode it properly.High-level design
SVM has 3 types of Receipts - one for each kind of Transaction:
Deploy Receipt
- A receipt returned after running aDeploy
transaction.Spawn Receipt
- A receipt returned after running aSpawn
transaction.Call Receipt
- A receipt returned after running aCall
transaction.In order to simplify things, each encoded Receipt of a successful transaction starts the same:
Transaction type
- 1 byteVersion
- 2 bytesAdditionally, there is only one encoding Receipt for failed transactions. There was not good reason to keep a different Error encoding for each kind of transaction. So this design also reduces the amount of work for implementing this spec.
Proposed implementation
Here is the current Receipts encoding implementation for SVM v0.3
Successful Deploy Receipt
tx type
- Should be0
is_success
- Should be1
version
- Should be0
Template Address
- TheAddress
of the newTemplate
gas_used
-u64
in Big-EndianSuccessful Spawn Receipt`
tx type
- Should be1
is_success
- Should be1
version
- Should be0
Account Address
- TheAddress
of the newAccount
init State
- The newGlobal-State
RootHash
returndata
- Thereturndata
given as a blobgas_used
-u64
in Big-Endianlogs
- TBDSuccessful Call Receipt
tx type
- Should be2
is_success
- Should be1
version
- Should be0
init State
- The newGlobal-State
RootHash
returndata
- Thereturndata
given as a blobgas_used
-u64
in Big-Endianlogs
- TBDFailed Transaction Receipts
tx type
- The transaction typeis_success
- Should be0
version
- Should be0
error code
- The erorr codelogs
- TBDError blob
- seeError Blob
section below.Error Blob
The
Error Blob
is determined by theerror code
field.Important:
Each
Error Message
Field is truncated to fit into at most 255 bytes. In such a case theMessage
might not make a valid UTF-String.OOG (Out-of-Gas)
Error Blob
is emptyTemplate Not Found
Account Not Found
Compilation Failed
Instantiation Failed
Function Not Found
Function Failed
Function Not Allowed
Function Invalid Signature
Questions/concerns
Are there any other fields we'd like to be become a part of the Receipts? It can even be a field given in the Transactions or something related to the
Context
(layer
for example) of the running transaction.There is an existing implementation under
svm-codec
that transforms each Receipt into a JSON form. Sosvm_codec
WASM API can be easily extended to expose that functionality as well. We'll revist this topic when the Node API (gRPC) will be implemented for v0.3Dependencies and interactions
As described above, since the communication between
go-svm
andSVM
is by passing blobs - this spec should be implemented bygo-svm
.Any non-Rust client that we'd like to integrate with SVM will have go through the FFI layer and implement this SMIP spec.
Stakeholders and reviewers
@YaronWittenstein @neysofu @sudachen @noamnelke @lrettig @avive