diff --git a/.changelog/unreleased/improvements/2795-improve-wasm-build.md b/.changelog/unreleased/improvements/2795-improve-wasm-build.md new file mode 100644 index 0000000000..ab843164a1 --- /dev/null +++ b/.changelog/unreleased/improvements/2795-improve-wasm-build.md @@ -0,0 +1,2 @@ +- Split up WASM transaction and validity-predicates into individual crates to + improve build time. ([\#2795](https://github.com/anoma/namada/pull/2795)) \ No newline at end of file diff --git a/Makefile b/Makefile index ecd9658e83..76388b8f03 100644 --- a/Makefile +++ b/Makefile @@ -17,10 +17,8 @@ debug-cargo := $(env) $(debug-env) cargo nightly := $(shell cat rust-nightly-version) # Path to the wasm source for the provided txs and VPs -wasms := wasm/wasm_source -wasms_for_tests := wasm_for_tests/wasm_source -# Paths for all the wasm templates -wasm_templates := wasm/tx_template wasm/vp_template +wasms := wasm +wasms_for_tests := wasm_for_tests ifdef JOBS jobs := -j $(JOBS) @@ -93,8 +91,7 @@ check-wasm = $(cargo) check --target wasm32-unknown-unknown --manifest-path $(wa check: $(cargo) check --workspace && \ make -C $(wasms) check && \ - make -C $(wasms_for_tests) check && \ - $(foreach wasm,$(wasm_templates),$(check-wasm) && ) true + make -C $(wasms_for_tests) check check-mainnet: $(cargo) check --workspace --features "mainnet" @@ -102,7 +99,9 @@ check-mainnet: # Check that every crate can be built with default features and that namada crate # can be built for wasm check-crates: + rustup target add --toolchain $(nightly) wasm32-unknown-unknown $(foreach p,$(crates), echo "Checking $(p)" && cargo +$(nightly) check -Z unstable-options --tests -p $(p) && ) \ + make -C $(wasms) check && \ make -C $(wasms_for_tests) check && \ cargo check --package namada --target wasm32-unknown-unknown --no-default-features --features "namada-sdk" && \ cargo check --package namada_sdk --all-features @@ -114,8 +113,7 @@ clippy: $(cargo) +$(nightly) clippy $(jobs) --all-targets --workspace --exclude namada_benchmarks -- -D warnings && \ $(cargo) +$(nightly) clippy $(jobs) --all-targets --package namada_benchmarks -- -D warnings && \ make -C $(wasms) clippy && \ - make -C $(wasms_for_tests) clippy && \ - $(foreach wasm,$(wasm_templates),$(clippy-wasm) && ) true + make -C $(wasms_for_tests) clippy clippy-mainnet: $(cargo) +$(nightly) clippy --all-targets --features "mainnet" -- -D warnings @@ -247,15 +245,11 @@ test-pos-sm: fmt-wasm = $(cargo) +$(nightly) fmt --manifest-path $(wasm)/Cargo.toml fmt: - $(cargo) +$(nightly) fmt --all && \ - make -C $(wasms) fmt && \ - $(foreach wasm,$(wasm_templates),$(fmt-wasm) && ) true + $(cargo) +$(nightly) fmt --all && make -C $(wasms) fmt fmt-check-wasm = $(cargo) +$(nightly) fmt --manifest-path $(wasm)/Cargo.toml -- --check fmt-check: - $(cargo) +$(nightly) fmt --all -- --check && \ - make -C $(wasms) fmt-check && \ - $(foreach wasm,$(wasm_templates),$(fmt-check-wasm) && ) true + $(cargo) +$(nightly) fmt --all -- --check && make -C $(wasms) fmt-check watch: $(cargo) watch @@ -284,7 +278,7 @@ debug-wasm-scripts-docker: build-wasm-image-docker # Build the validity predicate and transactions wasm build-wasm-scripts: - rm wasm/*.wasm || true + rm $(wasms)/*.wasm || true make -C $(wasms) make opt-wasm make checksum-wasm @@ -296,6 +290,18 @@ debug-wasm-scripts: make opt-wasm make checksum-wasm +# Build the validity predicate and transactions wasm for tests +build-wasm-tests-scripts: + rm $(wasms_for_tests)/*.wasm || true + make -C $(wasms_for_tests) + make opt-wasm-tests + +# Debug build the validity predicate and transactions wasm for tests +debug-wasm-tests-scripts: + rm $(wasms_for_tests)/*.wasm || true + make -C $(wasms_for_tests) debug + make opt-wasm-tests + # need python checksum-wasm: python3 wasm/checksums.py @@ -304,6 +310,9 @@ checksum-wasm: opt-wasm: @for file in $(shell ls wasm/*.wasm); do wasm-opt -Oz -o $${file} $${file}; done +opt-wasm-tests: + @for file in $(shell ls wasm_for_tests/*.wasm); do wasm-opt -Oz -o $${file} $${file}; done + clean-wasm-scripts: make -C $(wasms) clean diff --git a/crates/tests/src/e2e/ibc_tests.rs b/crates/tests/src/e2e/ibc_tests.rs index 4822de8b88..52f20742a7 100644 --- a/crates/tests/src/e2e/ibc_tests.rs +++ b/crates/tests/src/e2e/ibc_tests.rs @@ -1910,7 +1910,7 @@ fn propose_inflation(test: &Test) -> Result { "author": albert, "voting_start_epoch": start_epoch, "voting_end_epoch": start_epoch + 3_u64, - "grace_epoch": start_epoch + 6_u64, + "activation_epoch": start_epoch + 6_u64, }, "data": TestWasms::TxProposalIbcTokenInflation.read_bytes() }); diff --git a/scripts/release.sh b/scripts/release.sh index 659e275f1f..ece65a0e0f 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -25,15 +25,15 @@ HASH_BEFORE=$(git rev-parse HEAD) cargo release --execute $VERSION HASH_AFTER=$(git rev-parse HEAD) -# update the wasm crate versions (2 fixups) +# update the wasm workspace crate versions (2 fixups) cd $REPO_ROOT/wasm cargo update -w git add Cargo.lock git commit --fixup=$HASH_AFTER cargo release --execute $VERSION -# update the wasm_for_tests crate version, and rebuild them (3 fixups) -cd $REPO_ROOT/wasm_for_tests/wasm_source +# update the wasm_for_tests workspace crate version, and rebuild them (3 fixups) +cd $REPO_ROOT/wasm_for_tests cargo update -w git add Cargo.lock git commit --fixup=$HASH_AFTER diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index 12108fdebe..7e293d6e15 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -511,11 +511,11 @@ dependencies = [ [[package]] name = "borsh" -version = "1.2.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9897ef0f1bd2362169de6d7e436ea2237dc1085d7d1e4db75f4be34d86f309d1" +checksum = "0901fc8eb0aca4c83be0106d6f2db17d86a08dfc2c25f0e84464bf381158add6" dependencies = [ - "borsh-derive 1.2.1", + "borsh-derive 1.4.0", "cfg_aliases", ] @@ -534,12 +534,12 @@ dependencies = [ [[package]] name = "borsh-derive" -version = "1.2.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "478b41ff04256c5c8330f3dfdaaae2a5cc976a8e75088bafa4625b0d0208de8c" +checksum = "51670c3aa053938b0ee3bd67c3817e471e626151131b934038e83c5bf8de48f5" dependencies = [ "once_cell", - "proc-macro-crate 2.0.1", + "proc-macro-crate 3.1.0", "proc-macro2", "quote", "syn 2.0.52", @@ -562,7 +562,7 @@ name = "borsh-ext" version = "1.2.0" source = "git+https://github.com/heliaxdev/borsh-ext?tag=v1.2.0#a62fee3e847e512cad9ac0f1fd5a900e5db9ba37" dependencies = [ - "borsh 1.2.1", + "borsh 1.4.0", ] [[package]] @@ -2994,7 +2994,7 @@ name = "index-set" version = "0.8.0" source = "git+https://github.com/heliaxdev/index-set?tag=v0.8.1#b0d928f83cf0d465ccda299d131e8df2859b5184" dependencies = [ - "borsh 1.2.1", + "borsh 1.4.0", "serde", ] @@ -3024,7 +3024,7 @@ name = "indexmap" version = "2.2.4" source = "git+https://github.com/heliaxdev/indexmap?tag=2.2.4-heliax-1#b5b5b547bd6ab04bbb16e060326a50ddaeb6c909" dependencies = [ - "borsh 1.2.1", + "borsh 1.4.0", "equivalent", "hashbrown 0.14.3", "serde", @@ -3306,7 +3306,7 @@ name = "masp_note_encryption" version = "1.0.0" source = "git+https://github.com/anoma/masp?rev=6cbc8bd90a71cc280492c44bc3415162093daa76#6cbc8bd90a71cc280492c44bc3415162093daa76" dependencies = [ - "borsh 1.2.1", + "borsh 1.4.0", "chacha20", "chacha20poly1305", "cipher", @@ -3325,7 +3325,7 @@ dependencies = [ "blake2b_simd", "blake2s_simd", "bls12_381", - "borsh 1.2.1", + "borsh 1.4.0", "byteorder", "ff", "fpe", @@ -3490,7 +3490,7 @@ version = "0.32.1" dependencies = [ "async-trait", "bimap", - "borsh 1.2.1", + "borsh 1.4.0", "borsh-ext", "circular-queue", "clru", @@ -3566,7 +3566,7 @@ dependencies = [ name = "namada_account" version = "0.32.1" dependencies = [ - "borsh 1.2.1", + "borsh 1.4.0", "linkme", "namada_core", "namada_macros", @@ -3588,7 +3588,7 @@ name = "namada_core" version = "0.32.1" dependencies = [ "bech32 0.8.1", - "borsh 1.2.1", + "borsh 1.4.0", "borsh-ext", "chrono", "data-encoding", @@ -3634,7 +3634,7 @@ dependencies = [ name = "namada_ethereum_bridge" version = "0.32.1" dependencies = [ - "borsh 1.2.1", + "borsh 1.4.0", "ethabi", "ethers", "eyre", @@ -3665,7 +3665,7 @@ dependencies = [ name = "namada_gas" version = "0.32.1" dependencies = [ - "borsh 1.2.1", + "borsh 1.4.0", "namada_core", "namada_macros", "serde", @@ -3676,7 +3676,7 @@ dependencies = [ name = "namada_governance" version = "0.32.1" dependencies = [ - "borsh 1.2.1", + "borsh 1.4.0", "itertools 0.10.5", "linkme", "namada_core", @@ -3696,7 +3696,7 @@ dependencies = [ name = "namada_ibc" version = "0.32.1" dependencies = [ - "borsh 1.2.1", + "borsh 1.4.0", "ibc", "ibc-derive", "ibc-testkit", @@ -3735,7 +3735,7 @@ dependencies = [ name = "namada_merkle_tree" version = "0.32.1" dependencies = [ - "borsh 1.2.1", + "borsh 1.4.0", "eyre", "ics23", "namada_core", @@ -3749,7 +3749,7 @@ dependencies = [ name = "namada_migrations" version = "0.32.1" dependencies = [ - "borsh 1.2.1", + "borsh 1.4.0", "data-encoding", "lazy_static", "linkme", @@ -3761,7 +3761,7 @@ dependencies = [ name = "namada_parameters" version = "0.32.1" dependencies = [ - "borsh 1.2.1", + "borsh 1.4.0", "namada_core", "namada_macros", "namada_storage", @@ -3772,7 +3772,7 @@ dependencies = [ name = "namada_proof_of_stake" version = "0.32.1" dependencies = [ - "borsh 1.2.1", + "borsh 1.4.0", "data-encoding", "derivative", "linkme", @@ -3807,7 +3807,7 @@ dependencies = [ "async-trait", "bimap", "bls12_381", - "borsh 1.2.1", + "borsh 1.4.0", "borsh-ext", "circular-queue", "data-encoding", @@ -3870,7 +3870,7 @@ dependencies = [ name = "namada_shielded_token" version = "0.32.1" dependencies = [ - "borsh 1.2.1", + "borsh 1.4.0", "masp_primitives", "namada_controller", "namada_core", @@ -3885,7 +3885,7 @@ dependencies = [ name = "namada_state" version = "0.32.1" dependencies = [ - "borsh 1.2.1", + "borsh 1.4.0", "ics23", "itertools 0.10.5", "linkme", @@ -3911,7 +3911,7 @@ dependencies = [ name = "namada_storage" version = "0.32.1" dependencies = [ - "borsh 1.2.1", + "borsh 1.4.0", "itertools 0.10.5", "linkme", "namada_core", @@ -3931,7 +3931,7 @@ dependencies = [ name = "namada_test_utils" version = "0.32.1" dependencies = [ - "borsh 1.2.1", + "borsh 1.4.0", "namada_core", "strum 0.24.1", ] @@ -3994,7 +3994,7 @@ version = "0.32.1" dependencies = [ "ark-bls12-381", "bitflags 2.5.0", - "borsh 1.2.1", + "borsh 1.4.0", "data-encoding", "linkme", "masp_primitives", @@ -4026,7 +4026,7 @@ dependencies = [ name = "namada_tx_prelude" version = "0.32.1" dependencies = [ - "borsh 1.2.1", + "borsh 1.4.0", "masp_primitives", "namada_account", "namada_core", @@ -4048,7 +4048,7 @@ dependencies = [ name = "namada_vm_env" version = "0.32.1" dependencies = [ - "borsh 1.2.1", + "borsh 1.4.0", "masp_primitives", "namada_core", ] @@ -4057,7 +4057,7 @@ dependencies = [ name = "namada_vote_ext" version = "0.32.1" dependencies = [ - "borsh 1.2.1", + "borsh 1.4.0", "linkme", "namada_core", "namada_macros", @@ -4083,7 +4083,7 @@ dependencies = [ name = "namada_vp_prelude" version = "0.32.1" dependencies = [ - "borsh 1.2.1", + "borsh 1.4.0", "namada_account", "namada_core", "namada_governance", @@ -4100,23 +4100,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "namada_wasm" -version = "0.32.1" -dependencies = [ - "getrandom 0.2.11", - "namada", - "namada_test_utils", - "namada_tests", - "namada_tx_prelude", - "namada_vp_prelude", - "proptest", - "test-log", - "tracing", - "tracing-subscriber", - "wee_alloc", -] - [[package]] name = "nonempty" version = "0.7.0" @@ -4297,7 +4280,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c11e44798ad209ccdd91fc192f0526a369a01234f7373e1b141c96d7cee4f0e" dependencies = [ - "proc-macro-crate 2.0.1", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 2.0.52", @@ -4420,7 +4403,7 @@ version = "3.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be30eaf4b0a9fba5336683b38de57bb86d179a35862ba6bfcf57625d006bde5b" dependencies = [ - "proc-macro-crate 2.0.1", + "proc-macro-crate 2.0.0", "proc-macro2", "quote", "syn 1.0.109", @@ -4727,14 +4710,22 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "2.0.1" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97dc5fea232fc28d2f597b37c4876b348a40e33f3b02cc975c8d006d78d94b1a" +checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" dependencies = [ - "toml_datetime", "toml_edit 0.20.2", ] +[[package]] +name = "proc-macro-crate" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" +dependencies = [ + "toml_edit 0.21.1", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -5843,7 +5834,7 @@ name = "sparse-merkle-tree" version = "0.3.1-pre" source = "git+https://github.com/heliaxdev/sparse-merkle-tree?rev=515687fe7884cb365067ac86c66ac3613de176bb#515687fe7884cb365067ac86c66ac3613de176bb" dependencies = [ - "borsh 1.2.1", + "borsh 1.4.0", "cfg-if 1.0.0", "ics23", "sha2 0.9.9", @@ -6401,9 +6392,9 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" dependencies = [ "serde", ] @@ -6432,6 +6423,17 @@ dependencies = [ "winnow", ] +[[package]] +name = "toml_edit" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" +dependencies = [ + "indexmap 2.1.0", + "toml_datetime", + "winnow", +] + [[package]] name = "tonic-build" version = "0.8.4" @@ -6515,12 +6517,240 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] -name = "tx_template" +name = "tx_become_validator" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_tx_prelude", + "wee_alloc", +] + +[[package]] +name = "tx_bond" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + +[[package]] +name = "tx_bridge_pool" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_tx_prelude", + "wee_alloc", +] + +[[package]] +name = "tx_change_consensus_key" version = "0.32.1" dependencies = [ "getrandom 0.2.11", + "namada_tx_prelude", + "wee_alloc", +] + +[[package]] +name = "tx_change_validator_commission" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada", + "namada_test_utils", "namada_tests", "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + +[[package]] +name = "tx_change_validator_metadata" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_tx_prelude", + "wee_alloc", +] + +[[package]] +name = "tx_claim_rewards" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_tx_prelude", + "wee_alloc", +] + +[[package]] +name = "tx_deactivate_validator" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_tx_prelude", + "wee_alloc", +] + +[[package]] +name = "tx_ibc" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_tx_prelude", + "wee_alloc", +] + +[[package]] +name = "tx_init_account" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_tx_prelude", + "wee_alloc", +] + +[[package]] +name = "tx_init_proposal" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_tx_prelude", + "wee_alloc", +] + +[[package]] +name = "tx_reactivate_validator" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_tx_prelude", + "wee_alloc", +] + +[[package]] +name = "tx_redelegate" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + +[[package]] +name = "tx_resign_steward" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_tx_prelude", + "wee_alloc", +] + +[[package]] +name = "tx_reveal_pk" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_tx_prelude", + "wee_alloc", +] + +[[package]] +name = "tx_transfer" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_tx_prelude", + "wee_alloc", +] + +[[package]] +name = "tx_unbond" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + +[[package]] +name = "tx_unjail_validator" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_tx_prelude", + "wee_alloc", +] + +[[package]] +name = "tx_update_account" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_tx_prelude", + "wee_alloc", +] + +[[package]] +name = "tx_update_steward_commission" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_tx_prelude", + "wee_alloc", +] + +[[package]] +name = "tx_vote_proposal" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_tx_prelude", + "wee_alloc", +] + +[[package]] +name = "tx_withdraw" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", "wee_alloc", ] @@ -6669,12 +6899,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] -name = "vp_template" +name = "vp_implicit" version = "0.32.1" dependencies = [ "getrandom 0.2.11", + "namada", + "namada_test_utils", "namada_tests", + "namada_tx_prelude", "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + +[[package]] +name = "vp_user" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", "wee_alloc", ] diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index c4cb182c1a..68f9a1e420 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -2,11 +2,46 @@ resolver = "2" members = [ - "wasm_source", - "tx_template", - "vp_template", + "tx_become_validator", + "tx_bond", + "tx_change_bridge_pool", + "tx_change_consensus_key", + "tx_change_validator_commission", + "tx_change_validator_metadata", + "tx_claim_rewards", + "tx_deactivate_validator", + "tx_ibc", + "tx_init_account", + "tx_init_proposal", + "tx_reactivate_validator", + "tx_redelegate", + "tx_resign_steward", + "tx_transfer", + "tx_unbond", + "tx_update_account", + "tx_reveal_pk", + "tx_update_steward_commission", + "tx_unjail_validator", + "tx_vote_proposal", + "tx_withdraw", + "vp_implicit", + "vp_user", ] +[workspace.package] +authors = ["Heliax AG "] +edition = "2021" +license = "GPL-3.0" +version = "0.32.1" + +[workspace.dependencies] +namada_tx_prelude = { path = "../crates/tx_prelude" } +namada_vp_prelude = { path = "../crates/vp_prelude" } + +once_cell = { version = "1.8.0" } +wee_alloc = "0.4.5" +getrandom = { version = "0.2", features = ["custom"] } + [profile.release] # smaller and faster wasm (https://rustwasm.github.io/book/reference/code-size.html#compiling-with-link-time-optimizations-lto) lto = true @@ -14,3 +49,4 @@ lto = true panic = "abort" # tell llvm to optimize for size (https://rustwasm.github.io/book/reference/code-size.html#tell-llvm-to-optimize-for-size-instead-of-speed) opt-level = 'z' +strip = "debuginfo" diff --git a/wasm/Makefile b/wasm/Makefile new file mode 100644 index 0000000000..1bc09fcc1c --- /dev/null +++ b/wasm/Makefile @@ -0,0 +1,39 @@ +cargo := $(env) cargo +rustup := $(env) rustup +# Nightly build is currently used for rustfmt and clippy. +nightly := $(shell cat ../rust-nightly-version) + +# Build all wasms in release mode +all: + RUSTFLAGS='-C link-arg=-s' $(cargo) build --release --target wasm32-unknown-unknown --target-dir 'target' + cp target/wasm32-unknown-unknown/release/*.wasm . + +debug: + RUSTFLAGS='-C link-arg=-s' $(cargo) build --target wasm32-unknown-unknown --target-dir 'target' + cp target/wasm32-unknown-unknown/debug/*.wasm . + +check: + $(cargo) +$(nightly) check --workspace --target wasm32-unknown-unknown + +clippy: + $(cargo) +$(nightly) clippy --workspace -- -D warnings + +clippy-fix: + $(cargo) +$(nightly) clippy --fix -Z unstable-options --workspace --allow-dirty --allow-staged + +fmt: + $(cargo) +$(nightly) fmt + +fmt-check: + $(cargo) +$(nightly) fmt --check + +test: + $(cargo) +$(nightly) test -- -Z unstable-options --report-time + +clean: + $(cargo) clean + +deps: + $(rustup) target add wasm32-unknown-unknown + +.PHONY: all debug check clippy clippy-fix fmt fmt-check test clean deps \ No newline at end of file diff --git a/wasm/checksums.json b/wasm/checksums.json index 1044f72064..6e281fcadd 100644 --- a/wasm/checksums.json +++ b/wasm/checksums.json @@ -1,26 +1,26 @@ { - "tx_become_validator.wasm": "tx_become_validator.cc4234df4f4b761dd08c6150723f2e002dca472163851626897ebf60387063e4.wasm", - "tx_bond.wasm": "tx_bond.782cd825326d9ccf6e09b27fec7a924856df2235bbbc4746f0567a86e256a408.wasm", - "tx_bridge_pool.wasm": "tx_bridge_pool.6af8a6199d28cbb35b73bb6165294932355c43d3c4d9d90d2a42a6068e72dcd8.wasm", - "tx_change_consensus_key.wasm": "tx_change_consensus_key.f14664ad70a0abb9acca0fe29d52a1610ec45ca0c83da6ab239713cde46289b1.wasm", - "tx_change_validator_commission.wasm": "tx_change_validator_commission.87134834e6eafd234f33c2df29a67db295e36f6d3e1ce1c3edacf7231d172a6a.wasm", - "tx_change_validator_metadata.wasm": "tx_change_validator_metadata.87876a4e49264576dd571992df321b5bfa7e0ad9eeae62bce3b122e6328fd088.wasm", - "tx_claim_rewards.wasm": "tx_claim_rewards.bf1fae08207cab09f7bd625f2d1921a4a766d7d3998994789ea67c14b48a45b6.wasm", - "tx_deactivate_validator.wasm": "tx_deactivate_validator.7661c1112ee79039f405045cb58ddc983dec0655c306df36a20decfa57ae989a.wasm", - "tx_ibc.wasm": "tx_ibc.a1aa1ebc82661403974d943bf65cfe1df227c272daea8980e9207c6a6904ac71.wasm", - "tx_init_account.wasm": "tx_init_account.6521873b20fd15866a0f93098319db2b2aa1d02c64b3b4ef8ed4d7260cb41b12.wasm", - "tx_init_proposal.wasm": "tx_init_proposal.686d0ba8c7a3b45959a05f4f1b2a21b2f3d2aa75dd4ecd3cab80a451b7e3f649.wasm", - "tx_reactivate_validator.wasm": "tx_reactivate_validator.0ba5f3abbef8a9d99bbd62c58321c20c514968e1201ec5a42b7d9c0713a225e4.wasm", - "tx_redelegate.wasm": "tx_redelegate.ad4f509124dfcec939d170f3ef74a3787582fb09e300d41051c6e1137ddaf8c2.wasm", - "tx_resign_steward.wasm": "tx_resign_steward.a1a7da72f4a12e0e43315d6068a0d4eee7956f8ec3967b6852e1b748f4c08ce4.wasm", - "tx_reveal_pk.wasm": "tx_reveal_pk.0871dabc210bf60ea5914190a66d87f1fe567134ec0a6121d7e0ae9199eb63cd.wasm", - "tx_transfer.wasm": "tx_transfer.d4dca6f1c8d6030b3b32df24e5a847d3de9c55a26c3ed1e5ad2e1624b4d28846.wasm", - "tx_unbond.wasm": "tx_unbond.aa2fcca5674fbba4b3615e1aad38f1d1f1dd693711e24693fb15d4d0ec5b7aea.wasm", - "tx_unjail_validator.wasm": "tx_unjail_validator.980dbe0e750a11cd93d2d41207d39d245b1c5719dcaadc23eee81f6867fc6498.wasm", - "tx_update_account.wasm": "tx_update_account.fd2c304cfc92b0a5313d3a2a8027d5676e757ddf7262a618daf380a8c9a51620.wasm", - "tx_update_steward_commission.wasm": "tx_update_steward_commission.9d1ca33b89099414d05c20a98ebaf3caa4f3d01f3b69ceb0702f019704cf1de8.wasm", - "tx_vote_proposal.wasm": "tx_vote_proposal.10dba6fab0f5382921438675d90aa3a52bef73e0eb67c10ee1aa589a37fab212.wasm", - "tx_withdraw.wasm": "tx_withdraw.092ba9c6483663b247459215790e829045daeaa1b56ddf70648304641f246381.wasm", - "vp_implicit.wasm": "vp_implicit.edbe317958606ede19e05b320b83302df73efffb0125d3aec61baace94c44efa.wasm", - "vp_user.wasm": "vp_user.6065919f895d43099a567cb120ebdfa0c99c3ba4e803fe99159a14bd8f97f0ea.wasm" + "tx_become_validator.wasm": "tx_become_validator.33c55f03a6af30b652c3f503bafb18b18e0da56e4648bc95fb798fd969d17487.wasm", + "tx_bond.wasm": "tx_bond.c41249d3f737c18f6c200f138ad79a177d99410af5b6b60a84eb6a5a09edd5cb.wasm", + "tx_bridge_pool.wasm": "tx_bridge_pool.e972568f0d17d0425bec762d30f3d5bb8bbd91fbbed7769dd22c05691eb11fe4.wasm", + "tx_change_consensus_key.wasm": "tx_change_consensus_key.4aa1dbbc01468c8e10e6654a38762089a9aafef2d578c2130d0da0fafd68f8da.wasm", + "tx_change_validator_commission.wasm": "tx_change_validator_commission.96c13de1ab87f04b23f3b572ba50aea332f4d8fd880f532bcd8aa5b2369ce4ed.wasm", + "tx_change_validator_metadata.wasm": "tx_change_validator_metadata.ff0c751de6f3ad1dbbf91e4e0a596ec025c78e5e54d19f47c4a7b2f030a9bdbf.wasm", + "tx_claim_rewards.wasm": "tx_claim_rewards.470f39d246b3fcdec1f3ca6e8d9bf73406072aaaecae340c2fd59845eef593e1.wasm", + "tx_deactivate_validator.wasm": "tx_deactivate_validator.a7d19371a8ac9fc540ae79791bc4f1a5e0f107ca8e09b5c3a3ce30912724c365.wasm", + "tx_ibc.wasm": "tx_ibc.ce74e58f75d6224d1133d5ae6dc93014b0fbccd5605c7bb63e14871e1c33b2c4.wasm", + "tx_init_account.wasm": "tx_init_account.6c7538bc3afa89866224edb7b365e162545b6c69914c3e6d589ac0c619d8ddc5.wasm", + "tx_init_proposal.wasm": "tx_init_proposal.48e1087dee974cb2bc65dbe1ee2d0863aca8a1d19d4abe22ff658fa74fdb416c.wasm", + "tx_reactivate_validator.wasm": "tx_reactivate_validator.f8556383b428df1cf42c382505df475afacaf677d8de94a6e325a7fcf2facbd9.wasm", + "tx_redelegate.wasm": "tx_redelegate.b5e4cb63394e0a1b80068c381a3011fcbe091240ca551379b9e44405bef860ce.wasm", + "tx_resign_steward.wasm": "tx_resign_steward.cbc3c48b5fa3a1025cf35524be137eb1815ff0b22aeaefb0a59f50a8295e81ba.wasm", + "tx_reveal_pk.wasm": "tx_reveal_pk.90ccc96306edee9ce9283047e763872b764548f6edaffe99d71eb236030e7418.wasm", + "tx_transfer.wasm": "tx_transfer.96ebf6b2c0c47ac8005eac431faab5465660d9fd5acf2f24a2fefa4f86b73424.wasm", + "tx_unbond.wasm": "tx_unbond.a5f810a3a9a15c6394176cef3642be6c3946281e7382a88efa0d6753e4e1b0d4.wasm", + "tx_unjail_validator.wasm": "tx_unjail_validator.d7515dfac5015cd837f71aa205031cb1af964cb721719b45af48ac2c54688bb0.wasm", + "tx_update_account.wasm": "tx_update_account.9ae3e09ab1eac5efd48de75af92de25017108abbdc5283faf9a5baddd201c0b9.wasm", + "tx_update_steward_commission.wasm": "tx_update_steward_commission.e1751d69723ebdde1ee1eec9449621b23373c5175f696f8fe123823154a3a4f4.wasm", + "tx_vote_proposal.wasm": "tx_vote_proposal.411a18f72e903076c8cafdcec3309cc266571cc011ac8d7a1df0b0973378e826.wasm", + "tx_withdraw.wasm": "tx_withdraw.41b230456a7c8a157a1f637ea4f31f7c778325590ff0eb26988482237590aecc.wasm", + "vp_implicit.wasm": "vp_implicit.1c427e21034c407e3aa5f8eb968a94463919b6541fc67cd15366ac57bcbfb631.wasm", + "vp_user.wasm": "vp_user.d2ecb69ec0302ce492b32680fdf2426b659d44f569b5f9c655378f7878b65505.wasm" } \ No newline at end of file diff --git a/wasm/tx_become_validator/Cargo.toml b/wasm/tx_become_validator/Cargo.toml new file mode 100644 index 0000000000..67b57f5cc3 --- /dev/null +++ b/wasm/tx_become_validator/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "tx_become_validator" +description = "WASM transaction to create a validator" +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_become_validator.rs b/wasm/tx_become_validator/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/tx_become_validator.rs rename to wasm/tx_become_validator/src/lib.rs diff --git a/wasm/tx_bond/Cargo.toml b/wasm/tx_bond/Cargo.toml new file mode 100644 index 0000000000..804cb3edf7 --- /dev/null +++ b/wasm/tx_bond/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "tx_bond" +description = "WASM transaction to bond tokens" +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada = {path = "../../crates/namada"} +namada_tests = {path = "../../crates/tests"} +namada_test_utils = {path = "../../crates/test_utils"} +namada_vp_prelude = {path = "../../crates/vp_prelude"} + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_bond.rs b/wasm/tx_bond/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/tx_bond.rs rename to wasm/tx_bond/src/lib.rs diff --git a/wasm/tx_change_bridge_pool/Cargo.toml b/wasm/tx_change_bridge_pool/Cargo.toml new file mode 100644 index 0000000000..1999e31dea --- /dev/null +++ b/wasm/tx_change_bridge_pool/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "tx_bridge_pool" +description = "WASM transaction to interact with the bridge pool" +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_bridge_pool.rs b/wasm/tx_change_bridge_pool/src/lib.rs similarity index 95% rename from wasm/wasm_source/src/tx_bridge_pool.rs rename to wasm/tx_change_bridge_pool/src/lib.rs index 57345114c0..3b45c22bb0 100644 --- a/wasm/wasm_source/src/tx_bridge_pool.rs +++ b/wasm/tx_change_bridge_pool/src/lib.rs @@ -1,8 +1,8 @@ //! A tx for adding a transfer request across the Ethereum bridge //! into the bridge pool. -use eth_bridge_pool::{GasFee, PendingTransfer, TransferToEthereum}; use namada_tx_prelude::eth_bridge_pool::{ - get_pending_key, BRIDGE_POOL_ADDRESS, + get_pending_key, GasFee, PendingTransfer, TransferToEthereum, + BRIDGE_POOL_ADDRESS, }; use namada_tx_prelude::parameters::native_erc20_key; use namada_tx_prelude::*; diff --git a/wasm/tx_change_consensus_key/Cargo.toml b/wasm/tx_change_consensus_key/Cargo.toml new file mode 100644 index 0000000000..2f90bb8798 --- /dev/null +++ b/wasm/tx_change_consensus_key/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "tx_change_consensus_key" +description = "WASM transaction to change consensus keys" +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_change_consensus_key.rs b/wasm/tx_change_consensus_key/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/tx_change_consensus_key.rs rename to wasm/tx_change_consensus_key/src/lib.rs diff --git a/wasm/tx_change_validator_commission/Cargo.toml b/wasm/tx_change_validator_commission/Cargo.toml new file mode 100644 index 0000000000..a2c37ac52e --- /dev/null +++ b/wasm/tx_change_validator_commission/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "tx_change_validator_commission" +description = "WASM trasaction to change validator commission" +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada = {path = "../../crates/namada"} +namada_tests = {path = "../../crates/tests"} +namada_test_utils = {path = "../../crates/test_utils"} +namada_vp_prelude = {path = "../../crates/vp_prelude"} + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_change_validator_commission.rs b/wasm/tx_change_validator_commission/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/tx_change_validator_commission.rs rename to wasm/tx_change_validator_commission/src/lib.rs diff --git a/wasm/tx_change_validator_metadata/Cargo.toml b/wasm/tx_change_validator_metadata/Cargo.toml new file mode 100644 index 0000000000..f659bb0618 --- /dev/null +++ b/wasm/tx_change_validator_metadata/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "tx_change_validator_metadata" +description = "WASM transaction to change validator metadata" +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_change_validator_metadata.rs b/wasm/tx_change_validator_metadata/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/tx_change_validator_metadata.rs rename to wasm/tx_change_validator_metadata/src/lib.rs diff --git a/wasm/tx_claim_rewards/Cargo.toml b/wasm/tx_claim_rewards/Cargo.toml new file mode 100644 index 0000000000..696a67fa8f --- /dev/null +++ b/wasm/tx_claim_rewards/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "tx_claim_rewards" +description = "WASM transaction to claim proof-of-stake rewards" +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_claim_rewards.rs b/wasm/tx_claim_rewards/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/tx_claim_rewards.rs rename to wasm/tx_claim_rewards/src/lib.rs diff --git a/wasm/tx_deactivate_validator/Cargo.toml b/wasm/tx_deactivate_validator/Cargo.toml new file mode 100644 index 0000000000..e536c3a5e0 --- /dev/null +++ b/wasm/tx_deactivate_validator/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "tx_deactivate_validator" +description = "WASM transaction to deactivate a validator" +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_deactivate_validator.rs b/wasm/tx_deactivate_validator/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/tx_deactivate_validator.rs rename to wasm/tx_deactivate_validator/src/lib.rs diff --git a/wasm/tx_ibc/Cargo.toml b/wasm/tx_ibc/Cargo.toml new file mode 100644 index 0000000000..fca7472d87 --- /dev/null +++ b/wasm/tx_ibc/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "tx_ibc" +description = "WASM transaction for an IBC transfer" +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_ibc.rs b/wasm/tx_ibc/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/tx_ibc.rs rename to wasm/tx_ibc/src/lib.rs diff --git a/wasm/tx_init_account/Cargo.toml b/wasm/tx_init_account/Cargo.toml new file mode 100644 index 0000000000..560910893d --- /dev/null +++ b/wasm/tx_init_account/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "tx_init_account" +description = "WASM transaction to initialize an account" +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_init_account.rs b/wasm/tx_init_account/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/tx_init_account.rs rename to wasm/tx_init_account/src/lib.rs diff --git a/wasm/tx_init_proposal/Cargo.toml b/wasm/tx_init_proposal/Cargo.toml new file mode 100644 index 0000000000..5301f148b5 --- /dev/null +++ b/wasm/tx_init_proposal/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "tx_init_proposal" +description = "WASM transaction to initialize a governance proposal" +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_init_proposal.rs b/wasm/tx_init_proposal/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/tx_init_proposal.rs rename to wasm/tx_init_proposal/src/lib.rs diff --git a/wasm/tx_reactivate_validator/Cargo.toml b/wasm/tx_reactivate_validator/Cargo.toml new file mode 100644 index 0000000000..41b795f865 --- /dev/null +++ b/wasm/tx_reactivate_validator/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "tx_reactivate_validator" +description = "WASM transaction to reactivate a validator" +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_reactivate_validator.rs b/wasm/tx_reactivate_validator/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/tx_reactivate_validator.rs rename to wasm/tx_reactivate_validator/src/lib.rs diff --git a/wasm/tx_redelegate/Cargo.toml b/wasm/tx_redelegate/Cargo.toml new file mode 100644 index 0000000000..44d28a4a03 --- /dev/null +++ b/wasm/tx_redelegate/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "tx_redelegate" +description = "WASM transaction to redelegate bonds" +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada = {path = "../../crates/namada"} +namada_tests = {path = "../../crates/tests"} +namada_test_utils = {path = "../../crates/test_utils"} +namada_vp_prelude = {path = "../../crates/vp_prelude"} + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_redelegate.rs b/wasm/tx_redelegate/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/tx_redelegate.rs rename to wasm/tx_redelegate/src/lib.rs diff --git a/wasm/tx_resign_steward/Cargo.toml b/wasm/tx_resign_steward/Cargo.toml new file mode 100644 index 0000000000..8f6fa2424e --- /dev/null +++ b/wasm/tx_resign_steward/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "tx_resign_steward" +description = "WASM transaction to resign a PGF steward" +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_resign_steward.rs b/wasm/tx_resign_steward/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/tx_resign_steward.rs rename to wasm/tx_resign_steward/src/lib.rs diff --git a/wasm/tx_reveal_pk/Cargo.toml b/wasm/tx_reveal_pk/Cargo.toml new file mode 100644 index 0000000000..236862f2c3 --- /dev/null +++ b/wasm/tx_reveal_pk/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "tx_reveal_pk" +description = "WASM transaction to update reveal pk" +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[lib] +crate-type = ["cdylib"] diff --git a/wasm/wasm_source/src/tx_reveal_pk.rs b/wasm/tx_reveal_pk/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/tx_reveal_pk.rs rename to wasm/tx_reveal_pk/src/lib.rs diff --git a/wasm/tx_template/.gitignore b/wasm/tx_template/.gitignore deleted file mode 100644 index 3df254e13b..0000000000 --- a/wasm/tx_template/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -# Built wasm module -tx.wasm - -# Generated by Cargo -# will have compiled files and executables -debug/ -target/ - -# These are backup files generated by rustfmt -**/*.rs.bk \ No newline at end of file diff --git a/wasm/tx_template/Cargo.toml b/wasm/tx_template/Cargo.toml deleted file mode 100644 index fd65409057..0000000000 --- a/wasm/tx_template/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -authors = ["Heliax AG "] -edition = "2021" -license = "GPL-3.0" -name = "tx_template" -resolver = "2" -version = "0.32.1" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -namada_tx_prelude = {path = "../../crates/tx_prelude"} -wee_alloc = "0.4.5" -getrandom = { version = "0.2", features = ["custom"] } - -[dev-dependencies] -namada_tests = {path = "../../crates/tests"} diff --git a/wasm/tx_template/Makefile b/wasm/tx_template/Makefile deleted file mode 100644 index 02e33ac6d8..0000000000 --- a/wasm/tx_template/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -cargo = $(env) cargo -rustup = $(env) rustup - -# Linker flag "-s" for stripping (https://github.com/rust-lang/cargo/issues/3483#issuecomment-431209957) -build-release: - # wasm is built into target/wasm32-unknown-unknown/release - RUSTFLAGS='-C link-arg=-s' $(cargo) build --release --target wasm32-unknown-unknown - -build: - $(cargo) build --target wasm32-unknown-unknown - -watch: - $(cargo) watch - -clean: - $(cargo) clean && if [ -e $(wasm) ]; then rm $(wasm); fi - -deps: - $(rustup) target add wasm32-unknown-unknown - -.PHONY : build-release build watch clean deps diff --git a/wasm/tx_template/README.md b/wasm/tx_template/README.md deleted file mode 100644 index 79d163a114..0000000000 --- a/wasm/tx_template/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Transaction script wasm template - -This is a template of a wasm module for transaction script. - -## Quick start - -```shell -# To be able to build this, make sure to have -make deps - -# Build - this will create `.wasm` file -make build-release -``` diff --git a/wasm/tx_template/src/lib.rs b/wasm/tx_template/src/lib.rs deleted file mode 100644 index 5b0f8fb501..0000000000 --- a/wasm/tx_template/src/lib.rs +++ /dev/null @@ -1,28 +0,0 @@ -use namada_tx_prelude::*; - -#[transaction] -fn apply_tx(_ctx: &mut Ctx, tx_data: Tx) -> TxResult { - log_string(format!("apply_tx called with data: {:#?}", tx_data)); - Ok(()) -} - -#[cfg(test)] -mod tests { - use namada_tests::tx::*; - - use super::*; - - /// An example test, checking that this transaction performs no storage - /// modifications. - #[test] - fn test_no_op_transaction() { - // The environment must be initialized first - tx_host_env::init(); - - let tx = Tx::from_type(TxType::Raw); - apply_tx(ctx(), tx).unwrap(); - - let env = tx_host_env::take(); - assert!(env.all_touched_storage_keys().is_empty()); - } -} diff --git a/wasm/tx_transfer/Cargo.toml b/wasm/tx_transfer/Cargo.toml new file mode 100644 index 0000000000..593c7f35cd --- /dev/null +++ b/wasm/tx_transfer/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "tx_transfer" +description = "WASM transaction to transfer tokens" +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_transfer.rs b/wasm/tx_transfer/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/tx_transfer.rs rename to wasm/tx_transfer/src/lib.rs diff --git a/wasm/tx_unbond/Cargo.toml b/wasm/tx_unbond/Cargo.toml new file mode 100644 index 0000000000..95e3e032eb --- /dev/null +++ b/wasm/tx_unbond/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "tx_unbond" +description = "WASM transaction to unbond tokens" +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada = {path = "../../crates/namada"} +namada_tests = {path = "../../crates/tests"} +namada_test_utils = {path = "../../crates/test_utils"} +namada_vp_prelude = {path = "../../crates/vp_prelude"} + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_unbond.rs b/wasm/tx_unbond/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/tx_unbond.rs rename to wasm/tx_unbond/src/lib.rs diff --git a/wasm/tx_unjail_validator/Cargo.toml b/wasm/tx_unjail_validator/Cargo.toml new file mode 100644 index 0000000000..74a337ff95 --- /dev/null +++ b/wasm/tx_unjail_validator/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "tx_unjail_validator" +description = "WASM transaction to unjail a validator" +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_unjail_validator.rs b/wasm/tx_unjail_validator/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/tx_unjail_validator.rs rename to wasm/tx_unjail_validator/src/lib.rs diff --git a/wasm/tx_update_account/Cargo.toml b/wasm/tx_update_account/Cargo.toml new file mode 100644 index 0000000000..acae190b7a --- /dev/null +++ b/wasm/tx_update_account/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "tx_update_account" +description = "WASM transaction to update an account" +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_update_account.rs b/wasm/tx_update_account/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/tx_update_account.rs rename to wasm/tx_update_account/src/lib.rs diff --git a/wasm/tx_update_steward_commission/Cargo.toml b/wasm/tx_update_steward_commission/Cargo.toml new file mode 100644 index 0000000000..f05be319a6 --- /dev/null +++ b/wasm/tx_update_steward_commission/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "tx_update_steward_commission" +description = "WASM transaction to update steward commissions" +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_update_steward_commission.rs b/wasm/tx_update_steward_commission/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/tx_update_steward_commission.rs rename to wasm/tx_update_steward_commission/src/lib.rs diff --git a/wasm/tx_vote_proposal/Cargo.toml b/wasm/tx_vote_proposal/Cargo.toml new file mode 100644 index 0000000000..4f2f877287 --- /dev/null +++ b/wasm/tx_vote_proposal/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "tx_vote_proposal" +description = "WASM transaction to vote on a governance proposal" +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_vote_proposal.rs b/wasm/tx_vote_proposal/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/tx_vote_proposal.rs rename to wasm/tx_vote_proposal/src/lib.rs diff --git a/wasm/tx_withdraw/Cargo.toml b/wasm/tx_withdraw/Cargo.toml new file mode 100644 index 0000000000..4ef163017f --- /dev/null +++ b/wasm/tx_withdraw/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "tx_withdraw" +description = "WASM transaction to withdraw tokens" +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada = {path = "../../crates/namada"} +namada_tests = {path = "../../crates/tests"} +namada_test_utils = {path = "../../crates/test_utils"} +namada_vp_prelude = {path = "../../crates/vp_prelude"} + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_withdraw.rs b/wasm/tx_withdraw/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/tx_withdraw.rs rename to wasm/tx_withdraw/src/lib.rs diff --git a/wasm/vp_implicit/Cargo.toml b/wasm/vp_implicit/Cargo.toml new file mode 100644 index 0000000000..89e1b54348 --- /dev/null +++ b/wasm/vp_implicit/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "vp_implicit" +description = "Implicit account valididity predicate." +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +namada_vp_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada = {path = "../../crates/namada"} +namada_tests = {path = "../../crates/tests"} +namada_test_utils = {path = "../../crates/test_utils"} +namada_vp_prelude = {path = "../../crates/vp_prelude"} + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/vp_implicit.rs b/wasm/vp_implicit/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/vp_implicit.rs rename to wasm/vp_implicit/src/lib.rs diff --git a/wasm/vp_template/.gitignore b/wasm/vp_template/.gitignore deleted file mode 100644 index 1f7868d94e..0000000000 --- a/wasm/vp_template/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -# Built wasm module -vp.wasm - -# Generated by Cargo -# will have compiled files and executables -debug/ -target/ - -# These are backup files generated by rustfmt -**/*.rs.bk \ No newline at end of file diff --git a/wasm/vp_template/Cargo.toml b/wasm/vp_template/Cargo.toml deleted file mode 100644 index 3aa9573d24..0000000000 --- a/wasm/vp_template/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -authors = ["Heliax AG "] -edition = "2021" -license = "GPL-3.0" -name = "vp_template" -resolver = "2" -version = "0.32.1" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -namada_vp_prelude = {path = "../../crates/vp_prelude"} -wee_alloc = "0.4.5" -getrandom = { version = "0.2", features = ["custom"] } - -[dev-dependencies] -namada_tests = {path = "../../crates/tests"} diff --git a/wasm/vp_template/Makefile b/wasm/vp_template/Makefile deleted file mode 100644 index 02e33ac6d8..0000000000 --- a/wasm/vp_template/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -cargo = $(env) cargo -rustup = $(env) rustup - -# Linker flag "-s" for stripping (https://github.com/rust-lang/cargo/issues/3483#issuecomment-431209957) -build-release: - # wasm is built into target/wasm32-unknown-unknown/release - RUSTFLAGS='-C link-arg=-s' $(cargo) build --release --target wasm32-unknown-unknown - -build: - $(cargo) build --target wasm32-unknown-unknown - -watch: - $(cargo) watch - -clean: - $(cargo) clean && if [ -e $(wasm) ]; then rm $(wasm); fi - -deps: - $(rustup) target add wasm32-unknown-unknown - -.PHONY : build-release build watch clean deps diff --git a/wasm/vp_template/README.md b/wasm/vp_template/README.md deleted file mode 100644 index 58c6b6198b..0000000000 --- a/wasm/vp_template/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Validity predicate wasm template - -This is a template of a wasm module for a validity predicate. - -## Quick start - -```shell -# To be able to build this, make sure to have -make deps - -# Build - this will create `.wasm` file -make build-release -``` diff --git a/wasm/vp_template/src/lib.rs b/wasm/vp_template/src/lib.rs deleted file mode 100644 index aa4929e59f..0000000000 --- a/wasm/vp_template/src/lib.rs +++ /dev/null @@ -1,26 +0,0 @@ -use namada_vp_prelude::*; - -#[validity_predicate] -fn validate_tx( - ctx: &Ctx, - tx_data: Tx, - addr: Address, - keys_changed: BTreeSet, - verifiers: BTreeSet
, -) -> VpResult { - log_string(format!( - "validate_tx called with addr: {}, key_changed: {:#?}, tx_data: \ - {:#?}, verifiers: {:?}", - addr, keys_changed, tx_data, verifiers - )); - - for key in keys_changed { - let pre: Option = ctx.read_pre(&key).into_vp_error()?; - let post: Option = ctx.read_post(&key).into_vp_error()?; - log_string(format!( - "validate_tx key: {}, pre: {:#?}, post: {:#?}", - key, pre, post, - )); - } - accept() -} diff --git a/wasm/vp_user/Cargo.toml b/wasm/vp_user/Cargo.toml new file mode 100644 index 0000000000..f94e5e6b85 --- /dev/null +++ b/wasm/vp_user/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "vp_user" +description = "User validity predicate." +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_tx_prelude.workspace = true +namada_vp_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada = {path = "../../crates/namada"} +namada_tests = {path = "../../crates/tests"} +namada_test_utils = {path = "../../crates/test_utils"} +namada_vp_prelude = {path = "../../crates/vp_prelude"} + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm/wasm_source/src/vp_user.rs b/wasm/vp_user/src/lib.rs similarity index 100% rename from wasm/wasm_source/src/vp_user.rs rename to wasm/vp_user/src/lib.rs diff --git a/wasm/wasm_source/.gitignore b/wasm/wasm_source/.gitignore deleted file mode 100644 index 5028f0063a..0000000000 --- a/wasm/wasm_source/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -# Generated by Cargo -# will have compiled files and executables -debug/ -target/ - -# These are backup files generated by rustfmt -**/*.rs.bk \ No newline at end of file diff --git a/wasm/wasm_source/Cargo.toml b/wasm/wasm_source/Cargo.toml deleted file mode 100644 index 3f22acdc21..0000000000 --- a/wasm/wasm_source/Cargo.toml +++ /dev/null @@ -1,58 +0,0 @@ -[package] -authors = ["Heliax AG "] -edition = "2021" -license = "GPL-3.0" -name = "namada_wasm" -resolver = "2" -version = "0.32.1" - -[lib] -crate-type = ["cdylib"] - -# The features should be used individually to build the selected wasm. -# Newly added wasms should also be added into the Makefile `$(wasms)` list. -[features] -tx_bond = ["namada_tx_prelude"] -tx_bridge_pool = ["namada_tx_prelude"] -tx_change_validator_commission = ["namada_tx_prelude"] -tx_change_consensus_key = ["namada_tx_prelude"] -tx_change_validator_metadata = ["namada_tx_prelude"] -tx_claim_rewards = ["namada_tx_prelude"] -tx_deactivate_validator = ["namada_tx_prelude"] -tx_from_intent = ["namada_tx_prelude"] -tx_ibc = ["namada_tx_prelude"] -tx_init_account = ["namada_tx_prelude"] -tx_init_proposal = ["namada_tx_prelude"] -tx_become_validator = ["namada_tx_prelude"] -tx_reactivate_validator = ["namada_tx_prelude"] -tx_redelegate = ["namada_tx_prelude"] -tx_reveal_pk = ["namada_tx_prelude"] -tx_transfer = ["namada_tx_prelude"] -tx_unbond = ["namada_tx_prelude"] -tx_unjail_validator = ["namada_tx_prelude"] -tx_update_account = ["namada_tx_prelude"] -tx_vote_proposal = ["namada_tx_prelude"] -tx_withdraw = ["namada_tx_prelude"] -tx_update_steward_commission = ["namada_tx_prelude"] -tx_resign_steward = ["namada_tx_prelude"] -vp_implicit = ["namada_vp_prelude"] -vp_user = ["namada_vp_prelude"] - -[dependencies] -namada_tx_prelude = {path = "../../crates/tx_prelude", optional = true} -namada_vp_prelude = {path = "../../crates/vp_prelude", optional = true} - -wee_alloc = "0.4.5" -getrandom = { version = "0.2", features = ["custom"] } - -[dev-dependencies] -namada = {path = "../../crates/namada"} -namada_tests = {path = "../../crates/tests", default-features = false, features = ["wasm-runtime"]} -namada_test_utils = {path = "../../crates/test_utils"} -namada_tx_prelude = {path = "../../crates/tx_prelude"} -namada_vp_prelude = {path = "../../crates/vp_prelude"} - -proptest = "1.4.0" -test-log = {version = "0.2.14", default-features = false, features = ["trace"]} -tracing = "0.1.30" -tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} diff --git a/wasm/wasm_source/Makefile b/wasm/wasm_source/Makefile deleted file mode 100644 index f01292af1e..0000000000 --- a/wasm/wasm_source/Makefile +++ /dev/null @@ -1,97 +0,0 @@ -cargo := $(env) cargo -rustup := $(env) rustup -# Nightly build is currently used for rustfmt and clippy. -nightly := $(shell cat ../../rust-nightly-version) - -# All the wasms that can be built from this source, switched via Cargo features -# Wasms can be added via the Cargo.toml `[features]` list. -wasms := tx_bond -wasms += tx_bridge_pool -wasms += tx_change_validator_commission -wasms += tx_change_consensus_key -wasms += tx_change_validator_metadata -wasms += tx_claim_rewards -wasms += tx_deactivate_validator -wasms += tx_ibc -wasms += tx_init_account -wasms += tx_init_proposal -wasms += tx_become_validator -wasms += tx_redelegate -wasms += tx_reactivate_validator -wasms += tx_reveal_pk -wasms += tx_transfer -wasms += tx_unbond -wasms += tx_unjail_validator -wasms += tx_update_account -wasms += tx_vote_proposal -wasms += tx_withdraw -wasms += tx_update_steward_commission -wasms += tx_resign_steward -wasms += vp_implicit -wasms += vp_user - -# Build all wasms in release mode -all: $(wasms) - -# Build all wasms in debug mode -debug: - $(foreach wasm,$(wasms),make debug_$(wasm) && ) true - -# `cargo check` all wasms -check: - $(foreach wasm,$(wasms),make check_$(wasm) && ) true - -# `cargo test` all wasms -test: - $(foreach wasm,$(wasms),make test_$(wasm) && ) true - -# `cargo clippy` all wasms -clippy: - $(foreach wasm,$(wasms),make clippy_$(wasm) && ) true - -clippy-fix: - $(cargo) +$(nightly) clippy --fix -Z unstable-options --all-targets --allow-dirty --allow-staged - -fmt: - $(cargo) +$(nightly) fmt --all - -fmt-check: - $(cargo) +$(nightly) fmt --all -- --check - -# Build a selected wasm -# Linker flag "-s" for stripping (https://github.com/rust-lang/cargo/issues/3483#issuecomment-431209957) -$(wasms): %: - RUSTFLAGS='-C link-arg=-s' $(cargo) build --release --target wasm32-unknown-unknown --target-dir 'target' --features $@ && \ - cp "./target/wasm32-unknown-unknown/release/namada_wasm.wasm" ../$@.wasm - -# Build a selected wasm in debug mode -$(patsubst %,debug_%,$(wasms)): debug_%: - RUSTFLAGS='-C link-arg=-s' $(cargo) build --target wasm32-unknown-unknown --target-dir 'target' --features $* && \ - cp "./target/wasm32-unknown-unknown/debug/namada_wasm.wasm" ../$*.wasm - -# `cargo check` one of the wasms, e.g. `make check_tx_transfer` -$(patsubst %,check_%,$(wasms)): check_%: - $(cargo) check --target wasm32-unknown-unknown --features $* - -# `cargo test` one of the wasms, e.g. `make test_tx_transfer` -$(patsubst %,test_%,$(wasms)): test_%: - $(cargo) +$(nightly) test --features $* \ - -- \ - -Z unstable-options --report-time - -# `cargo watch` one of the wasms, e.g. `make watch_tx_transfer` -$(patsubst %,watch_%,$(wasms)): watch_%: - $(cargo) watch --features $* - -# `cargo clippy` one of the wasms, e.g. `make clippy_tx_transfer` -$(patsubst %,clippy_%,$(wasms)): clippy_%: - $(cargo) +$(nightly) clippy --all-targets --features $* -- -D warnings - -clean-wasm = rm ../$(wasm).*.wasm -clean: - $(foreach wasm,$(wasms),$(clean-wasm) && ) true - -deps: - $(rustup) target add wasm32-unknown-unknown - -.PHONY : all debug check test clippy fmt fmt-check clean deps diff --git a/wasm/wasm_source/README.md b/wasm/wasm_source/README.md deleted file mode 100644 index 423e29d034..0000000000 --- a/wasm/wasm_source/README.md +++ /dev/null @@ -1,22 +0,0 @@ -# WASM source code in Rust - -This crate contains WASM implementations of various transactions and validity predicates. - -## Quick start - -```shell -# To be able to build this, make sure to have -make deps - -# Build - this will output .wasm files in the parent dir -make all - -# Each source that is included here can also be build and checked individually, e.g. for "tx_transfer" source: - -make tx_transfer # optimized build (strips `debug_log!` statements) -make debug_tx_transfer # debug build -make check_tx_transfer # cargo check -make test_tx_transfer # cargo test -make watch_tx_transfer # cargo watch -make clippy_tx_transfer # cargo clippy -``` diff --git a/wasm/wasm_source/proptest-regressions/tx_bond.txt b/wasm/wasm_source/proptest-regressions/tx_bond.txt deleted file mode 100644 index 8c589d1abd..0000000000 --- a/wasm/wasm_source/proptest-regressions/tx_bond.txt +++ /dev/null @@ -1 +0,0 @@ -cc f22e874350910b197cb02a4a07ec5bef18e16c0d1a39eaabaee43d1fc05ce11d diff --git a/wasm/wasm_source/proptest-regressions/tx_redelegate.txt b/wasm/wasm_source/proptest-regressions/tx_redelegate.txt deleted file mode 100644 index a8d6e7edba..0000000000 --- a/wasm/wasm_source/proptest-regressions/tx_redelegate.txt +++ /dev/null @@ -1,2 +0,0 @@ -cc 90825d666558e208bb8f4f46c746177abf8bf9499114dcdac1525ab600b7c6ce - diff --git a/wasm/wasm_source/src/lib.rs b/wasm/wasm_source/src/lib.rs deleted file mode 100644 index 4e27cb92ad..0000000000 --- a/wasm/wasm_source/src/lib.rs +++ /dev/null @@ -1,49 +0,0 @@ -#[cfg(feature = "tx_become_validator")] -pub mod tx_become_validator; -#[cfg(feature = "tx_bond")] -pub mod tx_bond; -#[cfg(feature = "tx_bridge_pool")] -pub mod tx_bridge_pool; -#[cfg(feature = "tx_change_consensus_key")] -pub mod tx_change_consensus_key; -#[cfg(feature = "tx_change_validator_commission")] -pub mod tx_change_validator_commission; -#[cfg(feature = "tx_change_validator_metadata")] -pub mod tx_change_validator_metadata; -#[cfg(feature = "tx_claim_rewards")] -pub mod tx_claim_rewards; -#[cfg(feature = "tx_deactivate_validator")] -pub mod tx_deactivate_validator; -#[cfg(feature = "tx_ibc")] -pub mod tx_ibc; -#[cfg(feature = "tx_init_account")] -pub mod tx_init_account; -#[cfg(feature = "tx_init_proposal")] -pub mod tx_init_proposal; -#[cfg(feature = "tx_reactivate_validator")] -pub mod tx_reactivate_validator; -#[cfg(feature = "tx_redelegate")] -pub mod tx_redelegate; -#[cfg(feature = "tx_resign_steward")] -pub mod tx_resign_steward; -#[cfg(feature = "tx_reveal_pk")] -pub mod tx_reveal_pk; -#[cfg(feature = "tx_transfer")] -pub mod tx_transfer; -#[cfg(feature = "tx_unbond")] -pub mod tx_unbond; -#[cfg(feature = "tx_unjail_validator")] -pub mod tx_unjail_validator; -#[cfg(feature = "tx_update_account")] -pub mod tx_update_account; -#[cfg(feature = "tx_update_steward_commission")] -pub mod tx_update_steward_commission; -#[cfg(feature = "tx_vote_proposal")] -pub mod tx_vote_proposal; -#[cfg(feature = "tx_withdraw")] -pub mod tx_withdraw; - -#[cfg(feature = "vp_implicit")] -pub mod vp_implicit; -#[cfg(feature = "vp_user")] -pub mod vp_user; diff --git a/wasm_for_tests/wasm_source/Cargo.lock b/wasm_for_tests/Cargo.lock similarity index 97% rename from wasm_for_tests/wasm_source/Cargo.lock rename to wasm_for_tests/Cargo.lock index 25fa0dfde0..b1d5ab3726 100644 --- a/wasm_for_tests/wasm_source/Cargo.lock +++ b/wasm_for_tests/Cargo.lock @@ -4046,18 +4046,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "namada_wasm_for_tests" -version = "0.32.1" -dependencies = [ - "getrandom 0.2.11", - "namada_test_utils", - "namada_tests", - "namada_tx_prelude", - "namada_vp_prelude", - "wee_alloc", -] - [[package]] name = "nonempty" version = "0.7.0" @@ -6455,6 +6443,182 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" +[[package]] +name = "tx_fail" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + +[[package]] +name = "tx_infinite_guest_gas" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + +[[package]] +name = "tx_infinite_host_gas" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + +[[package]] +name = "tx_invalid_data" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + +[[package]] +name = "tx_memory_limit" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + +[[package]] +name = "tx_no_op" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + +[[package]] +name = "tx_proposal_code" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + +[[package]] +name = "tx_proposal_ibc_token_inflation" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + +[[package]] +name = "tx_proposal_masp_reward" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + +[[package]] +name = "tx_read_storage_key" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + +[[package]] +name = "tx_write" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + [[package]] name = "typed-builder" version = "0.18.0" @@ -6599,6 +6763,118 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "vp_always_false" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + +[[package]] +name = "vp_always_true" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + +[[package]] +name = "vp_eval" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + +[[package]] +name = "vp_infinite_guest_gas" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + +[[package]] +name = "vp_infinite_host_gas" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + +[[package]] +name = "vp_memory_limit" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + +[[package]] +name = "vp_read_storage_key" +version = "0.32.1" +dependencies = [ + "getrandom 0.2.11", + "namada_test_utils", + "namada_tests", + "namada_tx_prelude", + "namada_vp_prelude", + "proptest", + "test-log", + "tracing", + "tracing-subscriber", + "wee_alloc", +] + [[package]] name = "wait-timeout" version = "0.2.0" diff --git a/wasm_for_tests/Cargo.toml b/wasm_for_tests/Cargo.toml new file mode 100644 index 0000000000..069ca169cc --- /dev/null +++ b/wasm_for_tests/Cargo.toml @@ -0,0 +1,45 @@ +[workspace] +resolver = "2" + +members = [ + "tx_fail", + "tx_infinite_guest_gas", + "tx_infinite_host_gas", + "tx_invalid_data", + "tx_memory_limit", + "tx_no_op", + "tx_proposal_code", + "tx_proposal_ibc_token_inflation", + "tx_proposal_masp_reward", + "tx_read_storage_key", + "tx_write", + "vp_always_false", + "vp_always_true", + "vp_eval", + "vp_infinite_guest_gas", + "vp_infinite_host_gas", + "vp_memory_limit", + "vp_read_storage_key", +] + +[workspace.package] +authors = ["Heliax AG "] +edition = "2021" +license = "GPL-3.0" +version = "0.32.1" + +[workspace.dependencies] +namada_test_utils = { path = "../crates/test_utils" } +namada_tx_prelude = { path = "../crates/tx_prelude" } +namada_vp_prelude = { path = "../crates/vp_prelude" } +wee_alloc = "0.4.5" +getrandom = { version = "0.2", features = ["custom"] } + +[profile.release] +# smaller and faster wasm (https://rustwasm.github.io/book/reference/code-size.html#compiling-with-link-time-optimizations-lto) +lto = true +# simply terminate on panics, no unwinding +panic = "abort" +# tell llvm to optimize for size (https://rustwasm.github.io/book/reference/code-size.html#tell-llvm-to-optimize-for-size-instead-of-speed) +opt-level = 'z' +strip = "debuginfo" \ No newline at end of file diff --git a/wasm_for_tests/Makefile b/wasm_for_tests/Makefile new file mode 100644 index 0000000000..fc63e4bfea --- /dev/null +++ b/wasm_for_tests/Makefile @@ -0,0 +1,61 @@ +cargo := $(env) cargo +rustup := $(env) rustup +# Nightly build is currently used for rustfmt and clippy. +nightly := $(shell cat ../rust-nightly-version) + +# All the wasms that can be built from this source, switched via Cargo features +# Wasms can be added via the Cargo.toml `[features]` list. +wasms := tx_fail +wasms += tx_infinite_guest_gas +wasms += tx_infinite_host_gas +wasms += tx_invalid_data +wasms += tx_memory_limit +wasms += tx_no_op +wasms += tx_proposal_code +wasms += tx_proposal_ibc_token_inflation +wasms += tx_proposal_masp_reward +wasms += tx_read_storage_key +wasms += tx_write +wasms += vp_always_false +wasms += vp_always_true +wasms += vp_eval +wasms += vp_infinite_guest_gas +wasms += vp_infinite_host_gas +wasms += vp_memory_limit +wasms += vp_read_storage_key + + +# Build all wasms in release mode +all: + RUSTFLAGS='-C link-arg=-s' $(cargo) build --release --target wasm32-unknown-unknown --target-dir 'target' + cp target/wasm32-unknown-unknown/release/*.wasm . + +debug: + RUSTFLAGS='-C link-arg=-s' $(cargo) build --target wasm32-unknown-unknown --target-dir 'target' + cp target/wasm32-unknown-unknown/debug/*.wasm . + +check: + $(cargo) +$(nightly) check --workspace --target wasm32-unknown-unknown + +clippy: + $(cargo) +$(nightly) clippy --workspace -- -D warnings + +clippy-fix: + $(cargo) +$(nightly) clippy --fix -Z unstable-options --workspace --allow-dirty --allow-staged + +fmt: + $(cargo) +$(nightly) fmt + +fmt-check: + $(cargo) +$(nightly) fmt --check + +test: + $(cargo) +$(nightly) test -- -Z unstable-options --report-time + +clean: + $(cargo) clean + +deps: + $(rustup) target add wasm32-unknown-unknown + +.PHONY: all debug check clippy clippy-fix fmt fmt-check test clean deps \ No newline at end of file diff --git a/wasm_for_tests/README.md b/wasm_for_tests/README.md new file mode 100644 index 0000000000..9ae40634f3 --- /dev/null +++ b/wasm_for_tests/README.md @@ -0,0 +1,12 @@ +# WASM source code in Rust + +This crate contains WASM implementations of various transactions and validity predicates, used for testing. + +## Quick start + +```shell +# To be able to build this, make sure to have +make deps + +# Build - this will output .wasm files in the parent dir +make all diff --git a/wasm_for_tests/release.toml b/wasm_for_tests/release.toml new file mode 100644 index 0000000000..3a264faa08 --- /dev/null +++ b/wasm_for_tests/release.toml @@ -0,0 +1,7 @@ +allow-branch = ["main", "maint-*"] +consolidate-commits = true +pre-release-commit-message = "fixup! Namada {{version}}" +publish = false +push = false +shared-version = true +tag = false diff --git a/wasm_for_tests/tx_fail.wasm b/wasm_for_tests/tx_fail.wasm index dc63cb3a47..c133ea8e64 100755 Binary files a/wasm_for_tests/tx_fail.wasm and b/wasm_for_tests/tx_fail.wasm differ diff --git a/wasm_for_tests/tx_fail/Cargo.toml b/wasm_for_tests/tx_fail/Cargo.toml new file mode 100644 index 0000000000..03fd1a3235 --- /dev/null +++ b/wasm_for_tests/tx_fail/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "tx_fail" +description = "Wasm transaction used for testing." +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_test_utils.workspace = true +namada_tx_prelude.workspace = true +namada_vp_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada_tests = { path = "../../crates/tests", default-features = false, features = [ + "wasm-runtime", +] } + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm_for_tests/tx_fail/src/lib.rs b/wasm_for_tests/tx_fail/src/lib.rs new file mode 100644 index 0000000000..df94e287d4 --- /dev/null +++ b/wasm_for_tests/tx_fail/src/lib.rs @@ -0,0 +1,6 @@ +use namada_tx_prelude::*; + +#[transaction] +fn apply_tx(_ctx: &mut Ctx, _tx_data: Tx) -> TxResult { + Err(Error::SimpleMessage("failed tx")) +} diff --git a/wasm_for_tests/tx_infinite_guest_gas.wasm b/wasm_for_tests/tx_infinite_guest_gas.wasm index e04a0779b4..befe9c6726 100755 Binary files a/wasm_for_tests/tx_infinite_guest_gas.wasm and b/wasm_for_tests/tx_infinite_guest_gas.wasm differ diff --git a/wasm_for_tests/tx_infinite_guest_gas/Cargo.toml b/wasm_for_tests/tx_infinite_guest_gas/Cargo.toml new file mode 100644 index 0000000000..d4734326ff --- /dev/null +++ b/wasm_for_tests/tx_infinite_guest_gas/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "tx_infinite_guest_gas" +description = "Wasm transaction used for testing." +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_test_utils.workspace = true +namada_tx_prelude.workspace = true +namada_vp_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada_tests = { path = "../../crates/tests", default-features = false, features = [ + "wasm-runtime", +] } + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm_for_tests/tx_infinite_guest_gas/src/lib.rs b/wasm_for_tests/tx_infinite_guest_gas/src/lib.rs new file mode 100644 index 0000000000..a6d63067ac --- /dev/null +++ b/wasm_for_tests/tx_infinite_guest_gas/src/lib.rs @@ -0,0 +1,8 @@ +use namada_tx_prelude::*; + +/// A tx that endlessly charges gas from the guest environment +#[transaction] +fn apply_tx(_ctx: &mut Ctx, _tx_data: Tx) -> TxResult { + #[allow(clippy::empty_loop)] + loop {} +} diff --git a/wasm_for_tests/tx_infinite_host_gas.wasm b/wasm_for_tests/tx_infinite_host_gas.wasm index 9129edbd28..48c2adb274 100755 Binary files a/wasm_for_tests/tx_infinite_host_gas.wasm and b/wasm_for_tests/tx_infinite_host_gas.wasm differ diff --git a/wasm_for_tests/tx_infinite_host_gas/Cargo.toml b/wasm_for_tests/tx_infinite_host_gas/Cargo.toml new file mode 100644 index 0000000000..1c6167e9ba --- /dev/null +++ b/wasm_for_tests/tx_infinite_host_gas/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "tx_infinite_host_gas" +description = "Wasm transaction used for testing." +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_test_utils.workspace = true +namada_tx_prelude.workspace = true +namada_vp_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada_tests = { path = "../../crates/tests", default-features = false, features = [ + "wasm-runtime", +] } + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm_for_tests/tx_infinite_host_gas/src/lib.rs b/wasm_for_tests/tx_infinite_host_gas/src/lib.rs new file mode 100644 index 0000000000..b15e7ab276 --- /dev/null +++ b/wasm_for_tests/tx_infinite_host_gas/src/lib.rs @@ -0,0 +1,12 @@ +use namada_tx_prelude::*; + +/// A tx that endlessly charges gas from the host environment +#[transaction] +fn apply_tx(ctx: &mut Ctx, _tx_data: Tx) -> TxResult { + let target_key = parameters_storage::get_tx_allowlist_storage_key(); + loop { + // NOTE: don't propagate the error to verify that execution abortion + // is done in host and does not require guest cooperation + let _ = ctx.write(&target_key, vec!["hash"]); + } +} diff --git a/wasm_for_tests/tx_invalid_data.wasm b/wasm_for_tests/tx_invalid_data.wasm index 9ae23573fc..1e38fef5d4 100755 Binary files a/wasm_for_tests/tx_invalid_data.wasm and b/wasm_for_tests/tx_invalid_data.wasm differ diff --git a/wasm_for_tests/tx_invalid_data/Cargo.toml b/wasm_for_tests/tx_invalid_data/Cargo.toml new file mode 100644 index 0000000000..329aa86081 --- /dev/null +++ b/wasm_for_tests/tx_invalid_data/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "tx_invalid_data" +description = "Wasm transaction used for testing." +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_test_utils.workspace = true +namada_tx_prelude.workspace = true +namada_vp_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada_tests = { path = "../../crates/tests", default-features = false, features = [ + "wasm-runtime", +] } + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm_for_tests/tx_invalid_data/src/lib.rs b/wasm_for_tests/tx_invalid_data/src/lib.rs new file mode 100644 index 0000000000..eda9df65c4 --- /dev/null +++ b/wasm_for_tests/tx_invalid_data/src/lib.rs @@ -0,0 +1,11 @@ +use namada_tx_prelude::*; + +#[transaction] +fn apply_tx(ctx: &mut Ctx, tx_data: Tx) -> TxResult { + let signed = tx_data; + let _data = signed.data().ok_or_err_msg("Missing data").map_err(|err| { + ctx.set_commitment_sentinel(); + err + })?; + Ok(()) +} diff --git a/wasm_for_tests/tx_memory_limit.wasm b/wasm_for_tests/tx_memory_limit.wasm index 2c8bc9ca12..dd5b173a0f 100755 Binary files a/wasm_for_tests/tx_memory_limit.wasm and b/wasm_for_tests/tx_memory_limit.wasm differ diff --git a/wasm_for_tests/tx_memory_limit/Cargo.toml b/wasm_for_tests/tx_memory_limit/Cargo.toml new file mode 100644 index 0000000000..434ebe0b88 --- /dev/null +++ b/wasm_for_tests/tx_memory_limit/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "tx_memory_limit" +description = "Wasm transaction used for testing." +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_test_utils.workspace = true +namada_tx_prelude.workspace = true +namada_vp_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada_tests = { path = "../../crates/tests", default-features = false, features = [ + "wasm-runtime", +] } + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm_for_tests/tx_memory_limit/src/lib.rs b/wasm_for_tests/tx_memory_limit/src/lib.rs new file mode 100644 index 0000000000..a9a17ebde5 --- /dev/null +++ b/wasm_for_tests/tx_memory_limit/src/lib.rs @@ -0,0 +1,12 @@ +use namada_tx_prelude::*; + +#[transaction] +fn apply_tx(_ctx: &mut Ctx, tx_data: Tx) -> TxResult { + let len = + usize::try_from_slice(&tx_data.data().as_ref().unwrap()[..]).unwrap(); + log_string(format!("allocate len {}", len)); + let bytes: Vec = vec![6_u8; len]; + // use the variable to prevent it from compiler optimizing it away + log_string(format!("{:?}", &bytes[..8])); + Ok(()) +} diff --git a/wasm_for_tests/tx_mint_tokens.wasm b/wasm_for_tests/tx_mint_tokens.wasm deleted file mode 100755 index 761e1a14e9..0000000000 Binary files a/wasm_for_tests/tx_mint_tokens.wasm and /dev/null differ diff --git a/wasm_for_tests/tx_no_op.wasm b/wasm_for_tests/tx_no_op.wasm index 1b85a13bef..60830f4a2d 100755 Binary files a/wasm_for_tests/tx_no_op.wasm and b/wasm_for_tests/tx_no_op.wasm differ diff --git a/wasm_for_tests/tx_no_op/Cargo.toml b/wasm_for_tests/tx_no_op/Cargo.toml new file mode 100644 index 0000000000..665504cdf1 --- /dev/null +++ b/wasm_for_tests/tx_no_op/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "tx_no_op" +description = "Wasm transaction used for testing." +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_test_utils.workspace = true +namada_tx_prelude.workspace = true +namada_vp_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada_tests = { path = "../../crates/tests", default-features = false, features = [ + "wasm-runtime", +] } + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm_for_tests/tx_no_op/src/lib.rs b/wasm_for_tests/tx_no_op/src/lib.rs new file mode 100644 index 0000000000..a819b73be6 --- /dev/null +++ b/wasm_for_tests/tx_no_op/src/lib.rs @@ -0,0 +1,6 @@ +use namada_tx_prelude::*; + +#[transaction] +fn apply_tx(_ctx: &mut Ctx, _tx_data: Tx) -> TxResult { + Ok(()) +} diff --git a/wasm_for_tests/tx_proposal_code.wasm b/wasm_for_tests/tx_proposal_code.wasm index a2d9a0d8c3..cb04028e69 100755 Binary files a/wasm_for_tests/tx_proposal_code.wasm and b/wasm_for_tests/tx_proposal_code.wasm differ diff --git a/wasm_for_tests/tx_proposal_code/Cargo.toml b/wasm_for_tests/tx_proposal_code/Cargo.toml new file mode 100644 index 0000000000..eaaa7177e6 --- /dev/null +++ b/wasm_for_tests/tx_proposal_code/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "tx_proposal_code" +description = "Wasm transaction used for testing." +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_test_utils.workspace = true +namada_tx_prelude.workspace = true +namada_vp_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada_tests = { path = "../../crates/tests", default-features = false, features = [ + "wasm-runtime", +] } + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm_for_tests/tx_proposal_code/src/lib.rs b/wasm_for_tests/tx_proposal_code/src/lib.rs new file mode 100644 index 0000000000..2d050755e7 --- /dev/null +++ b/wasm_for_tests/tx_proposal_code/src/lib.rs @@ -0,0 +1,13 @@ +use namada_tx_prelude::*; + +#[transaction] +fn apply_tx(ctx: &mut Ctx, _tx_data: Tx) -> TxResult { + // governance + let target_key = gov_storage::keys::get_min_proposal_grace_epochs_key(); + ctx.write(&target_key, 9_u64)?; + + // parameters + let target_key = parameters_storage::get_vp_allowlist_storage_key(); + ctx.write(&target_key, vec!["hash"])?; + Ok(()) +} diff --git a/wasm_for_tests/tx_proposal_ibc_token_inflation.wasm b/wasm_for_tests/tx_proposal_ibc_token_inflation.wasm index f0d6593fd0..40333f8ba3 100755 Binary files a/wasm_for_tests/tx_proposal_ibc_token_inflation.wasm and b/wasm_for_tests/tx_proposal_ibc_token_inflation.wasm differ diff --git a/wasm_for_tests/tx_proposal_ibc_token_inflation/Cargo.toml b/wasm_for_tests/tx_proposal_ibc_token_inflation/Cargo.toml new file mode 100644 index 0000000000..25d31ccd51 --- /dev/null +++ b/wasm_for_tests/tx_proposal_ibc_token_inflation/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "tx_proposal_ibc_token_inflation" +description = "Wasm transaction used for testing." +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_test_utils.workspace = true +namada_tx_prelude.workspace = true +namada_vp_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada_tests = { path = "../../crates/tests", default-features = false, features = [ + "wasm-runtime", +] } + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm_for_tests/tx_proposal_ibc_token_inflation/src/lib.rs b/wasm_for_tests/tx_proposal_ibc_token_inflation/src/lib.rs new file mode 100644 index 0000000000..176dc0eeaa --- /dev/null +++ b/wasm_for_tests/tx_proposal_ibc_token_inflation/src/lib.rs @@ -0,0 +1,57 @@ +use std::str::FromStr; + +use dec::Dec; +use namada_tx_prelude::*; + +// Denom of tokens over IBC is always zero +const IBC_TOKEN_DENOM: u8 = 0; +const CHANNEL_ID: &str = "channel-0"; +const BASE_TOKEN: &str = "tnam1qyvfwdkz8zgs9n3qn9xhp8scyf8crrxwuq26r6gy"; + +#[transaction] +fn apply_tx(ctx: &mut Ctx, _tx_data: Tx) -> TxResult { + let ibc_denom = format!("transfer/{CHANNEL_ID}/{BASE_TOKEN}"); + let ibc_token = ibc::ibc_token(&ibc_denom); + + let shielded_token_last_inflation_key = + token::storage_key::masp_last_inflation_key(&ibc_token); + let shielded_token_last_locked_amount_key = + token::storage_key::masp_last_locked_amount_key(&ibc_token); + let shielded_token_max_rewards_key = + token::storage_key::masp_max_reward_rate_key(&ibc_token); + let shielded_token_target_locked_amount_key = + token::storage_key::masp_locked_amount_target_key(&ibc_token); + let shielded_token_kp_gain_key = + token::storage_key::masp_kp_gain_key(&ibc_token); + let shielded_token_kd_gain_key = + token::storage_key::masp_kd_gain_key(&ibc_token); + + let token_map_key = token::storage_key::masp_token_map_key(); + let mut token_map: masp::TokenMap = + ctx.read(&token_map_key)?.unwrap_or_default(); + token_map.insert(ibc_denom, ibc_token); + ctx.write(&token_map_key, token_map)?; + + ctx.write(&shielded_token_last_inflation_key, token::Amount::zero())?; + ctx.write( + &shielded_token_last_locked_amount_key, + token::Amount::zero(), + )?; + ctx.write( + &shielded_token_max_rewards_key, + Dec::from_str("0.01").unwrap(), + )?; + ctx.write( + &shielded_token_target_locked_amount_key, + token::Amount::from_uint(1_000_000_000, IBC_TOKEN_DENOM).unwrap(), + )?; + ctx.write( + &shielded_token_kp_gain_key, + Dec::from_str("120000").unwrap(), + )?; + ctx.write( + &shielded_token_kd_gain_key, + Dec::from_str("120000").unwrap(), + )?; + Ok(()) +} diff --git a/wasm_for_tests/tx_proposal_masp_reward.wasm b/wasm_for_tests/tx_proposal_masp_reward.wasm index f54edf14a5..5535ba4213 100755 Binary files a/wasm_for_tests/tx_proposal_masp_reward.wasm and b/wasm_for_tests/tx_proposal_masp_reward.wasm differ diff --git a/wasm_for_tests/tx_proposal_masp_reward/Cargo.toml b/wasm_for_tests/tx_proposal_masp_reward/Cargo.toml new file mode 100644 index 0000000000..83dd4e1f61 --- /dev/null +++ b/wasm_for_tests/tx_proposal_masp_reward/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "tx_proposal_masp_reward" +description = "Wasm transaction used for testing." +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_test_utils.workspace = true +namada_tx_prelude.workspace = true +namada_vp_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada_tests = { path = "../../crates/tests", default-features = false, features = [ + "wasm-runtime", +] } + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm_for_tests/tx_proposal_masp_reward/src/lib.rs b/wasm_for_tests/tx_proposal_masp_reward/src/lib.rs new file mode 100644 index 0000000000..5ca9e23d77 --- /dev/null +++ b/wasm_for_tests/tx_proposal_masp_reward/src/lib.rs @@ -0,0 +1,15 @@ +use std::str::FromStr; + +use dec::Dec; +use namada_tx_prelude::*; + +#[transaction] +fn apply_tx(ctx: &mut Ctx, _tx_data: Tx) -> TxResult { + let native_token = ctx.get_native_token()?; + let shielded_rewards_key = + token::storage_key::masp_max_reward_rate_key(&native_token); + + ctx.write(&shielded_rewards_key, Dec::from_str("0.05").unwrap())?; + + Ok(()) +} diff --git a/wasm_for_tests/tx_read_storage_key.wasm b/wasm_for_tests/tx_read_storage_key.wasm index e084776585..6c8c68fee7 100755 Binary files a/wasm_for_tests/tx_read_storage_key.wasm and b/wasm_for_tests/tx_read_storage_key.wasm differ diff --git a/wasm_for_tests/tx_read_storage_key/Cargo.toml b/wasm_for_tests/tx_read_storage_key/Cargo.toml new file mode 100644 index 0000000000..8d6f97fa22 --- /dev/null +++ b/wasm_for_tests/tx_read_storage_key/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "tx_read_storage_key" +description = "Wasm transaction used for testing." +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_test_utils.workspace = true +namada_tx_prelude.workspace = true +namada_vp_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada_tests = { path = "../../crates/tests", default-features = false, features = [ + "wasm-runtime", +] } + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm_for_tests/tx_read_storage_key/src/lib.rs b/wasm_for_tests/tx_read_storage_key/src/lib.rs new file mode 100644 index 0000000000..fab14f404a --- /dev/null +++ b/wasm_for_tests/tx_read_storage_key/src/lib.rs @@ -0,0 +1,12 @@ +use namada_tx_prelude::*; + +#[transaction] +fn apply_tx(ctx: &mut Ctx, tx_data: Tx) -> TxResult { + // Allocates a memory of size given from the `tx_data (usize)` + let key = + storage::Key::try_from_slice(&tx_data.data().as_ref().unwrap()[..]) + .unwrap(); + log_string(format!("key {}", key)); + let _result: Vec = ctx.read(&key)?.unwrap(); + Ok(()) +} diff --git a/wasm_for_tests/tx_write.wasm b/wasm_for_tests/tx_write.wasm index 90e09886f7..321f95bc50 100755 Binary files a/wasm_for_tests/tx_write.wasm and b/wasm_for_tests/tx_write.wasm differ diff --git a/wasm_for_tests/tx_write/Cargo.toml b/wasm_for_tests/tx_write/Cargo.toml new file mode 100644 index 0000000000..25ee6acc5a --- /dev/null +++ b/wasm_for_tests/tx_write/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "tx_write" +description = "Wasm transaction used for testing." +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_test_utils.workspace = true +namada_tx_prelude.workspace = true +namada_vp_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada_tests = { path = "../../crates/tests", default-features = false, features = [ + "wasm-runtime", +] } + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm_for_tests/tx_write/src/lib.rs b/wasm_for_tests/tx_write/src/lib.rs new file mode 100644 index 0000000000..f8fd53f71b --- /dev/null +++ b/wasm_for_tests/tx_write/src/lib.rs @@ -0,0 +1,58 @@ +use namada_test_utils::tx_data::TxWriteData; +use namada_tx_prelude::*; + +const TX_NAME: &str = "tx_write"; + +fn log(msg: &str) { + log_string(format!("[{}] {}", TX_NAME, msg)) +} + +fn fatal(msg: &str, err: impl std::error::Error) -> ! { + log(&format!("ERROR: {} - {:?}", msg, err)); + panic!() +} + +fn fatal_msg(msg: &str) -> ! { + log(msg); + panic!() +} + +#[transaction] +fn apply_tx(ctx: &mut Ctx, tx_data: Tx) -> TxResult { + let signed = tx_data; + let data = match signed.data() { + Some(data) => { + log(&format!("got data ({} bytes)", data.len())); + data + } + None => { + fatal_msg("no data provided"); + } + }; + let TxWriteData { key, value } = + match TxWriteData::try_from_slice(&data[..]) { + Ok(write_op) => { + log(&format!( + "parsed WriteOp to key {} ({} bytes)", + &write_op.key, + &write_op.value.len(), + )); + write_op + } + Err(error) => fatal("deserializing WriteOp", error), + }; + let existing_value: Option = ctx.read(&key)?; + match existing_value { + Some(existing_value) => { + log(&format!("already present value is {}", existing_value)); + } + None => { + log("no already present value"); + } + } + log(&format!("attempting to write new value to key {}", key)); + // using `ctx.write_bytes` instead of `ctx.write` here, as we want to + // write the actual bytes, not a Borsh-serialization of a `Vec` + ctx.write_bytes(&key, &value[..])?; + Ok(()) +} diff --git a/wasm_for_tests/tx_write_storage_key.wasm b/wasm_for_tests/tx_write_storage_key.wasm deleted file mode 100755 index 2f6e3946b4..0000000000 Binary files a/wasm_for_tests/tx_write_storage_key.wasm and /dev/null differ diff --git a/wasm_for_tests/vp_always_false.wasm b/wasm_for_tests/vp_always_false.wasm index 0b1672cf59..f01e3167fb 100755 Binary files a/wasm_for_tests/vp_always_false.wasm and b/wasm_for_tests/vp_always_false.wasm differ diff --git a/wasm_for_tests/vp_always_false/Cargo.toml b/wasm_for_tests/vp_always_false/Cargo.toml new file mode 100644 index 0000000000..c3211d7e01 --- /dev/null +++ b/wasm_for_tests/vp_always_false/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "vp_always_false" +description = "Wasm vp used for testing." +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_test_utils.workspace = true +namada_tx_prelude.workspace = true +namada_vp_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada_tests = { path = "../../crates/tests", default-features = false, features = [ + "wasm-runtime", +] } + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm_for_tests/vp_always_false/src/lib.rs b/wasm_for_tests/vp_always_false/src/lib.rs new file mode 100644 index 0000000000..17b64ddbd6 --- /dev/null +++ b/wasm_for_tests/vp_always_false/src/lib.rs @@ -0,0 +1,12 @@ +use namada_vp_prelude::*; + +#[validity_predicate] +fn validate_tx( + _ctx: &Ctx, + _tx_data: Tx, + _addr: Address, + _keys_changed: BTreeSet, + _verifiers: BTreeSet
, +) -> VpResult { + reject() +} diff --git a/wasm_for_tests/vp_always_true.wasm b/wasm_for_tests/vp_always_true.wasm index 5ac5977994..4422ebaef0 100755 Binary files a/wasm_for_tests/vp_always_true.wasm and b/wasm_for_tests/vp_always_true.wasm differ diff --git a/wasm_for_tests/vp_always_true/Cargo.toml b/wasm_for_tests/vp_always_true/Cargo.toml new file mode 100644 index 0000000000..b790d374a1 --- /dev/null +++ b/wasm_for_tests/vp_always_true/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "vp_always_true" +description = "Wasm vp used for testing." +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_test_utils.workspace = true +namada_tx_prelude.workspace = true +namada_vp_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada_tests = { path = "../../crates/tests", default-features = false, features = [ + "wasm-runtime", +] } + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm_for_tests/vp_always_true/src/lib.rs b/wasm_for_tests/vp_always_true/src/lib.rs new file mode 100644 index 0000000000..55daff519a --- /dev/null +++ b/wasm_for_tests/vp_always_true/src/lib.rs @@ -0,0 +1,12 @@ +use namada_vp_prelude::*; + +#[validity_predicate] +fn validate_tx( + _ctx: &Ctx, + _tx_data: Tx, + _addr: Address, + _keys_changed: BTreeSet, + _verifiers: BTreeSet
, +) -> VpResult { + accept() +} diff --git a/wasm_for_tests/vp_eval.wasm b/wasm_for_tests/vp_eval.wasm index b4cc97f944..bc49415cfb 100755 Binary files a/wasm_for_tests/vp_eval.wasm and b/wasm_for_tests/vp_eval.wasm differ diff --git a/wasm_for_tests/vp_eval/Cargo.toml b/wasm_for_tests/vp_eval/Cargo.toml new file mode 100644 index 0000000000..dfd2aa4520 --- /dev/null +++ b/wasm_for_tests/vp_eval/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "vp_eval" +description = "Wasm vp used for testing." +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_test_utils.workspace = true +namada_tx_prelude.workspace = true +namada_vp_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada_tests = { path = "../../crates/tests", default-features = false, features = [ + "wasm-runtime", +] } + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm_for_tests/vp_eval/src/lib.rs b/wasm_for_tests/vp_eval/src/lib.rs new file mode 100644 index 0000000000..be8deecb96 --- /dev/null +++ b/wasm_for_tests/vp_eval/src/lib.rs @@ -0,0 +1,18 @@ +use namada_vp_prelude::*; + +#[validity_predicate] +fn validate_tx( + ctx: &Ctx, + tx_data: Tx, + _addr: Address, + _keys_changed: BTreeSet, + _verifiers: BTreeSet
, +) -> VpResult { + use namada_tx_prelude::transaction::eval_vp::EvalVp; + let EvalVp { + vp_code_hash, + input, + }: EvalVp = + EvalVp::try_from_slice(&tx_data.data().as_ref().unwrap()[..]).unwrap(); + ctx.eval(vp_code_hash, input).into_vp_error() +} diff --git a/wasm_for_tests/vp_infinite_guest_gas.wasm b/wasm_for_tests/vp_infinite_guest_gas.wasm index f66c513b73..2e2fd81ccc 100755 Binary files a/wasm_for_tests/vp_infinite_guest_gas.wasm and b/wasm_for_tests/vp_infinite_guest_gas.wasm differ diff --git a/wasm_for_tests/vp_infinite_guest_gas/Cargo.toml b/wasm_for_tests/vp_infinite_guest_gas/Cargo.toml new file mode 100644 index 0000000000..976e458fef --- /dev/null +++ b/wasm_for_tests/vp_infinite_guest_gas/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "vp_infinite_guest_gas" +description = "Wasm vp used for testing." +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_test_utils.workspace = true +namada_tx_prelude.workspace = true +namada_vp_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada_tests = { path = "../../crates/tests", default-features = false, features = [ + "wasm-runtime", +] } + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm_for_tests/vp_infinite_guest_gas/src/lib.rs b/wasm_for_tests/vp_infinite_guest_gas/src/lib.rs new file mode 100644 index 0000000000..5e7f66e08d --- /dev/null +++ b/wasm_for_tests/vp_infinite_guest_gas/src/lib.rs @@ -0,0 +1,15 @@ + +use namada_vp_prelude::*; + +/// A vp that endlessly charges gas from the guest environment +#[validity_predicate] +fn validate_tx( + _ctx: &Ctx, + _tx_data: Tx, + _addr: Address, + _keys_changed: BTreeSet, + _verifiers: BTreeSet
, +) -> VpResult { + #[allow(clippy::empty_loop)] + loop {} +} diff --git a/wasm_for_tests/vp_infinite_host_gas.wasm b/wasm_for_tests/vp_infinite_host_gas.wasm index 01f2ce9968..09696a2e26 100755 Binary files a/wasm_for_tests/vp_infinite_host_gas.wasm and b/wasm_for_tests/vp_infinite_host_gas.wasm differ diff --git a/wasm_for_tests/vp_infinite_host_gas/Cargo.toml b/wasm_for_tests/vp_infinite_host_gas/Cargo.toml new file mode 100644 index 0000000000..5908f8a48d --- /dev/null +++ b/wasm_for_tests/vp_infinite_host_gas/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "vp_infinite_host_gas" +description = "Wasm vp used for testing." +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_test_utils.workspace = true +namada_tx_prelude.workspace = true +namada_vp_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada_tests = { path = "../../crates/tests", default-features = false, features = [ + "wasm-runtime", +] } + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm_for_tests/vp_infinite_host_gas/src/lib.rs b/wasm_for_tests/vp_infinite_host_gas/src/lib.rs new file mode 100644 index 0000000000..bf0ee79041 --- /dev/null +++ b/wasm_for_tests/vp_infinite_host_gas/src/lib.rs @@ -0,0 +1,19 @@ +use namada_vp_prelude::*; + +/// A vp that endlessly charges gas from the host environment +#[validity_predicate] +fn validate_tx( + ctx: &Ctx, + _tx_data: Tx, + _addr: Address, + _keys_changed: BTreeSet, + _verifiers: BTreeSet
, +) -> VpResult { + let target_key = + namada_tx_prelude::parameters_storage::get_tx_allowlist_storage_key(); + loop { + // NOTE: don't propagate the error to verify that execution abortion + // is done in host and does not require guest cooperation + let _ = ctx.read_bytes_pre(&target_key); + } +} diff --git a/wasm_for_tests/vp_memory_limit.wasm b/wasm_for_tests/vp_memory_limit.wasm index 663e3ebf25..2cbb0e2fb3 100755 Binary files a/wasm_for_tests/vp_memory_limit.wasm and b/wasm_for_tests/vp_memory_limit.wasm differ diff --git a/wasm_for_tests/vp_memory_limit/Cargo.toml b/wasm_for_tests/vp_memory_limit/Cargo.toml new file mode 100644 index 0000000000..23aef54c5f --- /dev/null +++ b/wasm_for_tests/vp_memory_limit/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "vp_memory_limit" +description = "Wasm vp used for testing." +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_test_utils.workspace = true +namada_tx_prelude.workspace = true +namada_vp_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada_tests = { path = "../../crates/tests", default-features = false, features = [ + "wasm-runtime", +] } + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm_for_tests/vp_memory_limit/src/lib.rs b/wasm_for_tests/vp_memory_limit/src/lib.rs new file mode 100644 index 0000000000..09284f61b1 --- /dev/null +++ b/wasm_for_tests/vp_memory_limit/src/lib.rs @@ -0,0 +1,18 @@ +use namada_vp_prelude::*; + +#[validity_predicate] +fn validate_tx( + _ctx: &Ctx, + tx_data: Tx, + _addr: Address, + _keys_changed: BTreeSet, + _verifiers: BTreeSet
, +) -> VpResult { + let len = + usize::try_from_slice(&tx_data.data().as_ref().unwrap()[..]).unwrap(); + log_string(format!("allocate len {}", len)); + let bytes: Vec = vec![6_u8; len]; + // use the variable to prevent it from compiler optimizing it away + log_string(format!("{:?}", &bytes[..8])); + accept() +} diff --git a/wasm_for_tests/vp_read_storage_key.wasm b/wasm_for_tests/vp_read_storage_key.wasm index 1d37962592..7b8f5b3283 100755 Binary files a/wasm_for_tests/vp_read_storage_key.wasm and b/wasm_for_tests/vp_read_storage_key.wasm differ diff --git a/wasm_for_tests/vp_read_storage_key/Cargo.toml b/wasm_for_tests/vp_read_storage_key/Cargo.toml new file mode 100644 index 0000000000..ef545b8c7b --- /dev/null +++ b/wasm_for_tests/vp_read_storage_key/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "vp_read_storage_key" +description = "Wasm vp used for testing." +authors.workspace = true +edition.workspace = true +license.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +namada_test_utils.workspace = true +namada_tx_prelude.workspace = true +namada_vp_prelude.workspace = true +wee_alloc.workspace = true +getrandom.workspace = true + +[dev-dependencies] +namada_tests = { path = "../../crates/tests", default-features = false, features = [ + "wasm-runtime", +] } + +proptest = "1.4.0" +test-log = {version = "0.2.14", default-features = false, features = ["trace"]} +tracing = "0.1.30" +tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]} + +[lib] +crate-type = ["cdylib"] \ No newline at end of file diff --git a/wasm_for_tests/vp_read_storage_key/src/lib.rs b/wasm_for_tests/vp_read_storage_key/src/lib.rs new file mode 100644 index 0000000000..40bc8a4a53 --- /dev/null +++ b/wasm_for_tests/vp_read_storage_key/src/lib.rs @@ -0,0 +1,18 @@ +use namada_vp_prelude::*; + +#[validity_predicate] +fn validate_tx( + ctx: &Ctx, + tx_data: Tx, + _addr: Address, + _keys_changed: BTreeSet, + _verifiers: BTreeSet
, +) -> VpResult { + // Allocates a memory of size given from the `tx_data (usize)` + let key = + storage::Key::try_from_slice(&tx_data.data().as_ref().unwrap()[..]) + .unwrap(); + log_string(format!("key {}", key)); + let _result: Vec = ctx.read_pre(&key).into_vp_error()?.unwrap(); + accept() +} diff --git a/wasm_for_tests/wasm_source/.gitignore b/wasm_for_tests/wasm_source/.gitignore deleted file mode 100644 index 5028f0063a..0000000000 --- a/wasm_for_tests/wasm_source/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -# Generated by Cargo -# will have compiled files and executables -debug/ -target/ - -# These are backup files generated by rustfmt -**/*.rs.bk \ No newline at end of file diff --git a/wasm_for_tests/wasm_source/Makefile b/wasm_for_tests/wasm_source/Makefile deleted file mode 100644 index d741e8f33a..0000000000 --- a/wasm_for_tests/wasm_source/Makefile +++ /dev/null @@ -1,88 +0,0 @@ -cargo := $(env) cargo -rustup := $(env) rustup -# Nightly build is currently used for rustfmt and clippy. -nightly := $(shell cat ../../rust-nightly-version) - -# All the wasms that can be built from this source, switched via Cargo features -# Wasms can be added via the Cargo.toml `[features]` list. -wasms := tx_memory_limit -wasms += tx_no_op -wasms += tx_fail -wasms += tx_infinite_guest_gas -wasms += tx_infinite_host_gas -wasms += tx_invalid_data -wasms += tx_proposal_code -wasms += tx_proposal_masp_reward -wasms += tx_proposal_ibc_token_inflation -wasms += tx_read_storage_key -wasms += tx_write -wasms += vp_always_false -wasms += vp_always_true -wasms += vp_eval -wasms += vp_infinite_guest_gas -wasms += vp_infinite_host_gas -wasms += vp_memory_limit -wasms += vp_read_storage_key - - -# Build all wasms -all: - make $(wasms) - make opt-wasm - -# `cargo check` all wasms -check: - $(foreach wasm,$(wasms),make check_$(wasm) && ) true - -# `cargo test` all wasms -test: - $(foreach wasm,$(wasms),make test_$(wasm) && ) true - -# `cargo clippy` all wasms -clippy: - $(foreach wasm,$(wasms),make clippy_$(wasm) && ) true - -clippy-fix: - $(cargo) +$(nightly) clippy --fix -Z unstable-options --all-targets --allow-dirty --allow-staged - -fmt: - $(cargo) +$(nightly) fmt --all - -fmt-check: - $(cargo) +$(nightly) fmt --all -- --check - -# Build a selected wasm -$(wasms): %: - $(cargo) build --release --target wasm32-unknown-unknown --target-dir 'target' --features $@ && \ - cp "./target/wasm32-unknown-unknown/release/namada_wasm_for_tests.wasm" ../$@.wasm - -# `cargo check` one of the wasms, e.g. `make check_tx_no_op` -$(patsubst %,check_%,$(wasms)): check_%: - $(cargo) check --target wasm32-unknown-unknown --features $* - -# `cargo test` one of the wasms, e.g. `make test_tx_no_op` -$(patsubst %,test_%,$(wasms)): test_%: - $(cargo) test --features $* \ - -- \ - -Z unstable-options --report-time - -# `cargo watch` one of the wasms, e.g. `make watch_tx_no_op` -$(patsubst %,watch_%,$(wasms)): watch_%: - $(cargo) watch --features $* - -# `cargo clippy` one of the wasms, e.g. `make clippy_tx_no_op` -$(patsubst %,clippy_%,$(wasms)): clippy_%: - $(cargo) +$(nightly) clippy --all-targets --features $* -- -D warnings - -clean-wasm = rm ../$(wasm).wasm -clean: - $(foreach wasm,$(wasms),$(clean-wasm) && ) true - -deps: - $(rustup) target add wasm32-unknown-unknown - -# this command needs wasm-opt installed -opt-wasm: - @for file in $(shell ls ../*.wasm); do wasm-opt -Oz -o $${file} $${file}; done - -.PHONY : all check test clippy fmt fmt-check clean deps opt-wasm diff --git a/wasm_for_tests/wasm_source/README.md b/wasm_for_tests/wasm_source/README.md deleted file mode 100644 index 07d1f3f976..0000000000 --- a/wasm_for_tests/wasm_source/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# WASM source code in Rust - -This crate contains WASM implementations of various transactions and validity predicates, used for testing. - -## Quick start - -```shell -# To be able to build this, make sure to have -make deps - -# Build - this will output .wasm files in the parent dir -make all - -# Each source that is included here can also be build and checked individually, e.g. for "tx_no_op" source: - -make tx_no_op # build -make check_tx_no_op # cargo check -make test_tx_no_op # cargo test -make watch_tx_no_op # cargo watch -make clippy_tx_no_op # cargo clippy -``` diff --git a/wasm_for_tests/wasm_source/release.toml b/wasm_for_tests/wasm_source/release.toml deleted file mode 100644 index dbacf2cec3..0000000000 --- a/wasm_for_tests/wasm_source/release.toml +++ /dev/null @@ -1,7 +0,0 @@ -allow-branch = ["main", "maint-*"] -consolidate-commits = true -pre-release-commit-message = "fixup! Namada {{version}}" -publish = false -push = false -shared-version = true -tag = false diff --git a/wasm_for_tests/wasm_source/src/lib.rs b/wasm_for_tests/wasm_source/src/lib.rs deleted file mode 100644 index 601278bf68..0000000000 --- a/wasm_for_tests/wasm_source/src/lib.rs +++ /dev/null @@ -1,412 +0,0 @@ -/// A tx that doesn't do anything. -#[cfg(feature = "tx_no_op")] -pub mod main { - use namada_tx_prelude::*; - - #[transaction] - fn apply_tx(_ctx: &mut Ctx, _tx_data: Tx) -> TxResult { - Ok(()) - } -} - -/// A tx that fails every time. -#[cfg(feature = "tx_fail")] -pub mod main { - use namada_tx_prelude::*; - - #[transaction] - fn apply_tx(_ctx: &mut Ctx, _tx_data: Tx) -> TxResult { - Err(Error::SimpleMessage("failed tx")) - } -} - -/// A tx that allocates a memory of size given from the `tx_data: usize`. -#[cfg(feature = "tx_memory_limit")] -pub mod main { - use namada_tx_prelude::*; - - #[transaction] - fn apply_tx(_ctx: &mut Ctx, tx_data: Tx) -> TxResult { - let len = usize::try_from_slice(&tx_data.data().as_ref().unwrap()[..]) - .unwrap(); - log_string(format!("allocate len {}", len)); - let bytes: Vec = vec![6_u8; len]; - // use the variable to prevent it from compiler optimizing it away - log_string(format!("{:?}", &bytes[..8])); - Ok(()) - } -} - -/// A tx that endlessly charges gas from the host environment -#[cfg(feature = "tx_infinite_host_gas")] -pub mod main { - use namada_tx_prelude::*; - - #[transaction] - fn apply_tx(ctx: &mut Ctx, _tx_data: Tx) -> TxResult { - let target_key = parameters_storage::get_tx_allowlist_storage_key(); - loop { - // NOTE: don't propagate the error to verify that execution abortion - // is done in host and does not require guest cooperation - let _ = ctx.write(&target_key, vec!["hash"]); - } - } -} - -/// A tx that endlessly charges gas from the guest environment -#[cfg(feature = "tx_infinite_guest_gas")] -pub mod main { - use namada_tx_prelude::*; - - #[transaction] - fn apply_tx(_ctx: &mut Ctx, _tx_data: Tx) -> TxResult { - #[allow(clippy::empty_loop)] - loop {} - } -} - -/// A tx to be used as proposal_code -#[cfg(feature = "tx_proposal_code")] -pub mod main { - use namada_tx_prelude::*; - - #[transaction] - fn apply_tx(ctx: &mut Ctx, _tx_data: Tx) -> TxResult { - // governance - let target_key = gov_storage::keys::get_min_proposal_grace_epochs_key(); - ctx.write(&target_key, 9_u64)?; - - // parameters - let target_key = parameters_storage::get_vp_allowlist_storage_key(); - ctx.write(&target_key, vec!["hash"])?; - Ok(()) - } -} - -/// A tx to be used as proposal_code for changing shielded rewards -#[cfg(feature = "tx_proposal_masp_reward")] -pub mod main { - use std::str::FromStr; - - use dec::Dec; - use namada_tx_prelude::*; - - #[transaction] - fn apply_tx(ctx: &mut Ctx, _tx_data: Tx) -> TxResult { - let native_token = ctx.get_native_token()?; - let shielded_rewards_key = - token::storage_key::masp_max_reward_rate_key(&native_token); - - ctx.write(&shielded_rewards_key, Dec::from_str("0.05").unwrap())?; - - Ok(()) - } -} - -/// A tx to be used as proposal_code to set the inflation params for a token -/// over IBC -#[cfg(feature = "tx_proposal_ibc_token_inflation")] -pub mod main { - use std::str::FromStr; - - use dec::Dec; - use namada_tx_prelude::*; - - // Denom of tokens over IBC is always zero - const IBC_TOKEN_DENOM: u8 = 0; - const CHANNEL_ID: &str = "channel-0"; - const BASE_TOKEN: &str = "tnam1qyvfwdkz8zgs9n3qn9xhp8scyf8crrxwuq26r6gy"; - - #[transaction(gas = 1000)] - fn apply_tx(ctx: &mut Ctx, _tx_data: Tx) -> TxResult { - let ibc_denom = format!("transfer/{CHANNEL_ID}/{BASE_TOKEN}"); - let ibc_token = ibc::ibc_token(&ibc_denom); - - let shielded_token_last_inflation_key = - token::storage_key::masp_last_inflation_key(&ibc_token); - let shielded_token_last_locked_amount_key = - token::storage_key::masp_last_locked_amount_key(&ibc_token); - let shielded_token_max_rewards_key = - token::storage_key::masp_max_reward_rate_key(&ibc_token); - let shielded_token_target_locked_amount_key = - token::storage_key::masp_locked_amount_target_key(&ibc_token); - let shielded_token_kp_gain_key = - token::storage_key::masp_kp_gain_key(&ibc_token); - let shielded_token_kd_gain_key = - token::storage_key::masp_kd_gain_key(&ibc_token); - - let token_map_key = token::storage_key::masp_token_map_key(); - let mut token_map: masp::TokenMap = - ctx.read(&token_map_key)?.unwrap_or_default(); - token_map.insert(ibc_denom, ibc_token); - ctx.write(&token_map_key, token_map)?; - - ctx.write(&shielded_token_last_inflation_key, token::Amount::zero())?; - ctx.write( - &shielded_token_last_locked_amount_key, - token::Amount::zero(), - )?; - ctx.write( - &shielded_token_max_rewards_key, - Dec::from_str("0.01").unwrap(), - )?; - ctx.write( - &shielded_token_target_locked_amount_key, - token::Amount::from_uint(1_000_000_000, IBC_TOKEN_DENOM).unwrap(), - )?; - ctx.write( - &shielded_token_kp_gain_key, - Dec::from_str("120000").unwrap(), - )?; - ctx.write( - &shielded_token_kd_gain_key, - Dec::from_str("120000").unwrap(), - )?; - Ok(()) - } -} - -/// A tx that attempts to read the given key from storage. -#[cfg(feature = "tx_read_storage_key")] -pub mod main { - use namada_tx_prelude::*; - - #[transaction] - fn apply_tx(ctx: &mut Ctx, tx_data: Tx) -> TxResult { - // Allocates a memory of size given from the `tx_data (usize)` - let key = - storage::Key::try_from_slice(&tx_data.data().as_ref().unwrap()[..]) - .unwrap(); - log_string(format!("key {}", key)); - let _result: Vec = ctx.read(&key)?.unwrap(); - Ok(()) - } -} - -/// A tx that attempts to write arbitrary data to the given key -#[cfg(feature = "tx_write")] -pub mod main { - use namada_test_utils::tx_data::TxWriteData; - use namada_tx_prelude::*; - - const TX_NAME: &str = "tx_write"; - - fn log(msg: &str) { - log_string(format!("[{}] {}", TX_NAME, msg)) - } - - fn fatal(msg: &str, err: impl std::error::Error) -> ! { - log(&format!("ERROR: {} - {:?}", msg, err)); - panic!() - } - - fn fatal_msg(msg: &str) -> ! { - log(msg); - panic!() - } - - #[transaction] - fn apply_tx(ctx: &mut Ctx, tx_data: Tx) -> TxResult { - let signed = tx_data; - let data = match signed.data() { - Some(data) => { - log(&format!("got data ({} bytes)", data.len())); - data - } - None => { - fatal_msg("no data provided"); - } - }; - let TxWriteData { key, value } = - match TxWriteData::try_from_slice(&data[..]) { - Ok(write_op) => { - log(&format!( - "parsed WriteOp to key {} ({} bytes)", - &write_op.key, - &write_op.value.len(), - )); - write_op - } - Err(error) => fatal("deserializing WriteOp", error), - }; - let existing_value: Option = ctx.read(&key)?; - match existing_value { - Some(existing_value) => { - log(&format!("already present value is {}", existing_value)); - } - None => { - log("no already present value"); - } - } - log(&format!("attempting to write new value to key {}", key)); - // using `ctx.write_bytes` instead of `ctx.write` here, as we want to - // write the actual bytes, not a Borsh-serialization of a `Vec` - ctx.write_bytes(&key, &value[..])?; - Ok(()) - } -} - -#[cfg(feature = "tx_invalid_data")] -pub mod main { - use namada_tx_prelude::*; - - #[transaction(gas = 1000)] - fn apply_tx(ctx: &mut Ctx, tx_data: Tx) -> TxResult { - let signed = tx_data; - let _data = - signed.data().ok_or_err_msg("Missing data").map_err(|err| { - ctx.set_commitment_sentinel(); - err - })?; - Ok(()) - } -} - -/// A VP that always returns `true`. -#[cfg(feature = "vp_always_true")] -pub mod main { - use namada_vp_prelude::*; - - #[validity_predicate] - fn validate_tx( - _ctx: &Ctx, - _tx_data: Tx, - _addr: Address, - _keys_changed: BTreeSet, - _verifiers: BTreeSet
, - ) -> VpResult { - accept() - } -} - -/// A VP that always returns `false`. -#[cfg(feature = "vp_always_false")] -pub mod main { - use namada_vp_prelude::*; - - #[validity_predicate] - fn validate_tx( - _ctx: &Ctx, - _tx_data: Tx, - _addr: Address, - _keys_changed: BTreeSet, - _verifiers: BTreeSet
, - ) -> VpResult { - reject() - } -} - -/// A VP that runs the VP given in `tx_data` via `eval`. It returns the result -/// of `eval`. -#[cfg(feature = "vp_eval")] -pub mod main { - use namada_vp_prelude::*; - - #[validity_predicate] - fn validate_tx( - ctx: &Ctx, - tx_data: Tx, - _addr: Address, - _keys_changed: BTreeSet, - _verifiers: BTreeSet
, - ) -> VpResult { - use namada_tx_prelude::transaction::eval_vp::EvalVp; - let EvalVp { - vp_code_hash, - input, - }: EvalVp = - EvalVp::try_from_slice(&tx_data.data().as_ref().unwrap()[..]) - .unwrap(); - ctx.eval(vp_code_hash, input).into_vp_error() - } -} - -// A VP that allocates a memory of size given from the `tx_data: usize`. -// Returns `true`, if the allocation is within memory limits. -#[cfg(feature = "vp_memory_limit")] -pub mod main { - use namada_vp_prelude::*; - - #[validity_predicate] - fn validate_tx( - _ctx: &Ctx, - tx_data: Tx, - _addr: Address, - _keys_changed: BTreeSet, - _verifiers: BTreeSet
, - ) -> VpResult { - let len = usize::try_from_slice(&tx_data.data().as_ref().unwrap()[..]) - .unwrap(); - log_string(format!("allocate len {}", len)); - let bytes: Vec = vec![6_u8; len]; - // use the variable to prevent it from compiler optimizing it away - log_string(format!("{:?}", &bytes[..8])); - accept() - } -} - -/// A VP that attempts to read the given key from storage (state prior to tx -/// execution). Returns `true`, if the allocation is within memory limits. -#[cfg(feature = "vp_read_storage_key")] -pub mod main { - use namada_vp_prelude::*; - - #[validity_predicate] - fn validate_tx( - ctx: &Ctx, - tx_data: Tx, - _addr: Address, - _keys_changed: BTreeSet, - _verifiers: BTreeSet
, - ) -> VpResult { - // Allocates a memory of size given from the `tx_data (usize)` - let key = - storage::Key::try_from_slice(&tx_data.data().as_ref().unwrap()[..]) - .unwrap(); - log_string(format!("key {}", key)); - let _result: Vec = ctx.read_pre(&key).into_vp_error()?.unwrap(); - accept() - } -} - -/// A vp that endlessly charges gas from the host environment -#[cfg(feature = "vp_infinite_host_gas")] -pub mod main { - use namada_vp_prelude::*; - - #[validity_predicate] - fn validate_tx( - ctx: &Ctx, - _tx_data: Tx, - _addr: Address, - _keys_changed: BTreeSet, - _verifiers: BTreeSet
, - ) -> VpResult { - let target_key = - namada_tx_prelude::parameters_storage::get_tx_allowlist_storage_key( - ); - loop { - // NOTE: don't propagate the error to verify that execution abortion - // is done in host and does not require guest cooperation - let _ = ctx.read_bytes_pre(&target_key); - } - } -} - -/// A vp that endlessly charges gas from the guest environment -#[cfg(feature = "vp_infinite_guest_gas")] -pub mod main { - use namada_vp_prelude::*; - - #[validity_predicate] - fn validate_tx( - _ctx: &Ctx, - _tx_data: Tx, - _addr: Address, - _keys_changed: BTreeSet, - _verifiers: BTreeSet
, - ) -> VpResult { - #[allow(clippy::empty_loop)] - loop {} - } -}