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

Support new WASM features - WIP #2065

Draft
wants to merge 28 commits into
base: develop
Choose a base branch
from

Conversation

lrubasze
Copy link
Contributor

@lrubasze lrubasze commented Jan 23, 2025

Summary

This PR attempts to add support for following WASM features in the Radix Engine:

  • reference-types
  • multi-value
    The features shall be enabled with the oncoming protocol update. Change shall be backward-compatible.
    Packages published before shall work in the exactly same way as before.

NOTE!
This is still work-in-progress. Still to be done:

  • More tests (see Testing section)
  • wasm-instrument does not support reference types at the moment.
    Decide if it needs updating or we can live without support (see this).
  • Weights for instructions added by reference-types are missing.
    As above decide if we need to add them or we can live without it.
  • Decide if we want to update InvalidTable errors to take into account multiple tables.
  • also search for TODO WASM in the code

NOTE!
*.wasm files built with Rust 1.82+ will not be compatible with historic ledger version (Rust 1.82 enables reference-types and multi-value by default)

Testing

Added

  • Tests with*.wat files that validate enabled features

Missing

  • Test '*.wasm' files built with older versions against a historic and updated ledger version

Changelog

  • Added ScryptoVmVersion::V1_3, which will be set upon protocol update and enable new WASM features.
  • Added WasmFeaturesConfig module to keep WASM config in one place.
  • Allow to set specific ScryptoVmVersion in Scrypto compiler
  • Replace outdated wabt crate (used to convert between *.wat and *.wasm files) with wat and wasmprinter
    wabt is no longer maintained and apparently it does not handle 'externref' type properly (and maybe more).
    Switched to wat and wasmprinter from https://github.com/bytecodealliance/wasm-tools repo, which is actively maintained.
  • Allow multiple tables in WASM validator as reference-proposal allows it

Copy link

github-actions bot commented Jan 23, 2025

Docker tags
docker.io/radixdlt/private-scrypto-dev-container:d39f13a29b

Copy link

github-actions bot commented Jan 23, 2025

Docker tags
docker.io/radixdlt/private-scrypto-builder:d39f13a29b

@lrubasze lrubasze force-pushed the feature/support-new-wasm-features branch from 7526e96 to 338d7ed Compare January 24, 2025 08:13
Copy link

github-actions bot commented Jan 24, 2025

Benchmark for d39f13a

