spacemeshos / svm

SVM - Spacemesh Virtual Machine
https://spacemesh.io
MIT License
85 stars 14 forks source link

Extending `svm-codec` with the `Envelope` #458

Closed YaronWittenstein closed 2 years ago

YaronWittenstein commented 2 years ago

As discussed in the AA Transactions & SVM Integration

The Envelope will consist of the following fields:

  1. version - For versioning (to ease introducing new changes in the future). Right now, we'll only accept the value 0x0 (for Genesis) We can use a variable length-integer encoding here. Or allocate a fixed number of bytes

  2. type - The Transaction type (Deploy / Spawn / Call) A single byte seems the right choice.

  3. principal - The Address of the Account paying for the Gas. This will consume 20 bytes.

  4. amount - For funding. This field will be of type 64-bit integer (Big-Endian order). We can use a variable length-integer encoding here.

  5. tx_nonce - For the tx nonce. I think can use a variable length-integer encoding here (encoding up to say 128 bit). The number 128-bit should suffice for any imaginable Generalized Nonce Scheme to be implemented.

  6. gas_limit - Maximum units of Gas to be paid. This field will be of type 64-bit integer (Big-Endian order). We can use a variable length-integer encoding here.

  7. gas_fee - Fee per Unit of Gas. This field will be of type 64-bit integer (Big-Endian order). We can use a variable length-integer encoding here.

Notes

It should be extended to have the version and type fields as well.

When it was implemented we've thought about the encoding between go-svm and SVM. Since we've decided that SVM will own the encoding of the Envelope the implementation might change to be more compact. (and of course, it should adjust to include version andtype` as well).

The Message will be an enum that will hold one of the Message types:

enum Message {
  Deploy(Template), 
  Spawn(SpawnAccount),
  Call(Transaction),
}

Now we could implement the Codec trait for Message. This implementation will look on the transaction type and delegate the rest of the work to the current implementations of Template/SpawnAccunt/Transaction types.

@lrettig FYI

neysofu commented 2 years ago

Not relevant anymore due to changes to transaction syntax.