From bb3b1a30977c04a2b4cd3725c91d22a2fd82b4d2 Mon Sep 17 00:00:00 2001 From: Bobbin Threadbare Date: Wed, 12 Jun 2024 01:11:05 -0700 Subject: [PATCH 1/3] feat: backport changes for v0.3.1 release --- .config/nextest.toml | 9 +- .github/workflows/build.yml | 39 +++++++++ .github/workflows/lint.yml | 44 ++++------ .github/workflows/no-std.yml | 30 ------- .github/workflows/test.yml | 25 +++--- CHANGELOG.md | 4 + Cargo.lock | 91 ++++++++++++--------- Makefile | 84 +++++++++++++++++++ Makefile.toml | 113 -------------------------- miden-tx/Cargo.toml | 2 + miden-tx/src/executor/data_store.rs | 3 + miden-tx/src/executor/mod.rs | 18 ++-- miden-tx/src/host/tx_authenticator.rs | 2 +- miden-tx/src/tests.rs | 3 + miden-tx/tests/integration/main.rs | 3 + objects/src/assets/mod.rs | 12 +-- objects/src/block/header.rs | 2 +- 17 files changed, 236 insertions(+), 248 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/no-std.yml create mode 100644 Makefile delete mode 100644 Makefile.toml diff --git a/.config/nextest.toml b/.config/nextest.toml index 1ba5fd25c..ffdd281a3 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -1,15 +1,8 @@ [profile.default] -slow-timeout = { period = "5s", terminate-after = 2 } - -[profile.prove] -# A test which also generates a proof takes around 1min to complete on a M2 -slow-timeout = { period = "120s", terminate-after = 2 } - -[profile.ci-default] failure-output = "immediate-final" fail-fast = false -[profile.ci-prove] +[profile.prove] # A test which also generates a proof takes around 120sec to complete in the CI slow-timeout = { period = "200s", terminate-after = 2 } failure-output = "immediate-final" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..129fa1a90 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,39 @@ +# Runs build related jobs. + +name: build + +on: + push: + branches: [main, next] + pull_request: + types: [opened, reopened, synchronize] + +jobs: + async: + name: Build using `async` feature + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + toolchain: [stable, nightly] + steps: + - uses: actions/checkout@main + - name: Build using `async` feature + run: | + rustup update --no-self-update ${{ matrix.toolchain }} + make build-async + + no-std: + name: Build for no-std + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + toolchain: [stable, nightly] + steps: + - uses: actions/checkout@main + - name: Build for no-std + run: | + rustup update --no-self-update ${{ matrix.toolchain }} + rustup target add wasm32-unknown-unknown + make build-no-std diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 1f9e6a9e8..63fbdb86d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -3,18 +3,17 @@ name: lint on: - push: - branches: - - main - pull_request: - types: [opened, reopened, synchronize] + push: + branches: [main, next] + pull_request: + types: [opened, reopened, synchronize] jobs: version: name: check rust version consistency runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@main with: profile: minimal override: true @@ -25,29 +24,20 @@ jobs: name: rustfmt check nightly on ubuntu-latest runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Install minimal Rust with rustfmt & cargo-make - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - components: rustfmt - override: true - - uses: davidB/rust-cargo-make@v1 - - name: cargo make - format-check - run: cargo make format-check + - uses: actions/checkout@main + - name: Rustfmt + run: | + rustup update --no-self-update nightly + rustup +nightly component add rustfmt + make format-check clippy: name: clippy stable on ubuntu-latest runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Install minimal Rust with clippy & cargo-make - uses: actions-rs/toolchain@v1 - with: - profile: minimal - components: clippy - override: true - - uses: davidB/rust-cargo-make@v1 - - name: cargo make - clippy - run: cargo make clippy + - uses: actions/checkout@main + - name: Install minimal Rust with clippy + run: | + rustup update --no-self-update nightly + rustup +nightly component add clippy + make clippy diff --git a/.github/workflows/no-std.yml b/.github/workflows/no-std.yml deleted file mode 100644 index 8ede3cfca..000000000 --- a/.github/workflows/no-std.yml +++ /dev/null @@ -1,30 +0,0 @@ -# Runs no-std related jobs. - -name: no-std - -on: - push: - branches: - - main - pull_request: - types: [opened, reopened, synchronize] - -jobs: - no-std: - name: build ${{matrix.toolchain}} no-std for wasm32-unknown-unknown - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - toolchain: [stable, nightly] - steps: - - uses: actions/checkout@v4 - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{matrix.toolchain}} - override: true - - run: rustup target add wasm32-unknown-unknown - - uses: davidB/rust-cargo-make@v1 - - name: cargo make - build-no-std - run: cargo make build-no-std diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 13484187d..8738507b8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,11 +1,12 @@ +# Runs build related jobs. + name: test on: push: - branches: - - main + branches: [main, next] pull_request: - types: [opened, reopened, synchronize] + types: [opened, reopened, synchronize] jobs: test: @@ -16,16 +17,12 @@ jobs: matrix: toolchain: [stable, nightly] os: [ubuntu] - args: ["default", "prove"] + args: [default, prove] timeout-minutes: 30 steps: - - uses: actions/checkout@v4 - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{matrix.toolchain}} - override: true - - uses: davidB/rust-cargo-make@v1 - - uses: taiki-e/install-action@nextest - - name: cargo make - test - run: cargo make ci-test-${{matrix.args}} + - uses: actions/checkout@main + - uses: taiki-e/install-action@nextest + - name: Perform tests + run: | + rustup update --no-self-update ${{matrix.toolchain}} + make test-${{matrix.args}} diff --git a/CHANGELOG.md b/CHANGELOG.md index d6beab1c6..260cd9cec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.3.1 (2024-06-12) +* Replaced `cargo-make` with just `make` for running tasks (#696). +* Made `DataStore` conditionally async using `winter-maybe-async` (#725) + ## 0.3.0 (2024-05-14) * Introduce the `miden-bench-tx` crate used for transactions benchmarking (#577). diff --git a/Cargo.lock b/Cargo.lock index d0ff1ed8f..6730d82ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -49,9 +49,9 @@ dependencies = [ [[package]] name = "anstyle-query" -version = "1.0.3" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5" +checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" dependencies = [ "windows-sys", ] @@ -135,9 +135,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.0.97" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" dependencies = [ "jobserver", "libc", @@ -179,9 +179,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.4" +version = "4.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +checksum = "5db83dced34638ad474f39f250d7fea9598bdd239eaced1bdf45d597da0f433f" dependencies = [ "clap_builder", "clap_derive", @@ -189,9 +189,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.2" +version = "4.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +checksum = "f7e204572485eb3fbf28f871612191521df159bc3e15a9f5064c66dba3a8c05f" dependencies = [ "anstream", "anstyle", @@ -201,9 +201,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.4" +version = "4.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" +checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6" dependencies = [ "heck", "proc-macro2", @@ -213,9 +213,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" +checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" [[package]] name = "cobs" @@ -305,9 +305,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.19" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" [[package]] name = "crunchy" @@ -337,9 +337,9 @@ dependencies = [ [[package]] name = "either" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" [[package]] name = "embedded-io" @@ -544,9 +544,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.154" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libm" @@ -556,9 +556,9 @@ checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "linux-raw-sys" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "lock_api" @@ -720,9 +720,9 @@ dependencies = [ [[package]] name = "miden-stdlib" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60994609096a8cb1e32f1fcf1c8ed63bed9b24b32730658609bad841e8caeaf9" +checksum = "71db091ccda04c854d2da3ee4978c14066bf93442c246de8585ffa22f8b0e5ef" dependencies = [ "miden-assembly", ] @@ -739,6 +739,7 @@ dependencies = [ "miden-verifier", "rand", "rand_chacha", + "winter-maybe-async", ] [[package]] @@ -895,9 +896,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.82" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" dependencies = [ "unicode-ident", ] @@ -973,9 +974,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.4" +version = "1.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" dependencies = [ "aho-corasick", "memchr", @@ -985,9 +986,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", @@ -996,9 +997,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "rustc_version" @@ -1051,18 +1052,18 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.201" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.201" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", @@ -1114,9 +1115,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.63" +version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ "proc-macro2", "quote", @@ -1147,9 +1148,9 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" [[package]] name = "toml_edit" @@ -1204,9 +1205,9 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "utf8parse" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "version_check" @@ -1367,6 +1368,16 @@ dependencies = [ "winter-utils", ] +[[package]] +name = "winter-maybe-async" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77eafc7944188b941c90759b938b8377247ee6e440952a0a7c4dbde7edc4ecbb" +dependencies = [ + "quote", + "syn", +] + [[package]] name = "winter-prover" version = "0.8.3" diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..2bf6d1b03 --- /dev/null +++ b/Makefile @@ -0,0 +1,84 @@ +.DEFAULT_GOAL := help + +.PHONY: help +help: + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +# -- variables -------------------------------------------------------------------------------------- + +WARNINGS=RUSTDOCFLAGS="-D warnings" +DEBUG_ASSERTIONS=RUSTFLAGS="-C debug-assertions" +ALL_FEATURES_BUT_ASYNC=--features concurrent,testing,serde + +# -- linting -------------------------------------------------------------------------------------- + +.PHONY: clippy +clippy: ## Runs Clippy with configs + cargo +nightly clippy --workspace --all-targets $(ALL_FEATURES_BUT_ASYNC) -- -D warnings + + +.PHONY: fix +fix: ## Runs Fix with configs + cargo +nightly fix --allow-staged --allow-dirty --all-targets $(ALL_FEATURES_BUT_ASYNC) + + +.PHONY: format +format: ## Runs Format using nightly toolchain + cargo +nightly fmt --all + + +.PHONY: format-check +format-check: ## Runs Format using nightly toolchain but only in check mode + cargo +nightly fmt --all --check + + +.PHONY: lint +lint: format fix clippy ## Runs all linting tasks at once (Clippy, fixing, formatting) + +# --- docs ---------------------------------------------------------------------------------------- + +.PHONY: doc +doc: ## Generates & checks documentation + $(WARNINGS) cargo doc $(ALL_FEATURES_BUT_ASYNC) --keep-going --release + + +.PHONY: doc-serve +doc-serve: ## Serves documentation site + ./scripts/serve-doc-site.sh + +# --- testing ------------------------------------------------------------------------------------- + +.PHONY: test-default +test-default: ## Run default tests excluding `prove` + $(DEBUG_ASSERTIONS) cargo nextest run --profile default --cargo-profile test-release --features concurrent,testing --filter-expr "not test(prove)" + + +.PHONY: test-prove +test-prove: ## Run `prove` tests (tests which use the Miden prover) + $(DEBUG_ASSERTIONS) cargo nextest run --profile prove --cargo-profile test-release --features concurrent,testing --filter-expr "test(prove)" + + +.PHONY: test +test: test-default test-prove ## Run all tests + +# --- building ------------------------------------------------------------------------------------ + +.PHONY: build +build: ## By default we should build in release mode + cargo build --release + + +.PHONY: build-no-std +build-no-std: ## Build without the standard library + cargo build --no-default-features --target wasm32-unknown-unknown --workspace --exclude miden-bench-tx --exclude miden-mock + +.PHONY: build-async +build-async: ## Build with the `async` feature enabled (only libraries) + cargo build --lib --release --features async + + +# --- benchmarking -------------------------------------------------------------------------------- + +.PHONY: bench-tx +bench-tx: ## Run transaction benchmarks + cargo run --bin bench-tx \ No newline at end of file diff --git a/Makefile.toml b/Makefile.toml deleted file mode 100644 index 96751e6aa..000000000 --- a/Makefile.toml +++ /dev/null @@ -1,113 +0,0 @@ -# Cargo Makefile - -# This env variable is need by cargo-make to enable correct functionality of commands -# in the context of a rust workspace: https://github.com/sagiegurari/cargo-make?tab=readme-ov-file#usage -[env] -CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true - -# -- linting -------------------------------------------------------------------------------------- -[tasks.clippy] -description = "Runs Clippy" -command = "cargo" -args = ["clippy", "--workspace", "--all-targets", "--all-features", "--", "-D", "warnings"] - -[tasks.fix] -description = "Runs Fix" -command = "cargo" -toolchain = "nightly" -args = ["fix", "--allow-staged", "--allow-dirty", "--all-targets", "--all-features"] - -[tasks.format] -toolchain = "nightly" -command = "cargo" -args = ["fmt", "--all"] - -[tasks.format-check] -toolchain = "nightly" -command = "cargo" -args = ["fmt", "--all", "--check"] - -[tasks.lint] -description = "Runs all linting tasks (Clippy, fixing, formatting)" -dependencies = [ - "fix", - "format", - "clippy" -] - -# --- docs ---------------------------------------------------------------------------------------- -[tasks.doc] -env = { "RUSTDOCFLAGS" = "-D warnings" } -command = "cargo" -args = ["doc", "--all-features", "--keep-going", "--release"] - -[tasks.doc-serve] -workspace = false -script = [ "./scripts/serve-doc-site.sh" ] - -# --- testing ------------------------------------------------------------------------------------- -[tasks.test] -disabled = true - -[tasks.test-default] -description = "Run default tests excluding `prove`" -workspace = false -env = { "RUSTFLAGS" = "-C debug-assertions" } -command = "cargo" -args = ["nextest", "run", "--profile", "default", "--cargo-profile", "test-release", "--features", "concurrent,testing", "--filter-expr", "not test(prove)"] - -[tasks.test-prove] -description = "Run `prove` tests (tests which use the Miden prover)" -workspace = false -env = { "RUSTFLAGS" = "-C debug-assertions" } -command = "cargo" -args = ["nextest", "run", "--profile", "prove", "--cargo-profile", "test-release", "--features", "concurrent,testing", "--filter-expr", "test(prove)"] - -[tasks.test-all] -description = "Run all tests" -workspace = false -env = { "RUSTFLAGS" = "-C debug-assertions" } -run_task = { name = ["test-default", "test-prove"], parallel = true } - -[tasks.ci-test-default] -description = "Run default tests excluding `prove`" -workspace = false -command = "cargo" -args = ["nextest", "run", "--profile", "ci-default", "--cargo-profile", "test-release", "--features", "concurrent,testing", "--filter-expr", "not test(prove)"] - -[tasks.ci-test-prove] -description = "Run `prove` tests (tests which use the Miden prover)" -workspace = false -command = "cargo" -args = ["nextest", "run", "--profile", "ci-prove", "--cargo-profile", "test-release", "--features", "concurrent,testing", "--filter-expr", "test(prove)"] - -[tasks.ci-test-all] -description = "Run all tests" -workspace = false -env = { "RUSTFLAGS" = "-C debug-assertions" } -run_task = { name = ["nextest-default", "nextest-prove"], parallel = true } - -# --- building ------------------------------------------------------------------------------------ -[tasks.build] -description = "Build in release mode" -command = "cargo" -args = ["build", "--release"] - -[tasks.build-no-std] -description = "Build using no-std" -command = "cargo" -args = ["build", "--no-default-features", "--target", "wasm32-unknown-unknown", "--workspace", "--exclude", "miden-mock", "--exclude", "miden-bench-tx"] - -# --- benchmarking -------------------------------------------------------------------------------- -[tasks.bench-tx] -description = "Run all available transaction benchmarks" -workspace = false -command = "cargo" -args = ["run", "--bin", "bench-tx"] - -# --- utilities ----------------------------------------------------------------------------------- -[tasks.watch] -description = "Watch for changes and rebuild" -workspace = false -command = "cargo" -args = ["watch", "-w", "miden-lib/asm", "-x", "build"] diff --git a/miden-tx/Cargo.toml b/miden-tx/Cargo.toml index af34d8526..ddd56464b 100644 --- a/miden-tx/Cargo.toml +++ b/miden-tx/Cargo.toml @@ -17,6 +17,7 @@ name = "miden-tx" path = "tests/integration/main.rs" [features] +async = ["winter-maybe-async/async"] concurrent = ["miden-lib/concurrent", "miden-objects/concurrent", "miden-prover/concurrent", "std"] default = ["std"] std = ["miden-lib/std", "miden-objects/std", "miden-prover/std", "miden-verifier/std", "vm-processor/std"] @@ -28,6 +29,7 @@ miden-prover = { workspace = true } miden-verifier = { workspace = true } rand = { workspace = true } vm-processor = { workspace = true } +winter-maybe-async = { version = "0.10.0" } [dev-dependencies] mock = { package = "miden-mock", path = "../mock", default-features = false } diff --git a/miden-tx/src/executor/data_store.rs b/miden-tx/src/executor/data_store.rs index cbf877bdf..5bdcc09d7 100644 --- a/miden-tx/src/executor/data_store.rs +++ b/miden-tx/src/executor/data_store.rs @@ -1,6 +1,7 @@ use miden_objects::{ accounts::AccountId, assembly::ModuleAst, notes::NoteId, transaction::TransactionInputs, }; +use winter_maybe_async::maybe_async; use crate::DataStoreError; @@ -25,6 +26,7 @@ pub trait DataStore { /// - Any of the notes with the specified IDs were already consumed. /// - The combination of specified inputs resulted in a transaction input error. /// - The data store encountered some internal error + #[maybe_async] fn get_transaction_inputs( &self, account_id: AccountId, @@ -33,5 +35,6 @@ pub trait DataStore { ) -> Result; /// Returns the account code [ModuleAst] associated with the specified [AccountId]. + #[maybe_async] fn get_account_code(&self, account_id: AccountId) -> Result; } diff --git a/miden-tx/src/executor/mod.rs b/miden-tx/src/executor/mod.rs index c9b2941e5..a3ea359c9 100644 --- a/miden-tx/src/executor/mod.rs +++ b/miden-tx/src/executor/mod.rs @@ -8,6 +8,7 @@ use miden_objects::{ Felt, Word, ZERO, }; use vm_processor::ExecutionOptions; +use winter_maybe_async::{maybe_async, maybe_await}; use super::{ AccountCode, AccountId, Digest, ExecutedTransaction, NoteId, NoteScript, PreparedTransaction, @@ -102,13 +103,12 @@ impl TransactionExecutor { /// Returns an error if: /// - If the account code cannot be fetched from the [DataStore]. /// - If the account code fails to be loaded into the compiler. + #[maybe_async] pub fn load_account( &mut self, account_id: AccountId, ) -> Result { - let account_code = self - .data_store - .get_account_code(account_id) + let account_code = maybe_await!(self.data_store.get_account_code(account_id)) .map_err(TransactionExecutorError::FetchAccountCodeFailed)?; self.compiler .load_account(account_id, account_code) @@ -174,6 +174,7 @@ impl TransactionExecutor { /// - If required data can not be fetched from the [DataStore]. /// - If the transaction program can not be compiled. /// - If the transaction program can not be executed. + #[maybe_async] pub fn execute_transaction( &self, account_id: AccountId, @@ -181,7 +182,8 @@ impl TransactionExecutor { notes: &[NoteId], tx_args: TransactionArgs, ) -> Result { - let transaction = self.prepare_transaction(account_id, block_ref, notes, tx_args)?; + let transaction = + maybe_await!(self.prepare_transaction(account_id, block_ref, notes, tx_args))?; let (stack_inputs, advice_inputs) = transaction.get_kernel_inputs(); let advice_recorder: RecAdviceProvider = advice_inputs.into(); @@ -221,6 +223,7 @@ impl TransactionExecutor { /// Returns an error if: /// - If required data can not be fetched from the [DataStore]. /// - If the transaction can not be compiled. + #[maybe_async] pub fn prepare_transaction( &self, account_id: AccountId, @@ -228,10 +231,9 @@ impl TransactionExecutor { notes: &[NoteId], tx_args: TransactionArgs, ) -> Result { - let tx_inputs = self - .data_store - .get_transaction_inputs(account_id, block_ref, notes) - .map_err(TransactionExecutorError::FetchTransactionInputsFailed)?; + let tx_inputs = + maybe_await!(self.data_store.get_transaction_inputs(account_id, block_ref, notes)) + .map_err(TransactionExecutorError::FetchTransactionInputsFailed)?; let tx_program = self .compiler diff --git a/miden-tx/src/host/tx_authenticator.rs b/miden-tx/src/host/tx_authenticator.rs index 80b76effa..b14f6914b 100644 --- a/miden-tx/src/host/tx_authenticator.rs +++ b/miden-tx/src/host/tx_authenticator.rs @@ -114,7 +114,7 @@ impl TransactionAuthenticator for BasicAuthenticator { /// 2. The expanded public key represented as the coefficients of a polynomial of degree < 512. /// 3. The signature represented as the coefficients of a polynomial of degree < 512. /// 4. The product of the above two polynomials in the ring of polynomials with coefficients -/// in the Miden field. +/// in the Miden field. /// /// # Errors /// Will return an error if either: diff --git a/miden-tx/src/tests.rs b/miden-tx/src/tests.rs index a2f3fdf51..dacef6ba9 100644 --- a/miden-tx/src/tests.rs +++ b/miden-tx/src/tests.rs @@ -41,6 +41,7 @@ use vm_processor::{ utils::{Deserializable, Serializable}, Digest, MemAdviceProvider, }; +use winter_maybe_async::maybe_async; use super::{ AccountId, DataStore, DataStoreError, TransactionExecutor, TransactionHost, TransactionInputs, @@ -659,6 +660,7 @@ impl Default for MockDataStore { } impl DataStore for MockDataStore { + #[maybe_async] fn get_transaction_inputs( &self, account_id: AccountId, @@ -686,6 +688,7 @@ impl DataStore for MockDataStore { .unwrap()) } + #[maybe_async] fn get_account_code(&self, account_id: AccountId) -> Result { assert_eq!(account_id, self.account.id()); Ok(self.account.code().module().clone()) diff --git a/miden-tx/tests/integration/main.rs b/miden-tx/tests/integration/main.rs index 53a271b5e..14bdb3cc5 100644 --- a/miden-tx/tests/integration/main.rs +++ b/miden-tx/tests/integration/main.rs @@ -33,6 +33,7 @@ use mock::{ }; use rand_chacha::{rand_core::SeedableRng, ChaCha20Rng}; use vm_processor::utils::Deserializable; +use winter_maybe_async::maybe_async; // MOCK DATA STORE // ================================================================================================ @@ -98,6 +99,7 @@ impl Default for MockDataStore { } impl DataStore for MockDataStore { + #[maybe_async] fn get_transaction_inputs( &self, account_id: AccountId, @@ -125,6 +127,7 @@ impl DataStore for MockDataStore { .unwrap()) } + #[maybe_async] fn get_account_code(&self, account_id: AccountId) -> Result { assert_eq!(account_id, self.account.id()); Ok(self.account.code().module().clone()) diff --git a/objects/src/assets/mod.rs b/objects/src/assets/mod.rs index cde4f4c74..8d5ccec4d 100644 --- a/objects/src/assets/mod.rs +++ b/objects/src/assets/mod.rs @@ -25,12 +25,12 @@ pub use vault::AssetVault; /// /// All assets are encoded using a single word (4 elements) such that it is easy to determine the /// type of an asset both inside and outside Miden VM. Specifically: -/// Element 1 will be: -/// - ZERO for a fungible asset -/// - non-ZERO for a non-fungible asset -/// The 3rd most significant bit will be: -/// - 1 for a fungible asset -/// - 0 for a non-fungible asset +/// - Element 1 will be: +/// - ZERO for a fungible asset +/// - non-ZERO for a non-fungible asset +/// - The 3rd most significant bit will be: +/// - 1 for a fungible asset +/// - 0 for a non-fungible asset /// /// The above properties guarantee that there can never be a collision between a fungible and a /// non-fungible asset. diff --git a/objects/src/block/header.rs b/objects/src/block/header.rs index 931ab51ec..00df92a1b 100644 --- a/objects/src/block/header.rs +++ b/objects/src/block/header.rs @@ -231,7 +231,7 @@ impl Deserializable for BlockHeader { } } -#[cfg(feature = "testing")] +#[cfg(all(feature = "testing", not(target_family = "wasm")))] mod mock { use alloc::vec::Vec; From cd59d087588bc3b0d26236356e70671b5be58bc7 Mon Sep 17 00:00:00 2001 From: Dominik Schmid <35031754+Dominik1999@users.noreply.github.com> Date: Wed, 12 Jun 2024 17:52:40 +0800 Subject: [PATCH 2/3] fix: StorageMap bug for patch release (#745) --- CHANGELOG.md | 1 + objects/src/accounts/mod.rs | 83 ++++++++++++++++++++++++----- objects/src/accounts/storage/mod.rs | 67 +++++++++++++++++++++-- objects/src/errors.rs | 3 +- 4 files changed, 136 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 260cd9cec..681661631 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 0.3.1 (2024-06-12) * Replaced `cargo-make` with just `make` for running tasks (#696). * Made `DataStore` conditionally async using `winter-maybe-async` (#725) +* Fixed `StorageMap`s implementation and included into apply_delta (#745) ## 0.3.0 (2024-05-14) diff --git a/objects/src/accounts/mod.rs b/objects/src/accounts/mod.rs index 9bdd37d9c..4f5f2839b 100644 --- a/objects/src/accounts/mod.rs +++ b/objects/src/accounts/mod.rs @@ -302,14 +302,19 @@ pub mod testing { }, code::testing::make_account_code, Account, AccountDelta, AccountId, AccountStorage, AccountStorageDelta, AccountVaultDelta, - Felt, SlotItem, StorageSlot, StorageSlotType, Word, + Felt, SlotItem, StorageMap, StorageSlot, StorageSlotType, Word, }; use crate::assets::{Asset, AssetVault, FungibleAsset}; // UTILITIES // -------------------------------------------------------------------------------------------- - pub fn build_account(assets: Vec, nonce: Felt, storage_items: Vec) -> Account { + pub fn build_account( + assets: Vec, + nonce: Felt, + storage_items: Vec, + storage_map: Option, + ) -> Account { let id = AccountId::try_from(ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN).unwrap(); let code = make_account_code(); @@ -317,7 +322,7 @@ pub mod testing { let vault = AssetVault::new(&assets).unwrap(); let slot_type = StorageSlotType::Value { value_arity: 0 }; - let slot_items: Vec = storage_items + let mut slot_items: Vec = storage_items .into_iter() .enumerate() .map(|(index, item)| SlotItem { @@ -325,7 +330,24 @@ pub mod testing { slot: StorageSlot { slot_type, value: item }, }) .collect(); - let storage = AccountStorage::new(slot_items, vec![]).unwrap(); + + let mut maps = Vec::new(); + let slot_type_map = StorageSlotType::Map { value_arity: 0 }; + if let Some(storage_map) = storage_map { + let map_item = SlotItem { + // slot index * 10 to avoid conflicts with value slots + // this should only stay until we merge next with the proper solution + index: 100_u8, + slot: StorageSlot { + slot_type: slot_type_map, + value: storage_map.root().into(), + }, + }; + slot_items.push(map_item); + maps.push(storage_map); + } + + let storage = AccountStorage::new(slot_items, maps).unwrap(); Account::new(id, vault, storage, code, nonce) } @@ -361,15 +383,18 @@ mod tests { Felt, Word, }; - use super::{testing::*, AccountDelta, AccountStorageDelta, AccountVaultDelta}; - use crate::accounts::{delta::AccountStorageDeltaBuilder, Account}; + use super::{testing::*, AccountDelta, AccountStorageDelta, AccountVaultDelta, Digest}; + use crate::accounts::{ + delta::{AccountStorageDeltaBuilder, StorageMapDelta}, + Account, StorageMap, + }; #[test] fn test_serde_account() { let init_nonce = Felt::new(1); let (asset_0, _) = build_assets(); let word = [Felt::new(1), Felt::new(2), Felt::new(3), Felt::new(4)]; - let account = build_account(vec![asset_0], init_nonce, vec![word]); + let account = build_account(vec![asset_0], init_nonce, vec![word], None); let serialized = account.to_bytes(); let deserialized = Account::read_from_bytes(&serialized).unwrap(); @@ -399,13 +424,38 @@ mod tests { let init_nonce = Felt::new(1); let (asset_0, asset_1) = build_assets(); let word = [Felt::new(1), Felt::new(2), Felt::new(3), Felt::new(4)]; - let mut account = build_account(vec![asset_0], init_nonce, vec![word]); + // StorageMap with values + let storage_map_leaves_2: [(Digest, Word); 2] = [ + ( + Digest::new([Felt::new(101), Felt::new(102), Felt::new(103), Felt::new(104)]), + [Felt::new(1_u64), Felt::new(2_u64), Felt::new(3_u64), Felt::new(4_u64)], + ), + ( + Digest::new([Felt::new(105), Felt::new(106), Felt::new(107), Felt::new(108)]), + [Felt::new(5_u64), Felt::new(6_u64), Felt::new(7_u64), Felt::new(8_u64)], + ), + ]; + let mut storage_map = StorageMap::with_entries(storage_map_leaves_2).unwrap(); + let mut account = + build_account(vec![asset_0], init_nonce, vec![word], Some(storage_map.clone())); + + let new_map_entry = ( + Digest::new([Felt::new(101), Felt::new(102), Felt::new(103), Felt::new(104)]), + [Felt::new(9_u64), Felt::new(10_u64), Felt::new(11_u64), Felt::new(12_u64)], + ); + let updated_map = + StorageMapDelta::from(vec![], vec![(new_map_entry.0.into(), new_map_entry.1)]); + storage_map.insert(new_map_entry.0, new_map_entry.1); // build account delta let final_nonce = Felt::new(2); let storage_delta = AccountStorageDeltaBuilder::new() .add_cleared_items([0]) - .add_updated_items([(1_u8, [Felt::new(1), Felt::new(2), Felt::new(3), Felt::new(4)])]) + .add_updated_items([ + (1_u8, [Felt::new(1), Felt::new(2), Felt::new(3), Felt::new(4)]), + (100_u8, storage_map.root().into()), + ]) + .add_updated_maps([(100_u8, updated_map)]) .build() .unwrap(); let account_delta = @@ -413,9 +463,14 @@ mod tests { // apply delta and create final_account account.apply_delta(&account_delta).unwrap(); - let final_account = build_account(vec![asset_1], final_nonce, vec![Word::default(), word]); - // assert account is what it should be + let final_account = build_account( + vec![asset_1], + final_nonce, + vec![Word::default(), word], + Some(storage_map), + ); + assert_eq!(account, final_account); } @@ -425,7 +480,7 @@ mod tests { // build account let init_nonce = Felt::new(1); let (asset, _) = build_assets(); - let mut account = build_account(vec![asset], init_nonce, vec![Word::default()]); + let mut account = build_account(vec![asset], init_nonce, vec![Word::default()], None); // build account delta let storage_delta = AccountStorageDeltaBuilder::new() @@ -445,7 +500,7 @@ mod tests { // build account let init_nonce = Felt::new(2); let (asset, _) = build_assets(); - let mut account = build_account(vec![asset], init_nonce, vec![Word::default()]); + let mut account = build_account(vec![asset], init_nonce, vec![Word::default()], None); // build account delta let final_nonce = Felt::new(1); @@ -466,7 +521,7 @@ mod tests { // build account let init_nonce = Felt::new(1); let word = [Felt::new(1), Felt::new(2), Felt::new(3), Felt::new(4)]; - let mut account = build_account(vec![], init_nonce, vec![word]); + let mut account = build_account(vec![], init_nonce, vec![word], None); // build account delta let final_nonce = Felt::new(2); diff --git a/objects/src/accounts/storage/mod.rs b/objects/src/accounts/storage/mod.rs index 48f24d281..a14f53145 100644 --- a/objects/src/accounts/storage/mod.rs +++ b/objects/src/accounts/storage/mod.rs @@ -2,9 +2,12 @@ use alloc::{collections::BTreeMap, string::ToString, vec::Vec}; use super::{ AccountError, AccountStorageDelta, ByteReader, ByteWriter, Deserializable, - DeserializationError, Digest, Felt, Hasher, Serializable, Word, + DeserializationError, Digest, Felt, Hasher, Serializable, Word, ZERO, +}; +use crate::{ + accounts::StorageMapDelta, + crypto::merkle::{LeafIndex, NodeIndex, SimpleSmt}, }; -use crate::crypto::merkle::{LeafIndex, NodeIndex, SimpleSmt}; mod slot; pub use slot::StorageSlotType; @@ -206,6 +209,11 @@ impl AccountStorage { &self.maps } + // Returns the storage map with a given root. + pub fn find_storage_map_by_root(&mut self, target_root: Digest) -> Option<&mut StorageMap> { + self.maps.iter_mut().find(|map| map.root() == target_root) + } + // DATA MUTATORS // -------------------------------------------------------------------------------------------- @@ -219,6 +227,12 @@ impl AccountStorage { /// - The delta implies an update to a reserved account slot. /// - The updates violate storage layout constraints. pub(super) fn apply_delta(&mut self, delta: &AccountStorageDelta) -> Result<(), AccountError> { + // Map updates are applied first as we need to find the storage map by its old root + // and every map updates always involves updating the root in the Storage slots as well. + for &(slot_idx, ref map_delta) in delta.updated_maps.iter() { + self.set_map_item(slot_idx, map_delta.clone())?; + } + for &slot_idx in delta.cleared_items.iter() { self.set_item(slot_idx, Word::default())?; } @@ -253,7 +267,16 @@ impl AccountStorage { }); } }, - slot_type => Err(AccountError::StorageSlotNotValueSlot(index, slot_type))?, + StorageSlotType::Map { value_arity } => { + if value_arity > 0 { + return Err(AccountError::StorageSlotInvalidValueArity { + slot: index, + expected: 0, + actual: value_arity, + }); + } + }, + slot_type => Err(AccountError::StorageSlotArrayNotSupportedYet(index, slot_type))?, } // update the slot and return @@ -261,6 +284,44 @@ impl AccountStorage { let slot_value = self.slots.insert(index, value); Ok(slot_value) } + + /// Updates a storage map at the specified index. + /// + /// # Errors + /// Returns an error if: + /// - The index specifies a reserved storage slot. + /// - The index is not u8. + /// - The map does not exist at the specified index. + pub fn set_map_item( + &mut self, + index: u8, + map_delta: StorageMapDelta, + ) -> Result<(), AccountError> { + // layout commitment slot cannot be updated + if index == Self::SLOT_LAYOUT_COMMITMENT_INDEX { + return Err(AccountError::StorageSlotIsReserved(index)); + } + + // load the storage map + let index = LeafIndex::new(index as u64).expect("index is u8 - index within range"); + let old_map_root: Digest = self.slots.get_leaf(&index).into(); + + let storage_map = self + .find_storage_map_by_root(old_map_root) + .ok_or(AccountError::StorageMapNotFound { index: index.value() })?; + + // apply the updated leaves to the storage map + for (key, value) in map_delta.updated_leaves.iter() { + storage_map.insert(key.into(), *value); + } + + // apply the cleared leaves to the storage map + for key in map_delta.cleared_leaves.iter() { + storage_map.insert(key.into(), [ZERO; 4]); + } + + Ok(()) + } } // SERIALIZATION diff --git a/objects/src/errors.rs b/objects/src/errors.rs index 94c624bbe..3ac795a39 100644 --- a/objects/src/errors.rs +++ b/objects/src/errors.rs @@ -33,8 +33,9 @@ pub enum AccountError { SeedDigestTooFewTrailingZeros { expected: u32, actual: u32 }, StorageSlotInvalidValueArity { slot: u8, expected: u8, actual: u8 }, StorageSlotIsReserved(u8), - StorageSlotNotValueSlot(u8, StorageSlotType), + StorageSlotArrayNotSupportedYet(u8, StorageSlotType), StorageMapToManyMaps { expected: usize, actual: usize }, + StorageMapNotFound { index: u64 }, StubDataIncorrectLength(usize, usize), } From 40ec598f9532a42c9fd711b4c147800fb8a7eb16 Mon Sep 17 00:00:00 2001 From: Bobbin Threadbare Date: Wed, 12 Jun 2024 03:08:50 -0700 Subject: [PATCH 3/3] chore: increment crate versions to v0.3.1 --- Cargo.lock | 8 ++++---- miden-lib/Cargo.toml | 2 +- miden-tx/Cargo.toml | 2 +- mock/Cargo.toml | 2 +- objects/Cargo.toml | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6730d82ef..2f70862f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -651,7 +651,7 @@ dependencies = [ [[package]] name = "miden-lib" -version = "0.3.0" +version = "0.3.1" dependencies = [ "miden-assembly", "miden-mock", @@ -662,7 +662,7 @@ dependencies = [ [[package]] name = "miden-mock" -version = "0.3.0" +version = "0.3.1" dependencies = [ "clap", "env_logger", @@ -680,7 +680,7 @@ dependencies = [ [[package]] name = "miden-objects" -version = "0.3.0" +version = "0.3.1" dependencies = [ "criterion", "log", @@ -729,7 +729,7 @@ dependencies = [ [[package]] name = "miden-tx" -version = "0.3.0" +version = "0.3.1" dependencies = [ "miden-lib", "miden-mock", diff --git a/miden-lib/Cargo.toml b/miden-lib/Cargo.toml index 005aca85f..8f6a68621 100644 --- a/miden-lib/Cargo.toml +++ b/miden-lib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "miden-lib" -version = "0.3.0" +version = "0.3.1" description = "Standard library of the Miden rollup" readme = "README.md" categories = ["no-std"] diff --git a/miden-tx/Cargo.toml b/miden-tx/Cargo.toml index ddd56464b..fe5e3bd12 100644 --- a/miden-tx/Cargo.toml +++ b/miden-tx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "miden-tx" -version = "0.3.0" +version = "0.3.1" description = "Miden rollup transaction compiler, executor, and prover" readme = "README.md" categories = ["no-std"] diff --git a/mock/Cargo.toml b/mock/Cargo.toml index 4c521ee23..574f483a6 100644 --- a/mock/Cargo.toml +++ b/mock/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "miden-mock" -version = "0.3.0" +version = "0.3.1" description = "Library for mocking and testing core Miden rollup components" readme = "README.md" keywords = ["miden", "mock"] diff --git a/objects/Cargo.toml b/objects/Cargo.toml index 8fdd43c0a..0f0f45122 100644 --- a/objects/Cargo.toml +++ b/objects/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "miden-objects" -version = "0.3.0" +version = "0.3.1" description = "Core components of the Miden rollup" readme = "README.md" categories = ["no-std"]