Click to view benchmark
Test Base PR %
costing::bench_prepare_wasm 45.1±0.35ms 45.2±0.10ms +0.22%
costing::decode_encoded_i8_array_to_manifest_raw_value 19.3±0.02ms 19.7±0.09ms +2.07%
costing::decode_encoded_i8_array_to_manifest_value 41.5±0.04ms 41.9±0.06ms +0.96%
costing::decode_encoded_tuple_array_to_manifest_raw_value 70.4±0.12ms 71.4±0.28ms +1.42%
costing::decode_encoded_tuple_array_to_manifest_value 98.7±0.19ms 98.7±0.18ms 0.00%
costing::decode_encoded_u8_array_to_manifest_raw_value 32.0±0.11µs 25.8±0.05µs -19.37%
costing::decode_encoded_u8_array_to_manifest_value 41.5±0.03ms 41.6±0.08ms +0.24%
costing::decode_rpd_to_manifest_raw_value 14.6±0.03µs 14.6±0.03µs 0.00%
costing::decode_rpd_to_manifest_value 10.8±0.02µs 11.0±0.10µs +1.85%
costing::deserialize_wasm 1224.9±4.21µs 1239.3±2.80µs +1.18%
costing::execute_transaction_creating_big_vec_substates 698.1±8.74ms 699.6±7.75ms +0.21%
costing::execute_transaction_reading_big_vec_substates 581.9±1.66ms 583.2±1.63ms +0.22%
costing::instantiate_flash_loan 1006.9±1342.86µs 955.0±633.90µs -5.15%
costing::instantiate_radiswap 953.0±660.42µs 1056.1±1670.47µs +10.82%
costing::scrypto_malloc 674.4±1.34ms 677.1±1.41ms +0.40%
costing::scrypto_sbor_decode 673.9±1.42ms 661.8±0.84ms -1.80%
costing::scrypto_sha256 584.5±1.00ms 593.2±0.89ms +1.49%
costing::spin_loop_v1 516.8±1.40ms 515.5±1.10ms -0.25%
costing::spin_loop_v2 594.3±0.36ms 598.3±2.27ms +0.67%
costing::validate_sbor_payload 30.3±0.05µs 29.5±0.06µs -2.64%
costing::validate_sbor_payload_bytes 247.8±0.74ns 246.1±1.10ns -0.69%
costing::validate_secp256k1 76.5±0.04µs 78.0±0.05µs +1.96%
costing::validate_wasm 33.6±0.04ms 33.9±0.04ms +0.89%
decimal::add/0 8.4±0.05ns 8.5±0.10ns +1.19%
decimal::add/rust-native 9.8±0.00ns 9.8±0.00ns 0.00%
decimal::add/wasmi 322.8±2.32ns 329.1±4.22ns +1.95%
decimal::add/wasmi-call-native 2.9±0.01µs 3.0±0.00µs +3.45%
decimal::div/0 167.3±0.10ns 167.2±0.15ns -0.06%
decimal::from_string/0 157.0±0.16ns 157.3±0.14ns +0.19%
decimal::mul/0 129.2±0.71ns 129.6±0.51ns +0.31%
decimal::mul/rust-native 127.7±0.03ns 128.1±0.06ns +0.31%
decimal::mul/wasmi 19.3±0.06µs 19.2±0.04µs -0.52%
decimal::mul/wasmi-call-native 3.1±0.01µs 3.1±0.00µs 0.00%
decimal::pow/0 593.6±0.84ns 594.1±0.27ns +0.08%
decimal::pow/rust-native 590.2±0.63ns 586.6±0.43ns -0.61%
decimal::pow/wasmi 90.0±0.17µs 91.4±0.31µs +1.56%
decimal::pow/wasmi-call-native 4.8±0.01µs 4.7±0.01µs -2.08%
decimal::root/0 8.1±0.00µs 8.4±0.00µs +3.70%
decimal::sub/0 8.1±0.00ns 8.1±0.00ns 0.00%
decimal::to_string/0 442.6±0.49ns 463.7±1.44ns +4.77%
large_transaction_processing::prepare 2.6±0.00ms 2.5±0.00ms -3.85%
large_transaction_processing::prepare_and_decompile 6.3±0.02ms 6.2±0.01ms -1.59%
large_transaction_processing::prepare_and_decompile_and_recompile 31.9±0.31ms 31.8±0.30ms -0.31%
metadata_validation::validate_urls 4.9±0.18µs 4.7±0.04µs -4.08%
precise_decimal::add/0 8.9±0.03ns 8.9±0.03ns 0.00%
precise_decimal::add/rust-native 10.9±0.04ns 11.0±0.18ns +0.92%
precise_decimal::add/wasmi 432.0±4.91ns 430.7±1.15ns -0.30%
precise_decimal::add/wasmi-call-native 3.8±0.01µs 3.8±0.00µs 0.00%
precise_decimal::div/0 315.9±1.85ns 290.9±0.24ns -7.91%
precise_decimal::from_string/0 206.4±0.19ns 206.9±0.35ns +0.24%
precise_decimal::mul/0 339.0±0.34ns 332.2±0.54ns -2.01%
precise_decimal::mul/rust-native 285.2±0.39ns 283.1±0.64ns -0.74%
precise_decimal::mul/wasmi 48.7±0.18µs 48.0±0.13µs -1.44%
precise_decimal::mul/wasmi-call-native 4.1±0.00µs 4.2±0.02µs +2.44%
precise_decimal::pow/0 1744.5±6.65ns 1751.2±5.07ns +0.38%
precise_decimal::pow/rust-native 1352.5±0.85ns 1352.3±1.28ns -0.01%
precise_decimal::pow/wasmi 230.0±1.07µs 230.1±1.01µs +0.04%
precise_decimal::pow/wasmi-call-native 7.4±0.01µs 7.5±0.01µs +1.35%
precise_decimal::root/0 59.4±0.13µs 59.2±0.14µs -0.34%
precise_decimal::sub/0 8.9±0.02ns 8.9±0.03ns 0.00%
precise_decimal::to_string/0 696.1±1.98ns 697.8±0.59ns +0.24%
schema::validate_payload 379.4±0.91µs 384.2±1.10µs +1.27%
transaction::radiswap 5.1±0.04ms 5.0±0.02ms -1.96%
transaction::transfer 1825.5±4.12µs 1817.3±2.77µs -0.45%
transaction_validation::validate_manifest 43.2±0.19µs 43.1±0.02µs -0.23%
transaction_validation::verify_bls_2KB 1050.4±26.39µs 1002.5±6.23µs -4.56%
transaction_validation::verify_bls_32B 1014.5±27.07µs 1046.8±26.81µs +3.18%
transaction_validation::verify_ecdsa 74.6±0.05µs 74.6±0.05µs 0.00%
transaction_validation::verify_ed25519 42.3±0.08µs 46.5±0.06µs +9.93%

@lrubasze lrubasze force-pushed the feature/support-new-wasm-features branch from 1405636 to d2ee1a3 Compare January 24, 2025 18:31
@lrubasze lrubasze changed the title Support new WASM features Support new WASM features - WIP Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant