Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 requested a review from moshababo Jul 12, 2020
@YaronWittenstein YaronWittenstein marked this pull request as ready for review Jul 12, 2020
@YaronWittenstein YaronWittenstein removed the request for review from moshababo Jul 12, 2020
@YaronWittenstein YaronWittenstein marked this pull request as draft Jul 12, 2020
@YaronWittenstein YaronWittenstein marked this pull request as ready for review Jul 14, 2020
@YaronWittenstein YaronWittenstein requested a review from moshababo Jul 14, 2020
Copy link
Member

@moshababo moshababo left a comment

Looks good. Had some minor comments.

}};
}

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

@moshababo moshababo Jul 16, 2020

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
Member

@moshababo moshababo Jul 16, 2020

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

@YaronWittenstein YaronWittenstein Jul 19, 2020

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
Member

@moshababo moshababo Jul 16, 2020

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
Member

@moshababo moshababo Jul 16, 2020

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 Jul 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
big Big-sized task enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants