Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

ABI Encoding #159

Merged
merged 145 commits into from
Jul 19, 2020
Merged

ABI Encoding #159

merged 145 commits into from
Jul 19, 2020

Conversation

YaronWittenstein
Copy link
Contributor

@YaronWittenstein YaronWittenstein commented Jun 30, 2020

Motivation

The purpose of this PR is to implement a well-defined ABI encoding & decoding specification for the blob data passed to the func_buffer. (called ctor_buf in the context of spawn app - but it's the same mechanism).

Since WASM MVP comes out-of-the-box only 2 types relevant for us (SVM don't work for floats for determinism concerns).
We need to come up with an encoding method so that we can feed a function with composite data such as:

  1. Tuple
  2. Address
  3. PublicKey
  4. More (in the future)

This svm-codec should extend its exposed WASM API and it'll do so by importing this crate.
So when smapp (or any other future Wallet client) will want to dispatch a new SVM transaction of spawn-app (or exec-app) to the network, it will do so in two steps:

  1. Encode the data passed to the func_buf and func_args - using the svm-abi crate (implemented in this PR).
  2. Encode the SVM transaction and filling-in the func_buf and func_args with the results of step 1.

In the future, we may add new ABI encoding schemes. But hopefully, we can get away with this one.
Also, this ABI encoding scheme should be leveraged by the future so-called SMESH language.

Important:

There will be high-level API exposed as JSON for each App. This data will contain variables names and types for each function. That's how smapp (or similar) will know that a function input expects in a high-level without caring about the low-level implementation details.

Also, this data will be off-chain. This functionality is out of scope for this PR.

@YaronWittenstein YaronWittenstein marked this pull request as ready for review July 12, 2020 18:05
@YaronWittenstein YaronWittenstein removed the request for review from moshababo July 12, 2020 18:56
@YaronWittenstein YaronWittenstein marked this pull request as draft July 12, 2020 18:57
@YaronWittenstein YaronWittenstein marked this pull request as ready for review July 14, 2020 11:42
Copy link
Contributor

@moshababo moshababo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Had some minor comments.

}};
}

/// Decodes a encoded function buffer back into a `sdk_values::Value`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a -> an

let mut values = Vec::new();

while next_byte != marker::ARRAY_END {
let v = self.decode_value(cursor)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this supports infinite nesting of arrays. Is this intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a marker-trait to prohibit encoding of nested arrays

@@ -0,0 +1,96 @@
#![no_std]

//! This crate is responsible of encoding SVM types (its actuall type and their values to be precise),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actuall => actual

value::{Address, AddressOwned, PubKey256, PubKey256Owned},
};

/// A traits to be implemented by of types.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is wrong with this sentence.

@YaronWittenstein YaronWittenstein merged commit fdde238 into master Jul 19, 2020
@YaronWittenstein YaronWittenstein deleted the abi-encoding branch July 19, 2020 13:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
big Big-sized task enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants