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

Fixed-Gas Pricing #238

merged 80 commits into from Jun 27, 2021

Fixed-Gas Pricing #238

merged 80 commits into from Jun 27, 2021


Copy link

@YaronWittenstein YaronWittenstein commented May 25, 2021


This PR builds on top of the two previous PRs:

In high-level, in order to price a program (which has passed validation) we have to:

  1. Order its functions in topological-order
  2. Iterate over the ordered functions, and for each function:
    2.1 Build its CFG
    2.2 Find the most expensive execution path in the CFG
  3. The final pricing of a transaction takes into account:
    3.1 The transaction CallData input
    3.2 The price of the Wasm instance initiation (it involves memory initialization)
    3.3 The price of calling svm_alloc (determined at 2.2) with the byte size of the input CallData
    3.4 The price of the invoked function (determined at 2.2)

This PR implements bullets 1. and 2. above.
Implementing 3. and the pricing of deploy-template and spawn-app transactions will be added in a future PR as part of integrating the updated svm-gas crate's functionality into the svm-runtime crate.

Implemented the `svm_allocate` host function.

adding some debugging printing to the new `svm_allocate` host function.

WIP: computing the `returns` byte-size for a function (sdk-macros)

* `calldata` is allocated on instance only when non-empty.

The `svm-sdk` relies on the host function for Wasm targeted code and on the default global allocator otherwise.

adding `svm_sdk_std::panic` (aborts for Wasm and unwinds otherwise)

WIP: adding an explicit feature flag for the host static allocation.

svm-codec is using the default global-alloactor (not the "static allocation")

codec - js tests pass (commenting the `verify_data` for now)

tests pass

CI - running only on Windows + running the tests 10 times (there seems to be a sporadic failures)

CI - skipping the build stage

svm-sdk-std: exposing Rust `Vec`

svm-sdk-std: using `panic!`

running only the `svm-runtime` crate tests.

Removing `wabt` (using only `wat`) - it takes much less time to build.

using cache action v2

Adding GitHub Action for LLVM

Adding caching to the llvm


Returning back the original LLVM action for Windows

adding feature-flags `default-cranelift` and `default-llvm`

trying to run CI against `llvm`

running tests with a single thread

runtime - removing two ignored tests related to gas-metering

Commenting a test

runtime: ignoring all tests except one

running tests in dev-mode

Building on Linux and macOS

svm-sdk-std: returning back Rust `Vec`

Commenting part of the problematic test

Commenting another part of the problematic test

uncomment part of the problematic test

cbindgen version bump

problemtic test - wasm input file "runtime_calldata.wasm" isn't using the "static-alloc"

problemtic test: input wasm is being compiled with less code and no `.cargo/config` file

Uncommenting all the problematic test

Trying to locate the bug

Trying again to pinpoint the bug

Adding asserts against setting explicitly empty `returndata`

WIP: debugging

WIP: debugging...

WIP: debugging...

skipping the last CI stages for now...

WIP: trying to locate the cause of the bug...


commenting the "static-alloc" related code from `svm-sdk-alloc`


Trying again to make the test fail

Trying to figure out whether the #[endpoint] return-type has anything to do with the bug...

Commenting "Storage" from the wasm input of the failing test...

More debugging the root cause of the problem


adding "Cache workspace" step

Splitting cargo caching into isloated steps.

adding "Dump GitHub context" step.

CI: changing to `crates/runtime` before running the tests

Try again to run CI...

Try again

CI: disabling LLVM installation for now (Windows)

Trying again to reproduce a broken CI on Windows...

Checking whether the bug has something to do with `svm_sdk::Address`

Trying to find a minimal failing input using `Amount`

WIP: Debugging...

WIP: removing the parameter from the problematic endpoint

This should pass (not using `endpoint`)

This should fail again...

`ExtHost#get_calldata` - returning a static data

Re-compile the wasm input

Empty `endpoint` prologue.



Trying to narrow the bug


Narrowing the epilogue part

should fail...

Uncommenting part of the epilogue

@YaronWittenstein YaronWittenstein force-pushed the fixed-gas-pricing branch 7 times, most recently from ebf7736 to 01cb5e0 Compare June 2, 2021 19:39
@YaronWittenstein YaronWittenstein force-pushed the fixed-gas-pricing branch 2 times, most recently from ea41442 to 3385ac8 Compare June 3, 2021 19:59
@YaronWittenstein YaronWittenstein marked this pull request as ready for review June 6, 2021 15:19
@YaronWittenstein YaronWittenstein merged commit 3008694 into master Jun 27, 2021
@YaronWittenstein YaronWittenstein deleted the fixed-gas-pricing branch June 27, 2021 09:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

1 participant