Skip to content

Instantly share code, notes, and snippets.

@pepyakin
Last active November 14, 2017 20:07
Show Gist options
  • Save pepyakin/f22e7941211ec8eba9fb4457b5c42db6 to your computer and use it in GitHub Desktop.
Save pepyakin/f22e7941211ec8eba9fb4457b5c42db6 to your computer and use it in GitHub Desktop.

EWasm eth interface https://github.com/ewasm/design/blob/master/eth_interface.md

Glosarry:

  • pwasm - Parity Wasm
  • ewasm - Ethereum Wasm

Notable differences:

Calling into contract

In pwasm, runtime prepares the environment, i.e. allocates memory for and copies input data into this memory, and then calls into _call(*const Descriptor) function. To return the execution result, contract needs to write result's data into a location in the memory designated by the Descriptor.

Descriptor definition looks like this:

struct Descriptor {
  args_ptr: *const u8,
  args_len: usize,
  result_ptr: *const u8,
  result_len: usize,
}

Runtime environment

pwasm publishes some functions that can be commonly found in the libc, namely:

  • malloc,
  • free,
  • memcpy,
  • memmemove,
  • memset,

Extracting this functions might improve binary size and performance of a contract.

Also, pwasm provides several functions:

  • debug, log message into the console,
  • panic, traps immediatelly with provided message/payload,

Misc

  • pwasm's uses U256 to represent value, whereas ewasm uses u128,
  • pwasm's gas expects i32 arguments, whereas ewasm's useGas uses i64,
  • pwasm's blockhash might return error (according to signature), ewasm's not.
  • at the moment, there is no way to limit amount of gas transfered into a call in pwasm, but it is planned to fix this,
  • pwasm's call returns -1 to denote error state,
  • pwasm's log accepts topic_count and pointer to array of the topic values, whereas ewasm's log takes pointers to each topic's value separately.
  • pwasm's gaslimit returns U256, whereas ewasm uses i64,
@lexfro
Copy link

lexfro commented Nov 14, 2017

few notes

there is no way to limit amount of gas transfered into a call in pwasm

it's not intentionally, will be fixed

pwasm's balance returns H256, wheres ewasm's getBalance returns u128,

U256 to be exact

@pepyakin
Copy link
Author

Fixed, thanks @fckt!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment