Skip to content

Wasm testsuite#586

Merged
PlasmaPower merged 52 commits intoredo-devnet-reinit-1from
wasm-testsuite
Jun 17, 2022
Merged

Wasm testsuite#586
PlasmaPower merged 52 commits intoredo-devnet-reinit-1from
wasm-testsuite

Conversation

@rachel-bousfield
Copy link
Contributor

@rachel-bousfield rachel-bousfield commented May 9, 2022

Introduces the official wasm testsuite to ensure compliance with the standard and fixes current deviations including

  • fixing floating point truncation cuttoffs and adding traps when out of bounds
  • adding new saturating truncation functions
  • respecting max module sizes and adding them to the OSP's machine state
  • fixing an off-by-one validiation issue for initializing data segments
  • trapping on divisions and mods by 0
  • checking for signed-division overflow

Additionally, this PR

  • adds a new language_support flag for enabling rust & go support
  • adds start- and stop- merkle_caching for faster proof generation
  • adds utilities for jumping into a function and retrieving its return values
  • adds console colors and pretty-printing of WAVM values
  • fixes a bug in one-step-proof.ts causing tests to sometimes not run
  • updates the hardhat config to make the gas reporter environment-configurable

Base automatically changed from wasmparser-frontend to master May 9, 2022 18:12
@PlasmaPower PlasmaPower added the arbitrator Relates to the Arbitrator proving component label May 9, 2022
@rachel-bousfield rachel-bousfield changed the base branch from master to arbitrator-return-optimization May 9, 2022 18:45
@rachel-bousfield rachel-bousfield changed the base branch from arbitrator-return-optimization to master May 12, 2022 05:28
@codecov
Copy link

codecov bot commented May 12, 2022

Codecov Report

Merging #586 (1105cd4) into redo-devnet-reinit-1 (101c211) will decrease coverage by 1.09%.
The diff coverage is 28.57%.

@@                   Coverage Diff                    @@
##           redo-devnet-reinit-1     #586      +/-   ##
========================================================
- Coverage                 51.92%   50.82%   -1.10%     
========================================================
  Files                       223      223              
  Lines                     26043    26610     +567     
  Branches                    497      486      -11     
========================================================
+ Hits                      13522    13525       +3     
- Misses                    11142    11700     +558     
- Partials                   1379     1385       +6     

@PlasmaPower PlasmaPower changed the base branch from master to devnet-reinit-1 June 2, 2022 18:35
@rachel-bousfield rachel-bousfield mentioned this pull request Jun 2, 2022
Copy link
Contributor

@tsahee tsahee left a comment

Choose a reason for hiding this comment

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

some naming comments/thoughts. Feel free to ignore.

still reviewing: testsuit itself

let main_module = &modules[main_module_idx];
// Rust support
if let Some(&f) = main_module.exports.get("main") {
if let Some(&f) = main_module.exports.get("main").filter(|_| language_support) {
Copy link
Contributor

Choose a reason for hiding this comment

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

that filter is a little backwards..
maybe just put lines 1041..1109 under if(language_support?)

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 wish if let Some() = expr && conditional was stable. For now let's keep this since otherwise there's a comment with a URL that'll be too wide

pub fn from_binaries(
libraries: &[WasmBinary<'_>],
bin: WasmBinary<'_>,
language_support: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

runtime_support?
runtime_emulation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to runtime_support :)

int32_t wavm__i32_trunc_sat_f32_s(uint32_t v) {
// signed truncation is defined over (i32::min - 1, i32::max + 1)
float32_t max = {0x4f000000}; // i32::max + 1 = 0x4F000000
float32_t min = {0xcf000001}; // i32::min - 1 = 0xCF000000 (adjusted due to rounding)
Copy link
Contributor

Choose a reason for hiding this comment

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

value and comments don't match

Copy link
Contributor Author

@rachel-bousfield rachel-bousfield Jun 16, 2022

Choose a reason for hiding this comment

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

0xCF000000 is the min, but our comparator is inclusive so it's up by 1. The max rounds differently

return (1u << 31) - 1;
// signed truncation is defined over (i32::min - 1, i32::max + 1)
float32_t max = {0x4f000000}; // i32::max + 1 = 0x4F000000
float32_t min = {0xcf000001}; // i32::min - 1 = 0xCF000000 (adjusted due to rounding)
Copy link
Contributor

Choose a reason for hiding this comment

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

value and comment don't match

Copy link
Contributor Author

@rachel-bousfield rachel-bousfield Jun 16, 2022

Choose a reason for hiding this comment

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

0xCF000000 is the min, but our comparator is inclusive so it's up by 1. The max rounds differently

@@ -198,39 +202,113 @@ uint8_t wavm__f32_ge(uint32_t va, uint32_t vb) {
}

int32_t wavm__i32_trunc_f32_s(uint32_t v) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible to merge the truncated and non-truncated versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The go and rust compilers currently do not generate truncating floating point ops, but they might one day and it's probably better to keep things general

if (f32_le(max, f)) {
return (1u << 31) - 1;
// signed truncation is defined over (i32::min - 1, i32::max + 1)
float32_t max = {0x4f000000}; // i32::max + 1 = 0x4F000000
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the best way to create these would be with funcs like i32_to_f32 (will cost CPU cycles, but probably worth the readability).
If not.. maybe at least have constants like I32MAX_F32?

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 hesitate to do that because in each case it's not exactly the min or max integers as floating points, it's the first integer that is out of bounds. It's very particular hex for the funcs they're in so I think that, although not ideal, we should have the hex inline

return 0;
}
if (f32_le(max, val)) {
return 2147483647;
Copy link
Contributor

Choose a reason for hiding this comment

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

these would be more readable in hex

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed but due to C parsing that'd cause type warnings in the negative case

@tsahee
Copy link
Contributor

tsahee commented Jun 14, 2022

tests pass for me after rebuilding

Copy link
Contributor

@PlasmaPower PlasmaPower left a comment

Choose a reason for hiding this comment

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

LGTM except a couple minor code cleanup comments

@rachel-bousfield rachel-bousfield changed the base branch from devnet-reinit-1 to redo-devnet-reinit-1 June 17, 2022 15:37
Copy link
Contributor

@PlasmaPower PlasmaPower left a comment

Choose a reason for hiding this comment

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

LGTM

@PlasmaPower PlasmaPower merged commit 0783c83 into redo-devnet-reinit-1 Jun 17, 2022
@PlasmaPower PlasmaPower deleted the wasm-testsuite branch June 17, 2022 16:50
tsahee pushed a commit that referenced this pull request Jul 29, 2025
      Co-authored-by: Goran Vladika <goran.vladika@gmail.com>
Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arbitrator Relates to the Arbitrator proving component cla-signed consensus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants