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

Fixed-Gas Call-Graph #235

Merged
merged 57 commits into from May 16, 2021
Merged

Fixed-Gas Call-Graph #235

merged 57 commits into from May 16, 2021

Conversation

YaronWittenstein
Copy link
Contributor

@YaronWittenstein YaronWittenstein commented May 4, 2021

Motivation

This PR implements a Call-Graph which is derived from running static-analysis over input Wasm programs.
In order for a Wasm program to be considered a Fixed-Gas valid, it must not have any loops or call-cycles.

So if function f0 has an explicit call to function f1 which might call in some circumstances to f0 we have a cycle under our corresponding Call-Graph. Of course, a call cycle may involve more than two functions as in the example here.

A recursive call (function f0 calling itself) is treated outside of the Call-Graph (it's done while scanning the Wasm code and building the Call-Graph).

When the Call-Graph has no cycles, it's considered a DAG.
The implications of it are that we can use Topological sorting in order to determine the processing order of functions for pricing.
(it will be done in a future PR).

When the Call-Graph has cycles, the Topological sort will fail.

This PR implements the Topological sort - and if it reaches a dead-end it continues to move forward and returns a cycle.
(Note: there might be more than a single cycle under the Call-Graph).

Returning a cycle is optional since its purpose is only for debugging or testing.
In production mode, it should be disabled since it's a waste of CPU cycles. It will suffice to report that the input has cycles without giving any specific occurrences.

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

LLVM 10

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...

WIP

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

WIP

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

debugging...

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.

debugging

debugging...

Trying to narrow the bug

WIP

Narrowing the epilogue part

should fail...

Uncommenting part of the epilogue

WIP
@YaronWittenstein YaronWittenstein force-pushed the fixed-gas-call-graph branch 2 times, most recently from 77d0390 to ec11cae Compare May 5, 2021 05:51
@YaronWittenstein YaronWittenstein marked this pull request as ready for review May 5, 2021 07:30
crates/gas/src/call_graph/sort.rs Outdated Show resolved Hide resolved
crates/gas/src/call_graph/sort.rs Outdated Show resolved Hide resolved
crates/gas/src/call_graph/builder.rs Show resolved Hide resolved
crates/gas/src/call_graph/node.rs Outdated Show resolved Hide resolved
crates/gas/src/call_graph/node.rs Outdated Show resolved Hide resolved
crates/gas/src/call_graph/node.rs Show resolved Hide resolved
@YaronWittenstein YaronWittenstein merged commit 63eb00f into master May 16, 2021
@YaronWittenstein YaronWittenstein deleted the fixed-gas-call-graph branch May 16, 2021 17:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants