spacemeshos / svm

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

Add support for 32-byte and 64-byte ABI types #439

Open YaronWittenstein opened 2 years ago

YaronWittenstein commented 2 years ago
  1. Add these Blob32 and Blob64 (or Blob256 and Blob512 if you prefer bits) types to the ABI layouts used for the Fixed-Gas. We can take advantage of these Reserved types encodings: https://github.com/spacemeshos/svm/blob/6edb73de199fafce0953f82af061ca1090ff911c/crates/abi-layout/src/lib.rs#L10-L12

or

https://github.com/spacemeshos/svm/blob/6edb73de199fafce0953f82af061ca1090ff911c/crates/abi-layout/src/lib.rs#L29-L30

  1. Add the corresponding types to the svm-sdk-types crate:

https://github.com/spacemeshos/svm/blob/6edb73de199fafce0953f82af061ca1090ff911c/crates/sdk-types/src/blob.rs#L162

impl_blob_type!(Blob32, 32);
impl_blob_type!(Blob64, 64);
  1. Add the encoding implementation to svm-abi-encoder crate:

    impl Encoder for use svm_sdk_types::Blob32 { ...}
    impl Encoder for use svm_sdk_types::Blob64 { ...}
  2. Add the decoding part to the svm-abi-decoder crate:

Add Blob32 and Blob64 here: https://github.com/spacemeshos/svm/blob/6edb73de199fafce0953f82af061ca1090ff911c/crates/abi-decoder/src/decoder.rs#L28

Implement decode_blob32 and blob64 here: https://github.com/spacemeshos/svm/blob/6edb73de199fafce0953f82af061ca1090ff911c/crates/abi-decoder/src/decoder.rs#L94

Should be easy, just use the decode_fixed_primitive! macro as done in decode_addr

  1. Re-expose types under svm-sdk crate: https://github.com/spacemeshos/svm/blob/6edb73de199fafce0953f82af061ca1090ff911c/crates/sdk/src/lib.rs#L388

So add the Blob32 and Blob64