diff --git a/.cargo/release-version b/.cargo/release-version index ef9b3919c6..f08075098e 100644 --- a/.cargo/release-version +++ b/.cargo/release-version @@ -1 +1 @@ -v0.16.15 \ No newline at end of file +v0.16.19 \ No newline at end of file diff --git a/.circleci/config.yml b/.circleci/config.yml index 2402f7faa9..18c9b8d2f7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,7 +1,7 @@ version: 2.1 orbs: - windows: circleci/windows@2.4.0 + windows: circleci/windows@5.0 commands: check_windows: @@ -17,11 +17,14 @@ commands: name: "Install Rust and run cargo check" command: | $ProgressPreference = "SilentlyContinue" + # Remove the circleci installed rustc. + choco uninstall rust + # Install rust with rustup. Invoke-WebRequest -Uri "https://win.rustup.rs/" -OutFile "C:\rustup-init.exe" & C:\rustup-init.exe -y --default-toolchain "stable-x86_64-pc-windows-msvc" --no-modify-path --profile minimal - $env:Path += ";C:\Users\circleci\.cargo\bin" - rustc -Vv - cargo --version + $Env:Path += ";$Env:USERPROFILE\.cargo\bin" + # Verify the installation. + cargo --version --verbose rustc --version | Out-File -FilePath "rust-version" if (!(Test-Path "Cargo.lock" -PathType Leaf)) { cargo generate-lockfile @@ -134,7 +137,7 @@ commands: jobs: snarkvm: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - checkout @@ -144,7 +147,7 @@ jobs: algorithms: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -153,7 +156,7 @@ jobs: algorithms-profiler: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: # This runs a single test with profiler enabled @@ -163,7 +166,7 @@ jobs: circuit: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -172,7 +175,7 @@ jobs: circuit-account: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -182,7 +185,7 @@ jobs: # This checks that no `console` structs are used in core circuit logic. circuit-account-noconsole: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -192,7 +195,7 @@ jobs: circuit-algorithms: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -201,7 +204,7 @@ jobs: circuit-collections: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -211,7 +214,7 @@ jobs: # This checks that no `console` structs are used in core circuit logic. circuit-collections-noconsole: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -221,7 +224,7 @@ jobs: circuit-environment: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -230,7 +233,7 @@ jobs: circuit-network: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -239,7 +242,7 @@ jobs: circuit-program: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -248,7 +251,7 @@ jobs: circuit-types: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -257,7 +260,7 @@ jobs: circuit-types-address: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -266,7 +269,7 @@ jobs: circuit-types-boolean: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -275,7 +278,7 @@ jobs: circuit-types-field: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -284,7 +287,7 @@ jobs: circuit-types-group: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -293,7 +296,7 @@ jobs: circuit-types-integers: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -303,7 +306,7 @@ jobs: circuit-types-scalar: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -312,7 +315,7 @@ jobs: circuit-types-string: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -320,7 +323,7 @@ jobs: cache_key: snarkvm-circuit-types-string-cache console: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -329,7 +332,7 @@ jobs: console-account: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -338,7 +341,7 @@ jobs: console-algorithms: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -347,7 +350,7 @@ jobs: console-collections: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -356,7 +359,7 @@ jobs: console-network: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -365,7 +368,7 @@ jobs: console-network-environment: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -374,7 +377,7 @@ jobs: console-program: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -383,7 +386,7 @@ jobs: console-types: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -392,7 +395,7 @@ jobs: console-types-address: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -401,7 +404,7 @@ jobs: console-types-boolean: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -410,7 +413,7 @@ jobs: console-types-field: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -419,7 +422,7 @@ jobs: console-types-group: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -428,7 +431,7 @@ jobs: console-types-integers: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -437,7 +440,7 @@ jobs: console-types-scalar: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -446,7 +449,7 @@ jobs: console-types-string: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -455,7 +458,7 @@ jobs: curves: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -464,7 +467,7 @@ jobs: fields: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -473,7 +476,7 @@ jobs: ledger: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -482,7 +485,7 @@ jobs: ledger-with-rocksdb: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -492,7 +495,7 @@ jobs: ledger-authority: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -501,7 +504,7 @@ jobs: ledger-block: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -510,7 +513,7 @@ jobs: ledger-coinbase: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -519,7 +522,7 @@ jobs: ledger-committee: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -528,7 +531,7 @@ jobs: ledger-narwhal: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -537,7 +540,7 @@ jobs: ledger-narwhal-batch-certificate: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -546,7 +549,7 @@ jobs: ledger-narwhal-batch-header: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -555,7 +558,7 @@ jobs: ledger-narwhal-data: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -564,7 +567,7 @@ jobs: ledger-narwhal-subdag: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -573,7 +576,7 @@ jobs: ledger-narwhal-transmission: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -582,7 +585,7 @@ jobs: ledger-narwhal-transmission-id: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -591,7 +594,7 @@ jobs: ledger-query: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -600,7 +603,7 @@ jobs: ledger-store: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -610,7 +613,7 @@ jobs: ledger-test-helpers: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -619,7 +622,7 @@ jobs: parameters: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -628,7 +631,7 @@ jobs: synthesizer: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -638,7 +641,7 @@ jobs: synthesizer-integration: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -648,7 +651,7 @@ jobs: synthesizer-process: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -657,7 +660,7 @@ jobs: synthesizer-process-with-rocksdb: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -667,7 +670,7 @@ jobs: synthesizer-program: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -677,7 +680,7 @@ jobs: synthesizer-program-integration-keccak: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -687,7 +690,7 @@ jobs: synthesizer-program-integration-psd: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -697,7 +700,7 @@ jobs: synthesizer-program-integration-sha: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -707,7 +710,7 @@ jobs: synthesizer-program-integration-rest: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -717,7 +720,7 @@ jobs: synthesizer-snark: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - run_serial: @@ -726,7 +729,7 @@ jobs: utilities: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -735,7 +738,7 @@ jobs: utilities-derives: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - run_serial: @@ -744,7 +747,7 @@ jobs: wasm: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - checkout @@ -762,7 +765,7 @@ jobs: check-fmt: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - checkout @@ -778,7 +781,7 @@ jobs: check-clippy: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: 2xlarge steps: - checkout @@ -795,7 +798,7 @@ jobs: check-all-targets: docker: - - image: cimg/rust:1.71.1 + - image: cimg/rust:1.72.1 resource_class: xlarge steps: - checkout diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 0fe536b67d..17610f64a1 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,5 +1,5 @@ blank_issues_enabled: true contact_links: - name: ❓ Q&A Technical Support Channel - url: https://aleo.org/discord + url: https://discord.gg/aleo about: For quick questions or technical troubleshooting, please ask them on our dedicated Discord channel. diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index bd6e7ad390..c2e1481726 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -3,7 +3,7 @@ name: Run snarkVM Benchmarks on: push: branches: - - 'testnet3' + - 'mainnet' jobs: # Run benchmarks and stores the output to a file @@ -62,6 +62,12 @@ jobs: cargo bench --bench merkle_tree -- --output-format bencher | tee -a ../../output.txt cd ../.. + - name: Benchmark console/types + run: | + cd console/types + cargo bench --bench group -- --output-format bencher | tee -a ../../output.txt + cd ../.. + - name: Benchmark curves run: | cd curves diff --git a/.rusty-hook.toml b/.rusty-hook.toml index c8bbf1f690..210316b294 100644 --- a/.rusty-hook.toml +++ b/.rusty-hook.toml @@ -1,5 +1,5 @@ [hooks] -pre-commit = "cargo clippy --workspace --all-targets --all-features && cargo +nightly fmt --all -- --check" +pre-commit = "cargo +nightly fmt --all -- --check && cargo clippy --workspace --all-targets --all-features" [logging] verbose = true diff --git a/Cargo.lock b/Cargo.lock index d5dfef8577..8f828fc23e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,13 +19,14 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ahash" -version = "0.8.3" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" dependencies = [ "cfg-if", "once_cell", "version_check", + "zerocopy", ] [[package]] @@ -39,9 +40,9 @@ dependencies = [ [[package]] name = "aleo-std" -version = "0.1.18" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3aa6ad1a3bb96698e7e8d8e42a6f2fda3b8611a43aab4d5effb921f18798833" +checksum = "a3ec648bb4d936c62d63cb85983059c7fecd92175912c145470da3b03010c7c6" dependencies = [ "aleo-std-cpu", "aleo-std-profiler", @@ -68,9 +69,9 @@ dependencies = [ [[package]] name = "aleo-std-storage" -version = "0.1.3" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "503e2538d5158b869bc9c30c9754f9a23f4210987008014a9f118db99f22c217" +checksum = "453100af40d56582265853ecb2ef660d1bc1ba6920bff020a77ceba1122c8eb5" dependencies = [ "dirs", ] @@ -82,7 +83,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72f2a841f04c2eaeb5a95312e5201a9e4b7c95b64ca99870d6bd2e2376df540a" dependencies = [ "proc-macro2", - "quote 1.0.33", + "quote 1.0.35", "syn 1.0.109", ] @@ -93,7 +94,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6118baab6285accf088b31d5ea5029c37bbf9d98e62b4d8720a0a5a66bc2e427" dependencies = [ "proc-macro2", - "quote 1.0.33", + "quote 1.0.35", "syn 1.0.109", ] @@ -120,9 +121,9 @@ checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" [[package]] name = "anstream" -version = "0.6.4" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" +checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" dependencies = [ "anstyle", "anstyle-parse", @@ -140,37 +141,37 @@ checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" [[package]] name = "anstyle-parse" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.0.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.1" +version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" dependencies = [ "anstyle", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "anyhow" -version = "1.0.75" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" [[package]] name = "arrayref" @@ -186,13 +187,13 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "async-trait" -version = "0.1.73" +version = "0.1.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" +checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", - "quote 1.0.33", - "syn 2.0.38", + "quote 1.0.35", + "syn 2.0.48", ] [[package]] @@ -218,9 +219,9 @@ dependencies = [ [[package]] name = "base64" -version = "0.21.4" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ba43ea6f343b788c8764558649e08df62f86c6ef251fdaeb1ffd010a9ae50a2" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "bech32" @@ -251,11 +252,11 @@ dependencies = [ "peeking_take_while", "prettyplease", "proc-macro2", - "quote 1.0.33", + "quote 1.0.35", "regex", "rustc-hash", "shlex", - "syn 2.0.38", + "syn 2.0.48", ] [[package]] @@ -281,9 +282,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.0" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "blake2" @@ -433,9 +434,9 @@ dependencies = [ [[package]] name = "cl3" -version = "0.9.2" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "215a3aa32ab5d7928c539c4289d1cf144257c3cb05e05a4b7e61d5a6bb6583a5" +checksum = "b823f24e72fa0c68aa14a250ae1c0848e68d4ae188b71c3972343e45b46f8644" dependencies = [ "libc", "opencl-sys", @@ -444,9 +445,9 @@ dependencies = [ [[package]] name = "clang-sys" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f" +checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1" dependencies = [ "glob", "libc", @@ -455,9 +456,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.6" +version = "4.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" +checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c" dependencies = [ "clap_builder", "clap_derive", @@ -465,9 +466,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.6" +version = "4.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45" +checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7" dependencies = [ "anstream", "anstyle", @@ -477,21 +478,21 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.4.2" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" +checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" dependencies = [ "heck", "proc-macro2", - "quote 1.0.33", - "syn 2.0.38", + "quote 1.0.35", + "syn 2.0.48", ] [[package]] name = "clap_lex" -version = "0.5.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" [[package]] name = "colorchoice" @@ -501,26 +502,25 @@ checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] name = "colored" -version = "2.0.4" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2674ec482fbc38012cf31e6c42ba0177b431a0cb6f15fe40efa5aab1bda516f6" +checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" dependencies = [ - "is-terminal", "lazy_static", "windows-sys 0.48.0", ] [[package]] name = "console" -version = "0.15.7" +version = "0.15.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8" +checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" dependencies = [ "encode_unicode", "lazy_static", "libc", "unicode-width", - "windows-sys 0.45.0", + "windows-sys 0.52.0", ] [[package]] @@ -541,9 +541,9 @@ checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" [[package]] name = "core-foundation" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" dependencies = [ "core-foundation-sys", "libc", @@ -551,15 +551,15 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.4" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "cpufeatures" -version = "0.2.9" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" dependencies = [ "libc", ] @@ -611,46 +611,37 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.8" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +checksum = "176dc175b78f56c0f321911d9c8eb2b77a78a4860b9c19db83835fea1a46649b" dependencies = [ - "cfg-if", "crossbeam-utils", ] [[package]] name = "crossbeam-deque" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" dependencies = [ - "cfg-if", "crossbeam-epoch", "crossbeam-utils", ] [[package]] name = "crossbeam-epoch" -version = "0.9.15" +version = "0.9.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" dependencies = [ - "autocfg", - "cfg-if", "crossbeam-utils", - "memoffset", - "scopeguard", ] [[package]] name = "crossbeam-utils" -version = "0.8.16" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" -dependencies = [ - "cfg-if", -] +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" [[package]] name = "crunchy" @@ -697,15 +688,15 @@ dependencies = [ "openssl-probe", "openssl-sys", "schannel", - "socket2 0.4.9", + "socket2 0.4.10", "winapi", ] [[package]] name = "curl-sys" -version = "0.4.68+curl-8.4.0" +version = "0.4.70+curl-8.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4a0d18d88360e374b16b2273c832b5e57258ffc1d4aa4f96b108e0738d5752f" +checksum = "3c0333d8849afe78a4c8102a429a446bfdd055832af071945520e835ae2d841e" dependencies = [ "cc", "libc", @@ -723,7 +714,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" dependencies = [ "cfg-if", - "hashbrown 0.14.1", + "hashbrown 0.14.3", "lock_api", "once_cell", "parking_lot_core", @@ -731,24 +722,13 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.9" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" dependencies = [ "powerfmt", ] -[[package]] -name = "derivative" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" -dependencies = [ - "proc-macro2", - "quote 1.0.33", - "syn 1.0.109", -] - [[package]] name = "digest" version = "0.10.7" @@ -911,12 +891,12 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.5" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" dependencies = [ "libc", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -989,9 +969,9 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "form_urlencoded" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" dependencies = [ "percent-encoding", ] @@ -1004,9 +984,9 @@ checksum = "c1fd087255f739f4f1aeea69f11b72f8080e9c2e7645cd06955dad4a178a49e3" [[package]] name = "futures" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" dependencies = [ "futures-channel", "futures-core", @@ -1019,9 +999,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", "futures-sink", @@ -1029,15 +1009,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" [[package]] name = "futures-executor" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" dependencies = [ "futures-core", "futures-task", @@ -1046,27 +1026,27 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" [[package]] name = "futures-sink" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" [[package]] name = "futures-task" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" [[package]] name = "futures-util" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-channel", "futures-core", @@ -1109,9 +1089,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.10" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", "js-sys", @@ -1122,9 +1102,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.28.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] name = "glob" @@ -1134,9 +1114,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "h2" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91fc23aa11be92976ef4729127f1a74adf36d8436f7816b185d18df956790833" +checksum = "bb2c4422095b67ee78da96fbb51a4cc413b3b25883c7717ff7ca1ab31022c9c9" dependencies = [ "bytes", "fnv", @@ -1144,7 +1124,7 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap 1.9.3", + "indexmap 2.1.0", "slab", "tokio", "tokio-util", @@ -1174,9 +1154,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.1" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" dependencies = [ "ahash", "allocator-api2", @@ -1190,9 +1170,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +checksum = "5d3d0e0f38255e7fa3cf31335b3a56f05febd18025f4db5ef7a0cfb4f8da651f" [[package]] name = "hex" @@ -1202,18 +1182,18 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "home" -version = "0.5.5" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "http" -version = "0.2.9" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" +checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" dependencies = [ "bytes", "fnv", @@ -1222,9 +1202,9 @@ dependencies = [ [[package]] name = "http-body" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", "http", @@ -1245,9 +1225,9 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hyper" -version = "0.14.27" +version = "0.14.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" +checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" dependencies = [ "bytes", "futures-channel", @@ -1260,7 +1240,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.9", + "socket2 0.5.5", "tokio", "tower-service", "tracing", @@ -1282,9 +1262,9 @@ dependencies = [ [[package]] name = "idna" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ "unicode-bidi", "unicode-normalization", @@ -1302,12 +1282,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" dependencies = [ "equivalent", - "hashbrown 0.14.1", + "hashbrown 0.14.3", "rayon", "serde", ] @@ -1336,19 +1316,19 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.8.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] name = "is-terminal" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455" dependencies = [ "hermit-abi", "rustix", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -1371,9 +1351,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "jobserver" @@ -1386,9 +1366,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.64" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" dependencies = [ "wasm-bindgen", ] @@ -1407,18 +1387,18 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.149" +version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" [[package]] name = "libloading" -version = "0.7.4" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" +checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161" dependencies = [ "cfg-if", - "winapi", + "windows-sys 0.48.0", ] [[package]] @@ -1427,6 +1407,17 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +[[package]] +name = "libredox" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" +dependencies = [ + "bitflags 2.4.2", + "libc", + "redox_syscall", +] + [[package]] name = "librocksdb-sys" version = "0.11.0+8.1.1" @@ -1444,9 +1435,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.12" +version = "1.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d97137b25e321a73eef1418d1d5d2eda4d77e12813f8e6dead84bc52c5870a7b" +checksum = "295c17e837573c8c821dbaeb3cceb3d745ad082f7572191409e69cbc1b3fd050" dependencies = [ "cc", "libc", @@ -1456,15 +1447,15 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.10" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "lock_api" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" dependencies = [ "autocfg", "scopeguard", @@ -1486,15 +1477,6 @@ dependencies = [ "libc", ] -[[package]] -name = "mach2" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d0d1830bcd151a6fc4aea1369af235b36c1528fe976b8ff678683c9995eade8" -dependencies = [ - "libc", -] - [[package]] name = "matchers" version = "0.1.0" @@ -1506,38 +1488,29 @@ dependencies = [ [[package]] name = "memchr" -version = "2.6.4" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - -[[package]] -name = "memoffset" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" -dependencies = [ - "autocfg", -] +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "metrics" -version = "0.21.1" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fde3af1a009ed76a778cb84fdef9e7dbbdf5775ae3e4cc1f434a6a307f6f76c5" +checksum = "77b9e10a211c839210fd7f99954bda26e5f8e26ec686ad68da6a32df7c80e782" dependencies = [ "ahash", - "metrics-macros", "portable-atomic", ] [[package]] name = "metrics-exporter-prometheus" -version = "0.12.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a4964177ddfdab1e3a2b37aec7cf320e14169abb0ed73999f558136409178d5" +checksum = "83a4c4718a371ddfb7806378f23617876eea8b82e5ff1324516bcd283249d9ea" dependencies = [ "base64", "hyper", + "hyper-tls", "indexmap 1.9.3", "ipnet", "metrics", @@ -1548,22 +1521,11 @@ dependencies = [ "tracing", ] -[[package]] -name = "metrics-macros" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddece26afd34c31585c74a4db0630c376df271c285d682d1e55012197830b6df" -dependencies = [ - "proc-macro2", - "quote 1.0.33", - "syn 2.0.38", -] - [[package]] name = "metrics-util" -version = "0.15.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4de2ed6e491ed114b40b732e4d1659a9d53992ebd87490c44a6ffe23739d973e" +checksum = "2670b8badcc285d486261e2e9f1615b506baff91427b61bd336a472b65bbf5ed" dependencies = [ "crossbeam-epoch", "crossbeam-utils", @@ -1597,9 +1559,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.8" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" dependencies = [ "libc", "wasi", @@ -1668,8 +1630,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfb77679af88f8b125209d354a202862602672222e7f2313fdd6dc349bad4712" dependencies = [ "proc-macro2", - "quote 1.0.33", - "syn 2.0.38", + "quote 1.0.35", + "syn 2.0.48", ] [[package]] @@ -1720,18 +1682,18 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" [[package]] name = "object" -version = "0.32.1" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" dependencies = [ "memchr", ] [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "oorandom" @@ -1741,18 +1703,18 @@ checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" [[package]] name = "opencl-sys" -version = "0.2.4" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e75919008b8ed7ce9620e2b3580c648db40c7f564a368f271b2647145046d8ba" +checksum = "3c18b75202f7354563065f0202ae77ec903261370bf7a0bb9a0c3fd11b5a39a2" dependencies = [ "libc", ] [[package]] name = "opencl3" -version = "0.9.3" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c247ee0c98af8a67ab9c836ed2ea663ac19a17d8bae71325b509835e536c18ad" +checksum = "26ab4a90cb496f787d3934deb0c54fa9d65e7bed710c10071234aab0196fba04" dependencies = [ "cl3", "libc", @@ -1760,11 +1722,11 @@ dependencies = [ [[package]] name = "openssl" -version = "0.10.57" +version = "0.10.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c" +checksum = "15c9d69dd87a29568d4d017cfe8ec518706046a05184e5aea92d0af890b803c8" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.2", "cfg-if", "foreign-types", "libc", @@ -1780,8 +1742,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", - "quote 1.0.33", - "syn 2.0.38", + "quote 1.0.35", + "syn 2.0.48", ] [[package]] @@ -1792,9 +1754,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.93" +version = "0.9.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db4d56a4c0478783083cfafcc42493dd4a981d41669da64b4572a2a089b51b1d" +checksum = "22e1bf214306098e4832460f797824c05d25aacdf896f64a985fb0fd992454ae" dependencies = [ "cc", "libc", @@ -1820,13 +1782,13 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.8" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.3.5", + "redox_syscall", "smallvec", "windows-targets 0.48.5", ] @@ -1845,9 +1807,9 @@ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "percent-encoding" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pin-project-lite" @@ -1863,9 +1825,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.27" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" +checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" [[package]] name = "plotters" @@ -1897,9 +1859,9 @@ dependencies = [ [[package]] name = "portable-atomic" -version = "1.4.3" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31114a898e107c51bb1609ffaf55a0e011cf6a4d7f1170d0015a165082c0338b" +checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" [[package]] name = "powerfmt" @@ -1915,38 +1877,38 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "prettyplease" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" +checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5" dependencies = [ "proc-macro2", - "syn 2.0.38", + "syn 2.0.48", ] [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" dependencies = [ "unicode-ident", ] [[package]] name = "proptest" -version = "1.3.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c003ac8c77cb07bb74f5f198bce836a689bcd5a42574612bf14d17bfd08c20e" +checksum = "31b476131c3c86cb68032fdc5cb6d5a1045e3e42d96b69fa599fd77701e1f5bf" dependencies = [ "bit-set", "bit-vec", - "bitflags 2.4.0", + "bitflags 2.4.2", "lazy_static", "num-traits", "rand", "rand_chacha", "rand_xorshift", - "regex-syntax 0.7.5", + "regex-syntax 0.8.2", "rusty-fork", "tempfile", "unarray", @@ -1954,13 +1916,12 @@ dependencies = [ [[package]] name = "quanta" -version = "0.11.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17e662a7a8291a865152364c20c7abc5e60486ab2001e8ec10b24862de0b9ab" +checksum = "9ca0b7bac0b97248c40bb77288fc52029cf1459c0461ea1b05ee32ccf011de2c" dependencies = [ "crossbeam-utils", "libc", - "mach2", "once_cell", "raw-cpuid", "wasi", @@ -1991,9 +1952,9 @@ checksum = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -2049,18 +2010,18 @@ dependencies = [ [[package]] name = "raw-cpuid" -version = "10.7.0" +version = "11.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c297679cb867470fa8c9f67dbba74a78d78e3e98d7cf2b08d6d71540f797332" +checksum = "9d86a7c4638d42c44551f4791a20e687dbb4c3de1f33c43dd71e355cd429def1" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.2", ] [[package]] name = "rayon" -version = "1.8.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" +checksum = "fa7237101a77a10773db45d62004a272517633fbcc3df19d96455ede1122e051" dependencies = [ "either", "rayon-core", @@ -2068,9 +2029,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.12.0" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" dependencies = [ "crossbeam-deque", "crossbeam-utils", @@ -2078,43 +2039,34 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "redox_syscall" -version = "0.3.5" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ "bitflags 1.3.2", ] [[package]] name = "redox_users" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +checksum = "a18479200779601e498ada4e8c1e1f50e3ee19deb0259c25825a98b5603b2cb4" dependencies = [ "getrandom", - "redox_syscall 0.2.16", + "libredox", "thiserror", ] [[package]] name = "regex" -version = "1.10.0" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d119d7c7ca818f8a53c300863d4f87566aac09943aef5b355bb83969dae75d87" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.1", - "regex-syntax 0.8.1", + "regex-automata 0.4.3", + "regex-syntax 0.8.2", ] [[package]] @@ -2128,13 +2080,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.1" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "465c6fc0621e4abc4187a2bda0937bfd4f722c2730b29562e19689ea796c9a4b" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.1", + "regex-syntax 0.8.2", ] [[package]] @@ -2145,21 +2097,15 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.7.5" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" - -[[package]] -name = "regex-syntax" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56d84fdd47036b038fc80dd333d10b6aab10d5d31f4a366e20014def75328d33" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "reqwest" -version = "0.11.22" +version = "0.11.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" +checksum = "37b1ae8d9ac08420c66222fb9096fc5de435c3c48542bc5336c51892cffafb41" dependencies = [ "base64", "bytes", @@ -2195,17 +2141,16 @@ dependencies = [ [[package]] name = "ring" -version = "0.16.20" +version = "0.17.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +checksum = "688c63d65483050968b2a8937f7995f443e27041a0f7700aa59b0822aedebb74" dependencies = [ "cc", + "getrandom", "libc", - "once_cell", "spin", "untrusted", - "web-sys", - "winapi", + "windows-sys 0.48.0", ] [[package]] @@ -2248,7 +2193,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43ce8670a1a1d0fc2514a3b846dacdb65646f9bd494b6674cfacbb4ce430bd7e" dependencies = [ "proc-macro2", - "quote 1.0.33", + "quote 1.0.35", "syn 1.0.109", ] @@ -2275,22 +2220,22 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.19" +version = "0.38.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "745ecfa778e66b2b63c88a61cb36e0eea109e803b0b86bf9879fbc77c70e86ed" +checksum = "322394588aaf33c24007e8bb3238ee3e4c5c09c084ab32bc73890b99ff326bca" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.2", "errno", "libc", "linux-raw-sys", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "rustls" -version = "0.21.7" +version = "0.21.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd8d6c9f025a446bc4d18ad9632e69aec8f287aa84499ee335599fabd20c3fd8" +checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" dependencies = [ "log", "ring", @@ -2300,9 +2245,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.101.6" +version = "0.101.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c7d5dece342910d9ba34d259310cae3e0154b873b35408b787b59bce53d34fe" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" dependencies = [ "ring", "untrusted", @@ -2334,9 +2279,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.15" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" [[package]] name = "same-file" @@ -2349,11 +2294,11 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" +checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -2370,9 +2315,9 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "sct" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ "ring", "untrusted", @@ -2433,37 +2378,37 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" [[package]] name = "serde" -version = "1.0.189" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.189" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" dependencies = [ "proc-macro2", - "quote 1.0.33", - "syn 2.0.38", + "quote 1.0.35", + "syn 2.0.48", ] [[package]] name = "serde_json" -version = "1.0.107" +version = "1.0.111" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" +checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" dependencies = [ - "indexmap 2.0.2", + "indexmap 2.1.0", "itoa", "ryu", "serde", @@ -2483,11 +2428,11 @@ dependencies = [ [[package]] name = "serde_yaml" -version = "0.9.25" +version = "0.9.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a49e178e4452f45cb61d0cd8cebc1b0fafd3e41929e996cef79aa3aca91f574" +checksum = "b1bf28c79a99f70ee1f1d83d10c875d2e70618417fda01ad1785e027579d9d38" dependencies = [ - "indexmap 2.0.2", + "indexmap 2.1.0", "itoa", "ryu", "serde", @@ -2515,8 +2460,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91d129178576168c589c9ec973feedf7d3126c01ac2bf08795109aa35b69fb8f" dependencies = [ "proc-macro2", - "quote 1.0.33", - "syn 2.0.38", + "quote 1.0.35", + "syn 2.0.48", ] [[package]] @@ -2562,22 +2507,22 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.1" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" [[package]] name = "smol_str" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74212e6bbe9a4352329b2f68ba3130c15a3f26fe88ff22dbdc6cdd58fa85e99c" +checksum = "e6845563ada680337a52d43bb0b29f396f2d911616f6573012645b9e3d048a49" dependencies = [ "serde", ] [[package]] name = "snarkvm" -version = "0.16.15" +version = "0.16.19" dependencies = [ "anstyle", "anyhow", @@ -2585,7 +2530,7 @@ dependencies = [ "clap", "colored", "dotenvy", - "indexmap 2.0.2", + "indexmap 2.1.0", "num-format", "once_cell", "parking_lot", @@ -2613,7 +2558,7 @@ dependencies = [ [[package]] name = "snarkvm-algorithms" -version = "0.16.15" +version = "0.16.19" dependencies = [ "aleo-std", "anyhow", @@ -2624,9 +2569,9 @@ dependencies = [ "crossbeam-channel", "expect-test", "fxhash", - "hashbrown 0.14.1", + "hashbrown 0.14.3", "hex", - "indexmap 2.0.2", + "indexmap 2.1.0", "itertools 0.11.0", "lazy_static", "num-traits", @@ -2652,7 +2597,7 @@ dependencies = [ [[package]] name = "snarkvm-algorithms-cuda" -version = "0.16.15" +version = "0.16.19" dependencies = [ "blst", "cc", @@ -2662,7 +2607,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit" -version = "0.16.15" +version = "0.16.19" dependencies = [ "snarkvm-circuit-account", "snarkvm-circuit-algorithms", @@ -2675,7 +2620,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-account" -version = "0.16.15" +version = "0.16.19" dependencies = [ "anyhow", "snarkvm-circuit-algorithms", @@ -2687,7 +2632,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-algorithms" -version = "0.16.15" +version = "0.16.19" dependencies = [ "anyhow", "snarkvm-circuit-types", @@ -2699,7 +2644,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-collections" -version = "0.16.15" +version = "0.16.19" dependencies = [ "anyhow", "snarkvm-circuit-algorithms", @@ -2713,10 +2658,10 @@ dependencies = [ [[package]] name = "snarkvm-circuit-environment" -version = "0.16.15" +version = "0.16.19" dependencies = [ "criterion", - "indexmap 2.0.2", + "indexmap 2.1.0", "itertools 0.11.0", "nom", "num-traits", @@ -2734,11 +2679,11 @@ dependencies = [ [[package]] name = "snarkvm-circuit-environment-witness" -version = "0.16.15" +version = "0.16.19" [[package]] name = "snarkvm-circuit-network" -version = "0.16.15" +version = "0.16.19" dependencies = [ "snarkvm-circuit-algorithms", "snarkvm-circuit-collections", @@ -2749,7 +2694,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-program" -version = "0.16.15" +version = "0.16.19" dependencies = [ "anyhow", "paste", @@ -2767,7 +2712,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types" -version = "0.16.15" +version = "0.16.19" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-address", @@ -2782,7 +2727,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-address" -version = "0.16.15" +version = "0.16.19" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -2794,7 +2739,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-boolean" -version = "0.16.15" +version = "0.16.19" dependencies = [ "criterion", "snarkvm-circuit-environment", @@ -2803,7 +2748,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-field" -version = "0.16.15" +version = "0.16.19" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -2812,7 +2757,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-group" -version = "0.16.15" +version = "0.16.19" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -2824,7 +2769,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-integers" -version = "0.16.15" +version = "0.16.19" dependencies = [ "paste", "snarkvm-circuit-environment", @@ -2837,7 +2782,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-scalar" -version = "0.16.15" +version = "0.16.19" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -2847,7 +2792,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-string" -version = "0.16.15" +version = "0.16.19" dependencies = [ "rand", "snarkvm-circuit-environment", @@ -2860,7 +2805,7 @@ dependencies = [ [[package]] name = "snarkvm-console" -version = "0.16.15" +version = "0.16.19" dependencies = [ "snarkvm-console-account", "snarkvm-console-algorithms", @@ -2872,7 +2817,7 @@ dependencies = [ [[package]] name = "snarkvm-console-account" -version = "0.16.15" +version = "0.16.19" dependencies = [ "bincode", "bs58", @@ -2885,7 +2830,7 @@ dependencies = [ [[package]] name = "snarkvm-console-algorithms" -version = "0.16.15" +version = "0.16.19" dependencies = [ "blake2s_simd", "criterion", @@ -2903,11 +2848,11 @@ dependencies = [ [[package]] name = "snarkvm-console-collections" -version = "0.16.15" +version = "0.16.19" dependencies = [ "aleo-std", "criterion", - "indexmap 2.0.2", + "indexmap 2.1.0", "rayon", "snarkvm-console-algorithms", "snarkvm-console-network", @@ -2916,10 +2861,10 @@ dependencies = [ [[package]] name = "snarkvm-console-network" -version = "0.16.15" +version = "0.16.19" dependencies = [ "anyhow", - "indexmap 2.0.2", + "indexmap 2.1.0", "itertools 0.11.0", "lazy_static", "once_cell", @@ -2938,7 +2883,7 @@ dependencies = [ [[package]] name = "snarkvm-console-network-environment" -version = "0.16.15" +version = "0.16.19" dependencies = [ "anyhow", "bech32", @@ -2955,12 +2900,12 @@ dependencies = [ [[package]] name = "snarkvm-console-program" -version = "0.16.15" +version = "0.16.19" dependencies = [ "bincode", "enum_index", "enum_index_derive", - "indexmap 2.0.2", + "indexmap 2.1.0", "num-derive", "num-traits", "once_cell", @@ -2976,8 +2921,10 @@ dependencies = [ [[package]] name = "snarkvm-console-types" -version = "0.16.15" +version = "0.16.19" dependencies = [ + "criterion", + "snarkvm-console-network", "snarkvm-console-network-environment", "snarkvm-console-types-address", "snarkvm-console-types-boolean", @@ -2990,7 +2937,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-address" -version = "0.16.15" +version = "0.16.19" dependencies = [ "bincode", "serde_json", @@ -3002,7 +2949,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-boolean" -version = "0.16.15" +version = "0.16.19" dependencies = [ "bincode", "serde_json", @@ -3011,7 +2958,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-field" -version = "0.16.15" +version = "0.16.19" dependencies = [ "bincode", "serde_json", @@ -3022,7 +2969,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-group" -version = "0.16.15" +version = "0.16.19" dependencies = [ "bincode", "serde_json", @@ -3034,7 +2981,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-integers" -version = "0.16.15" +version = "0.16.19" dependencies = [ "bincode", "serde_json", @@ -3046,7 +2993,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-scalar" -version = "0.16.15" +version = "0.16.19" dependencies = [ "bincode", "serde_json", @@ -3058,7 +3005,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-string" -version = "0.16.15" +version = "0.16.19" dependencies = [ "bincode", "serde_json", @@ -3070,7 +3017,7 @@ dependencies = [ [[package]] name = "snarkvm-curves" -version = "0.16.15" +version = "0.16.19" dependencies = [ "bincode", "criterion", @@ -3085,16 +3032,17 @@ dependencies = [ [[package]] name = "snarkvm-fields" -version = "0.16.15" +version = "0.16.19" dependencies = [ "aleo-std", "anyhow", - "derivative", + "criterion", "itertools 0.11.0", "num-traits", "rand", "rayon", "serde", + "snarkvm-curves", "snarkvm-utilities", "thiserror", "zeroize", @@ -3102,13 +3050,13 @@ dependencies = [ [[package]] name = "snarkvm-ledger" -version = "0.16.15" +version = "0.16.19" dependencies = [ "aleo-std", "anyhow", "bincode", "criterion", - "indexmap 2.0.2", + "indexmap 2.1.0", "parking_lot", "rand", "rayon", @@ -3129,7 +3077,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-authority" -version = "0.16.15" +version = "0.16.19" dependencies = [ "anyhow", "bincode", @@ -3142,10 +3090,10 @@ dependencies = [ [[package]] name = "snarkvm-ledger-block" -version = "0.16.15" +version = "0.16.19" dependencies = [ "bincode", - "indexmap 2.0.2", + "indexmap 2.1.0", "once_cell", "rayon", "serde_json", @@ -3166,14 +3114,14 @@ dependencies = [ [[package]] name = "snarkvm-ledger-coinbase" -version = "0.16.15" +version = "0.16.19" dependencies = [ "aleo-std", "anyhow", "bincode", "blake2", "criterion", - "indexmap 2.0.2", + "indexmap 2.1.0", "rand", "rayon", "serde_json", @@ -3187,11 +3135,11 @@ dependencies = [ [[package]] name = "snarkvm-ledger-committee" -version = "0.16.15" +version = "0.16.19" dependencies = [ "anyhow", "bincode", - "indexmap 2.0.2", + "indexmap 2.1.0", "parking_lot", "proptest", "rand", @@ -3208,7 +3156,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal" -version = "0.16.15" +version = "0.16.19" dependencies = [ "snarkvm-ledger-narwhal", "snarkvm-ledger-narwhal-batch-certificate", @@ -3221,10 +3169,10 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-batch-certificate" -version = "0.16.15" +version = "0.16.19" dependencies = [ "bincode", - "indexmap 2.0.2", + "indexmap 2.1.0", "rayon", "serde_json", "snarkvm-console", @@ -3235,10 +3183,10 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-batch-header" -version = "0.16.15" +version = "0.16.19" dependencies = [ "bincode", - "indexmap 2.0.2", + "indexmap 2.1.0", "serde_json", "snarkvm-console", "snarkvm-ledger-narwhal-batch-header", @@ -3248,7 +3196,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-data" -version = "0.16.15" +version = "0.16.19" dependencies = [ "bytes", "serde_json", @@ -3258,13 +3206,14 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-subdag" -version = "0.16.15" +version = "0.16.19" dependencies = [ "bincode", - "indexmap 2.0.2", + "indexmap 2.1.0", "rayon", "serde_json", "snarkvm-console", + "snarkvm-ledger-committee", "snarkvm-ledger-narwhal-batch-certificate", "snarkvm-ledger-narwhal-batch-header", "snarkvm-ledger-narwhal-subdag", @@ -3273,7 +3222,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-transmission" -version = "0.16.15" +version = "0.16.19" dependencies = [ "bincode", "bytes", @@ -3286,7 +3235,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-transmission-id" -version = "0.16.15" +version = "0.16.19" dependencies = [ "bincode", "serde_json", @@ -3296,7 +3245,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-query" -version = "0.16.15" +version = "0.16.19" dependencies = [ "async-trait", "reqwest", @@ -3308,12 +3257,12 @@ dependencies = [ [[package]] name = "snarkvm-ledger-store" -version = "0.16.15" +version = "0.16.19" dependencies = [ - "aleo-std", + "aleo-std-storage", "anyhow", "bincode", - "indexmap 2.0.2", + "indexmap 2.1.0", "once_cell", "parking_lot", "rayon", @@ -3336,7 +3285,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-test-helpers" -version = "0.16.15" +version = "0.16.19" dependencies = [ "once_cell", "snarkvm-circuit", @@ -3350,7 +3299,7 @@ dependencies = [ [[package]] name = "snarkvm-metrics" -version = "0.16.15" +version = "0.16.19" dependencies = [ "metrics", "metrics-exporter-prometheus", @@ -3358,7 +3307,7 @@ dependencies = [ [[package]] name = "snarkvm-parameters" -version = "0.16.15" +version = "0.16.19" dependencies = [ "aleo-std", "anyhow", @@ -3368,7 +3317,7 @@ dependencies = [ "curl", "encoding", "hex", - "indexmap 2.0.2", + "indexmap 2.1.0", "itertools 0.11.0", "js-sys", "lazy_static", @@ -3391,12 +3340,12 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer" -version = "0.16.15" +version = "0.16.19" dependencies = [ "aleo-std", "anyhow", "criterion", - "indexmap 2.0.2", + "indexmap 2.1.0", "itertools 0.11.0", "once_cell", "parking_lot", @@ -3408,7 +3357,6 @@ dependencies = [ "snarkvm-circuit", "snarkvm-console", "snarkvm-ledger-block", - "snarkvm-ledger-coinbase", "snarkvm-ledger-committee", "snarkvm-ledger-query", "snarkvm-ledger-store", @@ -3422,12 +3370,12 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer-process" -version = "0.16.15" +version = "0.16.19" dependencies = [ "aleo-std", "bincode", "colored", - "indexmap 2.0.2", + "indexmap 2.1.0", "once_cell", "parking_lot", "rand", @@ -3448,11 +3396,11 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer-program" -version = "0.16.15" +version = "0.16.19" dependencies = [ "bincode", "criterion", - "indexmap 2.0.2", + "indexmap 2.1.0", "paste", "rand", "rand_chacha", @@ -3464,7 +3412,7 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer-snark" -version = "0.16.15" +version = "0.16.19" dependencies = [ "bincode", "colored", @@ -3477,7 +3425,7 @@ dependencies = [ [[package]] name = "snarkvm-utilities" -version = "0.16.15" +version = "0.16.19" dependencies = [ "aleo-std", "anyhow", @@ -3497,16 +3445,16 @@ dependencies = [ [[package]] name = "snarkvm-utilities-derives" -version = "0.16.15" +version = "0.16.19" dependencies = [ "proc-macro2", - "quote 1.0.33", - "syn 2.0.38", + "quote 1.0.35", + "syn 2.0.48", ] [[package]] name = "snarkvm-wasm" -version = "0.16.15" +version = "0.16.19" dependencies = [ "getrandom", "snarkvm-circuit-network", @@ -3523,9 +3471,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" dependencies = [ "libc", "winapi", @@ -3533,9 +3481,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e" +checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" dependencies = [ "libc", "windows-sys 0.48.0", @@ -3543,9 +3491,9 @@ dependencies = [ [[package]] name = "spin" -version = "0.5.2" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] name = "sppark" @@ -3570,9 +3518,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ad9e09554f0456d67a69c1584c9798ba733a5b50349a6c0d0948710523922d" dependencies = [ "proc-macro2", - "quote 1.0.33", + "quote 1.0.35", "structmeta-derive", - "syn 2.0.38", + "syn 2.0.48", ] [[package]] @@ -3582,8 +3530,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a60bcaff7397072dca0017d1db428e30d5002e00b6847703e2e42005c95fbe00" dependencies = [ "proc-macro2", - "quote 1.0.33", - "syn 2.0.38", + "quote 1.0.35", + "syn 2.0.48", ] [[package]] @@ -3610,18 +3558,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", - "quote 1.0.33", + "quote 1.0.35", "unicode-ident", ] [[package]] name = "syn" -version = "2.0.38" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", - "quote 1.0.33", + "quote 1.0.35", "unicode-ident", ] @@ -3666,15 +3614,15 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.8.0" +version = "3.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" +checksum = "01ce4141aa927a6d1bd34a041795abd0db1cccba5d5f24b009f694bdf3a1f3fa" dependencies = [ "cfg-if", "fastrand 2.0.1", - "redox_syscall 0.3.5", + "redox_syscall", "rustix", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -3684,29 +3632,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8361c808554228ad09bfed70f5c823caf8a3450b6881cc3a38eb57e8c08c1d9" dependencies = [ "proc-macro2", - "quote 1.0.33", + "quote 1.0.35", "structmeta", - "syn 2.0.38", + "syn 2.0.48", ] [[package]] name = "thiserror" -version = "1.0.49" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.49" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", - "quote 1.0.33", - "syn 2.0.38", + "quote 1.0.35", + "syn 2.0.48", ] [[package]] @@ -3730,9 +3678,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" +checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e" dependencies = [ "deranged", "powerfmt", @@ -3782,9 +3730,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.33.0" +version = "1.35.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f38200e3ef7995e5ef13baec2f432a6da0aa9ac495b2c0e8f3b7eec2c92d653" +checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" dependencies = [ "backtrace", "bytes", @@ -3792,7 +3740,7 @@ dependencies = [ "mio", "num_cpus", "pin-project-lite", - "socket2 0.5.4", + "socket2 0.5.5", "windows-sys 0.48.0", ] @@ -3808,9 +3756,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.9" +version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d68074620f57a0b21594d9735eb2e98ab38b17f80d3fcb189fca266771ca60d" +checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" dependencies = [ "bytes", "futures-core", @@ -3837,9 +3785,9 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.39" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2ef2af84856a50c1d430afce2fdded0a4ec7eda868db86409b4543df0797f9" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "pin-project-lite", "tracing-attributes", @@ -3853,8 +3801,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", - "quote 1.0.33", - "syn 2.0.38", + "quote 1.0.35", + "syn 2.0.48", ] [[package]] @@ -3869,20 +3817,20 @@ dependencies = [ [[package]] name = "tracing-log" -version = "0.1.3" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" dependencies = [ - "lazy_static", "log", + "once_cell", "tracing-core", ] [[package]] name = "tracing-subscriber" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" dependencies = [ "matchers", "nu-ansi-term", @@ -3915,15 +3863,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "258bc1c4f8e2e73a977812ab339d503e6feeb92700f6d07a6de4d321522d5c08" dependencies = [ "lazy_static", - "quote 1.0.33", + "quote 1.0.35", "syn 1.0.109", ] [[package]] name = "try-lock" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "typenum" @@ -3939,9 +3887,9 @@ checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" [[package]] name = "unicode-bidi" -version = "0.3.13" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" @@ -3972,21 +3920,21 @@ checksum = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" [[package]] name = "unsafe-libyaml" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f28467d3e1d3c6586d8f25fa243f544f5800fec42d97032474e17222c2b75cfa" +checksum = "ab4c90930b95a82d00dc9e9ac071b4991924390d46cbd0dfe566148667605e4b" [[package]] name = "untrusted" -version = "0.7.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "ureq" -version = "2.8.0" +version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5ccd538d4a604753ebc2f17cd9946e89b77bf87f6a8e2309667c6f2e87855e3" +checksum = "f8cdd25c339e200129fe4de81451814e5228c9b771d57378817d6117cc2b3f97" dependencies = [ "base64", "flate2", @@ -4002,9 +3950,9 @@ dependencies = [ [[package]] name = "url" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" dependencies = [ "form_urlencoded", "idna", @@ -4077,9 +4025,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.87" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -4087,24 +4035,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.87" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", - "quote 1.0.33", - "syn 2.0.38", + "quote 1.0.35", + "syn 2.0.48", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.37" +version = "0.4.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" +checksum = "bde2032aeb86bdfaecc8b261eef3cba735cc426c1f3a3416d1e0791be95fc461" dependencies = [ "cfg-if", "js-sys", @@ -4114,38 +4062,38 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.87" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" dependencies = [ - "quote 1.0.33", + "quote 1.0.35", "wasm-bindgen-macro-support", ] [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.87" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" dependencies = [ "proc-macro2", - "quote 1.0.33", - "syn 2.0.38", + "quote 1.0.35", + "syn 2.0.48", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.87" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" [[package]] name = "wasm-bindgen-test" -version = "0.3.37" +version = "0.3.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e6e302a7ea94f83a6d09e78e7dc7d9ca7b186bc2829c24a22d0753efd680671" +checksum = "139bd73305d50e1c1c4333210c0db43d989395b64a237bd35c10ef3832a7f70c" dependencies = [ "console_error_panic_hook", "js-sys", @@ -4157,19 +4105,20 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.37" +version = "0.3.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecb993dd8c836930ed130e020e77d9b2e65dd0fbab1b67c790b0f5d80b11a575" +checksum = "70072aebfe5da66d2716002c729a14e4aec4da0e23cc2ea66323dac541c93928" dependencies = [ "proc-macro2", - "quote 1.0.33", + "quote 1.0.35", + "syn 2.0.48", ] [[package]] name = "web-sys" -version = "0.3.64" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +checksum = "58cd2333b6e0be7a39605f0e255892fd7418a682d8da8fe042fe25128794d2ed" dependencies = [ "js-sys", "wasm-bindgen", @@ -4177,9 +4126,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.25.2" +version = "0.25.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14247bb57be4f377dfb94c72830b8ce8fc6beac03cf4bf7b9732eadd414123fc" +checksum = "1778a42e8b3b90bff8d0f5032bf22250792889a5cdc752aa0020c84abe3aaf10" [[package]] name = "which" @@ -4224,15 +4173,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets 0.42.2", -] - [[package]] name = "windows-sys" version = "0.48.0" @@ -4243,18 +4183,12 @@ dependencies = [ ] [[package]] -name = "windows-targets" -version = "0.42.2" +name = "windows-sys" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", + "windows-targets 0.52.0", ] [[package]] @@ -4273,10 +4207,19 @@ dependencies = [ ] [[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.2" +name = "windows-targets" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +dependencies = [ + "windows_aarch64_gnullvm 0.52.0", + "windows_aarch64_msvc 0.52.0", + "windows_i686_gnu 0.52.0", + "windows_i686_msvc 0.52.0", + "windows_x86_64_gnu 0.52.0", + "windows_x86_64_gnullvm 0.52.0", + "windows_x86_64_msvc 0.52.0", +] [[package]] name = "windows_aarch64_gnullvm" @@ -4285,10 +4228,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] -name = "windows_aarch64_msvc" -version = "0.42.2" +name = "windows_aarch64_gnullvm" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" [[package]] name = "windows_aarch64_msvc" @@ -4297,10 +4240,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] -name = "windows_i686_gnu" -version = "0.42.2" +name = "windows_aarch64_msvc" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" [[package]] name = "windows_i686_gnu" @@ -4309,10 +4252,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] -name = "windows_i686_msvc" -version = "0.42.2" +name = "windows_i686_gnu" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" [[package]] name = "windows_i686_msvc" @@ -4321,10 +4264,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] -name = "windows_x86_64_gnu" -version = "0.42.2" +name = "windows_i686_msvc" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" [[package]] name = "windows_x86_64_gnu" @@ -4333,10 +4276,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.2" +name = "windows_x86_64_gnu" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" [[package]] name = "windows_x86_64_gnullvm" @@ -4345,10 +4288,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] -name = "windows_x86_64_msvc" -version = "0.42.2" +name = "windows_x86_64_gnullvm" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" [[package]] name = "windows_x86_64_msvc" @@ -4356,6 +4299,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" + [[package]] name = "winreg" version = "0.50.0" @@ -4366,11 +4315,31 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "zerocopy" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +dependencies = [ + "proc-macro2", + "quote 1.0.35", + "syn 2.0.48", +] + [[package]] name = "zeroize" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" dependencies = [ "zeroize_derive", ] @@ -4382,6 +4351,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", - "quote 1.0.33", - "syn 2.0.38", + "quote 1.0.35", + "syn 2.0.48", ] diff --git a/Cargo.toml b/Cargo.toml index 2932649638..4726092fa2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "A decentralized virtual machine" homepage = "https://aleo.org" @@ -22,7 +22,7 @@ categories = [ include = [ "Cargo.toml", "vm", "README.md", "LICENSE.md" ] license = "Apache-2.0" edition = "2021" -rust-version = "1.70" +rust-version = "1.72.1" [workspace] members = [ @@ -150,58 +150,58 @@ wasm = [ "snarkvm-wasm" ] [dependencies.snarkvm-algorithms] path = "./algorithms" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-circuit] path = "./circuit" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-console] path = "./console" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-curves] path = "./curves" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-fields] path = "./fields" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-ledger] path = "./ledger" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-metrics] path = "./metrics" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-parameters] path = "./parameters" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-synthesizer] path = "./synthesizer" -version = "=0.16.15" +version = "=0.16.19" default-features = false optional = true [dependencies.snarkvm-utilities] path = "./utilities" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-wasm] path = "./wasm" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.anstyle] diff --git a/README.md b/README.md index f496a6c566..142fa532db 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@

- + - +

diff --git a/SECURITY.md b/SECURITY.md index 57be86957f..9111a21e49 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -2,16 +2,10 @@ The following describes our procedure for addressing major and minor security concerns in snarkVM. -## Testnet - -As Aleo is currently in the prototype stage and does not operate a platform intended for production use, -our security procedures are designed to promote public disclosure and quick security resolution. - -In preparation for the production stage, we will release new security guidelines and -issue new procedures for addressing the disclosure of sensitive security vulnerabilities. +Our security procedures are designed to promote public disclosure and quick security resolution. ### Reporting a Bug -During Testnet, all software bugs should be reported by filing a Github issue. +All software bugs should be reported by filing a Github issue. If you are unsure and would like to reach out to us directly, please email security \_at\_ aleo.org to elaborate on the issue. diff --git a/algorithms/Cargo.toml b/algorithms/Cargo.toml index af5a76e19b..fd8e78c5e1 100644 --- a/algorithms/Cargo.toml +++ b/algorithms/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-algorithms" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Algorithms for a decentralized virtual machine" homepage = "https://aleo.org" @@ -47,31 +47,31 @@ required-features = [ "test" ] [dependencies.snarkvm-curves] path = "../curves" -version = "=0.16.15" +version = "=0.16.19" default-features = false [dependencies.snarkvm-fields] path = "../fields" -version = "=0.16.15" +version = "=0.16.19" default-features = false [dependencies.snarkvm-parameters] path = "../parameters" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-utilities] path = "../utilities" -version = "=0.16.15" +version = "=0.16.19" default-features = false [dependencies.snarkvm-algorithms-cuda] path = "./cuda" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.aleo-std] -version = "0.1.18" +version = "0.1.24" default-features = false [dependencies.anyhow] diff --git a/algorithms/cuda/Cargo.toml b/algorithms/cuda/Cargo.toml index f57066d0f1..3c1ff3f252 100644 --- a/algorithms/cuda/Cargo.toml +++ b/algorithms/cuda/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-algorithms-cuda" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Cuda optimizations for a decentralized virtual machine" homepage = "https://aleo.org" diff --git a/algorithms/src/fft/domain.rs b/algorithms/src/fft/domain.rs index c121e9bfe2..bbac0f4c1d 100644 --- a/algorithms/src/fft/domain.rs +++ b/algorithms/src/fft/domain.rs @@ -319,7 +319,7 @@ impl EvaluationDomain { /// Given an index in the `other` subdomain, return an index into this domain `self` /// This assumes the `other`'s elements are also `self`'s first elements pub fn reindex_by_subdomain(&self, other: &Self, index: usize) -> Result { - ensure!(self.size() >= other.size(), "other.size() must be smaller than self.size()"); + ensure!(self.size() > other.size(), "other.size() must be smaller than self.size()"); // Let this subgroup be G, and the subgroup we're re-indexing by be S. // Since its a subgroup, the 0th element of S is at index 0 in G, the first element of S is at diff --git a/algorithms/src/fft/polynomial/sparse.rs b/algorithms/src/fft/polynomial/sparse.rs index f38967f99f..16e397e357 100644 --- a/algorithms/src/fft/polynomial/sparse.rs +++ b/algorithms/src/fft/polynomial/sparse.rs @@ -105,7 +105,7 @@ impl SparsePolynomial { *cur_coeff += *self_coeff * other_coeff; } } - SparsePolynomial::from_coefficients(result.into_iter()) + SparsePolynomial::from_coefficients(result) } } } diff --git a/algorithms/src/polycommit/kzg10/data_structures.rs b/algorithms/src/polycommit/kzg10/data_structures.rs index 495e817788..0ceae0b654 100644 --- a/algorithms/src/polycommit/kzg10/data_structures.rs +++ b/algorithms/src/polycommit/kzg10/data_structures.rs @@ -18,7 +18,7 @@ use crate::{ }; use snarkvm_curves::{AffineCurve, PairingCurve, PairingEngine, ProjectiveCurve}; use snarkvm_fields::{ConstraintFieldError, ToConstraintField, Zero}; -use snarkvm_parameters::testnet3::PowersOfG; +use snarkvm_parameters::mainnet::PowersOfG; use snarkvm_utilities::{ borrow::Cow, error, diff --git a/algorithms/src/polycommit/test_templates.rs b/algorithms/src/polycommit/test_templates.rs index 5664111254..60f73f027f 100644 --- a/algorithms/src/polycommit/test_templates.rs +++ b/algorithms/src/polycommit/test_templates.rs @@ -263,7 +263,7 @@ where let max_degree = max_degree.unwrap_or_else(|| distributions::Uniform::from(8..=64).sample(rng)); let pp = SonicKZG10::::load_srs(max_degree)?; let universal_prover = &pp.to_universal_prover().unwrap(); - let supported_degree_bounds = vec![1 << 10, 1 << 15, 1 << 20, 1 << 25, 1 << 30]; + let supported_degree_bounds = [1 << 10, 1 << 15, 1 << 20, 1 << 25, 1 << 30]; for _ in 0..num_iters { let supported_degree = @@ -391,7 +391,7 @@ fn equation_test_template>( let max_degree = max_degree.unwrap_or_else(|| distributions::Uniform::from(8..=64).sample(rng)); let pp = SonicKZG10::::load_srs(max_degree)?; let universal_prover = &pp.to_universal_prover().unwrap(); - let supported_degree_bounds = vec![1 << 10, 1 << 15, 1 << 20, 1 << 25, 1 << 30]; + let supported_degree_bounds = [1 << 10, 1 << 15, 1 << 20, 1 << 25, 1 << 30]; for _ in 0..num_iters { let supported_degree = diff --git a/algorithms/src/r1cs/constraint_variable.rs b/algorithms/src/r1cs/constraint_variable.rs deleted file mode 100644 index 9aa613cb91..0000000000 --- a/algorithms/src/r1cs/constraint_variable.rs +++ /dev/null @@ -1,309 +0,0 @@ -// Copyright (C) 2019-2023 Aleo Systems Inc. -// This file is part of the snarkVM library. - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// http://www.apache.org/licenses/LICENSE-2.0 - -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::r1cs::{LinearCombination, Variable}; -use snarkvm_fields::Field; - -use std::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub}; - -/// Either a `Variable` or a `LinearCombination`. -#[derive(Clone, Debug)] -pub enum ConstraintVariable { - /// A wrapper around a `LinearCombination`. - LC(LinearCombination), - /// A wrapper around a `Variable`. - Var(Variable), -} - -impl From for ConstraintVariable { - #[inline] - fn from(var: Variable) -> Self { - ConstraintVariable::Var(var) - } -} - -impl From<(F, Variable)> for ConstraintVariable { - #[inline] - fn from(coeff_var: (F, Variable)) -> Self { - ConstraintVariable::LC(coeff_var.into()) - } -} - -impl From> for ConstraintVariable { - #[inline] - fn from(lc: LinearCombination) -> Self { - ConstraintVariable::LC(lc) - } -} - -impl From<(F, LinearCombination)> for ConstraintVariable { - #[inline] - fn from((coeff, mut lc): (F, LinearCombination)) -> Self { - lc *= coeff; - ConstraintVariable::LC(lc) - } -} - -impl From<(F, ConstraintVariable)> for ConstraintVariable { - #[inline] - fn from((coeff, var): (F, ConstraintVariable)) -> Self { - match var { - ConstraintVariable::LC(lc) => (coeff, lc).into(), - ConstraintVariable::Var(var) => (coeff, var).into(), - } - } -} - -impl ConstraintVariable { - /// Returns an empty linear combination. - #[inline] - pub fn zero() -> Self { - ConstraintVariable::LC(LinearCombination::zero()) - } - - /// Negate the coefficients of all variables in `self`. - pub fn negate_in_place(&mut self) { - match self { - ConstraintVariable::LC(ref mut lc) => lc.negate_in_place(), - ConstraintVariable::Var(var) => *self = (-F::one(), *var).into(), - } - } - - /// Double the coefficients of all variables in `self`. - pub fn double_in_place(&mut self) { - match self { - ConstraintVariable::LC(lc) => lc.double_in_place(), - ConstraintVariable::Var(var) => *self = (F::one().double(), *var).into(), - } - } -} - -impl Add> for ConstraintVariable { - type Output = LinearCombination; - - #[inline] - fn add(self, other_lc: LinearCombination) -> LinearCombination { - match self { - ConstraintVariable::LC(lc) => other_lc + lc, - ConstraintVariable::Var(var) => other_lc + var, - } - } -} - -impl Sub> for ConstraintVariable { - type Output = LinearCombination; - - #[inline] - fn sub(self, other_lc: LinearCombination) -> LinearCombination { - let result = match self { - ConstraintVariable::LC(lc) => other_lc - lc, - ConstraintVariable::Var(var) => other_lc - var, - }; - -result - } -} - -impl Add> for &ConstraintVariable { - type Output = LinearCombination; - - #[inline] - fn add(self, other_lc: LinearCombination) -> LinearCombination { - match self { - ConstraintVariable::LC(lc) => other_lc + lc, - ConstraintVariable::Var(var) => other_lc + *var, - } - } -} - -impl Sub> for &ConstraintVariable { - type Output = LinearCombination; - - #[inline] - fn sub(self, other_lc: LinearCombination) -> LinearCombination { - let result = match self { - ConstraintVariable::LC(lc) => other_lc - lc, - ConstraintVariable::Var(var) => other_lc - *var, - }; - -result - } -} - -impl Add<(F, Variable)> for ConstraintVariable { - type Output = Self; - - #[inline] - fn add(self, var: (F, Variable)) -> Self { - let lc = match self { - ConstraintVariable::LC(lc) => lc + var, - ConstraintVariable::Var(var2) => LinearCombination::from(var2) + var, - }; - ConstraintVariable::LC(lc) - } -} - -impl AddAssign<(F, Variable)> for ConstraintVariable { - #[inline] - fn add_assign(&mut self, var: (F, Variable)) { - match self { - ConstraintVariable::LC(ref mut lc) => *lc += var, - ConstraintVariable::Var(var2) => *self = ConstraintVariable::LC(LinearCombination::from(*var2) + var), - }; - } -} - -impl Neg for ConstraintVariable { - type Output = Self; - - #[inline] - fn neg(mut self) -> Self { - self.negate_in_place(); - self - } -} - -impl Mul for ConstraintVariable { - type Output = Self; - - #[inline] - fn mul(self, scalar: F) -> Self { - match self { - ConstraintVariable::LC(lc) => ConstraintVariable::LC(lc * scalar), - ConstraintVariable::Var(var) => (scalar, var).into(), - } - } -} - -impl MulAssign for ConstraintVariable { - #[inline] - fn mul_assign(&mut self, scalar: F) { - match self { - ConstraintVariable::LC(lc) => *lc *= scalar, - ConstraintVariable::Var(var) => *self = (scalar, *var).into(), - } - } -} - -impl Sub<(F, Variable)> for ConstraintVariable { - type Output = Self; - - #[inline] - fn sub(self, (coeff, var): (F, Variable)) -> Self { - self + (-coeff, var) - } -} - -impl Add for ConstraintVariable { - type Output = Self; - - fn add(self, other: Variable) -> Self { - self + (F::one(), other) - } -} - -impl Sub for ConstraintVariable { - type Output = Self; - - #[inline] - fn sub(self, other: Variable) -> Self { - self - (F::one(), other) - } -} - -impl<'a, F: Field> Add<&'a Self> for ConstraintVariable { - type Output = Self; - - #[inline] - fn add(self, other: &'a Self) -> Self { - let lc = match self { - ConstraintVariable::LC(lc2) => lc2, - ConstraintVariable::Var(var) => var.into(), - }; - let lc2 = match other { - ConstraintVariable::LC(lc2) => lc + lc2, - ConstraintVariable::Var(var) => lc + *var, - }; - ConstraintVariable::LC(lc2) - } -} - -impl<'a, F: Field> Sub<&'a Self> for ConstraintVariable { - type Output = Self; - - #[inline] - fn sub(self, other: &'a Self) -> Self { - let lc = match self { - ConstraintVariable::LC(lc2) => lc2, - ConstraintVariable::Var(var) => var.into(), - }; - let lc2 = match other { - ConstraintVariable::LC(lc2) => lc - lc2, - ConstraintVariable::Var(var) => lc - *var, - }; - ConstraintVariable::LC(lc2) - } -} - -impl Add<&ConstraintVariable> for &ConstraintVariable { - type Output = ConstraintVariable; - - #[inline] - fn add(self, other: &ConstraintVariable) -> Self::Output { - (ConstraintVariable::zero() + self) + other - } -} - -impl Sub<&ConstraintVariable> for &ConstraintVariable { - type Output = ConstraintVariable; - - #[inline] - fn sub(self, other: &ConstraintVariable) -> Self::Output { - (ConstraintVariable::zero() + self) - other - } -} - -impl<'a, F: Field> Add<(F, &'a Self)> for ConstraintVariable { - type Output = Self; - - #[inline] - fn add(self, (coeff, other): (F, &'a Self)) -> Self { - let mut lc = match self { - ConstraintVariable::LC(lc2) => lc2, - ConstraintVariable::Var(var) => LinearCombination::zero() + var, - }; - - lc = match other { - ConstraintVariable::LC(lc2) => lc + (coeff, lc2), - ConstraintVariable::Var(var) => lc + (coeff, *var), - }; - ConstraintVariable::LC(lc) - } -} - -impl<'a, F: Field> Sub<(F, &'a Self)> for ConstraintVariable { - type Output = Self; - - #[inline] - #[allow(clippy::suspicious_arithmetic_impl)] - fn sub(self, (coeff, other): (F, &'a Self)) -> Self { - let mut lc = match self { - ConstraintVariable::LC(lc2) => lc2, - ConstraintVariable::Var(var) => LinearCombination::zero() + var, - }; - lc = match other { - ConstraintVariable::LC(lc2) => lc - (coeff, lc2), - ConstraintVariable::Var(var) => lc - (coeff, *var), - }; - ConstraintVariable::LC(lc) - } -} diff --git a/algorithms/src/r1cs/linear_combination.rs b/algorithms/src/r1cs/linear_combination.rs index b0d0a38763..20465fca64 100644 --- a/algorithms/src/r1cs/linear_combination.rs +++ b/algorithms/src/r1cs/linear_combination.rs @@ -114,7 +114,12 @@ impl AddAssign<(F, Variable)> for LinearCombination { #[inline] fn add_assign(&mut self, (coeff, var): (F, Variable)) { match self.get_var_loc(&var) { - Ok(found) => self.0[found].1 += &coeff, + Ok(found) => { + self.0[found].1 += &coeff; + if self.0[found].1.is_zero() { + self.0.remove(found); + } + } Err(not_found) => self.0.insert(not_found, (var, coeff)), } } diff --git a/algorithms/src/r1cs/mod.rs b/algorithms/src/r1cs/mod.rs index 11fc8042d5..4dd40feaa0 100644 --- a/algorithms/src/r1cs/mod.rs +++ b/algorithms/src/r1cs/mod.rs @@ -21,9 +21,6 @@ pub use constraint_counter::*; mod constraint_system; pub use constraint_system::{ConstraintSynthesizer, ConstraintSystem}; -mod constraint_variable; -pub use constraint_variable::*; - pub mod errors; pub use errors::*; @@ -33,13 +30,19 @@ pub use linear_combination::*; mod namespace; pub use namespace::*; +#[cfg(feature = "test")] mod optional_vec; +#[cfg(feature = "test")] pub use optional_vec::*; +#[cfg(feature = "test")] mod test_constraint_system; +#[cfg(feature = "test")] pub use test_constraint_system::{Fr, TestConstraintSystem}; +#[cfg(feature = "test")] mod test_constraint_checker; +#[cfg(feature = "test")] pub use test_constraint_checker::TestConstraintChecker; use snarkvm_utilities::serialize::*; diff --git a/algorithms/src/snark/varuna/ahp/prover/mod.rs b/algorithms/src/snark/varuna/ahp/prover/mod.rs index 9cb0f042bb..68adb3038c 100644 --- a/algorithms/src/snark/varuna/ahp/prover/mod.rs +++ b/algorithms/src/snark/varuna/ahp/prover/mod.rs @@ -26,4 +26,4 @@ pub(crate) use oracles::*; mod round_functions; mod state; -pub(self) use state::*; +use state::*; diff --git a/algorithms/src/snark/varuna/ahp/prover/oracles.rs b/algorithms/src/snark/varuna/ahp/prover/oracles.rs index 725b6a291d..37b1c94728 100644 --- a/algorithms/src/snark/varuna/ahp/prover/oracles.rs +++ b/algorithms/src/snark/varuna/ahp/prover/oracles.rs @@ -37,7 +37,7 @@ impl FirstOracles { /// Iterate over the polynomials output by the prover in the first round. pub fn into_iter(self) -> impl Iterator> { - self.batches.into_values().flat_map(|b| b.into_iter()).map(|b| b.0).chain(self.mask_poly.into_iter()) + self.batches.into_values().flat_map(|b| b.into_iter()).map(|b| b.0).chain(self.mask_poly) } pub fn matches_info(&self, info: &BTreeMap) -> bool { diff --git a/algorithms/src/snark/varuna/ahp/prover/round_functions/fifth.rs b/algorithms/src/snark/varuna/ahp/prover/round_functions/fifth.rs index c8e0b71e19..e393d8ed28 100644 --- a/algorithms/src/snark/varuna/ahp/prover/round_functions/fifth.rs +++ b/algorithms/src/snark/varuna/ahp/prover/round_functions/fifth.rs @@ -44,6 +44,8 @@ impl AHPForR1CS { state: prover::State<'_, F, SM>, _r: &mut R, ) -> Result, AHPError> { + let round_time = start_timer!(|| "AHP::Prover::FifthRound"); + let lhs_sum: DensePolynomial = cfg_reduce!( cfg_par_bridge!(verifier_message.into_iter().zip_eq(state.lhs_polys_into_iter())).map( |(delta, mut lhs)| { @@ -62,6 +64,8 @@ impl AHPForR1CS { let h_2 = LabeledPolynomial::new("h_2", lhs_sum, None, None); let oracles = prover::FifthOracles { h_2 }; assert!(oracles.matches_info(&Self::fifth_round_polynomial_info())); + + end_timer!(round_time); Ok(oracles) } diff --git a/algorithms/src/snark/varuna/ahp/selectors.rs b/algorithms/src/snark/varuna/ahp/selectors.rs index b6831e5423..6bf9744ae2 100644 --- a/algorithms/src/snark/varuna/ahp/selectors.rs +++ b/algorithms/src/snark/varuna/ahp/selectors.rs @@ -85,7 +85,7 @@ pub(crate) fn apply_randomized_selector( // This removes a mul and div by v_H operation over each circuit's (target_domain - src_domain) // We have two scenario's: either we return a remainder witness or there is none. if !remainder_witness { - // Substituting in s_i, we get that poly_i * s_i / v_H = poly_i / v_H * (H_i.size() / H.size()); + // Substituting in s_i, we get that poly_i * s_i / v_H = poly_i / v_H_i * (H_i.size() / H.size()); let selector_time = start_timer!(|| "Compute selector without remainder witness"); let (mut h_i, remainder) = poly.divide_by_vanishing_poly(*src_domain)?; diff --git a/algorithms/src/snark/varuna/ahp/verifier/messages.rs b/algorithms/src/snark/varuna/ahp/verifier/messages.rs index b939a86c74..1abd254d6d 100644 --- a/algorithms/src/snark/varuna/ahp/verifier/messages.rs +++ b/algorithms/src/snark/varuna/ahp/verifier/messages.rs @@ -62,11 +62,7 @@ pub struct FourthMessage { impl FourthMessage { pub fn into_iter(self) -> impl Iterator { - self.delta_a - .into_iter() - .zip_eq(self.delta_b.into_iter()) - .zip_eq(self.delta_c.into_iter()) - .flat_map(|((r_a, r_b), r_c)| [r_a, r_b, r_c]) + self.delta_a.into_iter().zip_eq(self.delta_b).zip_eq(self.delta_c).flat_map(|((r_a, r_b), r_c)| [r_a, r_b, r_c]) } } diff --git a/algorithms/src/snark/varuna/data_structures/proof.rs b/algorithms/src/snark/varuna/data_structures/proof.rs index 1fc4962215..7ebc495714 100644 --- a/algorithms/src/snark/varuna/data_structures/proof.rs +++ b/algorithms/src/snark/varuna/data_structures/proof.rs @@ -88,7 +88,7 @@ impl Commitments { compress: Compress, validate: Validate, ) -> Result { - let mut w = Vec::with_capacity(batch_sizes.iter().sum()); + let mut w = Vec::new(); for batch_size in batch_sizes { w.extend(deserialize_vec_without_len(&mut reader, compress, validate, *batch_size)?); } @@ -261,7 +261,11 @@ impl Proof { /// Check that the number of messages is consistent with our batch size pub fn check_batch_sizes(&self) -> Result<(), SNARKError> { - let total_instances = self.batch_sizes.iter().sum::(); + let total_instances = self + .batch_sizes + .iter() + .try_fold(0usize, |acc, &size| acc.checked_add(size)) + .ok_or(SNARKError::BatchSizeMismatch)?; if self.commitments.witness_commitments.len() != total_instances { return Err(SNARKError::BatchSizeMismatch); } diff --git a/algorithms/src/snark/varuna/data_structures/test_circuit.rs b/algorithms/src/snark/varuna/data_structures/test_circuit.rs index 2bd66fa259..6af4ae7f98 100644 --- a/algorithms/src/snark/varuna/data_structures/test_circuit.rs +++ b/algorithms/src/snark/varuna/data_structures/test_circuit.rs @@ -96,7 +96,9 @@ impl TestCircuit { num_variables: usize, rng: &mut R, ) -> (Self, Vec) { - let mut public_inputs: Vec = Vec::with_capacity(mul_depth); + let mut public_inputs: Vec = Vec::with_capacity(1 + mul_depth); + public_inputs.push(F::one()); + let a = F::rand(rng); let b = F::rand(rng); @@ -119,7 +121,8 @@ impl TestCircuit { num_constraints: usize, num_variables: usize, ) -> (Self, Vec) { - let mut public_inputs: Vec = Vec::with_capacity(mul_depth); + let mut public_inputs: Vec = Vec::with_capacity(1 + mul_depth); + public_inputs.push(F::one()); let a = F::from(a); let b = F::from(b); for j in 1..(mul_depth + 1) { diff --git a/algorithms/src/snark/varuna/tests.rs b/algorithms/src/snark/varuna/tests.rs index 3c786162b5..2271c9f703 100644 --- a/algorithms/src/snark/varuna/tests.rs +++ b/algorithms/src/snark/varuna/tests.rs @@ -26,6 +26,7 @@ mod varuna { }, traits::{AlgebraicSponge, SNARK}, }; + use std::collections::BTreeMap; use snarkvm_curves::bls12_377::{Bls12_377, Fq, Fr}; @@ -57,6 +58,8 @@ mod varuna { let mul_depth = 1; println!("running test with SM::ZK: {}, mul_depth: {}, num_constraints: {}, num_variables: {}", $snark_mode::ZK, mul_depth + i, num_constraints + i, num_variables + i); let (circ, public_inputs) = TestCircuit::gen_rand(mul_depth + i, num_constraints + i, num_variables + i, rng); + let mut fake_inputs = public_inputs.clone(); + fake_inputs[public_inputs.len() - 1] = random; let (index_pk, index_vk) = $snark_inst::circuit_setup(&universal_srs, &circ).unwrap(); println!("Called circuit setup"); @@ -76,7 +79,7 @@ mod varuna { assert!($snark_inst::verify(universal_verifier, &fs_parameters, &index_vk, public_inputs, &proof).unwrap()); println!("Called verifier"); eprintln!("\nShould not verify (i.e. verifier messages should print below):"); - assert!(!$snark_inst::verify(universal_verifier, &fs_parameters, &index_vk, [random], &proof).unwrap()); + assert!(!$snark_inst::verify(universal_verifier, &fs_parameters, &index_vk, fake_inputs, &proof).unwrap()); } for circuit_batch_size in (0..4).map(|i| 2usize.pow(i)) { @@ -129,7 +132,8 @@ mod varuna { for instance_input in vks_to_inputs.values() { let mut fake_instance_input = Vec::with_capacity(instance_input.len()); for input in instance_input.iter() { - let fake_input: Vec<_> = (0..input.len()).map(|_| Fr::rand(rng)).collect(); + let mut fake_input = input.clone(); + fake_input[input.len() - 1] = Fr::rand(rng); fake_instance_input.push(fake_input); } fake_instance_inputs.push(fake_instance_input); @@ -332,6 +336,8 @@ mod varuna_hiding { for _ in 0..num_times { let mul_depth = 2; let (circuit, public_inputs) = TestCircuit::gen_rand(mul_depth, num_constraints, num_variables, rng); + let mut fake_inputs = public_inputs.clone(); + fake_inputs[public_inputs.len() - 1] = Fr::rand(rng); let (index_pk, index_vk) = VarunaInst::circuit_setup(&universal_srs, &circuit).unwrap(); println!("Called circuit setup"); @@ -342,16 +348,7 @@ mod varuna_hiding { assert!(VarunaInst::verify(universal_verifier, &fs_parameters, &index_vk, public_inputs, &proof).unwrap()); println!("Called verifier"); eprintln!("\nShould not verify (i.e. verifier messages should print below):"); - assert!( - !VarunaInst::verify( - universal_verifier, - &fs_parameters, - &index_vk, - [Fr::rand(rng), Fr::rand(rng)], - &proof - ) - .unwrap() - ); + assert!(!VarunaInst::verify(universal_verifier, &fs_parameters, &index_vk, fake_inputs, &proof).unwrap()); } } diff --git a/algorithms/src/snark/varuna/varuna.rs b/algorithms/src/snark/varuna/varuna.rs index 329cc776b0..ccd1da99a6 100644 --- a/algorithms/src/snark/varuna/varuna.rs +++ b/algorithms/src/snark/varuna/varuna.rs @@ -302,7 +302,7 @@ where // (since the first coeff is 1), and so we squeeze out `num_polynomials` points. let mut challenges = sponge.squeeze_nonnative_field_elements(verifying_key.circuit_commitments.len()); let point = challenges.pop().ok_or(anyhow!("Failed to squeeze random element"))?; - let combiners = core::iter::once(E::Fr::one()).chain(challenges.into_iter()); + let combiners = core::iter::once(E::Fr::one()).chain(challenges); // We will construct a linear combination and provide a proof of evaluation of the lc at `point`. let (lc, evaluation) = @@ -672,7 +672,9 @@ where .iter() .map(|input| { let input = input.borrow().to_field_elements()?; - if input.len() > input_domain.size() - 1 { + ensure!(input.len() > 0); + ensure!(input[0] == E::Fr::one()); + if input.len() > input_domain.size() { bail!(SNARKError::PublicInputSizeMismatch); } Ok(input) @@ -683,10 +685,10 @@ where input_fields .iter() .map(|input| { - let mut new_input = Vec::with_capacity((1 + input.len()).max(input_domain.size())); - new_input.push(E::Fr::one()); + let input_len = input.len().max(input_domain.size()); + let mut new_input = Vec::with_capacity(input_len); new_input.extend_from_slice(input); - new_input.resize(input.len().max(input_domain.size()), E::Fr::zero()); + new_input.resize(input_len, E::Fr::zero()); if cfg!(debug_assertions) { println!("Number of padded public variables: {}", new_input.len()); } diff --git a/circuit/Cargo.toml b/circuit/Cargo.toml index 801a7d7160..bfc0896c5f 100644 --- a/circuit/Cargo.toml +++ b/circuit/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-circuit" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Circuits for a decentralized virtual machine" homepage = "https://aleo.org" @@ -25,28 +25,28 @@ edition = "2021" [dependencies.snarkvm-circuit-account] path = "./account" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-algorithms] path = "./algorithms" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-collections] path = "./collections" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-environment] path = "./environment" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-network] path = "./network" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-program] path = "./program" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types] path = "./types" -version = "=0.16.15" +version = "=0.16.19" diff --git a/circuit/account/Cargo.toml b/circuit/account/Cargo.toml index 99ab62b6c4..8c493b19bc 100644 --- a/circuit/account/Cargo.toml +++ b/circuit/account/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-circuit-account" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Account circuit library for a decentralized virtual machine" license = "Apache-2.0" @@ -9,20 +9,20 @@ edition = "2021" [dependencies.console] package = "snarkvm-console-account" path = "../../console/account" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-circuit-algorithms] path = "../algorithms" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-network] path = "../network" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types] path = "../types" -version = "=0.16.15" +version = "=0.16.19" [dev-dependencies.snarkvm-utilities] path = "../../utilities" diff --git a/circuit/algorithms/Cargo.toml b/circuit/algorithms/Cargo.toml index 918caade59..8749d46f84 100644 --- a/circuit/algorithms/Cargo.toml +++ b/circuit/algorithms/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-circuit-algorithms" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Algorithm circuit library for a decentralized virtual machine" license = "Apache-2.0" @@ -9,16 +9,16 @@ edition = "2021" [dependencies.console] package = "snarkvm-console-algorithms" path = "../../console/algorithms" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-circuit-types] path = "../types" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-fields] path = "../../fields" -version = "=0.16.15" +version = "=0.16.19" default-features = false [dev-dependencies.anyhow] diff --git a/circuit/algorithms/src/poseidon/hash_many.rs b/circuit/algorithms/src/poseidon/hash_many.rs index 4d6dbc2ce5..d2baf7fcc5 100644 --- a/circuit/algorithms/src/poseidon/hash_many.rs +++ b/circuit/algorithms/src/poseidon/hash_many.rs @@ -130,10 +130,9 @@ impl Poseidon { let num_squeezed = RATE - squeeze_index; remaining[..num_squeezed].clone_from_slice(&state[start..(start + num_squeezed)]); - // Unless we are done with squeezing in this call, permute. - if remaining.len() != RATE { - self.permute(state); - } + // Permute. + self.permute(state); + // Repeat with the updated output slice and squeeze index. remaining = &mut remaining[num_squeezed..]; squeeze_index = 0; diff --git a/circuit/collections/Cargo.toml b/circuit/collections/Cargo.toml index 7a24023f22..6cc949c5b9 100644 --- a/circuit/collections/Cargo.toml +++ b/circuit/collections/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-circuit-collections" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Collections circuit library for a decentralized virtual machine" license = "Apache-2.0" @@ -9,16 +9,16 @@ edition = "2021" [dependencies.console] package = "snarkvm-console-collections" path = "../../console/collections" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-circuit-algorithms] path = "../algorithms" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types] path = "../types" -version = "=0.16.15" +version = "=0.16.19" [dev-dependencies.snarkvm-circuit-network] path = "../network" diff --git a/circuit/environment/Cargo.toml b/circuit/environment/Cargo.toml index eda3378021..894d81274c 100644 --- a/circuit/environment/Cargo.toml +++ b/circuit/environment/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-circuit-environment" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Circuit environment for a decentralized virtual machine" license = "Apache-2.0" @@ -14,32 +14,32 @@ harness = false [dependencies.console] package = "snarkvm-console-network" path = "../../console/network" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-algorithms] path = "../../algorithms" -version = "=0.16.15" +version = "=0.16.19" default-features = false features = [ "r1cs" ] [dependencies.snarkvm-circuit-environment-witness] path = "./witness" -version = "=0.16.15" +version = "=0.16.19" default-features = false [dependencies.snarkvm-curves] path = "../../curves" -version = "=0.16.15" +version = "=0.16.19" default-features = false [dependencies.snarkvm-fields] path = "../../fields" -version = "=0.16.15" +version = "=0.16.19" default-features = false [dependencies.snarkvm-utilities] path = "../../utilities" -version = "=0.16.15" +version = "=0.16.19" default-features = false [dependencies.indexmap] @@ -59,7 +59,7 @@ version = "1.18.0" [dev-dependencies.snarkvm-algorithms] path = "../../algorithms" -features = [ "polycommit_full", "snark" ] +features = [ "polycommit_full", "snark", "test" ] [dev-dependencies.snarkvm-circuit] path = "../../circuit" diff --git a/circuit/environment/src/circuit.rs b/circuit/environment/src/circuit.rs index be60fe946b..56ff721b0c 100644 --- a/circuit/environment/src/circuit.rs +++ b/circuit/environment/src/circuit.rs @@ -19,9 +19,10 @@ use core::{ fmt, }; -type Field = ::Field; +type Field = ::Field; thread_local! { + pub(super) static CONSTRAINT_LIMIT: Cell> = Cell::new(None); pub(super) static CIRCUIT: RefCell> = RefCell::new(R1CS::new()); pub(super) static IN_WITNESS: Cell = Cell::new(false); pub(super) static ZERO: LinearCombination = LinearCombination::zero(); @@ -32,10 +33,10 @@ thread_local! { pub struct Circuit; impl Environment for Circuit { - type Affine = ::Affine; + type Affine = ::Affine; type BaseField = Field; - type Network = console::Testnet3; - type ScalarField = ::Scalar; + type Network = console::MainnetV0; + type ScalarField = ::Scalar; /// Returns the `zero` constant. fn zero() -> LinearCombination { @@ -146,6 +147,15 @@ impl Environment for Circuit { // Ensure we are not in witness mode. if !in_witness.get() { CIRCUIT.with(|circuit| { + // Ensure that we do not surpass the constraint limit for the circuit. + CONSTRAINT_LIMIT.with(|constraint_limit| { + if let Some(limit) = constraint_limit.get() { + if circuit.borrow().num_constraints() > limit { + Self::halt(format!("Surpassed the constraint limit ({limit})")) + } + } + }); + let (a, b, c) = constraint(); let (a, b, c) = (a.into(), b.into(), c.into()); @@ -248,8 +258,16 @@ impl Environment for Circuit { panic!("{}", &error) } - /// TODO (howardwu): Abstraction - Refactor this into an appropriate design. - /// Circuits should not have easy access to this during synthesis. + /// Returns the constraint limit for the circuit, if one exists. + fn get_constraint_limit() -> Option { + CONSTRAINT_LIMIT.with(|current_limit| current_limit.get()) + } + + /// Sets the constraint limit for the circuit. + fn set_constraint_limit(limit: Option) { + CONSTRAINT_LIMIT.with(|current_limit| current_limit.replace(limit)); + } + /// Returns the R1CS circuit, resetting the circuit. fn inject_r1cs(r1cs: R1CS) { CIRCUIT.with(|circuit| { @@ -268,13 +286,13 @@ impl Environment for Circuit { }) } - /// TODO (howardwu): Abstraction - Refactor this into an appropriate design. - /// Circuits should not have easy access to this during synthesis. /// Returns the R1CS circuit, resetting the circuit. fn eject_r1cs_and_reset() -> R1CS { CIRCUIT.with(|circuit| { // Reset the witness mode. IN_WITNESS.with(|in_witness| in_witness.replace(false)); + // Reset the constraint limit. + Self::set_constraint_limit(None); // Eject the R1CS instance. let r1cs = circuit.replace(R1CS::<::BaseField>::new()); // Ensure the circuit is now empty. @@ -287,13 +305,13 @@ impl Environment for Circuit { }) } - /// TODO (howardwu): Abstraction - Refactor this into an appropriate design. - /// Circuits should not have easy access to this during synthesis. /// Returns the R1CS assignment of the circuit, resetting the circuit. fn eject_assignment_and_reset() -> Assignment<::Field> { CIRCUIT.with(|circuit| { // Reset the witness mode. IN_WITNESS.with(|in_witness| in_witness.replace(false)); + // Reset the constraint limit. + Self::set_constraint_limit(None); // Eject the R1CS instance. let r1cs = circuit.replace(R1CS::<::BaseField>::new()); assert_eq!(0, circuit.borrow().num_constants()); @@ -310,6 +328,9 @@ impl Environment for Circuit { CIRCUIT.with(|circuit| { // Reset the witness mode. IN_WITNESS.with(|in_witness| in_witness.replace(false)); + // Reset the constraint limit. + Self::set_constraint_limit(None); + // Reset the circuit. *circuit.borrow_mut() = R1CS::<::BaseField>::new(); assert_eq!(0, circuit.borrow().num_constants()); assert_eq!(1, circuit.borrow().num_public()); diff --git a/circuit/environment/src/environment.rs b/circuit/environment/src/environment.rs index 34ef4370ea..d8fdc5a181 100644 --- a/circuit/environment/src/environment.rs +++ b/circuit/environment/src/environment.rs @@ -160,6 +160,12 @@ pub trait Environment: 'static + Copy + Clone + fmt::Debug + fmt::Display + Eq + ::halt(message) } + /// Returns the constraint limit for the circuit, if one exists. + fn get_constraint_limit() -> Option; + + /// Sets the constraint limit for the circuit. + fn set_constraint_limit(limit: Option); + /// Returns the R1CS circuit, resetting the circuit. fn inject_r1cs(r1cs: R1CS); diff --git a/circuit/environment/src/helpers/assignment.rs b/circuit/environment/src/helpers/assignment.rs index c9f51c7c95..b5e14ec241 100644 --- a/circuit/environment/src/helpers/assignment.rs +++ b/circuit/environment/src/helpers/assignment.rs @@ -167,14 +167,18 @@ impl snarkvm_algorithms::r1cs::ConstraintSynthesizer for Assig assert_eq!(0, cs.num_private_variables()); assert_eq!(0, cs.num_constraints()); + let result = converter.public.insert(0, CS::one()); + assert!(result.is_none(), "Overwrote an existing public variable in the converter"); + // Allocate the public variables. - for (i, (index, value)) in self.public.iter().enumerate() { - assert_eq!(i as u64, *index, "Public variables in first system must be processed in lexicographic order"); + // NOTE: we skip the first public `One` variable because we already allocated it in the `ConstraintSystem` constructor. + for (i, (index, value)) in self.public.iter().skip(1).enumerate() { + assert_eq!((i + 1) as u64, *index, "Public vars in first system must be processed in lexicographic order"); let gadget = cs.alloc_input(|| format!("Public {i}"), || Ok(*value))?; assert_eq!( - snarkvm_algorithms::r1cs::Index::Public((index + 1) as usize), + snarkvm_algorithms::r1cs::Index::Public(*index as usize), gadget.get_unchecked(), "Public variables in the second system must match the first system (with an off-by-1 for the public case)" ); @@ -219,7 +223,7 @@ impl snarkvm_algorithms::r1cs::ConstraintSynthesizer for Assig AssignmentVariable::Public(index) => { let gadget = converter.public.get(index).unwrap(); assert_eq!( - snarkvm_algorithms::r1cs::Index::Public((index + 1) as usize), + snarkvm_algorithms::r1cs::Index::Public(*index as usize), gadget.get_unchecked(), "Failed during constraint translation. The public variable in the second system must match the first system (with an off-by-1 for the public case)" ); @@ -258,7 +262,7 @@ impl snarkvm_algorithms::r1cs::ConstraintSynthesizer for Assig } // Ensure the given `cs` matches in size with the first system. - assert_eq!(self.num_public() + 1, cs.num_public_variables() as u64); + assert_eq!(self.num_public(), cs.num_public_variables() as u64); assert_eq!(self.num_private(), cs.num_private_variables() as u64); assert_eq!(self.num_constraints(), cs.num_constraints() as u64); @@ -309,7 +313,7 @@ mod tests { assignment.generate_constraints(&mut cs).unwrap(); { use snarkvm_algorithms::r1cs::ConstraintSystem; - assert_eq!(assignment.num_public() + 1, cs.num_public_variables() as u64); + assert_eq!(assignment.num_public(), cs.num_public_variables() as u64); assert_eq!(assignment.num_private(), cs.num_private_variables() as u64); assert_eq!(assignment.num_constraints(), cs.num_constraints() as u64); assert!(cs.is_satisfied()); diff --git a/circuit/environment/src/helpers/converter.rs b/circuit/environment/src/helpers/converter.rs index 2466c5954d..6347d13f4c 100644 --- a/circuit/environment/src/helpers/converter.rs +++ b/circuit/environment/src/helpers/converter.rs @@ -47,21 +47,26 @@ impl R1CS { assert_eq!(0, cs.num_private_variables()); assert_eq!(0, cs.num_constraints()); + let result = converter.public.insert(0, CS::one()); + assert!(result.is_none(), "Overwrote an existing public variable in the converter"); + // Allocate the public variables. - for (i, public) in self.to_public_variables().iter().enumerate() { + // NOTE: we skip the first public `One` variable because we already allocated it in the `ConstraintSystem` constructor. + for (i, public) in self.to_public_variables().iter().skip(1).enumerate() { match public { Variable::Public(index_value) => { let (index, value) = index_value.as_ref(); assert_eq!( - i as u64, *index, - "Public variables in first system must be processed in lexicographic order" + (i + 1) as u64, + *index, + "Public vars in first system must be processed in lexicographic order" ); let gadget = cs.alloc_input(|| format!("Public {i}"), || Ok(*value))?; assert_eq!( - snarkvm_algorithms::r1cs::Index::Public((index + 1) as usize), + snarkvm_algorithms::r1cs::Index::Public(*index as usize), gadget.get_unchecked(), "Public variables in the second system must match the first system (with an off-by-1 for the public case)" ); @@ -165,7 +170,7 @@ impl R1CS { } // Ensure the given `cs` matches in size with the first system. - assert_eq!(self.num_public() + 1, cs.num_public_variables() as u64); + assert_eq!(self.num_public(), cs.num_public_variables() as u64); assert_eq!(self.num_private(), cs.num_private_variables() as u64); assert_eq!(self.num_constraints(), cs.num_constraints() as u64); @@ -211,7 +216,7 @@ mod tests { Circuit.generate_constraints(&mut cs).unwrap(); { use snarkvm_algorithms::r1cs::ConstraintSystem; - assert_eq!(Circuit::num_public() + 1, cs.num_public_variables() as u64); + assert_eq!(Circuit::num_public(), cs.num_public_variables() as u64); assert_eq!(Circuit::num_private(), cs.num_private_variables() as u64); assert_eq!(Circuit::num_constraints(), cs.num_constraints() as u64); assert!(cs.is_satisfied()); diff --git a/circuit/environment/src/lib.rs b/circuit/environment/src/lib.rs index 01c93b598d..9443e5eabd 100644 --- a/circuit/environment/src/lib.rs +++ b/circuit/environment/src/lib.rs @@ -29,6 +29,7 @@ pub mod helpers; pub use helpers::*; pub mod macros; +#[allow(unused_imports)] pub use macros::*; pub mod traits; diff --git a/circuit/environment/src/macros/mod.rs b/circuit/environment/src/macros/mod.rs index 2aa1051a4a..bed7fb825f 100644 --- a/circuit/environment/src/macros/mod.rs +++ b/circuit/environment/src/macros/mod.rs @@ -13,10 +13,13 @@ // limitations under the License. mod metrics; +#[allow(unused_imports)] pub use metrics::*; mod scope; +#[allow(unused_imports)] pub use scope::*; mod witness; +#[allow(unused_imports)] pub use witness::*; diff --git a/circuit/environment/witness/Cargo.toml b/circuit/environment/witness/Cargo.toml index 64c87aca08..a6660d0684 100644 --- a/circuit/environment/witness/Cargo.toml +++ b/circuit/environment/witness/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-circuit-environment-witness" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "A procedural macro to construct a witness in an environment" license = "Apache-2.0" diff --git a/circuit/network/Cargo.toml b/circuit/network/Cargo.toml index 6d9e086b43..efd63a8cdc 100644 --- a/circuit/network/Cargo.toml +++ b/circuit/network/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-circuit-network" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Network circuit library for a decentralized virtual machine" license = "Apache-2.0" @@ -9,20 +9,20 @@ edition = "2021" [dependencies.console] package = "snarkvm-console-network" path = "../../console/network" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-circuit-algorithms] path = "../algorithms" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-collections] path = "../collections" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types] path = "../types" -version = "=0.16.15" +version = "=0.16.19" [dev-dependencies.snarkvm-console-types] path = "../../console/types" diff --git a/circuit/network/src/v0.rs b/circuit/network/src/v0.rs index 9dc7a9d8da..26bda8513c 100644 --- a/circuit/network/src/v0.rs +++ b/circuit/network/src/v0.rs @@ -52,14 +52,14 @@ type E = Circuit; thread_local! { /// The group bases for the Aleo signature and encryption schemes. - static GENERATOR_G: Vec> = Vec::constant(::g_powers().to_vec()); + static GENERATOR_G: Vec> = Vec::constant(::g_powers().to_vec()); /// The encryption domain as a constant field element. - static ENCRYPTION_DOMAIN: Field = Field::constant(::encryption_domain()); + static ENCRYPTION_DOMAIN: Field = Field::constant(::encryption_domain()); /// The graph key domain as a constant field element. - static GRAPH_KEY_DOMAIN: Field = Field::constant(::graph_key_domain()); + static GRAPH_KEY_DOMAIN: Field = Field::constant(::graph_key_domain()); /// The serial number domain as a constant field element. - static SERIAL_NUMBER_DOMAIN: Field = Field::constant(::serial_number_domain()); + static SERIAL_NUMBER_DOMAIN: Field = Field::constant(::serial_number_domain()); /// The BHP hash function, which can take an input of up to 256 bits. static BHP_256: BHP256 = BHP256::::constant(console::BHP_256.clone()); @@ -466,6 +466,16 @@ impl Environment for AleoV0 { E::halt(message) } + /// Returns the constraint limit for the circuit, if one exists. + fn get_constraint_limit() -> Option { + E::get_constraint_limit() + } + + /// Sets the constraint limit for the circuit. + fn set_constraint_limit(limit: Option) { + E::set_constraint_limit(limit) + } + /// Returns the R1CS circuit, resetting the circuit. fn inject_r1cs(r1cs: R1CS) { E::inject_r1cs(r1cs) diff --git a/circuit/program/Cargo.toml b/circuit/program/Cargo.toml index 7b0e18ce2c..2a222e0093 100644 --- a/circuit/program/Cargo.toml +++ b/circuit/program/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-circuit-program" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Program circuit library for a decentralized virtual machine" license = "Apache-2.0" @@ -9,32 +9,32 @@ edition = "2021" [dependencies.console] package = "snarkvm-console-program" path = "../../console/program" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-circuit-account] path = "../account" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-algorithms] path = "../algorithms" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-collections] path = "../collections" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-network] path = "../network" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types] path = "../types" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-utilities] path = "../../utilities" -version = "=0.16.15" +version = "=0.16.19" [dependencies.paste] version = "1.0" diff --git a/circuit/program/src/data/literal/cast/boolean.rs b/circuit/program/src/data/literal/cast/boolean.rs index 955df86b40..6753261ca3 100644 --- a/circuit/program/src/data/literal/cast/boolean.rs +++ b/circuit/program/src/data/literal/cast/boolean.rs @@ -66,7 +66,7 @@ impl Cast> for Boolean { mod tests { use super::*; use console::Cast as _; - use console_root::{network::Testnet3, prelude::TestRng}; + use console_root::{network::MainnetV0, prelude::TestRng}; use snarkvm_circuit_types::environment::{count_is, Circuit, Eject, Inject, Mode, UpdatableCount}; use std::fmt::Debug; @@ -77,114 +77,114 @@ mod tests { i: usize, mode: Mode, _: &mut TestRng, - ) -> (console_root::types::Boolean, Boolean) { + ) -> (console_root::types::Boolean, Boolean) { (console_root::types::Boolean::new(i % 2 == 0), Boolean::new(mode, i % 2 == 0)) } - impl_check_cast!(cast, Boolean, console_root::types::Boolean::); + impl_check_cast!(cast, Boolean, console_root::types::Boolean::); #[test] fn test_boolean_to_address() { - check_cast::, console_root::types::Address>(Mode::Constant, count_is!(10, 0, 0, 0)); - check_cast::, console_root::types::Address>(Mode::Public, count_is!(10, 0, 0, 0)); - check_cast::, console_root::types::Address>(Mode::Private, count_is!(10, 0, 0, 0)); + check_cast::, console_root::types::Address>(Mode::Constant, count_is!(10, 0, 0, 0)); + check_cast::, console_root::types::Address>(Mode::Public, count_is!(10, 0, 0, 0)); + check_cast::, console_root::types::Address>(Mode::Private, count_is!(10, 0, 0, 0)); } #[test] fn test_boolean_to_boolean() { - check_cast::, console_root::types::Boolean>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Boolean>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Boolean>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Boolean>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Boolean>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Boolean>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_boolean_to_field() { - check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_boolean_to_group() { - check_cast::, console_root::types::Group>(Mode::Constant, count_is!(10, 0, 0, 0)); - check_cast::, console_root::types::Group>(Mode::Public, count_is!(10, 0, 0, 0)); - check_cast::, console_root::types::Group>(Mode::Private, count_is!(10, 0, 0, 0)); + check_cast::, console_root::types::Group>(Mode::Constant, count_is!(10, 0, 0, 0)); + check_cast::, console_root::types::Group>(Mode::Public, count_is!(10, 0, 0, 0)); + check_cast::, console_root::types::Group>(Mode::Private, count_is!(10, 0, 0, 0)); } #[test] fn test_boolean_to_i8() { - check_cast::, console_root::types::I8>(Mode::Constant, count_is!(16, 0, 0, 0)); - check_cast::, console_root::types::I8>(Mode::Public, count_is!(16, 0, 0, 0)); - check_cast::, console_root::types::I8>(Mode::Private, count_is!(16, 0, 0, 0)); + check_cast::, console_root::types::I8>(Mode::Constant, count_is!(16, 0, 0, 0)); + check_cast::, console_root::types::I8>(Mode::Public, count_is!(16, 0, 0, 0)); + check_cast::, console_root::types::I8>(Mode::Private, count_is!(16, 0, 0, 0)); } #[test] fn test_boolean_to_i16() { - check_cast::, console_root::types::I16>(Mode::Constant, count_is!(32, 0, 0, 0)); - check_cast::, console_root::types::I16>(Mode::Public, count_is!(32, 0, 0, 0)); - check_cast::, console_root::types::I16>(Mode::Private, count_is!(32, 0, 0, 0)); + check_cast::, console_root::types::I16>(Mode::Constant, count_is!(32, 0, 0, 0)); + check_cast::, console_root::types::I16>(Mode::Public, count_is!(32, 0, 0, 0)); + check_cast::, console_root::types::I16>(Mode::Private, count_is!(32, 0, 0, 0)); } #[test] fn test_boolean_to_i32() { - check_cast::, console_root::types::I32>(Mode::Constant, count_is!(64, 0, 0, 0)); - check_cast::, console_root::types::I32>(Mode::Public, count_is!(64, 0, 0, 0)); - check_cast::, console_root::types::I32>(Mode::Private, count_is!(64, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Constant, count_is!(64, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Public, count_is!(64, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Private, count_is!(64, 0, 0, 0)); } #[test] fn test_boolean_to_i64() { - check_cast::, console_root::types::I64>(Mode::Constant, count_is!(128, 0, 0, 0)); - check_cast::, console_root::types::I64>(Mode::Public, count_is!(128, 0, 0, 0)); - check_cast::, console_root::types::I64>(Mode::Private, count_is!(128, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Constant, count_is!(128, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Public, count_is!(128, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Private, count_is!(128, 0, 0, 0)); } #[test] fn test_boolean_to_i128() { - check_cast::, console_root::types::I128>(Mode::Constant, count_is!(256, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Public, count_is!(256, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Private, count_is!(256, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Constant, count_is!(256, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Public, count_is!(256, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Private, count_is!(256, 0, 0, 0)); } #[test] fn test_boolean_to_scalar() { - check_cast::, console_root::types::Scalar>(Mode::Constant, count_is!(2, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(2, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(2, 0, 0, 0)); + check_cast::, console_root::types::Scalar>(Mode::Constant, count_is!(2, 0, 0, 0)); + check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(2, 0, 0, 0)); + check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(2, 0, 0, 0)); } #[test] fn test_boolean_to_u8() { - check_cast::, console_root::types::U8>(Mode::Constant, count_is!(16, 0, 0, 0)); - check_cast::, console_root::types::U8>(Mode::Public, count_is!(16, 0, 0, 0)); - check_cast::, console_root::types::U8>(Mode::Private, count_is!(16, 0, 0, 0)); + check_cast::, console_root::types::U8>(Mode::Constant, count_is!(16, 0, 0, 0)); + check_cast::, console_root::types::U8>(Mode::Public, count_is!(16, 0, 0, 0)); + check_cast::, console_root::types::U8>(Mode::Private, count_is!(16, 0, 0, 0)); } #[test] fn test_boolean_to_u16() { - check_cast::, console_root::types::U16>(Mode::Constant, count_is!(32, 0, 0, 0)); - check_cast::, console_root::types::U16>(Mode::Public, count_is!(32, 0, 0, 0)); - check_cast::, console_root::types::U16>(Mode::Private, count_is!(32, 0, 0, 0)); + check_cast::, console_root::types::U16>(Mode::Constant, count_is!(32, 0, 0, 0)); + check_cast::, console_root::types::U16>(Mode::Public, count_is!(32, 0, 0, 0)); + check_cast::, console_root::types::U16>(Mode::Private, count_is!(32, 0, 0, 0)); } #[test] fn test_boolean_to_u32() { - check_cast::, console_root::types::U32>(Mode::Constant, count_is!(64, 0, 0, 0)); - check_cast::, console_root::types::U32>(Mode::Public, count_is!(64, 0, 0, 0)); - check_cast::, console_root::types::U32>(Mode::Private, count_is!(64, 0, 0, 0)); + check_cast::, console_root::types::U32>(Mode::Constant, count_is!(64, 0, 0, 0)); + check_cast::, console_root::types::U32>(Mode::Public, count_is!(64, 0, 0, 0)); + check_cast::, console_root::types::U32>(Mode::Private, count_is!(64, 0, 0, 0)); } #[test] fn test_boolean_to_u64() { - check_cast::, console_root::types::U64>(Mode::Constant, count_is!(128, 0, 0, 0)); - check_cast::, console_root::types::U64>(Mode::Public, count_is!(128, 0, 0, 0)); - check_cast::, console_root::types::U64>(Mode::Private, count_is!(128, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Constant, count_is!(128, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Public, count_is!(128, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Private, count_is!(128, 0, 0, 0)); } #[test] fn test_boolean_to_u128() { - check_cast::, console_root::types::U128>(Mode::Constant, count_is!(256, 0, 0, 0)); - check_cast::, console_root::types::U128>(Mode::Public, count_is!(256, 0, 0, 0)); - check_cast::, console_root::types::U128>(Mode::Private, count_is!(256, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Constant, count_is!(256, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Public, count_is!(256, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Private, count_is!(256, 0, 0, 0)); } } diff --git a/circuit/program/src/data/literal/cast/field.rs b/circuit/program/src/data/literal/cast/field.rs index 9c515ab930..9331231a68 100644 --- a/circuit/program/src/data/literal/cast/field.rs +++ b/circuit/program/src/data/literal/cast/field.rs @@ -85,7 +85,7 @@ mod tests { use super::*; use console::Cast as _; use console_root::{ - network::Testnet3, + network::MainnetV0, prelude::{One, TestRng, Uniform, Zero}, }; use snarkvm_circuit_types::environment::{count_is, count_less_than, Circuit, Eject, Inject, Mode, UpdatableCount}; @@ -98,126 +98,126 @@ mod tests { i: usize, mode: Mode, rng: &mut TestRng, - ) -> (console_root::types::Field, Field) { + ) -> (console_root::types::Field, Field) { let console_value = match i { - 0 => console_root::types::Field::::zero(), - 1 => console_root::types::Field::::one(), + 0 => console_root::types::Field::::zero(), + 1 => console_root::types::Field::::one(), _ => Uniform::rand(rng), }; let circuit_value = Field::::new(mode, console_value); (console_value, circuit_value) } - impl_check_cast!(cast, Field, console_root::types::Field::); + impl_check_cast!(cast, Field, console_root::types::Field::); #[test] fn test_field_to_address() { - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Address>(Mode::Public, count_is!(4, 0, 13, 13)); - check_cast::, console_root::types::Address>(Mode::Private, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Address>(Mode::Public, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Address>(Mode::Private, count_is!(4, 0, 13, 13)); } #[test] fn test_field_to_boolean() { - check_cast::, console_root::types::Boolean>(Mode::Constant, count_is!(2, 0, 0, 0)); - check_cast::, console_root::types::Boolean>(Mode::Public, count_is!(0, 0, 5, 6)); - check_cast::, console_root::types::Boolean>(Mode::Private, count_is!(0, 0, 5, 6)); + check_cast::, console_root::types::Boolean>(Mode::Constant, count_is!(2, 0, 0, 0)); + check_cast::, console_root::types::Boolean>(Mode::Public, count_is!(0, 0, 5, 6)); + check_cast::, console_root::types::Boolean>(Mode::Private, count_is!(0, 0, 5, 6)); } #[test] fn test_field_to_field() { - check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_field_to_group() { - check_cast::, console_root::types::Group>( + check_cast::, console_root::types::Group>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); - check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); } #[test] fn test_field_to_i8() { - check_cast::, console_root::types::I8>(Mode::Constant, count_is!(8, 0, 0, 0)); - check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 8, 9)); - check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 8, 9)); + check_cast::, console_root::types::I8>(Mode::Constant, count_is!(8, 0, 0, 0)); + check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 8, 9)); + check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 8, 9)); } #[test] fn test_field_to_i16() { - check_cast::, console_root::types::I16>(Mode::Constant, count_is!(16, 0, 0, 0)); - check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 16, 17)); - check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 16, 17)); + check_cast::, console_root::types::I16>(Mode::Constant, count_is!(16, 0, 0, 0)); + check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 16, 17)); + check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 16, 17)); } #[test] fn test_field_to_i32() { - check_cast::, console_root::types::I32>(Mode::Constant, count_is!(32, 0, 0, 0)); - check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 32, 33)); - check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 32, 33)); + check_cast::, console_root::types::I32>(Mode::Constant, count_is!(32, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 32, 33)); + check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 32, 33)); } #[test] fn test_field_to_i64() { - check_cast::, console_root::types::I64>(Mode::Constant, count_is!(64, 0, 0, 0)); - check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 64, 65)); - check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 64, 65)); + check_cast::, console_root::types::I64>(Mode::Constant, count_is!(64, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 64, 65)); + check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 64, 65)); } #[test] fn test_field_to_i128() { - check_cast::, console_root::types::I128>(Mode::Constant, count_is!(128, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 128, 129)); - check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 128, 129)); + check_cast::, console_root::types::I128>(Mode::Constant, count_is!(128, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 128, 129)); + check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 128, 129)); } #[test] fn test_field_to_scalar() { - check_cast::, console_root::types::Scalar>(Mode::Constant, count_is!(253, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 755, 759)); - check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 755, 759)); + check_cast::, console_root::types::Scalar>(Mode::Constant, count_is!(253, 0, 0, 0)); + check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 755, 759)); + check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 755, 759)); } #[test] fn test_field_to_u8() { - check_cast::, console_root::types::U8>(Mode::Constant, count_is!(8, 0, 0, 0)); - check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 8, 9)); - check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 8, 9)); + check_cast::, console_root::types::U8>(Mode::Constant, count_is!(8, 0, 0, 0)); + check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 8, 9)); + check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 8, 9)); } #[test] fn test_field_to_u16() { - check_cast::, console_root::types::U16>(Mode::Constant, count_is!(16, 0, 0, 0)); - check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 16, 17)); - check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 16, 17)); + check_cast::, console_root::types::U16>(Mode::Constant, count_is!(16, 0, 0, 0)); + check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 16, 17)); + check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 16, 17)); } #[test] fn test_field_to_u32() { - check_cast::, console_root::types::U32>(Mode::Constant, count_is!(32, 0, 0, 0)); - check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 32, 33)); - check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 32, 33)); + check_cast::, console_root::types::U32>(Mode::Constant, count_is!(32, 0, 0, 0)); + check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 32, 33)); + check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 32, 33)); } #[test] fn test_field_to_u64() { - check_cast::, console_root::types::U64>(Mode::Constant, count_is!(64, 0, 0, 0)); - check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 64, 65)); - check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 64, 65)); + check_cast::, console_root::types::U64>(Mode::Constant, count_is!(64, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 64, 65)); + check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 64, 65)); } #[test] fn test_field_to_u128() { - check_cast::, console_root::types::U128>(Mode::Constant, count_is!(128, 0, 0, 0)); - check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 128, 129)); - check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 128, 129)); + check_cast::, console_root::types::U128>(Mode::Constant, count_is!(128, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 128, 129)); + check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 128, 129)); } } diff --git a/circuit/program/src/data/literal/cast/integer.rs b/circuit/program/src/data/literal/cast/integer.rs index 6c5aae4e5b..c25eab04a5 100644 --- a/circuit/program/src/data/literal/cast/integer.rs +++ b/circuit/program/src/data/literal/cast/integer.rs @@ -79,7 +79,7 @@ impl Cast> for // Then instantiate the new integer from the lower bits. false => { Boolean::assert_bits_are_zero(&bits_le[(I1::BITS.saturating_sub(1) as usize)..]); - Integer::::from_bits_le(&bits_le[..(I1::BITS.saturating_sub(1) as usize)]) + Integer::::from_bits_le(&bits_le[..(I1::BITS as usize)]) } }, // If the source type is signed and the destination type is unsigned, perform the required checks. @@ -88,7 +88,7 @@ impl Cast> for // Then instantiate the new integer from the lower bits. true => { E::assert(!&bits_le[I0::BITS.saturating_sub(1) as usize]); - Integer::::from_bits_le(&bits_le[..(I0::BITS.saturating_sub(1) as usize)]) + Integer::::from_bits_le(&bits_le) } // If the source type is larger than the destination type, check that the upper bits are zero. // Then instantiate the new integer from the lower bits. @@ -143,7 +143,7 @@ mod tests { use super::*; use console::Cast as _; use console_root::{ - network::Testnet3, + network::MainnetV0, prelude::{One, TestRng, Uniform, Zero}, }; use snarkvm_circuit_types::environment::{count_is, count_less_than, Circuit, Eject, Inject, Mode, UpdatableCount}; @@ -156,13 +156,13 @@ mod tests { i: usize, mode: Mode, rng: &mut TestRng, - ) -> (console_root::types::integers::Integer, Integer) { + ) -> (console_root::types::integers::Integer, Integer) { let console_value = match i { - 0 => console_root::types::integers::Integer::::zero(), - 1 => console_root::types::integers::Integer::::one(), - 2 => console_root::types::integers::Integer::::new(I::MAX), - 3 => console_root::types::integers::Integer::::new(I::MIN), - 4 if I::is_signed() => -console_root::types::integers::Integer::::one(), + 0 => console_root::types::integers::Integer::::zero(), + 1 => console_root::types::integers::Integer::::one(), + 2 => console_root::types::integers::Integer::::new(I::MAX), + 3 => console_root::types::integers::Integer::::new(I::MIN), + 4 if I::is_signed() => -console_root::types::integers::Integer::::one(), _ => Uniform::rand(rng), }; let circuit_value = Integer::::new(mode, console_value); @@ -172,23 +172,23 @@ mod tests { mod i8 { use super::*; - fn sample_values(i: usize, mode: Mode, rng: &mut TestRng) -> (console_root::types::I8, I8) { + fn sample_values(i: usize, mode: Mode, rng: &mut TestRng) -> (console_root::types::I8, I8) { super::sample_values(i, mode, rng) } - impl_check_cast!(cast, I8, console_root::types::I8); + impl_check_cast!(cast, I8, console_root::types::I8); #[test] fn test_i8_to_address() { - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Public, count_is!(4, 0, 13, 13), ); - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Private, count_is!(4, 0, 13, 13), ); @@ -196,15 +196,15 @@ mod tests { #[test] fn test_i8_to_boolean() { - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Constant, count_is!(16, 0, 0, 0), ); - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Public, count_is!(16, 0, 5, 6), ); - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Private, count_is!(16, 0, 5, 6), ); @@ -212,96 +212,99 @@ mod tests { #[test] fn test_i8_to_field() { - check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i8_to_group() { - check_cast::, console_root::types::Group>( + check_cast::, console_root::types::Group>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); - check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); } #[test] fn test_i8_to_i8() { - check_cast::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i8_to_i16() { - check_cast::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i8_to_i32() { - check_cast::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i8_to_i64() { - check_cast::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i8_to_i128() { - check_cast::, console_root::types::I128>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i8_to_scalar() { - check_cast::, console_root::types::Scalar>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i8_to_u8() { - check_cast::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_i8_to_u16() { - check_cast::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_i8_to_u32() { - check_cast::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_i8_to_u64() { - check_cast::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_i8_to_u128() { - check_cast::, console_root::types::U128>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U128>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 0, 1)); } } @@ -312,23 +315,23 @@ mod tests { i: usize, mode: Mode, rng: &mut TestRng, - ) -> (console_root::types::I16, I16) { + ) -> (console_root::types::I16, I16) { super::sample_values(i, mode, rng) } - impl_check_cast!(cast, I16, console_root::types::I16); + impl_check_cast!(cast, I16, console_root::types::I16); #[test] fn test_i16_to_address() { - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Public, count_is!(4, 0, 13, 13), ); - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Private, count_is!(4, 0, 13, 13), ); @@ -336,15 +339,15 @@ mod tests { #[test] fn test_i16_to_boolean() { - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Constant, count_is!(32, 0, 0, 0), ); - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Public, count_is!(32, 0, 5, 6), ); - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Private, count_is!(32, 0, 5, 6), ); @@ -352,96 +355,99 @@ mod tests { #[test] fn test_i16_to_field() { - check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i16_to_group() { - check_cast::, console_root::types::Group>( + check_cast::, console_root::types::Group>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); - check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); } #[test] fn test_i16_to_i8() { - check_cast::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 8)); - check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 8)); + check_cast::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 8)); + check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 8)); } #[test] fn test_i16_to_i16() { - check_cast::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i16_to_i32() { - check_cast::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i16_to_i64() { - check_cast::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i16_to_i128() { - check_cast::, console_root::types::I128>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i16_to_scalar() { - check_cast::, console_root::types::Scalar>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i16_to_u8() { - check_cast::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_i16_to_u16() { - check_cast::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_i16_to_u32() { - check_cast::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_i16_to_u64() { - check_cast::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_i16_to_u128() { - check_cast::, console_root::types::U128>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U128>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 0, 1)); } } @@ -452,23 +458,23 @@ mod tests { i: usize, mode: Mode, rng: &mut TestRng, - ) -> (console_root::types::I32, I32) { + ) -> (console_root::types::I32, I32) { super::sample_values(i, mode, rng) } - impl_check_cast!(cast, I32, console_root::types::I32); + impl_check_cast!(cast, I32, console_root::types::I32); #[test] fn test_i32_to_address() { - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Public, count_is!(4, 0, 13, 13), ); - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Private, count_is!(4, 0, 13, 13), ); @@ -476,15 +482,15 @@ mod tests { #[test] fn test_i32_to_boolean() { - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Constant, count_is!(64, 0, 0, 0), ); - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Public, count_is!(64, 0, 5, 6), ); - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Private, count_is!(64, 0, 5, 6), ); @@ -492,96 +498,99 @@ mod tests { #[test] fn test_i32_to_field() { - check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i32_to_group() { - check_cast::, console_root::types::Group>( + check_cast::, console_root::types::Group>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); - check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); } #[test] fn test_i32_to_i8() { - check_cast::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 24)); - check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 24)); + check_cast::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 24)); + check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 24)); } #[test] fn test_i32_to_i16() { - check_cast::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 16)); - check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 16)); + check_cast::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 16)); + check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 16)); } #[test] fn test_i32_to_i32() { - check_cast::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i32_to_i64() { - check_cast::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i32_to_i128() { - check_cast::, console_root::types::I128>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i32_to_scalar() { - check_cast::, console_root::types::Scalar>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i32_to_u8() { - check_cast::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_i32_to_u16() { - check_cast::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_i32_to_u32() { - check_cast::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_i32_to_u64() { - check_cast::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_i32_to_u128() { - check_cast::, console_root::types::U128>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U128>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 0, 1)); } } @@ -592,23 +601,23 @@ mod tests { i: usize, mode: Mode, rng: &mut TestRng, - ) -> (console_root::types::I64, I64) { + ) -> (console_root::types::I64, I64) { super::sample_values(i, mode, rng) } - impl_check_cast!(cast, I64, console_root::types::I64); + impl_check_cast!(cast, I64, console_root::types::I64); #[test] fn test_i64_to_address() { - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Public, count_is!(4, 0, 13, 13), ); - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Private, count_is!(4, 0, 13, 13), ); @@ -616,15 +625,15 @@ mod tests { #[test] fn test_i64_to_boolean() { - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Constant, count_is!(128, 0, 0, 0), ); - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Public, count_is!(128, 0, 5, 6), ); - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Private, count_is!(128, 0, 5, 6), ); @@ -632,96 +641,99 @@ mod tests { #[test] fn test_i64_to_field() { - check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i64_to_group() { - check_cast::, console_root::types::Group>( + check_cast::, console_root::types::Group>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); - check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); } #[test] fn test_i64_to_i8() { - check_cast::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 56)); - check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 56)); + check_cast::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 56)); + check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 56)); } #[test] fn test_i64_to_i16() { - check_cast::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 48)); - check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 48)); + check_cast::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 48)); + check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 48)); } #[test] fn test_i64_to_i32() { - check_cast::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 32)); - check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 32)); + check_cast::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 32)); + check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 32)); } #[test] fn test_i64_to_i64() { - check_cast::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i64_to_i128() { - check_cast::, console_root::types::I128>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i64_to_scalar() { - check_cast::, console_root::types::Scalar>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i64_to_u8() { - check_cast::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_i64_to_u16() { - check_cast::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_i64_to_u32() { - check_cast::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_i64_to_u64() { - check_cast::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_i64_to_u128() { - check_cast::, console_root::types::U128>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U128>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 0, 1)); } } @@ -732,23 +744,23 @@ mod tests { i: usize, mode: Mode, rng: &mut TestRng, - ) -> (console_root::types::I128, I128) { + ) -> (console_root::types::I128, I128) { super::sample_values(i, mode, rng) } - impl_check_cast!(cast, I128, console_root::types::I128); + impl_check_cast!(cast, I128, console_root::types::I128); #[test] fn test_i128_to_address() { - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Public, count_is!(4, 0, 13, 13), ); - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Private, count_is!(4, 0, 13, 13), ); @@ -756,15 +768,15 @@ mod tests { #[test] fn test_i128_to_boolean() { - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Constant, count_is!(256, 0, 0, 0), ); - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Public, count_is!(256, 0, 5, 6), ); - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Private, count_is!(256, 0, 5, 6), ); @@ -772,119 +784,122 @@ mod tests { #[test] fn test_i128_to_field() { - check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i128_to_group() { - check_cast::, console_root::types::Group>( + check_cast::, console_root::types::Group>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); - check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); } #[test] fn test_i128_to_i8() { - check_cast::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 120)); - check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 120)); + check_cast::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 120)); + check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 120)); } #[test] fn test_i128_to_i16() { - check_cast::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 112)); - check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 112)); + check_cast::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 112)); + check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 112)); } #[test] fn test_i128_to_i32() { - check_cast::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 96)); - check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 96)); + check_cast::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 96)); + check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 96)); } #[test] fn test_i128_to_i64() { - check_cast::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 64)); - check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 64)); + check_cast::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 64)); + check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 64)); } #[test] fn test_i128_to_i128() { - check_cast::, console_root::types::I128>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i128_to_scalar() { - check_cast::, console_root::types::Scalar>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i128_to_u8() { - check_cast::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_i128_to_u16() { - check_cast::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_i128_to_u32() { - check_cast::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_i128_to_u64() { - check_cast::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_i128_to_u128() { - check_cast::, console_root::types::U128>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U128>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 0, 1)); } } mod u8 { use super::*; - fn sample_values(i: usize, mode: Mode, rng: &mut TestRng) -> (console_root::types::U8, U8) { + fn sample_values(i: usize, mode: Mode, rng: &mut TestRng) -> (console_root::types::U8, U8) { super::sample_values(i, mode, rng) } - impl_check_cast!(cast, U8, console_root::types::U8); + impl_check_cast!(cast, U8, console_root::types::U8); #[test] fn test_u8_to_address() { - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Public, count_is!(4, 0, 13, 13), ); - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Private, count_is!(4, 0, 13, 13), ); @@ -892,15 +907,15 @@ mod tests { #[test] fn test_u8_to_boolean() { - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Constant, count_is!(16, 0, 0, 0), ); - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Public, count_is!(16, 0, 5, 6), ); - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Private, count_is!(16, 0, 5, 6), ); @@ -908,96 +923,99 @@ mod tests { #[test] fn test_u8_to_field() { - check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u8_to_group() { - check_cast::, console_root::types::Group>( + check_cast::, console_root::types::Group>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); - check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); } #[test] fn test_u8_to_i8() { - check_cast::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u8_to_i16() { - check_cast::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u8_to_i32() { - check_cast::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u8_to_i64() { - check_cast::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u8_to_i128() { - check_cast::, console_root::types::I128>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u8_to_scalar() { - check_cast::, console_root::types::Scalar>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u8_to_u8() { - check_cast::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u8_to_u16() { - check_cast::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u8_to_u32() { - check_cast::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u8_to_u64() { - check_cast::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u8_to_u128() { - check_cast::, console_root::types::U128>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 0, 0)); } } @@ -1008,23 +1026,23 @@ mod tests { i: usize, mode: Mode, rng: &mut TestRng, - ) -> (console_root::types::U16, U16) { + ) -> (console_root::types::U16, U16) { super::sample_values(i, mode, rng) } - impl_check_cast!(cast, U16, console_root::types::U16); + impl_check_cast!(cast, U16, console_root::types::U16); #[test] fn test_u16_to_address() { - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Public, count_is!(4, 0, 13, 13), ); - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Private, count_is!(4, 0, 13, 13), ); @@ -1032,15 +1050,15 @@ mod tests { #[test] fn test_u16_to_boolean() { - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Constant, count_is!(32, 0, 0, 0), ); - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Public, count_is!(32, 0, 5, 6), ); - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Private, count_is!(32, 0, 5, 6), ); @@ -1048,96 +1066,99 @@ mod tests { #[test] fn test_u16_to_field() { - check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u16_to_group() { - check_cast::, console_root::types::Group>( + check_cast::, console_root::types::Group>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); - check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); } #[test] fn test_u16_to_i8() { - check_cast::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u16_to_i16() { - check_cast::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u16_to_i32() { - check_cast::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u16_to_i64() { - check_cast::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u16_to_i128() { - check_cast::, console_root::types::I128>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u16_to_scalar() { - check_cast::, console_root::types::Scalar>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u16_to_u8() { - check_cast::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u16_to_u16() { - check_cast::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u16_to_u32() { - check_cast::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u16_to_u64() { - check_cast::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u16_to_u128() { - check_cast::, console_root::types::U128>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 0, 0)); } } @@ -1148,23 +1169,23 @@ mod tests { i: usize, mode: Mode, rng: &mut TestRng, - ) -> (console_root::types::U32, U32) { + ) -> (console_root::types::U32, U32) { super::sample_values(i, mode, rng) } - impl_check_cast!(cast, U32, console_root::types::U32); + impl_check_cast!(cast, U32, console_root::types::U32); #[test] fn test_u32_to_address() { - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Public, count_is!(4, 0, 13, 13), ); - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Private, count_is!(4, 0, 13, 13), ); @@ -1172,15 +1193,15 @@ mod tests { #[test] fn test_u32_to_boolean() { - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Constant, count_is!(64, 0, 0, 0), ); - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Public, count_is!(64, 0, 5, 6), ); - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Private, count_is!(64, 0, 5, 6), ); @@ -1188,96 +1209,99 @@ mod tests { #[test] fn test_u32_to_field() { - check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u32_to_group() { - check_cast::, console_root::types::Group>( + check_cast::, console_root::types::Group>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); - check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); } #[test] fn test_u32_to_i8() { - check_cast::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u32_to_i16() { - check_cast::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u32_to_i32() { - check_cast::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u32_to_i64() { - check_cast::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u32_to_i128() { - check_cast::, console_root::types::I128>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u32_to_scalar() { - check_cast::, console_root::types::Scalar>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u32_to_u8() { - check_cast::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u32_to_u16() { - check_cast::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u32_to_u32() { - check_cast::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u32_to_u64() { - check_cast::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u32_to_u128() { - check_cast::, console_root::types::U128>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 0, 0)); } } @@ -1288,23 +1312,23 @@ mod tests { i: usize, mode: Mode, rng: &mut TestRng, - ) -> (console_root::types::U64, U64) { + ) -> (console_root::types::U64, U64) { super::sample_values(i, mode, rng) } - impl_check_cast!(cast, U64, console_root::types::U64); + impl_check_cast!(cast, U64, console_root::types::U64); #[test] fn test_u64_to_address() { - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Public, count_is!(4, 0, 13, 13), ); - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Private, count_is!(4, 0, 13, 13), ); @@ -1312,15 +1336,15 @@ mod tests { #[test] fn test_u64_to_boolean() { - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Constant, count_is!(128, 0, 0, 0), ); - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Public, count_is!(128, 0, 5, 6), ); - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Private, count_is!(128, 0, 5, 6), ); @@ -1328,96 +1352,99 @@ mod tests { #[test] fn test_u64_to_field() { - check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u64_to_group() { - check_cast::, console_root::types::Group>( + check_cast::, console_root::types::Group>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); - check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); } #[test] fn test_u64_to_i8() { - check_cast::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u64_to_i16() { - check_cast::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u64_to_i32() { - check_cast::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u64_to_i64() { - check_cast::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u64_to_i128() { - check_cast::, console_root::types::I128>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u64_to_scalar() { - check_cast::, console_root::types::Scalar>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u64_to_u8() { - check_cast::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u64_to_u16() { - check_cast::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u64_to_u32() { - check_cast::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u64_to_u64() { - check_cast::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u64_to_u128() { - check_cast::, console_root::types::U128>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 0, 0)); } } @@ -1428,23 +1455,23 @@ mod tests { i: usize, mode: Mode, rng: &mut TestRng, - ) -> (console_root::types::U128, U128) { + ) -> (console_root::types::U128, U128) { super::sample_values(i, mode, rng) } - impl_check_cast!(cast, U128, console_root::types::U128); + impl_check_cast!(cast, U128, console_root::types::U128); #[test] fn test_u128_to_address() { - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Public, count_is!(4, 0, 13, 13), ); - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Private, count_is!(4, 0, 13, 13), ); @@ -1452,15 +1479,15 @@ mod tests { #[test] fn test_u128_to_boolean() { - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Constant, count_is!(256, 0, 0, 0), ); - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Public, count_is!(256, 0, 5, 6), ); - check_cast::, console_root::types::Boolean>( + check_cast::, console_root::types::Boolean>( Mode::Private, count_is!(256, 0, 5, 6), ); @@ -1468,96 +1495,99 @@ mod tests { #[test] fn test_u128_to_field() { - check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u128_to_group() { - check_cast::, console_root::types::Group>( + check_cast::, console_root::types::Group>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); - check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); } #[test] fn test_u128_to_i8() { - check_cast::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u128_to_i16() { - check_cast::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u128_to_i32() { - check_cast::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u128_to_i64() { - check_cast::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u128_to_i128() { - check_cast::, console_root::types::I128>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I128>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u128_to_scalar() { - check_cast::, console_root::types::Scalar>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u128_to_u8() { - check_cast::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u128_to_u16() { - check_cast::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u128_to_u32() { - check_cast::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u128_to_u64() { - check_cast::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 1)); - check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 1)); + check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 1)); } #[test] fn test_u128_to_u128() { - check_cast::, console_root::types::U128>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 0, 0)); } } } diff --git a/circuit/program/src/data/literal/cast/scalar.rs b/circuit/program/src/data/literal/cast/scalar.rs index 39e3b440b9..e9b0e53819 100644 --- a/circuit/program/src/data/literal/cast/scalar.rs +++ b/circuit/program/src/data/literal/cast/scalar.rs @@ -87,7 +87,7 @@ mod tests { use super::*; use console::Cast as _; use console_root::{ - network::Testnet3, + network::MainnetV0, prelude::{One, TestRng, Uniform, Zero}, }; use snarkvm_circuit_types::environment::{count_is, count_less_than, Circuit, Eject, Inject, Mode, UpdatableCount}; @@ -100,126 +100,126 @@ mod tests { i: usize, mode: Mode, rng: &mut TestRng, - ) -> (console_root::types::Scalar, Scalar) { + ) -> (console_root::types::Scalar, Scalar) { let console_value = match i { - 0 => console_root::types::Scalar::::zero(), - 1 => console_root::types::Scalar::::one(), + 0 => console_root::types::Scalar::::zero(), + 1 => console_root::types::Scalar::::one(), _ => Uniform::rand(rng), }; let circuit_value = Scalar::::new(mode, console_value); (console_value, circuit_value) } - impl_check_cast!(cast, Scalar, console_root::types::Scalar::); + impl_check_cast!(cast, Scalar, console_root::types::Scalar::); #[test] fn test_scalar_to_address() { - check_cast::, console_root::types::Address>( + check_cast::, console_root::types::Address>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Address>(Mode::Public, count_is!(4, 0, 13, 13)); - check_cast::, console_root::types::Address>(Mode::Private, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Address>(Mode::Public, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Address>(Mode::Private, count_is!(4, 0, 13, 13)); } #[test] fn test_scalar_to_boolean() { - check_cast::, console_root::types::Boolean>(Mode::Constant, count_is!(4, 0, 0, 0)); - check_cast::, console_root::types::Boolean>(Mode::Public, count_is!(2, 0, 5, 6)); - check_cast::, console_root::types::Boolean>(Mode::Private, count_is!(2, 0, 5, 6)); + check_cast::, console_root::types::Boolean>(Mode::Constant, count_is!(4, 0, 0, 0)); + check_cast::, console_root::types::Boolean>(Mode::Public, count_is!(2, 0, 5, 6)); + check_cast::, console_root::types::Boolean>(Mode::Private, count_is!(2, 0, 5, 6)); } #[test] fn test_scalar_to_field() { - check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_scalar_to_group() { - check_cast::, console_root::types::Group>( + check_cast::, console_root::types::Group>( Mode::Constant, count_less_than!(11, 0, 0, 0), ); - check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); - check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Public, count_is!(4, 0, 13, 13)); + check_cast::, console_root::types::Group>(Mode::Private, count_is!(4, 0, 13, 13)); } #[test] fn test_scalar_to_i8() { - check_cast::, console_root::types::I8>(Mode::Constant, count_is!(251, 0, 0, 0)); - check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 501, 504)); - check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 501, 504)); + check_cast::, console_root::types::I8>(Mode::Constant, count_is!(251, 0, 0, 0)); + check_cast::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 501, 504)); + check_cast::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 501, 504)); } #[test] fn test_scalar_to_i16() { - check_cast::, console_root::types::I16>(Mode::Constant, count_is!(251, 0, 0, 0)); - check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 501, 504)); - check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 501, 504)); + check_cast::, console_root::types::I16>(Mode::Constant, count_is!(251, 0, 0, 0)); + check_cast::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 501, 504)); + check_cast::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 501, 504)); } #[test] fn test_scalar_to_i32() { - check_cast::, console_root::types::I32>(Mode::Constant, count_is!(251, 0, 0, 0)); - check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 501, 504)); - check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 501, 504)); + check_cast::, console_root::types::I32>(Mode::Constant, count_is!(251, 0, 0, 0)); + check_cast::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 501, 504)); + check_cast::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 501, 504)); } #[test] fn test_scalar_to_i64() { - check_cast::, console_root::types::I64>(Mode::Constant, count_is!(251, 0, 0, 0)); - check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 501, 504)); - check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 501, 504)); + check_cast::, console_root::types::I64>(Mode::Constant, count_is!(251, 0, 0, 0)); + check_cast::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 501, 504)); + check_cast::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 501, 504)); } #[test] fn test_scalar_to_i128() { - check_cast::, console_root::types::I128>(Mode::Constant, count_is!(251, 0, 0, 0)); - check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 501, 504)); - check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 501, 504)); + check_cast::, console_root::types::I128>(Mode::Constant, count_is!(251, 0, 0, 0)); + check_cast::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 501, 504)); + check_cast::, console_root::types::I128>(Mode::Private, count_is!(0, 0, 501, 504)); } #[test] fn test_scalar_to_scalar() { - check_cast::, console_root::types::Scalar>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast::, console_root::types::Scalar>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_scalar_to_u8() { - check_cast::, console_root::types::U8>(Mode::Constant, count_is!(251, 0, 0, 0)); - check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 501, 504)); - check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 501, 504)); + check_cast::, console_root::types::U8>(Mode::Constant, count_is!(251, 0, 0, 0)); + check_cast::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 501, 504)); + check_cast::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 501, 504)); } #[test] fn test_scalar_to_u16() { - check_cast::, console_root::types::U16>(Mode::Constant, count_is!(251, 0, 0, 0)); - check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 501, 504)); - check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 501, 504)); + check_cast::, console_root::types::U16>(Mode::Constant, count_is!(251, 0, 0, 0)); + check_cast::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 501, 504)); + check_cast::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 501, 504)); } #[test] fn test_scalar_to_u32() { - check_cast::, console_root::types::U32>(Mode::Constant, count_is!(251, 0, 0, 0)); - check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 501, 504)); - check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 501, 504)); + check_cast::, console_root::types::U32>(Mode::Constant, count_is!(251, 0, 0, 0)); + check_cast::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 501, 504)); + check_cast::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 501, 504)); } #[test] fn test_scalar_to_u64() { - check_cast::, console_root::types::U64>(Mode::Constant, count_is!(251, 0, 0, 0)); - check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 501, 504)); - check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 501, 504)); + check_cast::, console_root::types::U64>(Mode::Constant, count_is!(251, 0, 0, 0)); + check_cast::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 501, 504)); + check_cast::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 501, 504)); } #[test] fn test_scalar_to_u128() { - check_cast::, console_root::types::U128>(Mode::Constant, count_is!(251, 0, 0, 0)); - check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 501, 504)); - check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 501, 504)); + check_cast::, console_root::types::U128>(Mode::Constant, count_is!(251, 0, 0, 0)); + check_cast::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 501, 504)); + check_cast::, console_root::types::U128>(Mode::Private, count_is!(0, 0, 501, 504)); } } diff --git a/circuit/program/src/data/literal/cast_lossy/boolean.rs b/circuit/program/src/data/literal/cast_lossy/boolean.rs index f2017d9857..64ac477894 100644 --- a/circuit/program/src/data/literal/cast_lossy/boolean.rs +++ b/circuit/program/src/data/literal/cast_lossy/boolean.rs @@ -77,7 +77,7 @@ impl CastLossy> for Boolean { mod tests { use super::*; use console::CastLossy as _; - use console_root::{network::Testnet3, prelude::TestRng}; + use console_root::{network::MainnetV0, prelude::TestRng}; use snarkvm_circuit_types::environment::{count_is, Circuit, Eject, Inject, Mode, UpdatableCount}; use std::fmt::Debug; @@ -88,23 +88,23 @@ mod tests { i: usize, mode: Mode, _: &mut TestRng, - ) -> (console_root::types::Boolean, Boolean) { + ) -> (console_root::types::Boolean, Boolean) { (console_root::types::Boolean::new(i % 2 == 0), Boolean::new(mode, i % 2 == 0)) } - check_cast_lossy!(cast_lossy, Boolean, console_root::types::Boolean::); + check_cast_lossy!(cast_lossy, Boolean, console_root::types::Boolean::); #[test] fn test_boolean_to_address() { - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Constant, count_is!(10, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Public, count_is!(10, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Private, count_is!(10, 0, 0, 0), ); @@ -112,15 +112,15 @@ mod tests { #[test] fn test_boolean_to_boolean() { - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -128,64 +128,76 @@ mod tests { #[test] fn test_boolean_to_field() { - check_cast_lossy::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::Field>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_boolean_to_group() { - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Constant, count_is!(10, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Group>(Mode::Public, count_is!(10, 0, 0, 0)); - check_cast_lossy::, console_root::types::Group>(Mode::Private, count_is!(10, 0, 0, 0)); + check_cast_lossy::, console_root::types::Group>(Mode::Public, count_is!(10, 0, 0, 0)); + check_cast_lossy::, console_root::types::Group>( + Mode::Private, + count_is!(10, 0, 0, 0), + ); } #[test] fn test_boolean_to_i8() { - check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(16, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(16, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(16, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(16, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(16, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(16, 0, 0, 0)); } #[test] fn test_boolean_to_i16() { - check_cast_lossy::, console_root::types::I16>(Mode::Constant, count_is!(32, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(32, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(32, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>(Mode::Constant, count_is!(32, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(32, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(32, 0, 0, 0)); } #[test] fn test_boolean_to_i32() { - check_cast_lossy::, console_root::types::I32>(Mode::Constant, count_is!(64, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(64, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(64, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>(Mode::Constant, count_is!(64, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(64, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(64, 0, 0, 0)); } #[test] fn test_boolean_to_i64() { - check_cast_lossy::, console_root::types::I64>(Mode::Constant, count_is!(128, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(128, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(128, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>(Mode::Constant, count_is!(128, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(128, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(128, 0, 0, 0)); } #[test] fn test_boolean_to_i128() { - check_cast_lossy::, console_root::types::I128>(Mode::Constant, count_is!(256, 0, 0, 0)); - check_cast_lossy::, console_root::types::I128>(Mode::Public, count_is!(256, 0, 0, 0)); - check_cast_lossy::, console_root::types::I128>(Mode::Private, count_is!(256, 0, 0, 0)); + check_cast_lossy::, console_root::types::I128>( + Mode::Constant, + count_is!(256, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I128>(Mode::Public, count_is!(256, 0, 0, 0)); + check_cast_lossy::, console_root::types::I128>(Mode::Private, count_is!(256, 0, 0, 0)); } #[test] fn test_boolean_to_scalar() { - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Constant, count_is!(2, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>(Mode::Public, count_is!(2, 0, 0, 0)); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( + Mode::Public, + count_is!(2, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::Scalar>( Mode::Private, count_is!(2, 0, 0, 0), ); @@ -193,36 +205,39 @@ mod tests { #[test] fn test_boolean_to_u8() { - check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(16, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(16, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(16, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(16, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(16, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(16, 0, 0, 0)); } #[test] fn test_boolean_to_u16() { - check_cast_lossy::, console_root::types::U16>(Mode::Constant, count_is!(32, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(32, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(32, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>(Mode::Constant, count_is!(32, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(32, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(32, 0, 0, 0)); } #[test] fn test_boolean_to_u32() { - check_cast_lossy::, console_root::types::U32>(Mode::Constant, count_is!(64, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(64, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(64, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>(Mode::Constant, count_is!(64, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(64, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(64, 0, 0, 0)); } #[test] fn test_boolean_to_u64() { - check_cast_lossy::, console_root::types::U64>(Mode::Constant, count_is!(128, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(128, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(128, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>(Mode::Constant, count_is!(128, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(128, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(128, 0, 0, 0)); } #[test] fn test_boolean_to_u128() { - check_cast_lossy::, console_root::types::U128>(Mode::Constant, count_is!(256, 0, 0, 0)); - check_cast_lossy::, console_root::types::U128>(Mode::Public, count_is!(256, 0, 0, 0)); - check_cast_lossy::, console_root::types::U128>(Mode::Private, count_is!(256, 0, 0, 0)); + check_cast_lossy::, console_root::types::U128>( + Mode::Constant, + count_is!(256, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U128>(Mode::Public, count_is!(256, 0, 0, 0)); + check_cast_lossy::, console_root::types::U128>(Mode::Private, count_is!(256, 0, 0, 0)); } } diff --git a/circuit/program/src/data/literal/cast_lossy/field.rs b/circuit/program/src/data/literal/cast_lossy/field.rs index b2be939819..705443d022 100644 --- a/circuit/program/src/data/literal/cast_lossy/field.rs +++ b/circuit/program/src/data/literal/cast_lossy/field.rs @@ -61,9 +61,12 @@ impl CastLossy> for Field { #[inline] fn cast_lossy(&self) -> Group { // This method requires that an `x-coordinate` of 1 is an invalid group element. - // This is used by the ternary below, which uses 'is_one' to determine whether to return the generator. + // This is used by the ternary below, which uses 'is_x_one' to determine whether to return the generator. debug_assert!(console::Group::from_x_coordinate( as console::One>::one()).is_err()); + // Attempt to find a group element with self as the x-coordinate. + let (point_with_x, x_is_not_in_group) = Group::from_x_coordinate_flagged(self.clone()); + // Determine if the field element is zero. let is_x_zero = self.is_zero(); // Determine if the field element is one. @@ -73,35 +76,20 @@ impl CastLossy> for Field { let generator = Group::generator(); // Determine the input to Elligator-2, based on the x-coordinate. + // If self is 0, we pass 1 to Elligator-2 instead. + // Note that, in this case, we won't use the result of Elligator-2, + // because the point (0, 1) is in the subgroup, and that is what we return. let elligator_input = Field::ternary(&is_x_zero, &Field::one(), self); // Perform Elligator-2 on the field element, to recover a group element. - let elligator = Elligator2::encode(&elligator_input); - - // Determine the initial x-coordinate, if the given field element is one. - let initial_x = Field::ternary(&is_x_one, &generator.to_x_coordinate(), &elligator.to_x_coordinate()); - // Determine the initial y-coordinate, if the given field element is one. - let initial_y = Field::ternary(&is_x_one, &generator.to_y_coordinate(), &elligator.to_y_coordinate()); - - // Determine the y-coordinate, if the x-coordinate is valid. - let possible_y: Field = { - // Set the x-coordinate. - let x = self.clone(); - // Derive the y-coordinate. - witness!(|x| match console::Group::from_x_coordinate(x) { - Ok(point) => point.to_y_coordinate(), - Err(_) => console::Zero::zero(), - }) - }; - // Determine if the recovered y-coordinate is zero. - let is_y_zero = possible_y.is_zero(); + let elligator_point = Elligator2::encode(&elligator_input); - // Determine the final x-coordinate, based on whether the possible y-coordinate is zero. - let final_x = Field::ternary(&is_y_zero, &initial_x, self); - // Determine the final y-coordinate, based on whether the possible y-coordinate is zero. - let final_y = Field::ternary(&is_y_zero, &initial_y, &possible_y); + // Select either the generator or the result of Elligator-2, depending on whether x is 1 or not. + // This is only used when x is not in the group, see below. + let generator_or_elligator_point = Group::ternary(&is_x_one, &generator, &elligator_point); - // Return the result. - Group::from_xy_coordinates(final_x, final_y) + // Select either the group point with x or the generator or the result of Elligator-2, + // depending on whether x is in the group or not, and, if it is not, based on whether it is 1 or not. + Group::ternary(&x_is_not_in_group, &generator_or_elligator_point, &point_with_x) } } @@ -128,7 +116,7 @@ mod tests { use super::*; use console::CastLossy as _; use console_root::{ - network::Testnet3, + network::MainnetV0, prelude::{One, TestRng, Uniform, Zero}, }; use snarkvm_circuit_types::environment::{count_is, count_less_than, Circuit, Eject, Inject, Mode, UpdatableCount}; @@ -141,45 +129,45 @@ mod tests { i: usize, mode: Mode, rng: &mut TestRng, - ) -> (console_root::types::Field, Field) { + ) -> (console_root::types::Field, Field) { let console_value = match i { - 0 => console_root::types::Field::::zero(), - 1 => console_root::types::Field::::one(), + 0 => console_root::types::Field::::zero(), + 1 => console_root::types::Field::::one(), _ => Uniform::rand(rng), }; let circuit_value = Field::::new(mode, console_value); (console_value, circuit_value) } - check_cast_lossy!(cast_lossy, Field, console_root::types::Field::); + check_cast_lossy!(cast_lossy, Field, console_root::types::Field::); #[test] fn test_field_to_address() { - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_field_to_boolean() { - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Constant, count_is!(253, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Public, count_is!(0, 0, 505, 507), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Private, count_is!(0, 0, 505, 507), ); @@ -187,60 +175,69 @@ mod tests { #[test] fn test_field_to_field() { - check_cast_lossy::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::Field>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_field_to_group() { - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_field_to_i8() { - check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(253, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 505, 507)); - check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 505, 507)); + check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(253, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 505, 507)); + check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 505, 507)); } #[test] fn test_field_to_i16() { - check_cast_lossy::, console_root::types::I16>(Mode::Constant, count_is!(253, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 505, 507)); - check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 505, 507)); + check_cast_lossy::, console_root::types::I16>(Mode::Constant, count_is!(253, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 505, 507)); + check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 505, 507)); } #[test] fn test_field_to_i32() { - check_cast_lossy::, console_root::types::I32>(Mode::Constant, count_is!(253, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 505, 507)); - check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 505, 507)); + check_cast_lossy::, console_root::types::I32>(Mode::Constant, count_is!(253, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 505, 507)); + check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 505, 507)); } #[test] fn test_field_to_i64() { - check_cast_lossy::, console_root::types::I64>(Mode::Constant, count_is!(253, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 505, 507)); - check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 505, 507)); + check_cast_lossy::, console_root::types::I64>(Mode::Constant, count_is!(253, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 505, 507)); + check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 505, 507)); } #[test] fn test_field_to_i128() { - check_cast_lossy::, console_root::types::I128>(Mode::Constant, count_is!(253, 0, 0, 0)); - check_cast_lossy::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 505, 507)); - check_cast_lossy::, console_root::types::I128>( + check_cast_lossy::, console_root::types::I128>( + Mode::Constant, + count_is!(253, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I128>( + Mode::Public, + count_is!(0, 0, 505, 507), + ); + check_cast_lossy::, console_root::types::I128>( Mode::Private, count_is!(0, 0, 505, 507), ); @@ -248,15 +245,15 @@ mod tests { #[test] fn test_field_to_scalar() { - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Constant, count_is!(253, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Public, count_is!(0, 0, 505, 507), ); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Private, count_is!(0, 0, 505, 507), ); @@ -264,37 +261,43 @@ mod tests { #[test] fn test_field_to_u8() { - check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(253, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 505, 507)); - check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 505, 507)); + check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(253, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 505, 507)); + check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 505, 507)); } #[test] fn test_field_to_u16() { - check_cast_lossy::, console_root::types::U16>(Mode::Constant, count_is!(253, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 505, 507)); - check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 505, 507)); + check_cast_lossy::, console_root::types::U16>(Mode::Constant, count_is!(253, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 505, 507)); + check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 505, 507)); } #[test] fn test_field_to_u32() { - check_cast_lossy::, console_root::types::U32>(Mode::Constant, count_is!(253, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 505, 507)); - check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 505, 507)); + check_cast_lossy::, console_root::types::U32>(Mode::Constant, count_is!(253, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 505, 507)); + check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 505, 507)); } #[test] fn test_field_to_u64() { - check_cast_lossy::, console_root::types::U64>(Mode::Constant, count_is!(253, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 505, 507)); - check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 505, 507)); + check_cast_lossy::, console_root::types::U64>(Mode::Constant, count_is!(253, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 505, 507)); + check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 505, 507)); } #[test] fn test_field_to_u128() { - check_cast_lossy::, console_root::types::U128>(Mode::Constant, count_is!(253, 0, 0, 0)); - check_cast_lossy::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 505, 507)); - check_cast_lossy::, console_root::types::U128>( + check_cast_lossy::, console_root::types::U128>( + Mode::Constant, + count_is!(253, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U128>( + Mode::Public, + count_is!(0, 0, 505, 507), + ); + check_cast_lossy::, console_root::types::U128>( Mode::Private, count_is!(0, 0, 505, 507), ); diff --git a/circuit/program/src/data/literal/cast_lossy/integer.rs b/circuit/program/src/data/literal/cast_lossy/integer.rs index 4531e0e504..1a50e3e8ca 100644 --- a/circuit/program/src/data/literal/cast_lossy/integer.rs +++ b/circuit/program/src/data/literal/cast_lossy/integer.rs @@ -91,7 +91,7 @@ mod tests { use super::*; use console::CastLossy as _; use console_root::{ - network::Testnet3, + network::MainnetV0, prelude::{One, TestRng, Uniform, Zero}, }; use snarkvm_circuit_types::environment::{count_is, count_less_than, Circuit, Eject, Inject, Mode, UpdatableCount}; @@ -104,13 +104,13 @@ mod tests { i: usize, mode: Mode, rng: &mut TestRng, - ) -> (console_root::types::integers::Integer, Integer) { + ) -> (console_root::types::integers::Integer, Integer) { let console_value = match i { - 0 => console_root::types::integers::Integer::::zero(), - 1 => console_root::types::integers::Integer::::one(), - 2 => console_root::types::integers::Integer::::new(I::MAX), - 3 => console_root::types::integers::Integer::::new(I::MIN), - 4 if I::is_signed() => -console_root::types::integers::Integer::::one(), + 0 => console_root::types::integers::Integer::::zero(), + 1 => console_root::types::integers::Integer::::one(), + 2 => console_root::types::integers::Integer::::new(I::MAX), + 3 => console_root::types::integers::Integer::::new(I::MIN), + 4 if I::is_signed() => -console_root::types::integers::Integer::::one(), _ => Uniform::rand(rng), }; let circuit_value = Integer::::new(mode, console_value); @@ -120,39 +120,39 @@ mod tests { mod i8 { use super::*; - fn sample_values(i: usize, mode: Mode, rng: &mut TestRng) -> (console_root::types::I8, I8) { + fn sample_values(i: usize, mode: Mode, rng: &mut TestRng) -> (console_root::types::I8, I8) { super::sample_values(i, mode, rng) } - check_cast_lossy!(cast_lossy, I8, console_root::types::I8); + check_cast_lossy!(cast_lossy, I8, console_root::types::I8); #[test] fn test_i8_to_address() { - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_i8_to_boolean() { - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -160,15 +160,15 @@ mod tests { #[test] fn test_i8_to_field() { - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -176,56 +176,68 @@ mod tests { #[test] fn test_i8_to_group() { - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_i8_to_i8() { - check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i8_to_i16() { - check_cast_lossy::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i8_to_i32() { - check_cast_lossy::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i8_to_i64() { - check_cast_lossy::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i8_to_i128() { - check_cast_lossy::, console_root::types::I128>( + check_cast_lossy::, console_root::types::I128>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I128>( + check_cast_lossy::, console_root::types::I128>( + Mode::Public, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I128>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -233,15 +245,15 @@ mod tests { #[test] fn test_i8_to_scalar() { - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -249,40 +261,52 @@ mod tests { #[test] fn test_i8_to_u8() { - check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i8_to_u16() { - check_cast_lossy::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i8_to_u32() { - check_cast_lossy::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i8_to_u64() { - check_cast_lossy::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i8_to_u128() { - check_cast_lossy::, console_root::types::U128>( + check_cast_lossy::, console_root::types::U128>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U128>( + check_cast_lossy::, console_root::types::U128>( + Mode::Public, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U128>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -296,39 +320,39 @@ mod tests { i: usize, mode: Mode, rng: &mut TestRng, - ) -> (console_root::types::I16, I16) { + ) -> (console_root::types::I16, I16) { super::sample_values(i, mode, rng) } - check_cast_lossy!(cast_lossy, I16, console_root::types::I16); + check_cast_lossy!(cast_lossy, I16, console_root::types::I16); #[test] fn test_i16_to_address() { - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_i16_to_boolean() { - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -336,15 +360,15 @@ mod tests { #[test] fn test_i16_to_field() { - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -352,56 +376,68 @@ mod tests { #[test] fn test_i16_to_group() { - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_i16_to_i8() { - check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i16_to_i16() { - check_cast_lossy::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i16_to_i32() { - check_cast_lossy::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i16_to_i64() { - check_cast_lossy::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i16_to_i128() { - check_cast_lossy::, console_root::types::I128>( + check_cast_lossy::, console_root::types::I128>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I128>( + check_cast_lossy::, console_root::types::I128>( + Mode::Public, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I128>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -409,15 +445,15 @@ mod tests { #[test] fn test_i16_to_scalar() { - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -425,40 +461,52 @@ mod tests { #[test] fn test_i16_to_u8() { - check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i16_to_u16() { - check_cast_lossy::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i16_to_u32() { - check_cast_lossy::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i16_to_u64() { - check_cast_lossy::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i16_to_u128() { - check_cast_lossy::, console_root::types::U128>( + check_cast_lossy::, console_root::types::U128>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U128>( + check_cast_lossy::, console_root::types::U128>( + Mode::Public, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U128>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -472,39 +520,39 @@ mod tests { i: usize, mode: Mode, rng: &mut TestRng, - ) -> (console_root::types::I32, I32) { + ) -> (console_root::types::I32, I32) { super::sample_values(i, mode, rng) } - check_cast_lossy!(cast_lossy, I32, console_root::types::I32); + check_cast_lossy!(cast_lossy, I32, console_root::types::I32); #[test] fn test_i32_to_address() { - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_i32_to_boolean() { - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -512,15 +560,15 @@ mod tests { #[test] fn test_i32_to_field() { - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -528,56 +576,68 @@ mod tests { #[test] fn test_i32_to_group() { - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_i32_to_i8() { - check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i32_to_i16() { - check_cast_lossy::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i32_to_i32() { - check_cast_lossy::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i32_to_i64() { - check_cast_lossy::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i32_to_i128() { - check_cast_lossy::, console_root::types::I128>( + check_cast_lossy::, console_root::types::I128>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I128>( + check_cast_lossy::, console_root::types::I128>( + Mode::Public, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I128>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -585,15 +645,15 @@ mod tests { #[test] fn test_i32_to_scalar() { - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -601,40 +661,52 @@ mod tests { #[test] fn test_i32_to_u8() { - check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i32_to_u16() { - check_cast_lossy::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i32_to_u32() { - check_cast_lossy::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i32_to_u64() { - check_cast_lossy::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i32_to_u128() { - check_cast_lossy::, console_root::types::U128>( + check_cast_lossy::, console_root::types::U128>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U128>( + check_cast_lossy::, console_root::types::U128>( + Mode::Public, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U128>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -648,39 +720,39 @@ mod tests { i: usize, mode: Mode, rng: &mut TestRng, - ) -> (console_root::types::I64, I64) { + ) -> (console_root::types::I64, I64) { super::sample_values(i, mode, rng) } - check_cast_lossy!(cast_lossy, I64, console_root::types::I64); + check_cast_lossy!(cast_lossy, I64, console_root::types::I64); #[test] fn test_i64_to_address() { - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_i64_to_boolean() { - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -688,15 +760,15 @@ mod tests { #[test] fn test_i64_to_field() { - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -704,56 +776,68 @@ mod tests { #[test] fn test_i64_to_group() { - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_i64_to_i8() { - check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i64_to_i16() { - check_cast_lossy::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i64_to_i32() { - check_cast_lossy::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i64_to_i64() { - check_cast_lossy::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i64_to_i128() { - check_cast_lossy::, console_root::types::I128>( + check_cast_lossy::, console_root::types::I128>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I128>( + check_cast_lossy::, console_root::types::I128>( + Mode::Public, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I128>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -761,15 +845,15 @@ mod tests { #[test] fn test_i64_to_scalar() { - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -777,40 +861,52 @@ mod tests { #[test] fn test_i64_to_u8() { - check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i64_to_u16() { - check_cast_lossy::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i64_to_u32() { - check_cast_lossy::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i64_to_u64() { - check_cast_lossy::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i64_to_u128() { - check_cast_lossy::, console_root::types::U128>( + check_cast_lossy::, console_root::types::U128>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U128>( + check_cast_lossy::, console_root::types::U128>( + Mode::Public, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U128>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -824,39 +920,39 @@ mod tests { i: usize, mode: Mode, rng: &mut TestRng, - ) -> (console_root::types::I128, I128) { + ) -> (console_root::types::I128, I128) { super::sample_values(i, mode, rng) } - check_cast_lossy!(cast_lossy, I128, console_root::types::I128); + check_cast_lossy!(cast_lossy, I128, console_root::types::I128); #[test] fn test_i128_to_address() { - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_i128_to_boolean() { - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -864,15 +960,15 @@ mod tests { #[test] fn test_i128_to_field() { - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -880,56 +976,68 @@ mod tests { #[test] fn test_i128_to_group() { - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_i128_to_i8() { - check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i128_to_i16() { - check_cast_lossy::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i128_to_i32() { - check_cast_lossy::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i128_to_i64() { - check_cast_lossy::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i128_to_i128() { - check_cast_lossy::, console_root::types::I128>( + check_cast_lossy::, console_root::types::I128>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I128>( + check_cast_lossy::, console_root::types::I128>( + Mode::Public, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I128>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -937,15 +1045,15 @@ mod tests { #[test] fn test_i128_to_scalar() { - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -953,40 +1061,52 @@ mod tests { #[test] fn test_i128_to_u8() { - check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i128_to_u16() { - check_cast_lossy::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i128_to_u32() { - check_cast_lossy::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i128_to_u64() { - check_cast_lossy::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_i128_to_u128() { - check_cast_lossy::, console_root::types::U128>( + check_cast_lossy::, console_root::types::U128>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U128>( + check_cast_lossy::, console_root::types::U128>( + Mode::Public, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U128>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -996,39 +1116,39 @@ mod tests { mod u8 { use super::*; - fn sample_values(i: usize, mode: Mode, rng: &mut TestRng) -> (console_root::types::U8, U8) { + fn sample_values(i: usize, mode: Mode, rng: &mut TestRng) -> (console_root::types::U8, U8) { super::sample_values(i, mode, rng) } - check_cast_lossy!(cast_lossy, U8, console_root::types::U8); + check_cast_lossy!(cast_lossy, U8, console_root::types::U8); #[test] fn test_u8_to_address() { - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_u8_to_boolean() { - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1036,15 +1156,15 @@ mod tests { #[test] fn test_u8_to_field() { - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1052,56 +1172,68 @@ mod tests { #[test] fn test_u8_to_group() { - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_u8_to_i8() { - check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u8_to_i16() { - check_cast_lossy::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u8_to_i32() { - check_cast_lossy::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u8_to_i64() { - check_cast_lossy::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u8_to_i128() { - check_cast_lossy::, console_root::types::I128>( + check_cast_lossy::, console_root::types::I128>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I128>( + check_cast_lossy::, console_root::types::I128>( + Mode::Public, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I128>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1109,15 +1241,15 @@ mod tests { #[test] fn test_u8_to_scalar() { - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1125,40 +1257,52 @@ mod tests { #[test] fn test_u8_to_u8() { - check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u8_to_u16() { - check_cast_lossy::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u8_to_u32() { - check_cast_lossy::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u8_to_u64() { - check_cast_lossy::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u8_to_u128() { - check_cast_lossy::, console_root::types::U128>( + check_cast_lossy::, console_root::types::U128>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U128>( + check_cast_lossy::, console_root::types::U128>( + Mode::Public, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U128>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1172,39 +1316,39 @@ mod tests { i: usize, mode: Mode, rng: &mut TestRng, - ) -> (console_root::types::U16, U16) { + ) -> (console_root::types::U16, U16) { super::sample_values(i, mode, rng) } - check_cast_lossy!(cast_lossy, U16, console_root::types::U16); + check_cast_lossy!(cast_lossy, U16, console_root::types::U16); #[test] fn test_u16_to_address() { - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_u16_to_boolean() { - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1212,15 +1356,15 @@ mod tests { #[test] fn test_u16_to_field() { - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1228,56 +1372,68 @@ mod tests { #[test] fn test_u16_to_group() { - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_u16_to_i8() { - check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u16_to_i16() { - check_cast_lossy::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u16_to_i32() { - check_cast_lossy::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u16_to_i64() { - check_cast_lossy::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u16_to_i128() { - check_cast_lossy::, console_root::types::I128>( + check_cast_lossy::, console_root::types::I128>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I128>( + check_cast_lossy::, console_root::types::I128>( + Mode::Public, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I128>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1285,15 +1441,15 @@ mod tests { #[test] fn test_u16_to_scalar() { - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1301,40 +1457,52 @@ mod tests { #[test] fn test_u16_to_u8() { - check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u16_to_u16() { - check_cast_lossy::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u16_to_u32() { - check_cast_lossy::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u16_to_u64() { - check_cast_lossy::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u16_to_u128() { - check_cast_lossy::, console_root::types::U128>( + check_cast_lossy::, console_root::types::U128>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U128>( + check_cast_lossy::, console_root::types::U128>( + Mode::Public, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U128>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1348,39 +1516,39 @@ mod tests { i: usize, mode: Mode, rng: &mut TestRng, - ) -> (console_root::types::U32, U32) { + ) -> (console_root::types::U32, U32) { super::sample_values(i, mode, rng) } - check_cast_lossy!(cast_lossy, U32, console_root::types::U32); + check_cast_lossy!(cast_lossy, U32, console_root::types::U32); #[test] fn test_u32_to_address() { - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_u32_to_boolean() { - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1388,15 +1556,15 @@ mod tests { #[test] fn test_u32_to_field() { - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1404,56 +1572,68 @@ mod tests { #[test] fn test_u32_to_group() { - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_u32_to_i8() { - check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u32_to_i16() { - check_cast_lossy::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u32_to_i32() { - check_cast_lossy::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u32_to_i64() { - check_cast_lossy::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u32_to_i128() { - check_cast_lossy::, console_root::types::I128>( + check_cast_lossy::, console_root::types::I128>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I128>( + check_cast_lossy::, console_root::types::I128>( + Mode::Public, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I128>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1461,15 +1641,15 @@ mod tests { #[test] fn test_u32_to_scalar() { - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1477,40 +1657,52 @@ mod tests { #[test] fn test_u32_to_u8() { - check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u32_to_u16() { - check_cast_lossy::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u32_to_u32() { - check_cast_lossy::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u32_to_u64() { - check_cast_lossy::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u32_to_u128() { - check_cast_lossy::, console_root::types::U128>( + check_cast_lossy::, console_root::types::U128>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U128>( + check_cast_lossy::, console_root::types::U128>( + Mode::Public, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U128>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1524,39 +1716,39 @@ mod tests { i: usize, mode: Mode, rng: &mut TestRng, - ) -> (console_root::types::U64, U64) { + ) -> (console_root::types::U64, U64) { super::sample_values(i, mode, rng) } - check_cast_lossy!(cast_lossy, U64, console_root::types::U64); + check_cast_lossy!(cast_lossy, U64, console_root::types::U64); #[test] fn test_u64_to_address() { - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_u64_to_boolean() { - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1564,15 +1756,15 @@ mod tests { #[test] fn test_u64_to_field() { - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1580,56 +1772,68 @@ mod tests { #[test] fn test_u64_to_group() { - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_u64_to_i8() { - check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u64_to_i16() { - check_cast_lossy::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u64_to_i32() { - check_cast_lossy::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u64_to_i64() { - check_cast_lossy::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u64_to_i128() { - check_cast_lossy::, console_root::types::I128>( + check_cast_lossy::, console_root::types::I128>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I128>( + check_cast_lossy::, console_root::types::I128>( + Mode::Public, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I128>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1637,15 +1841,15 @@ mod tests { #[test] fn test_u64_to_scalar() { - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1653,40 +1857,52 @@ mod tests { #[test] fn test_u64_to_u8() { - check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u64_to_u16() { - check_cast_lossy::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u64_to_u32() { - check_cast_lossy::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u64_to_u64() { - check_cast_lossy::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u64_to_u128() { - check_cast_lossy::, console_root::types::U128>( + check_cast_lossy::, console_root::types::U128>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U128>( + check_cast_lossy::, console_root::types::U128>( + Mode::Public, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U128>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1700,39 +1916,39 @@ mod tests { i: usize, mode: Mode, rng: &mut TestRng, - ) -> (console_root::types::U128, U128) { + ) -> (console_root::types::U128, U128) { super::sample_values(i, mode, rng) } - check_cast_lossy!(cast_lossy, U128, console_root::types::U128); + check_cast_lossy!(cast_lossy, U128, console_root::types::U128); #[test] fn test_u128_to_address() { - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_u128_to_boolean() { - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1740,15 +1956,15 @@ mod tests { #[test] fn test_u128_to_field() { - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Field>( + check_cast_lossy::, console_root::types::Field>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1756,56 +1972,68 @@ mod tests { #[test] fn test_u128_to_group() { - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_u128_to_i8() { - check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u128_to_i16() { - check_cast_lossy::, console_root::types::I16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u128_to_i32() { - check_cast_lossy::, console_root::types::I32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u128_to_i64() { - check_cast_lossy::, console_root::types::I64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u128_to_i128() { - check_cast_lossy::, console_root::types::I128>( + check_cast_lossy::, console_root::types::I128>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::I128>( + check_cast_lossy::, console_root::types::I128>( + Mode::Public, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I128>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1813,15 +2041,15 @@ mod tests { #[test] fn test_u128_to_scalar() { - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Public, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -1829,40 +2057,52 @@ mod tests { #[test] fn test_u128_to_u8() { - check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u128_to_u16() { - check_cast_lossy::, console_root::types::U16>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u128_to_u32() { - check_cast_lossy::, console_root::types::U32>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u128_to_u64() { - check_cast_lossy::, console_root::types::U64>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_u128_to_u128() { - check_cast_lossy::, console_root::types::U128>( + check_cast_lossy::, console_root::types::U128>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::U128>( + check_cast_lossy::, console_root::types::U128>( + Mode::Public, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U128>( Mode::Private, count_is!(0, 0, 0, 0), ); diff --git a/circuit/program/src/data/literal/cast_lossy/mod.rs b/circuit/program/src/data/literal/cast_lossy/mod.rs index eae6120f6f..ff36351fde 100644 --- a/circuit/program/src/data/literal/cast_lossy/mod.rs +++ b/circuit/program/src/data/literal/cast_lossy/mod.rs @@ -24,12 +24,8 @@ use snarkvm_circuit_network::Aleo; use snarkvm_circuit_types::prelude::{ bail, integers::Integer, - rename_selfs, - witness, - witness_mode, Address, Boolean, - Eject, Environment, Field, FromBits, @@ -38,7 +34,6 @@ use snarkvm_circuit_types::prelude::{ Group, Inject, IntegerType, - Mode, One, Result, Scalar, diff --git a/circuit/program/src/data/literal/cast_lossy/scalar.rs b/circuit/program/src/data/literal/cast_lossy/scalar.rs index 95fddba50b..2913265440 100644 --- a/circuit/program/src/data/literal/cast_lossy/scalar.rs +++ b/circuit/program/src/data/literal/cast_lossy/scalar.rs @@ -89,7 +89,7 @@ mod tests { use super::*; use console::CastLossy as _; use console_root::{ - network::Testnet3, + network::MainnetV0, prelude::{One, TestRng, Uniform, Zero}, }; use snarkvm_circuit_types::environment::{count_is, count_less_than, Circuit, Eject, Inject, Mode, UpdatableCount}; @@ -102,45 +102,45 @@ mod tests { i: usize, mode: Mode, rng: &mut TestRng, - ) -> (console_root::types::Scalar, Scalar) { + ) -> (console_root::types::Scalar, Scalar) { let console_value = match i { - 0 => console_root::types::Scalar::::zero(), - 1 => console_root::types::Scalar::::one(), + 0 => console_root::types::Scalar::::zero(), + 1 => console_root::types::Scalar::::one(), _ => Uniform::rand(rng), }; let circuit_value = Scalar::::new(mode, console_value); (console_value, circuit_value) } - check_cast_lossy!(cast_lossy, Scalar, console_root::types::Scalar::); + check_cast_lossy!(cast_lossy, Scalar, console_root::types::Scalar::); #[test] fn test_scalar_to_address() { - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Address>( + check_cast_lossy::, console_root::types::Address>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_scalar_to_boolean() { - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Constant, count_is!(251, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Public, count_is!(0, 0, 501, 503), ); - check_cast_lossy::, console_root::types::Boolean>( + check_cast_lossy::, console_root::types::Boolean>( Mode::Private, count_is!(0, 0, 501, 503), ); @@ -148,60 +148,69 @@ mod tests { #[test] fn test_scalar_to_field() { - check_cast_lossy::, console_root::types::Field>(Mode::Constant, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::Field>( + Mode::Constant, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::Field>(Mode::Public, count_is!(0, 0, 0, 0)); + check_cast_lossy::, console_root::types::Field>(Mode::Private, count_is!(0, 0, 0, 0)); } #[test] fn test_scalar_to_group() { - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Constant, - count_less_than!(551, 0, 0, 0), + count_less_than!(4303, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Public, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); - check_cast_lossy::, console_root::types::Group>( + check_cast_lossy::, console_root::types::Group>( Mode::Private, - count_is!(277, 0, 899, 904), + count_is!(2029, 0, 6745, 6750), ); } #[test] fn test_scalar_to_i8() { - check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(251, 0, 0, 0)); - check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 501, 503)); - check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 501, 503)); + check_cast_lossy::, console_root::types::I8>(Mode::Constant, count_is!(251, 0, 0, 0)); + check_cast_lossy::, console_root::types::I8>(Mode::Public, count_is!(0, 0, 501, 503)); + check_cast_lossy::, console_root::types::I8>(Mode::Private, count_is!(0, 0, 501, 503)); } #[test] fn test_scalar_to_i16() { - check_cast_lossy::, console_root::types::I16>(Mode::Constant, count_is!(251, 0, 0, 0)); - check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 501, 503)); - check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 501, 503)); + check_cast_lossy::, console_root::types::I16>(Mode::Constant, count_is!(251, 0, 0, 0)); + check_cast_lossy::, console_root::types::I16>(Mode::Public, count_is!(0, 0, 501, 503)); + check_cast_lossy::, console_root::types::I16>(Mode::Private, count_is!(0, 0, 501, 503)); } #[test] fn test_scalar_to_i32() { - check_cast_lossy::, console_root::types::I32>(Mode::Constant, count_is!(251, 0, 0, 0)); - check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 501, 503)); - check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 501, 503)); + check_cast_lossy::, console_root::types::I32>(Mode::Constant, count_is!(251, 0, 0, 0)); + check_cast_lossy::, console_root::types::I32>(Mode::Public, count_is!(0, 0, 501, 503)); + check_cast_lossy::, console_root::types::I32>(Mode::Private, count_is!(0, 0, 501, 503)); } #[test] fn test_scalar_to_i64() { - check_cast_lossy::, console_root::types::I64>(Mode::Constant, count_is!(251, 0, 0, 0)); - check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 501, 503)); - check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 501, 503)); + check_cast_lossy::, console_root::types::I64>(Mode::Constant, count_is!(251, 0, 0, 0)); + check_cast_lossy::, console_root::types::I64>(Mode::Public, count_is!(0, 0, 501, 503)); + check_cast_lossy::, console_root::types::I64>(Mode::Private, count_is!(0, 0, 501, 503)); } #[test] fn test_scalar_to_i128() { - check_cast_lossy::, console_root::types::I128>(Mode::Constant, count_is!(251, 0, 0, 0)); - check_cast_lossy::, console_root::types::I128>(Mode::Public, count_is!(0, 0, 501, 503)); - check_cast_lossy::, console_root::types::I128>( + check_cast_lossy::, console_root::types::I128>( + Mode::Constant, + count_is!(251, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::I128>( + Mode::Public, + count_is!(0, 0, 501, 503), + ); + check_cast_lossy::, console_root::types::I128>( Mode::Private, count_is!(0, 0, 501, 503), ); @@ -209,12 +218,15 @@ mod tests { #[test] fn test_scalar_to_scalar() { - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( Mode::Constant, count_is!(0, 0, 0, 0), ); - check_cast_lossy::, console_root::types::Scalar>(Mode::Public, count_is!(0, 0, 0, 0)); - check_cast_lossy::, console_root::types::Scalar>( + check_cast_lossy::, console_root::types::Scalar>( + Mode::Public, + count_is!(0, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::Scalar>( Mode::Private, count_is!(0, 0, 0, 0), ); @@ -222,37 +234,43 @@ mod tests { #[test] fn test_scalar_to_u8() { - check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(251, 0, 0, 0)); - check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 501, 503)); - check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 501, 503)); + check_cast_lossy::, console_root::types::U8>(Mode::Constant, count_is!(251, 0, 0, 0)); + check_cast_lossy::, console_root::types::U8>(Mode::Public, count_is!(0, 0, 501, 503)); + check_cast_lossy::, console_root::types::U8>(Mode::Private, count_is!(0, 0, 501, 503)); } #[test] fn test_scalar_to_u16() { - check_cast_lossy::, console_root::types::U16>(Mode::Constant, count_is!(251, 0, 0, 0)); - check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 501, 503)); - check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 501, 503)); + check_cast_lossy::, console_root::types::U16>(Mode::Constant, count_is!(251, 0, 0, 0)); + check_cast_lossy::, console_root::types::U16>(Mode::Public, count_is!(0, 0, 501, 503)); + check_cast_lossy::, console_root::types::U16>(Mode::Private, count_is!(0, 0, 501, 503)); } #[test] fn test_scalar_to_u32() { - check_cast_lossy::, console_root::types::U32>(Mode::Constant, count_is!(251, 0, 0, 0)); - check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 501, 503)); - check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 501, 503)); + check_cast_lossy::, console_root::types::U32>(Mode::Constant, count_is!(251, 0, 0, 0)); + check_cast_lossy::, console_root::types::U32>(Mode::Public, count_is!(0, 0, 501, 503)); + check_cast_lossy::, console_root::types::U32>(Mode::Private, count_is!(0, 0, 501, 503)); } #[test] fn test_scalar_to_u64() { - check_cast_lossy::, console_root::types::U64>(Mode::Constant, count_is!(251, 0, 0, 0)); - check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 501, 503)); - check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 501, 503)); + check_cast_lossy::, console_root::types::U64>(Mode::Constant, count_is!(251, 0, 0, 0)); + check_cast_lossy::, console_root::types::U64>(Mode::Public, count_is!(0, 0, 501, 503)); + check_cast_lossy::, console_root::types::U64>(Mode::Private, count_is!(0, 0, 501, 503)); } #[test] fn test_scalar_to_u128() { - check_cast_lossy::, console_root::types::U128>(Mode::Constant, count_is!(251, 0, 0, 0)); - check_cast_lossy::, console_root::types::U128>(Mode::Public, count_is!(0, 0, 501, 503)); - check_cast_lossy::, console_root::types::U128>( + check_cast_lossy::, console_root::types::U128>( + Mode::Constant, + count_is!(251, 0, 0, 0), + ); + check_cast_lossy::, console_root::types::U128>( + Mode::Public, + count_is!(0, 0, 501, 503), + ); + check_cast_lossy::, console_root::types::U128>( Mode::Private, count_is!(0, 0, 501, 503), ); diff --git a/circuit/program/src/data/plaintext/mod.rs b/circuit/program/src/data/plaintext/mod.rs index efe8c8eaca..8f717c34ea 100644 --- a/circuit/program/src/data/plaintext/mod.rs +++ b/circuit/program/src/data/plaintext/mod.rs @@ -132,144 +132,117 @@ mod tests { // Test a random struct with literal members. run_test(Plaintext::::Struct( - IndexMap::from_iter( - vec![ - ( - Identifier::new(Mode::Private, "a".try_into()?), - Plaintext::::Literal( - Literal::Boolean(Boolean::new(Mode::Private, true)), - OnceCell::new(), - ), - ), - ( - Identifier::new(Mode::Private, "b".try_into()?), - Plaintext::::Literal( - Literal::Field(Field::new(Mode::Private, Uniform::rand(&mut rng))), - OnceCell::new(), - ), + IndexMap::from_iter(vec![ + ( + Identifier::new(Mode::Private, "a".try_into()?), + Plaintext::::Literal(Literal::Boolean(Boolean::new(Mode::Private, true)), OnceCell::new()), + ), + ( + Identifier::new(Mode::Private, "b".try_into()?), + Plaintext::::Literal( + Literal::Field(Field::new(Mode::Private, Uniform::rand(&mut rng))), + OnceCell::new(), ), - ] - .into_iter(), - ), + ), + ]), OnceCell::new(), )); // Test a random struct with array members. run_test(Plaintext::::Struct( - IndexMap::from_iter( - vec![ - ( - Identifier::new(Mode::Private, "a".try_into()?), - Plaintext::::Literal( - Literal::Boolean(Boolean::new(Mode::Private, true)), - OnceCell::new(), - ), + IndexMap::from_iter(vec![ + ( + Identifier::new(Mode::Private, "a".try_into()?), + Plaintext::::Literal(Literal::Boolean(Boolean::new(Mode::Private, true)), OnceCell::new()), + ), + ( + Identifier::new(Mode::Private, "b".try_into()?), + Plaintext::::Array( + vec![ + Plaintext::::Literal( + Literal::Boolean(Boolean::new(Mode::Private, true)), + OnceCell::new(), + ), + Plaintext::::Literal( + Literal::Boolean(Boolean::new(Mode::Private, false)), + OnceCell::new(), + ), + ], + OnceCell::new(), ), - ( - Identifier::new(Mode::Private, "b".try_into()?), - Plaintext::::Array( - vec![ + ), + ]), + OnceCell::new(), + )); + + // Test random deeply-nested struct. + run_test(Plaintext::::Struct( + IndexMap::from_iter(vec![ + ( + Identifier::new(Mode::Private, "a".try_into()?), + Plaintext::::Literal(Literal::Boolean(Boolean::new(Mode::Private, true)), OnceCell::new()), + ), + ( + Identifier::new(Mode::Private, "b".try_into()?), + Plaintext::::Struct( + IndexMap::from_iter(vec![ + ( + Identifier::new(Mode::Private, "c".try_into()?), Plaintext::::Literal( Literal::Boolean(Boolean::new(Mode::Private, true)), OnceCell::new(), ), - Plaintext::::Literal( - Literal::Boolean(Boolean::new(Mode::Private, false)), + ), + ( + Identifier::new(Mode::Private, "d".try_into()?), + Plaintext::::Struct( + IndexMap::from_iter(vec![ + ( + Identifier::new(Mode::Private, "e".try_into()?), + Plaintext::::Literal( + Literal::Boolean(Boolean::new(Mode::Private, true)), + OnceCell::new(), + ), + ), + ( + Identifier::new(Mode::Private, "f".try_into()?), + Plaintext::::Literal( + Literal::Field(Field::new(Mode::Private, Uniform::rand(&mut rng))), + OnceCell::new(), + ), + ), + ]), OnceCell::new(), ), - ], - OnceCell::new(), - ), - ), - ] - .into_iter(), - ), - OnceCell::new(), - )); - - // Test random deeply-nested struct. - run_test(Plaintext::::Struct( - IndexMap::from_iter( - vec![ - ( - Identifier::new(Mode::Private, "a".try_into()?), - Plaintext::::Literal( - Literal::Boolean(Boolean::new(Mode::Private, true)), - OnceCell::new(), - ), - ), - ( - Identifier::new(Mode::Private, "b".try_into()?), - Plaintext::::Struct( - IndexMap::from_iter( - vec![ - ( - Identifier::new(Mode::Private, "c".try_into()?), + ), + ( + Identifier::new(Mode::Private, "g".try_into()?), + Plaintext::::Array( + vec![ Plaintext::::Literal( Literal::Boolean(Boolean::new(Mode::Private, true)), OnceCell::new(), ), - ), - ( - Identifier::new(Mode::Private, "d".try_into()?), - Plaintext::::Struct( - IndexMap::from_iter( - vec![ - ( - Identifier::new(Mode::Private, "e".try_into()?), - Plaintext::::Literal( - Literal::Boolean(Boolean::new(Mode::Private, true)), - OnceCell::new(), - ), - ), - ( - Identifier::new(Mode::Private, "f".try_into()?), - Plaintext::::Literal( - Literal::Field(Field::new( - Mode::Private, - Uniform::rand(&mut rng), - )), - OnceCell::new(), - ), - ), - ] - .into_iter(), - ), - OnceCell::new(), - ), - ), - ( - Identifier::new(Mode::Private, "g".try_into()?), - Plaintext::::Array( - vec![ - Plaintext::::Literal( - Literal::Boolean(Boolean::new(Mode::Private, true)), - OnceCell::new(), - ), - Plaintext::::Literal( - Literal::Boolean(Boolean::new(Mode::Private, false)), - OnceCell::new(), - ), - ], + Plaintext::::Literal( + Literal::Boolean(Boolean::new(Mode::Private, false)), OnceCell::new(), ), - ), - ] - .into_iter(), + ], + OnceCell::new(), + ), ), - OnceCell::new(), - ), + ]), + OnceCell::new(), ), - ( - Identifier::new(Mode::Private, "h".try_into()?), - Plaintext::::Literal( - Literal::Field(Field::new(Mode::Private, Uniform::rand(&mut rng))), - OnceCell::new(), - ), + ), + ( + Identifier::new(Mode::Private, "h".try_into()?), + Plaintext::::Literal( + Literal::Field(Field::new(Mode::Private, Uniform::rand(&mut rng))), + OnceCell::new(), ), - ] - .into_iter(), - ), + ), + ]), OnceCell::new(), )); @@ -304,69 +277,60 @@ mod tests { run_test(Plaintext::::Array( vec![ Plaintext::::Struct( - IndexMap::from_iter( - vec![ - ( - Identifier::new(Mode::Private, "x".try_into()?), - Plaintext::::Literal( - Literal::Field(Field::new(Mode::Private, Uniform::rand(&mut rng))), - OnceCell::new(), - ), + IndexMap::from_iter(vec![ + ( + Identifier::new(Mode::Private, "x".try_into()?), + Plaintext::::Literal( + Literal::Field(Field::new(Mode::Private, Uniform::rand(&mut rng))), + OnceCell::new(), ), - ( - Identifier::new(Mode::Private, "y".try_into()?), - Plaintext::::Literal( - Literal::Field(Field::new(Mode::Private, Uniform::rand(&mut rng))), - OnceCell::new(), - ), + ), + ( + Identifier::new(Mode::Private, "y".try_into()?), + Plaintext::::Literal( + Literal::Field(Field::new(Mode::Private, Uniform::rand(&mut rng))), + OnceCell::new(), ), - ] - .into_iter(), - ), + ), + ]), OnceCell::new(), ), Plaintext::::Struct( - IndexMap::from_iter( - vec![ - ( - Identifier::new(Mode::Private, "x".try_into()?), - Plaintext::::Literal( - Literal::Field(Field::new(Mode::Private, Uniform::rand(&mut rng))), - OnceCell::new(), - ), + IndexMap::from_iter(vec![ + ( + Identifier::new(Mode::Private, "x".try_into()?), + Plaintext::::Literal( + Literal::Field(Field::new(Mode::Private, Uniform::rand(&mut rng))), + OnceCell::new(), ), - ( - Identifier::new(Mode::Private, "y".try_into()?), - Plaintext::::Literal( - Literal::Field(Field::new(Mode::Private, Uniform::rand(&mut rng))), - OnceCell::new(), - ), + ), + ( + Identifier::new(Mode::Private, "y".try_into()?), + Plaintext::::Literal( + Literal::Field(Field::new(Mode::Private, Uniform::rand(&mut rng))), + OnceCell::new(), ), - ] - .into_iter(), - ), + ), + ]), OnceCell::new(), ), Plaintext::::Struct( - IndexMap::from_iter( - vec![ - ( - Identifier::new(Mode::Private, "x".try_into()?), - Plaintext::::Literal( - Literal::Field(Field::new(Mode::Private, Uniform::rand(&mut rng))), - OnceCell::new(), - ), + IndexMap::from_iter(vec![ + ( + Identifier::new(Mode::Private, "x".try_into()?), + Plaintext::::Literal( + Literal::Field(Field::new(Mode::Private, Uniform::rand(&mut rng))), + OnceCell::new(), ), - ( - Identifier::new(Mode::Private, "y".try_into()?), - Plaintext::::Literal( - Literal::Field(Field::new(Mode::Private, Uniform::rand(&mut rng))), - OnceCell::new(), - ), + ), + ( + Identifier::new(Mode::Private, "y".try_into()?), + Plaintext::::Literal( + Literal::Field(Field::new(Mode::Private, Uniform::rand(&mut rng))), + OnceCell::new(), ), - ] - .into_iter(), - ), + ), + ]), OnceCell::new(), ), ], @@ -382,25 +346,22 @@ mod tests { OnceCell::new(), ), Plaintext::::Struct( - IndexMap::from_iter( - vec![ - ( - Identifier::new(Mode::Private, "x".try_into()?), - Plaintext::::Literal( - Literal::Field(Field::new(Mode::Private, Uniform::rand(&mut rng))), - OnceCell::new(), - ), + IndexMap::from_iter(vec![ + ( + Identifier::new(Mode::Private, "x".try_into()?), + Plaintext::::Literal( + Literal::Field(Field::new(Mode::Private, Uniform::rand(&mut rng))), + OnceCell::new(), ), - ( - Identifier::new(Mode::Private, "y".try_into()?), - Plaintext::::Literal( - Literal::Field(Field::new(Mode::Private, Uniform::rand(&mut rng))), - OnceCell::new(), - ), + ), + ( + Identifier::new(Mode::Private, "y".try_into()?), + Plaintext::::Literal( + Literal::Field(Field::new(Mode::Private, Uniform::rand(&mut rng))), + OnceCell::new(), ), - ] - .into_iter(), - ), + ), + ]), OnceCell::new(), ), ], diff --git a/circuit/program/src/data/record/decrypt.rs b/circuit/program/src/data/record/decrypt.rs index 4be3944a2f..b7f9d1a0bd 100644 --- a/circuit/program/src/data/record/decrypt.rs +++ b/circuit/program/src/data/record/decrypt.rs @@ -102,22 +102,16 @@ mod tests { let randomizer = Scalar::new(Mode::Private, Uniform::rand(rng)); let record = Record { owner, - data: IndexMap::from_iter( - vec![ - ( - Identifier::from_str("a")?, - Entry::Private(Plaintext::from(Literal::Field(Field::new(Mode::Private, Uniform::rand(rng))))), - ), - ( - Identifier::from_str("b")?, - Entry::Private(Plaintext::from(Literal::Scalar(Scalar::new( - Mode::Private, - Uniform::rand(rng), - )))), - ), - ] - .into_iter(), - ), + data: IndexMap::from_iter(vec![ + ( + Identifier::from_str("a")?, + Entry::Private(Plaintext::from(Literal::Field(Field::new(Mode::Private, Uniform::rand(rng))))), + ), + ( + Identifier::from_str("b")?, + Entry::Private(Plaintext::from(Literal::Scalar(Scalar::new(Mode::Private, Uniform::rand(rng))))), + ), + ]), nonce: A::g_scalar_multiply(&randomizer), }; diff --git a/circuit/program/src/function_id/mod.rs b/circuit/program/src/function_id/mod.rs new file mode 100644 index 0000000000..af13541502 --- /dev/null +++ b/circuit/program/src/function_id/mod.rs @@ -0,0 +1,37 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the snarkVM library. + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use crate::{Identifier, ProgramID}; +use snarkvm_circuit_network::Aleo; +use snarkvm_circuit_types::{environment::prelude::*, Field, U16}; + +/// Compute the function ID as `Hash(network_id, program_id.len(), program_id, function_name.len(), function_name)`. +pub fn compute_function_id( + network_id: &U16, + program_id: &ProgramID, + function_name: &Identifier, +) -> Field { + A::hash_bhp1024( + &( + network_id, + program_id.name().size_in_bits(), + program_id.name(), + program_id.network().size_in_bits(), + program_id.network(), + function_name.size_in_bits(), + function_name, + ) + .to_bits_le(), + ) +} diff --git a/circuit/program/src/lib.rs b/circuit/program/src/lib.rs index cf9be261cd..ffc7c64960 100644 --- a/circuit/program/src/lib.rs +++ b/circuit/program/src/lib.rs @@ -22,6 +22,9 @@ use snarkvm_circuit_network::AleoV0 as Circuit; mod data; pub use data::*; +mod function_id; +pub use function_id::*; + mod id; pub use id::*; diff --git a/circuit/program/src/request/mod.rs b/circuit/program/src/request/mod.rs index 0a7424667a..b1c2c161ca 100644 --- a/circuit/program/src/request/mod.rs +++ b/circuit/program/src/request/mod.rs @@ -18,7 +18,7 @@ use snarkvm_circuit_types::environment::assert_scope; mod to_tpk; mod verify; -use crate::{Identifier, Plaintext, ProgramID, Record, Value}; +use crate::{compute_function_id, Identifier, Plaintext, ProgramID, Record, Value}; use snarkvm_circuit_account::Signature; use snarkvm_circuit_network::Aleo; use snarkvm_circuit_types::{environment::prelude::*, Address, Boolean, Field, Group, U16}; @@ -136,6 +136,8 @@ pub struct Request { tvk: Field, /// The transition commitment. tcm: Field, + /// The signer commitment. + scm: Field, } #[cfg(console)] @@ -147,6 +149,9 @@ impl Inject for Request { // Inject the transition commitment `tcm` as `Mode::Public`. let tcm = Field::new(Mode::Public, *request.tcm()); + // Inject the signer commitment `scm` as `Mode::Public`. + let scm = Field::new(Mode::Public, *request.scm()); + // Inject the inputs. let inputs = match request .input_ids() @@ -218,6 +223,7 @@ impl Inject for Request { sk_tag: Field::new(mode, *request.sk_tag()), tvk: Field::new(mode, *request.tvk()), tcm, + scm, } } } @@ -272,6 +278,11 @@ impl Request { pub const fn tcm(&self) -> &Field { &self.tcm } + + /// Returns the signer commitment. + pub const fn scm(&self) -> &Field { + &self.scm + } } #[cfg(console)] @@ -290,6 +301,7 @@ impl Eject for Request { self.sk_tag.eject_mode(), self.tvk.eject_mode(), self.tcm.eject_mode(), + self.scm.eject_mode(), ]) } @@ -306,6 +318,7 @@ impl Eject for Request { self.sk_tag.eject_value(), self.tvk.eject_value(), self.tcm.eject_value(), + self.scm.eject_value(), )) } } diff --git a/circuit/program/src/request/verify.rs b/circuit/program/src/request/verify.rs index 86dd773a28..30b3e3d5ae 100644 --- a/circuit/program/src/request/verify.rs +++ b/circuit/program/src/request/verify.rs @@ -16,21 +16,29 @@ use super::*; impl Request { /// Returns `true` if the input IDs are derived correctly, the input records all belong to the signer, - /// and the signature is valid. tpk is passed separately so it can have a Mode different from Self. + /// and the signature is valid. /// /// Verifies (challenge == challenge') && (address == address') && (serial_numbers == serial_numbers') where: /// challenge' := HashToScalar(r * G, pk_sig, pr_sig, signer, \[tvk, tcm, function ID, input IDs\]) - pub fn verify(&self, input_types: &[console::ValueType], tpk: &Group) -> Boolean { - // Compute the function ID as `Hash(network_id, program_id, function_name)`. - let function_id = A::hash_bhp1024( - &(&self.network_id, self.program_id.name(), self.program_id.network(), &self.function_name).to_bits_le(), - ); + pub fn verify( + &self, + input_types: &[console::ValueType], + tpk: &Group, + root_tvk: Option>, + is_root: Boolean, + ) -> Boolean { + // Compute the function ID. + let function_id = compute_function_id(&self.network_id, &self.program_id, &self.function_name); + + // Compute 'is_root' as a field element. + let is_root = Ternary::ternary(&is_root, &Field::::one(), &Field::::zero()); // Construct the signature message as `[tvk, tcm, function ID, input IDs]`. let mut message = Vec::with_capacity(3 + 4 * self.input_ids.len()); message.push(self.tvk.clone()); message.push(self.tcm.clone()); message.push(function_id); + message.push(is_root); // Check the input IDs and construct the rest of the signature message. let (input_checks, append_to_message) = Self::check_input_ids::( @@ -52,15 +60,21 @@ impl Request { None => A::halt("Missing input elements in request verification"), } - // Verify the transition public key and commitment are well-formed. + let root_tvk = root_tvk.unwrap_or(Field::::new(Mode::Private, self.tvk.eject_value())); + + // Verify the transition public key and commitments are well-formed. let tpk_checks = { // Compute the transition commitment as `Hash(tvk)`. let tcm = A::hash_psd2(&[self.tvk.clone()]); + // Compute the signer commitment as `Hash(signer || root_tvk)`. + let scm = A::hash_psd2(&[self.signer.to_field(), root_tvk]); // Ensure the transition public key matches with the saved one from the signature. tpk.is_equal(&self.to_tpk()) // Ensure the computed transition commitment matches. & tcm.is_equal(&self.tcm) + // Ensure the computed signer commitment matches. + & scm.is_equal(&self.scm) }; // Verify the signature. @@ -111,9 +125,8 @@ impl Request { false => assert!(signature.is_none()), } - // Compute the function ID as `Hash(network_id, program_id, function_name)`. - let function_id = - A::hash_bhp1024(&(network_id, program_id.name(), program_id.network(), function_name).to_bits_le()); + // Compute the function ID. + let function_id = compute_function_id(network_id, program_id, function_name); // Initialize a vector for a message. let mut message = Vec::new(); @@ -350,17 +363,33 @@ mod tests { console::ValueType::from_str("token.aleo/token.record").unwrap(), ]; + // Sample 'root_tvk'. + let root_tvk = None; + + // Sample 'is_root'. + let is_root = true; + // Compute the signed request. - let request = - console::Request::sign(&private_key, program_id, function_name, inputs.iter(), &input_types, rng)?; - assert!(request.verify(&input_types)); + let request = console::Request::sign( + &private_key, + program_id, + function_name, + inputs.iter(), + &input_types, + root_tvk, + is_root, + rng, + )?; + assert!(request.verify(&input_types, is_root)); // Inject the request into a circuit. let tpk = Group::::new(mode, request.to_tpk()); let request = Request::::new(mode, request); + let is_root = Boolean::new(mode, is_root); Circuit::scope(format!("Request {i}"), || { - let candidate = request.verify(&input_types, &tpk); + let root_tvk = None; + let candidate = request.verify(&input_types, &tpk, root_tvk, is_root); assert!(candidate.eject_value()); match mode.is_constant() { true => assert_scope!(<=num_constants, <=num_public, <=num_private, <=num_constraints), @@ -394,16 +423,16 @@ mod tests { // Note: This is correct. At this (high) level of a program, we override the default mode in the `Record` case, // based on the user-defined visibility in the record type. Thus, we have nonzero private and constraint values. // These bounds are determined experimentally. - check_verify(Mode::Constant, 42520, 0, 17494, 17518) + check_verify(Mode::Constant, 43000, 0, 18000, 18000) } #[test] fn test_sign_and_verify_public() -> Result<()> { - check_verify(Mode::Public, 40018, 0, 26401, 26429) + check_verify(Mode::Public, 40131, 0, 26675, 26702) } #[test] fn test_sign_and_verify_private() -> Result<()> { - check_verify(Mode::Private, 40018, 0, 26401, 26429) + check_verify(Mode::Private, 40131, 0, 26675, 26702) } } diff --git a/circuit/program/src/response/from_outputs.rs b/circuit/program/src/response/from_outputs.rs index 5618e8702d..b42ef9d875 100644 --- a/circuit/program/src/response/from_outputs.rs +++ b/circuit/program/src/response/from_outputs.rs @@ -27,9 +27,8 @@ impl Response { output_types: &[console::ValueType], // Note: Console type output_registers: &[Option>], // Note: Console type ) -> Self { - // Compute the function ID as `Hash(network_id, program_id, function_name)`. - let function_id = - A::hash_bhp1024(&(network_id, program_id.name(), program_id.network(), function_name).to_bits_le()); + // Compute the function ID. + let function_id = compute_function_id(network_id, program_id, function_name); // Compute the output IDs. let output_ids = outputs @@ -302,11 +301,11 @@ mod tests { #[test] fn test_from_outputs_public() -> Result<()> { - check_from_outputs(Mode::Public, 24793, 6, 13962, 13983) + check_from_outputs(Mode::Public, 24849, 6, 13962, 13983) } #[test] fn test_from_outputs_private() -> Result<()> { - check_from_outputs(Mode::Private, 24793, 6, 13962, 13983) + check_from_outputs(Mode::Private, 24849, 6, 13962, 13983) } } diff --git a/circuit/program/src/response/mod.rs b/circuit/program/src/response/mod.rs index 897f1c09a9..288e8f4653 100644 --- a/circuit/program/src/response/mod.rs +++ b/circuit/program/src/response/mod.rs @@ -18,7 +18,7 @@ use snarkvm_circuit_types::environment::assert_scope; mod from_outputs; mod process_outputs_from_callback; -use crate::{Identifier, ProgramID, Value}; +use crate::{compute_function_id, Identifier, ProgramID, Value}; use snarkvm_circuit_network::Aleo; use snarkvm_circuit_types::{environment::prelude::*, Field, U16}; diff --git a/circuit/program/src/response/process_outputs_from_callback.rs b/circuit/program/src/response/process_outputs_from_callback.rs index 287c8fd549..dfadc178e3 100644 --- a/circuit/program/src/response/process_outputs_from_callback.rs +++ b/circuit/program/src/response/process_outputs_from_callback.rs @@ -26,9 +26,8 @@ impl Response { outputs: Vec>, // Note: Console type output_types: &[console::ValueType], // Note: Console type ) -> Vec> { - // Compute the function ID as `Hash(network_id, program_id, function_name)`. - let function_id = - A::hash_bhp1024(&(network_id, program_id.name(), program_id.network(), function_name).to_bits_le()); + // Compute the function ID. + let function_id = compute_function_id(network_id, program_id, function_name); match outputs .iter() @@ -326,16 +325,16 @@ mod tests { #[test] fn test_from_callback_constant() -> Result<()> { - check_from_callback(Mode::Constant, 20788, 5, 4922, 4931) + check_from_callback(Mode::Constant, 20844, 5, 4922, 4931) } #[test] fn test_from_callback_public() -> Result<()> { - check_from_callback(Mode::Public, 20788, 5, 6217, 6226) + check_from_callback(Mode::Public, 20844, 5, 6217, 6226) } #[test] fn test_from_callback_private() -> Result<()> { - check_from_callback(Mode::Private, 20788, 5, 6217, 6226) + check_from_callback(Mode::Private, 20844, 5, 6217, 6226) } } diff --git a/circuit/program/src/state_path/mod.rs b/circuit/program/src/state_path/mod.rs index d8cf025aa6..6e8a30ed74 100644 --- a/circuit/program/src/state_path/mod.rs +++ b/circuit/program/src/state_path/mod.rs @@ -191,16 +191,16 @@ mod tests { #[test] fn test_state_path_new_constant() -> Result<()> { - check_new(Mode::Constant, 446, 1, 0, 0) + check_new(Mode::Constant, 450, 1, 0, 0) } #[test] fn test_state_path_new_public() -> Result<()> { - check_new(Mode::Public, 0, 447, 0, 376) + check_new(Mode::Public, 0, 451, 0, 376) } #[test] fn test_state_path_new_private() -> Result<()> { - check_new(Mode::Private, 0, 1, 446, 376) + check_new(Mode::Private, 0, 1, 450, 376) } } diff --git a/circuit/program/src/state_path/verify.rs b/circuit/program/src/state_path/verify.rs index f4c6e624cc..9101486ff9 100644 --- a/circuit/program/src/state_path/verify.rs +++ b/circuit/program/src/state_path/verify.rs @@ -225,43 +225,43 @@ mod tests { #[test] fn test_state_path_verify_global_constant() -> Result<()> { - check_verify_global(Mode::Constant, true, 106309, 1, 2, 2)?; - check_verify_global(Mode::Constant, false, 106309, 1, 2, 2) + check_verify_global(Mode::Constant, true, 112709, 1, 2, 2)?; + check_verify_global(Mode::Constant, false, 112709, 1, 2, 2) } #[test] fn test_state_path_verify_global_public() -> Result<()> { - check_verify_global(Mode::Public, true, 27814, 449, 123343, 123982)?; - check_verify_global(Mode::Public, false, 27814, 449, 123343, 123982) + check_verify_global(Mode::Public, true, 29450, 453, 130867, 131522)?; + check_verify_global(Mode::Public, false, 29450, 453, 130867, 131522) } #[test] fn test_state_path_verify_global_private() -> Result<()> { - check_verify_global(Mode::Private, true, 27814, 1, 123791, 123982)?; - check_verify_global(Mode::Private, false, 27814, 1, 123791, 123982) + check_verify_global(Mode::Private, true, 29450, 1, 131319, 131522)?; + check_verify_global(Mode::Private, false, 29450, 1, 131319, 131522) } #[test] fn test_state_path_verify_local_constant() -> Result<()> { - check_verify_local(Mode::Constant, false, true, 106309, 1, 2, 2)?; - check_verify_local(Mode::Constant, false, false, 106309, 1, 2, 2)?; - check_verify_local(Mode::Constant, true, true, 106309, 1, 2, 2)?; - check_verify_local(Mode::Constant, true, false, 106309, 1, 2, 2) + check_verify_local(Mode::Constant, false, true, 112709, 1, 2, 2)?; + check_verify_local(Mode::Constant, false, false, 112709, 1, 2, 2)?; + check_verify_local(Mode::Constant, true, true, 112709, 1, 2, 2)?; + check_verify_local(Mode::Constant, true, false, 112709, 1, 2, 2) } #[test] fn test_state_path_verify_local_public() -> Result<()> { - check_verify_local(Mode::Public, false, true, 27814, 449, 123343, 123982)?; - check_verify_local(Mode::Public, false, false, 27814, 449, 123343, 123982)?; - check_verify_local(Mode::Public, true, true, 27814, 449, 123343, 123982)?; - check_verify_local(Mode::Public, true, false, 27814, 449, 123343, 123982) + check_verify_local(Mode::Public, false, true, 29450, 453, 130867, 131522)?; + check_verify_local(Mode::Public, false, false, 29450, 453, 130867, 131522)?; + check_verify_local(Mode::Public, true, true, 29450, 453, 130867, 131522)?; + check_verify_local(Mode::Public, true, false, 29450, 453, 130867, 131522) } #[test] fn test_state_path_verify_local_private() -> Result<()> { - check_verify_local(Mode::Private, false, true, 27814, 1, 123791, 123982)?; - check_verify_local(Mode::Private, false, false, 27814, 1, 123791, 123982)?; - check_verify_local(Mode::Private, true, true, 27814, 1, 123791, 123982)?; - check_verify_local(Mode::Private, true, false, 27814, 1, 123791, 123982) + check_verify_local(Mode::Private, false, true, 29450, 1, 131319, 131522)?; + check_verify_local(Mode::Private, false, false, 29450, 1, 131319, 131522)?; + check_verify_local(Mode::Private, true, true, 29450, 1, 131319, 131522)?; + check_verify_local(Mode::Private, true, false, 29450, 1, 131319, 131522) } } diff --git a/circuit/types/Cargo.toml b/circuit/types/Cargo.toml index 8650ccc513..b2448c60b3 100644 --- a/circuit/types/Cargo.toml +++ b/circuit/types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-circuit-types" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Primitive circuit for a decentralized virtual machine" license = "Apache-2.0" @@ -8,35 +8,35 @@ edition = "2021" [dependencies.snarkvm-circuit-environment] path = "../environment" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-address] path = "./address" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-boolean] path = "./boolean" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-field] path = "./field" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-group] path = "./group" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-integers] path = "./integers" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-scalar] path = "./scalar" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-string] path = "./string" -version = "=0.16.15" +version = "=0.16.19" [dev-dependencies.console] package = "snarkvm-console" diff --git a/circuit/types/address/Cargo.toml b/circuit/types/address/Cargo.toml index 50e4b7c70b..d859d594f7 100644 --- a/circuit/types/address/Cargo.toml +++ b/circuit/types/address/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-circuit-types-address" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Address circuit for a decentralized virtual machine" license = "Apache-2.0" @@ -9,28 +9,28 @@ edition = "2021" [dependencies.console] package = "snarkvm-console-types-address" path = "../../../console/types/address" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-circuit-environment] path = "../../environment" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-boolean] path = "../boolean" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-field] path = "../field" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-group] path = "../group" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-scalar] path = "../scalar" -version = "=0.16.15" +version = "=0.16.19" [features] default = [ "enable_console" ] diff --git a/circuit/types/boolean/Cargo.toml b/circuit/types/boolean/Cargo.toml index d357cf45b0..6f9e9f2e3b 100644 --- a/circuit/types/boolean/Cargo.toml +++ b/circuit/types/boolean/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-circuit-types-boolean" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Boolean circuit for a decentralized virtual machine" license = "Apache-2.0" @@ -14,12 +14,12 @@ harness = false [dependencies.console] package = "snarkvm-console-types-boolean" path = "../../../console/types/boolean" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-circuit-environment] path = "../../environment" -version = "=0.16.15" +version = "=0.16.19" [dev-dependencies.criterion] version = "0.5" diff --git a/circuit/types/field/Cargo.toml b/circuit/types/field/Cargo.toml index 9f26acc523..acc1367886 100644 --- a/circuit/types/field/Cargo.toml +++ b/circuit/types/field/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-circuit-types-field" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Field circuit for a decentralized virtual machine" license = "Apache-2.0" @@ -9,16 +9,16 @@ edition = "2021" [dependencies.console] package = "snarkvm-console-types-field" path = "../../../console/types/field" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-circuit-environment] path = "../../environment" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-boolean] path = "../boolean" -version = "=0.16.15" +version = "=0.16.19" [features] default = [ "enable_console" ] diff --git a/circuit/types/field/src/helpers/from_bits.rs b/circuit/types/field/src/helpers/from_bits.rs index d1f7abfda2..3376cfa199 100644 --- a/circuit/types/field/src/helpers/from_bits.rs +++ b/circuit/types/field/src/helpers/from_bits.rs @@ -126,7 +126,7 @@ mod tests { }); // Add excess zero bits. - let candidate = vec![given_bits, vec![Boolean::new(mode, false); i as usize]].concat(); + let candidate = [given_bits, vec![Boolean::new(mode, false); i as usize]].concat(); Circuit::scope(&format!("Excess {mode} {i}"), || { let candidate = Field::::from_bits_le(&candidate); @@ -171,7 +171,7 @@ mod tests { }); // Add excess zero bits. - let candidate = vec![vec![Boolean::new(mode, false); i as usize], given_bits].concat(); + let candidate = [vec![Boolean::new(mode, false); i as usize], given_bits].concat(); Circuit::scope(&format!("Excess {mode} {i}"), || { let candidate = Field::::from_bits_be(&candidate); diff --git a/circuit/types/field/src/square_root.rs b/circuit/types/field/src/square_root.rs index 8430d0ae29..be7d350f71 100644 --- a/circuit/types/field/src/square_root.rs +++ b/circuit/types/field/src/square_root.rs @@ -63,6 +63,65 @@ impl Field { } } +impl Field { + /// Returns both square roots of `self` and a `Boolean` flag, which is set iff `self` is not a square. + /// + /// If `self` is a non-zero square, + /// - the first field result is the positive root (i.e. closer to 0) + /// - the second field result is the negative root (i.e. closer to the prime) + /// - the flag is 0 + /// + /// If `self` is 0, + /// - both field results are 0 + /// - the flag is 0 + /// + /// If `self` is not a square, + /// - both field results are 0 + /// - the flag is 1 + /// + /// Note that the constraints do **not** impose an ordering on the two roots returned by this function; + /// this is what the `nondeterministic` part of this function name refers to. + pub fn square_roots_flagged_nondeterministic(&self) -> (Self, Self, Boolean) { + // Obtain (p-1)/2, as a constant field element. + let modulus_minus_one_div_two = match E::BaseField::from_bigint(E::BaseField::modulus_minus_one_div_two()) { + Some(modulus_minus_one_div_two) => Field::constant(console::Field::new(modulus_minus_one_div_two)), + None => E::halt("Failed to initialize (modulus - 1) / 2"), + }; + + // Use Euler's criterion: self is a non-zero square iff self^((p-1)/2) is 1. + let euler = self.pow(modulus_minus_one_div_two); + let is_nonzero_square = euler.is_one(); + + // Calculate the witness for the first square result. + // Note that the **console** function `square_root` returns the square root closer to 0. + let root_witness = match self.eject_value().square_root() { + Ok(root) => root, + Err(_) => console::Field::zero(), + }; + + // Initialize the square element, which is either `self` or 0, depending on whether `self` is a square. + // This is done to ensure that the below constraint is satisfied even if `self` is not a square. + let square = Self::ternary(&is_nonzero_square, self, &Field::zero()); + + // Initialize a new variable for the first root. + let mode = if self.eject_mode() == Mode::Constant { Mode::Constant } else { Mode::Private }; + let first_root = Field::new(mode, root_witness); + + // Enforce that the first root squared is equal to the square. + // Note that if `self` is not a square, then `first_root` and `square` are both zero and the constraint is satisfied. + E::enforce(|| (&first_root, &first_root, &square)); + + // Initialize the second root as the negation of the first root. + let second_root = first_root.clone().neg(); + + // The error flag is set iff self is a non-square, i.e. it is neither zero nor a non-zero square. + let is_nonzero = !self.is_zero(); + let error_flag = is_nonzero.bitand(is_nonzero_square.not()); + + (first_root, second_root, error_flag) + } +} + impl Metrics>> for Field { type Case = Mode; @@ -96,7 +155,7 @@ mod tests { for _ in 0..ITERATIONS { // Sample a random element. let given: console::Field<::Network> = Uniform::rand(rng); - // Compute it's square root, or skip this iteration if it does not natively exist. + // Compute its square root, or skip this iteration if it does not natively exist. if let Ok(expected) = given.square_root() { let input = Field::::new(mode, given); @@ -123,7 +182,7 @@ mod tests { for _ in 0..ITERATIONS { // Sample a random element. let given: console::Field<::Network> = Uniform::rand(rng); - // Compute it's square root, or skip this iteration if it does not natively exist. + // Compute its square root, or skip this iteration if it does not natively exist. if let Ok(expected) = given.even_square_root() { let input = Field::::new(mode, given); @@ -137,6 +196,39 @@ mod tests { } } + fn check_square_roots_flagged_nondeterministic( + name: &str, + mode: Mode, + rng: &mut TestRng, + num_constants: u64, + num_public: u64, + num_private: u64, + num_constraints: u64, + ) { + for _ in 0..ITERATIONS { + // Sample a random element. + let given: console::Field<::Network> = Uniform::rand(rng); + // Compute square roots and error flag in console-land. + let (expected_error_flag, expected_positive_root, expected_negative_root) = match given.square_root() { + Ok(root) => (false, root, -root), + Err(_) => (true, console::Field::zero(), console::Field::zero()), + }; + // Compute square roots and error flag in circuit-land. + let input = Field::::new(mode, given); + Circuit::scope(name, || { + let (candidate_first_root, candidate_second_root, candidate_error_flag) = + input.square_roots_flagged_nondeterministic(); + // Although the order of the roots is unspecified in the circuit, + // the witness values are in a fixed order (first positive, then negative). + assert_eq!(expected_error_flag, candidate_error_flag.eject_value()); + assert_eq!(expected_positive_root, candidate_first_root.eject_value()); + assert_eq!(expected_negative_root, candidate_second_root.eject_value()); + assert_scope!(num_constants, num_public, num_private, num_constraints); + }); + Circuit::reset(); + } + } + #[test] fn test_square_root() { let mut rng = TestRng::default(); @@ -154,4 +246,13 @@ mod tests { check_even_square_root("Public", &mut rng, Mode::Public, 0, 0, 506, 509); check_even_square_root("Private", &mut rng, Mode::Private, 0, 0, 506, 509); } + + #[test] + fn test_square_roots_flagged_nondeterministic() { + let mut rng = TestRng::default(); + + check_square_roots_flagged_nondeterministic("Constant", Mode::Constant, &mut rng, 257, 0, 0, 0); + check_square_roots_flagged_nondeterministic("Public", Mode::Public, &mut rng, 254, 0, 344, 344); + check_square_roots_flagged_nondeterministic("Private", Mode::Private, &mut rng, 254, 0, 344, 344); + } } diff --git a/circuit/types/group/Cargo.toml b/circuit/types/group/Cargo.toml index 7138c5c1b9..c633da70d9 100644 --- a/circuit/types/group/Cargo.toml +++ b/circuit/types/group/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-circuit-types-group" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Group circuit for a decentralized virtual machine" license = "Apache-2.0" @@ -9,24 +9,24 @@ edition = "2021" [dependencies.console] package = "snarkvm-console-types-group" path = "../../../console/types/group" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-circuit-environment] path = "../../environment" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-boolean] path = "../boolean" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-field] path = "../field" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-scalar] path = "../scalar" -version = "=0.16.15" +version = "=0.16.19" [dev-dependencies.snarkvm-utilities] path = "../../../utilities" diff --git a/circuit/types/group/src/helpers/from_x_coordinate.rs b/circuit/types/group/src/helpers/from_x_coordinate.rs index acf87bf2f9..5dd2191060 100644 --- a/circuit/types/group/src/helpers/from_x_coordinate.rs +++ b/circuit/types/group/src/helpers/from_x_coordinate.rs @@ -26,6 +26,58 @@ impl Group { Self::from_xy_coordinates(x, y) } + + /// Initializes an affine group element from a given x-coordinate field element. + /// Additionally, returns an error flag. + /// If the error flag is set, there is **no** group element with the given x-coordinate. + /// If the error flag is set, the returned point is `(0, 0)`. + pub fn from_x_coordinate_flagged(x: Field) -> (Self, Boolean) { + // Obtain the A and D coefficients of the elliptic curve. + let a = Field::constant(console::Field::new(E::EDWARDS_A)); + let d = Field::constant(console::Field::new(E::EDWARDS_D)); + + // Compute x^2. + let xx = &x * &x; + + // Compute a * x^2 - 1. + let a_xx_minus_1 = a * &xx - Field::one(); + + // Compute d * x^2 - 1. + let d_xx_minus_1 = d * &xx - Field::one(); + + // Compute y^2 = (a * x^2 - 1) / (d * x^2 - 1), i.e. solve the curve equation for y^2. + let yy: Field = witness!(|a_xx_minus_1, d_xx_minus_1| { a_xx_minus_1 / d_xx_minus_1 }); + E::enforce(|| (&yy, &d_xx_minus_1, &a_xx_minus_1)); + + // Compute both square roots of y^2, with a flag indicating whether y^2 is a square or not. + // Note that there is **no** ordering on the square roots in the circuit computation. + // Note that if the x-coordinate line does not intersect the elliptic curve, this returns (0, 0, true). + let (y1, y2, yy_is_not_square) = yy.square_roots_flagged_nondeterministic(); + + // Construct the two points. + // Note that if `yy_is_not_square` is `false`, the points are guaranteed to be on the curve. + // Note that the two points are **not** necessarily in the subgroup. + let point1 = Self { x: x.clone(), y: y1.clone() }; + let point2 = Self { x: x.clone(), y: y2.clone() }; + + // Determine if either of the two points is in the subgroup. + // Note that at most **one** of the points can be in the subgroup. + let point1_is_in_group = point1.is_in_group(); + let point2_is_in_group = point2.is_in_group(); + + // Select y1 if (x, y1) is in the subgroup. + // Otherwise, select y2 if (x, y2) is in the subgroup. + // Otherwise, use the zero field element. + let y2_or_zero = Field::ternary(&point2_is_in_group, &y2, &Field::zero()); + let y1_or_y2_or_zero = Field::ternary(&point1_is_in_group, &y1, &y2_or_zero); + let y = Field::ternary(&yy_is_not_square, &Field::zero(), &y1_or_y2_or_zero); + + // The error flag is set iff x does not intersect the elliptic curve or neither intersection point is in the subgroup. + let neither_in_subgroup = point1_is_in_group.not().bitand(point2_is_in_group.not()); + let error_flag = yy_is_not_square.bitor(&neither_in_subgroup); + + (Self { x, y }, error_flag) + } } #[cfg(test)] @@ -60,6 +112,35 @@ mod tests { } } + fn check_from_x_coordinate_flagged( + mode: Mode, + num_constants: u64, + num_public: u64, + num_private: u64, + num_constraints: u64, + ) { + let mut rng = TestRng::default(); + + for i in 0..ITERATIONS { + // Sample a random x coordinate. + let x: console::Field<::Network> = Uniform::rand(&mut rng); + // Compute error flag and point in console-land. + let (expected_error_flag, expected_point) = match console::Group::from_x_coordinate(x) { + Ok(point) => (false, point), + Err(_) => (true, console::Group::from_xy_coordinates_unchecked(x, console::Field::zero())), + }; + // Compute error flag and point in circuit-land. + let input = Field::::new(mode, x); + Circuit::scope(format!("{mode} {i}"), || { + let (candidate_point, candidate_error_flag) = Group::from_x_coordinate_flagged(input); + assert_eq!(expected_error_flag, candidate_error_flag.eject_value()); + assert_eq!(expected_point, candidate_point.eject_value()); + assert_scope!(num_constants, num_public, num_private, num_constraints); + }); + Circuit::reset(); + } + } + #[test] fn test_from_x_coordinate_constant() { check_from_x_coordinate(Mode::Constant, 9, 0, 0, 0); @@ -74,4 +155,19 @@ mod tests { fn test_from_x_coordinate_private() { check_from_x_coordinate(Mode::Private, 4, 0, 13, 13); } + + #[test] + fn test_from_x_coordinate_flagged_constant() { + check_from_x_coordinate_flagged(Mode::Constant, 3764, 0, 0, 0); + } + + #[test] + fn test_from_x_coordinate_flagged_public() { + check_from_x_coordinate_flagged(Mode::Public, 1756, 0, 5861, 5861); + } + + #[test] + fn test_from_x_coordinate_flagged_private() { + check_from_x_coordinate_flagged(Mode::Private, 1756, 0, 5861, 5861); + } } diff --git a/circuit/types/group/src/lib.rs b/circuit/types/group/src/lib.rs index 36d1f7f821..a0f636b435 100644 --- a/circuit/types/group/src/lib.rs +++ b/circuit/types/group/src/lib.rs @@ -129,6 +129,22 @@ impl Group { // i.e. that it is 4 (= cofactor) times the postulated point on the curve. double_point.enforce_double(self); } + + /// Returns a `Boolean` indicating if `self` is in the largest prime-order subgroup, + /// assuming that `self` is on the curve. + pub fn is_in_group(&self) -> Boolean { + // Initialize the order of the subgroup as a bits. + let order = E::ScalarField::modulus(); + let order_bits_be = order.to_bits_be(); + let mut order_bits_be_constants = Vec::with_capacity(order_bits_be.len()); + for bit in order_bits_be.iter() { + order_bits_be_constants.push(Boolean::constant(*bit)); + } + // Multiply `self` by the order of the subgroup. + let self_times_order = order_bits_be_constants.mul(self); + // Check if the result is zero. + self_times_order.is_zero() + } } #[cfg(console)] @@ -382,4 +398,82 @@ mod tests { } } } + + #[test] + fn test_is_in_group() { + type PrimitiveField = console::Field<::Network>; + + // First test the points that have low order. + + // The two halves of (0,1) in group arithmetic are (0,1) and (0,-1). + let minus1_string = "8444461749428370424248824938781546531375899335154063827935233455917409239040field"; + // The two halves of (0,-1) in group arithmetic are (q1x,0) and (q2x,0), + // where q1x = sqrt(-1) mod F_q and q2x = -sqrt(-1) mod F_q. + let q1x_string = "880904806456922042258150504921383618666682042621506879489field"; + let q2x_string = "8444461749428370423367920132324624489117748830232680209268551413295902359552field"; + + // (0,1) is in the large prime subgroup. + let y1: Field = Field::new(Mode::Public, PrimitiveField::from_str("1field").unwrap()); + let group0 = Group::::from_xy_coordinates_unchecked(Field::zero(), y1); + Circuit::scope("group0", || { + let group0_is_in_group = group0.is_in_group(); + assert!(group0_is_in_group.eject_value()); + assert_scope!(750, 0, 2253, 2253); + }); + Circuit::reset(); + + // The other three low order points are on the curve but not in the large prime subgroup. + // Make sure is_in_group returns false for these. + let minus1: Field = Field::new(Mode::Public, PrimitiveField::from_str(minus1_string).unwrap()); + let half0 = Group::::from_xy_coordinates_unchecked(Field::zero(), minus1); + Circuit::scope("half0", || { + let half0_is_not_in_group = !half0.is_in_group(); + assert!(half0_is_not_in_group.eject_value()); + assert_scope!(750, 0, 2253, 2253); + }); + Circuit::reset(); + + let q1x: Field = Field::new(Mode::Public, PrimitiveField::from_str(q1x_string).unwrap()); + let quarter1 = Group::::from_xy_coordinates_unchecked(q1x, Field::zero()); + Circuit::scope("quarter1", || { + let quarter1_is_not_in_group = !quarter1.is_in_group(); + assert!(quarter1_is_not_in_group.eject_value()); + assert_scope!(750, 0, 2253, 2253); + }); + Circuit::reset(); + + let q2x: Field = Field::new(Mode::Public, PrimitiveField::from_str(q2x_string).unwrap()); + let quarter2 = Group::::from_xy_coordinates_unchecked(q2x, Field::zero()); + Circuit::scope("quarter2", || { + let quarter2_is_not_in_group = !quarter2.is_in_group(); + assert!(quarter2_is_not_in_group.eject_value()); + assert_scope!(750, 0, 2253, 2253); + }); + Circuit::reset(); + + fn check_is_in_group(mode: Mode, num_constants: u64, num_public: u64, num_private: u64, num_constraints: u64) { + let mut rng = TestRng::default(); + + for i in 0..ITERATIONS { + // Sample a random element. + let point: console::Group<::Network> = Uniform::rand(&mut rng); + + // Inject the x-coordinate. + let x_coordinate = Field::new(mode, point.to_x_coordinate()); + + // Initialize the group element. + let element = Group::::from_x_coordinate(x_coordinate); + + Circuit::scope(format!("{mode} {i}"), || { + let is_in_group = element.is_in_group(); + assert!(is_in_group.eject_value()); + assert_scope!(num_constants, num_public, num_private, num_constraints); + }); + Circuit::reset(); + } + } + check_is_in_group(Mode::Constant, 1752, 0, 0, 0); + check_is_in_group(Mode::Public, 750, 0, 2755, 2755); + check_is_in_group(Mode::Private, 750, 0, 2755, 2755); + } } diff --git a/circuit/types/integers/Cargo.toml b/circuit/types/integers/Cargo.toml index de9557a845..5903640f3f 100644 --- a/circuit/types/integers/Cargo.toml +++ b/circuit/types/integers/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-circuit-types-integers" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Integer circuit for a decentralized virtual machine" license = "Apache-2.0" @@ -9,24 +9,24 @@ edition = "2021" [dependencies.console] package = "snarkvm-console-types-integers" path = "../../../console/types/integers" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-circuit-environment] path = "../../environment" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-boolean] path = "../boolean" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-field] path = "../field" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-scalar] path = "../scalar" -version = "=0.16.15" +version = "=0.16.19" [dev-dependencies.snarkvm-utilities] path = "../../../utilities" diff --git a/circuit/types/integers/src/helpers/from_bits.rs b/circuit/types/integers/src/helpers/from_bits.rs index ffcdb0ff89..8919575dd8 100644 --- a/circuit/types/integers/src/helpers/from_bits.rs +++ b/circuit/types/integers/src/helpers/from_bits.rs @@ -74,7 +74,7 @@ mod tests { }); // Add excess zero bits. - let candidate = vec![given_bits, vec![Boolean::new(mode, false); i as usize]].concat(); + let candidate = [given_bits, vec![Boolean::new(mode, false); i as usize]].concat(); Circuit::scope(&format!("Excess {mode} {i}"), || { let candidate = Integer::::from_bits_le(&candidate); @@ -114,7 +114,7 @@ mod tests { }); // Add excess zero bits. - let candidate = vec![vec![Boolean::new(mode, false); i as usize], given_bits].concat(); + let candidate = [vec![Boolean::new(mode, false); i as usize], given_bits].concat(); Circuit::scope(&format!("Excess {mode} {i}"), || { let candidate = Integer::::from_bits_be(&candidate); diff --git a/circuit/types/scalar/Cargo.toml b/circuit/types/scalar/Cargo.toml index a9e64ddb22..99e813f11b 100644 --- a/circuit/types/scalar/Cargo.toml +++ b/circuit/types/scalar/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-circuit-types-scalar" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Scalar circuit for a decentralized virtual machine" license = "Apache-2.0" @@ -9,20 +9,20 @@ edition = "2021" [dependencies.console] package = "snarkvm-console-types-scalar" path = "../../../console/types/scalar" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-circuit-environment] path = "../../environment" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-boolean] path = "../boolean" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-field] path = "../field" -version = "=0.16.15" +version = "=0.16.19" [features] default = [ "enable_console" ] diff --git a/circuit/types/scalar/src/helpers/from_bits.rs b/circuit/types/scalar/src/helpers/from_bits.rs index 2b0522c70b..2422607938 100644 --- a/circuit/types/scalar/src/helpers/from_bits.rs +++ b/circuit/types/scalar/src/helpers/from_bits.rs @@ -116,7 +116,7 @@ mod tests { }); // Add excess zero bits. - let candidate = vec![given_bits, vec![Boolean::new(mode, false); i as usize]].concat(); + let candidate = [given_bits, vec![Boolean::new(mode, false); i as usize]].concat(); Circuit::scope(&format!("Excess {mode} {i}"), || { let candidate = Scalar::::from_bits_le(&candidate); @@ -157,7 +157,7 @@ mod tests { }); // Add excess zero bits. - let candidate = vec![vec![Boolean::new(mode, false); i as usize], given_bits].concat(); + let candidate = [vec![Boolean::new(mode, false); i as usize], given_bits].concat(); Circuit::scope(&format!("Excess {mode} {i}"), || { let candidate = Scalar::::from_bits_be(&candidate); diff --git a/circuit/types/string/Cargo.toml b/circuit/types/string/Cargo.toml index 1cebb5b626..716f2593c2 100644 --- a/circuit/types/string/Cargo.toml +++ b/circuit/types/string/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-circuit-types-string" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "String circuit for a decentralized virtual machine" license = "Apache-2.0" @@ -9,24 +9,24 @@ edition = "2021" [dependencies.console] package = "snarkvm-console-types-string" path = "../../../console/types/string" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-circuit-environment] path = "../../environment" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-boolean] path = "../boolean" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-field] path = "../field" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-circuit-types-integers] path = "../integers" -version = "=0.16.15" +version = "=0.16.19" [dev-dependencies.snarkvm-utilities] path = "../../../utilities" diff --git a/console/Cargo.toml b/console/Cargo.toml index a33a64fb29..f3f029f135 100644 --- a/console/Cargo.toml +++ b/console/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-console" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Console environment for a decentralized virtual machine" license = "Apache-2.0" @@ -8,32 +8,32 @@ edition = "2021" [dependencies.snarkvm-console-account] path = "./account" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-console-algorithms] path = "./algorithms" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-console-collections] path = "./collections" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-console-network] path = "./network" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-console-program] path = "./program" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-console-types] path = "./types" -version = "=0.16.15" +version = "=0.16.19" optional = true [features] diff --git a/console/account/Cargo.toml b/console/account/Cargo.toml index bb41a00122..568551104a 100644 --- a/console/account/Cargo.toml +++ b/console/account/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-console-account" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Account operations for a decentralized virtual machine" license = "Apache-2.0" @@ -13,11 +13,11 @@ harness = false [dependencies.snarkvm-console-network] path = "../network" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-types] path = "../types" -version = "=0.16.15" +version = "=0.16.19" default-features = false features = [ "address", "boolean", "field", "group", "scalar" ] diff --git a/console/account/benches/account.rs b/console/account/benches/account.rs index 5f3df699c1..ce8b6d7500 100644 --- a/console/account/benches/account.rs +++ b/console/account/benches/account.rs @@ -16,11 +16,11 @@ extern crate criterion; use snarkvm_console_account::{Address, PrivateKey, ViewKey}; -use snarkvm_console_network::{environment::prelude::*, Testnet3}; +use snarkvm_console_network::{environment::prelude::*, MainnetV0}; use criterion::Criterion; -type CurrentNetwork = Testnet3; +type CurrentNetwork = MainnetV0; fn account_private_key(c: &mut Criterion) { let rng = &mut TestRng::default(); diff --git a/console/account/src/address/try_from.rs b/console/account/src/address/try_from.rs index 299e09b72e..6080a5009e 100644 --- a/console/account/src/address/try_from.rs +++ b/console/account/src/address/try_from.rs @@ -77,9 +77,9 @@ impl TryFrom<&ViewKey> for Address { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1_000; diff --git a/console/account/src/compute_key/bytes.rs b/console/account/src/compute_key/bytes.rs index 1e064c8951..cd0e64edec 100644 --- a/console/account/src/compute_key/bytes.rs +++ b/console/account/src/compute_key/bytes.rs @@ -37,9 +37,9 @@ impl ToBytes for ComputeKey { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1000; diff --git a/console/account/src/compute_key/from_bits.rs b/console/account/src/compute_key/from_bits.rs index b26d7e0ddb..923689ddc3 100644 --- a/console/account/src/compute_key/from_bits.rs +++ b/console/account/src/compute_key/from_bits.rs @@ -53,9 +53,9 @@ impl FromBits for ComputeKey { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: usize = 100; @@ -73,7 +73,7 @@ mod tests { assert_eq!(expected, candidate); // Add excess zero bits. - let candidate = vec![given_bits, vec![false; i]].concat(); + let candidate = [given_bits, vec![false; i]].concat(); let candidate = ComputeKey::::from_bits_le(&candidate)?; assert_eq!(expected, candidate); @@ -96,7 +96,7 @@ mod tests { assert_eq!(expected, candidate); // Add excess zero bits. - let candidate = vec![given_bits, vec![false; i]].concat(); + let candidate = [given_bits, vec![false; i]].concat(); let candidate = ComputeKey::::from_bits_be(&candidate)?; assert_eq!(expected, candidate); diff --git a/console/account/src/compute_key/serialize.rs b/console/account/src/compute_key/serialize.rs index 78f809bdb0..9089c77a9d 100644 --- a/console/account/src/compute_key/serialize.rs +++ b/console/account/src/compute_key/serialize.rs @@ -35,9 +35,9 @@ impl<'de, N: Network> Deserialize<'de> for ComputeKey { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1000; diff --git a/console/account/src/compute_key/to_address.rs b/console/account/src/compute_key/to_address.rs index 3dc6eae1af..fc18b59910 100644 --- a/console/account/src/compute_key/to_address.rs +++ b/console/account/src/compute_key/to_address.rs @@ -27,9 +27,9 @@ impl ComputeKey { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1000; diff --git a/console/account/src/compute_key/to_bits.rs b/console/account/src/compute_key/to_bits.rs index 2a742b1c9e..78536394d4 100644 --- a/console/account/src/compute_key/to_bits.rs +++ b/console/account/src/compute_key/to_bits.rs @@ -35,9 +35,9 @@ impl ToBits for ComputeKey { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1_000; diff --git a/console/account/src/compute_key/try_from.rs b/console/account/src/compute_key/try_from.rs index e652ca8323..591452f87e 100644 --- a/console/account/src/compute_key/try_from.rs +++ b/console/account/src/compute_key/try_from.rs @@ -63,9 +63,9 @@ impl TryFrom<&(Group, Group)> for ComputeKey { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1000; diff --git a/console/account/src/graph_key/bytes.rs b/console/account/src/graph_key/bytes.rs index a6b3efb71c..8637453dea 100644 --- a/console/account/src/graph_key/bytes.rs +++ b/console/account/src/graph_key/bytes.rs @@ -34,9 +34,9 @@ impl ToBytes for GraphKey { mod tests { use super::*; use crate::PrivateKey; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1000; diff --git a/console/account/src/graph_key/serialize.rs b/console/account/src/graph_key/serialize.rs index 74739f8dbb..9592af6f03 100644 --- a/console/account/src/graph_key/serialize.rs +++ b/console/account/src/graph_key/serialize.rs @@ -32,9 +32,9 @@ impl<'de, N: Network> Deserialize<'de> for GraphKey { mod tests { use super::*; use crate::PrivateKey; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1000; diff --git a/console/account/src/graph_key/string.rs b/console/account/src/graph_key/string.rs index 5378a28d13..57198c01e6 100644 --- a/console/account/src/graph_key/string.rs +++ b/console/account/src/graph_key/string.rs @@ -49,9 +49,9 @@ impl fmt::Display for GraphKey { mod tests { use super::*; use crate::PrivateKey; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 10_000; diff --git a/console/account/src/graph_key/try_from.rs b/console/account/src/graph_key/try_from.rs index 61a124f5c9..13d95c65be 100644 --- a/console/account/src/graph_key/try_from.rs +++ b/console/account/src/graph_key/try_from.rs @@ -60,9 +60,9 @@ impl TryFrom<&Field> for GraphKey { mod tests { use super::*; use crate::PrivateKey; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1000; diff --git a/console/account/src/lib.rs b/console/account/src/lib.rs index 77e5874bbf..c06cea96e5 100644 --- a/console/account/src/lib.rs +++ b/console/account/src/lib.rs @@ -49,9 +49,9 @@ pub use view_key::*; #[cfg(test)] mod tests { use crate::{Address, ComputeKey, PrivateKey, Signature, ViewKey}; - use snarkvm_console_network::{prelude::*, Testnet3}; + use snarkvm_console_network::{prelude::*, MainnetV0}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ALEO_PRIVATE_KEY: &str = "APrivateKey1zkp8cC4jgHEBnbtu3xxs1Ndja2EMizcvTRDq5Nikdkukg1p"; const ALEO_VIEW_KEY: &str = "AViewKey1n1n3ZbnVEtXVe3La2xWkUvY3EY7XaCG6RZJJ3tbvrrrD"; diff --git a/console/account/src/private_key/bytes.rs b/console/account/src/private_key/bytes.rs index 291720c277..14fe867ef9 100644 --- a/console/account/src/private_key/bytes.rs +++ b/console/account/src/private_key/bytes.rs @@ -31,9 +31,9 @@ impl ToBytes for PrivateKey { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1000; diff --git a/console/account/src/private_key/serialize.rs b/console/account/src/private_key/serialize.rs index 3aeda9f436..44fdf3611f 100644 --- a/console/account/src/private_key/serialize.rs +++ b/console/account/src/private_key/serialize.rs @@ -41,9 +41,9 @@ impl<'de, N: Network> Deserialize<'de> for PrivateKey { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1000; diff --git a/console/account/src/private_key/sign.rs b/console/account/src/private_key/sign.rs index c330e50b23..3ced01a359 100644 --- a/console/account/src/private_key/sign.rs +++ b/console/account/src/private_key/sign.rs @@ -36,9 +36,9 @@ impl PrivateKey { mod tests { use super::*; use crate::Address; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 100; diff --git a/console/account/src/private_key/string.rs b/console/account/src/private_key/string.rs index 766178a079..f9a9705152 100644 --- a/console/account/src/private_key/string.rs +++ b/console/account/src/private_key/string.rs @@ -48,9 +48,9 @@ impl fmt::Display for PrivateKey { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1000; diff --git a/console/account/src/signature/bytes.rs b/console/account/src/signature/bytes.rs index bb7da60881..9f3714a7d6 100644 --- a/console/account/src/signature/bytes.rs +++ b/console/account/src/signature/bytes.rs @@ -38,9 +38,9 @@ impl ToBytes for Signature { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 100; diff --git a/console/account/src/signature/from_bits.rs b/console/account/src/signature/from_bits.rs index 95c30b02be..83eebac6ae 100644 --- a/console/account/src/signature/from_bits.rs +++ b/console/account/src/signature/from_bits.rs @@ -71,9 +71,9 @@ impl FromBits for Signature { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: usize = 100; @@ -91,7 +91,7 @@ mod tests { assert_eq!(expected, candidate); // Add excess zero bits. - let candidate = vec![given_bits, vec![false; i]].concat(); + let candidate = [given_bits, vec![false; i]].concat(); let candidate = Signature::::from_bits_le(&candidate)?; assert_eq!(expected, candidate); @@ -114,7 +114,7 @@ mod tests { assert_eq!(expected, candidate); // Add excess zero bits. - let candidate = vec![given_bits, vec![false; i]].concat(); + let candidate = [given_bits, vec![false; i]].concat(); let candidate = Signature::::from_bits_be(&candidate)?; assert_eq!(expected, candidate); diff --git a/console/account/src/signature/mod.rs b/console/account/src/signature/mod.rs index 1225af3b38..efa92938a6 100644 --- a/console/account/src/signature/mod.rs +++ b/console/account/src/signature/mod.rs @@ -114,9 +114,9 @@ impl Signature { #[cfg(test)] mod test_helpers { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Samples a random signature. pub(super) fn sample_signature(num_fields: u64, rng: &mut TestRng) -> Signature { diff --git a/console/account/src/signature/parse.rs b/console/account/src/signature/parse.rs index 78b69e7771..161054709c 100644 --- a/console/account/src/signature/parse.rs +++ b/console/account/src/signature/parse.rs @@ -74,9 +74,9 @@ impl Display for Signature { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1_000; diff --git a/console/account/src/signature/to_bits.rs b/console/account/src/signature/to_bits.rs index 0c4512c516..d7da5ab2ca 100644 --- a/console/account/src/signature/to_bits.rs +++ b/console/account/src/signature/to_bits.rs @@ -39,9 +39,9 @@ impl ToBits for Signature { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1_000; diff --git a/console/account/src/signature/verify.rs b/console/account/src/signature/verify.rs index c0b97bb2e4..65247213ab 100644 --- a/console/account/src/signature/verify.rs +++ b/console/account/src/signature/verify.rs @@ -80,9 +80,9 @@ impl Signature { #[cfg(feature = "private_key")] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 100; diff --git a/console/account/src/view_key/bytes.rs b/console/account/src/view_key/bytes.rs index 9592de8231..61631562d6 100644 --- a/console/account/src/view_key/bytes.rs +++ b/console/account/src/view_key/bytes.rs @@ -31,9 +31,9 @@ impl ToBytes for ViewKey { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1000; diff --git a/console/account/src/view_key/mod.rs b/console/account/src/view_key/mod.rs index ed7421d101..28a02c5d1a 100644 --- a/console/account/src/view_key/mod.rs +++ b/console/account/src/view_key/mod.rs @@ -51,9 +51,9 @@ impl Deref for ViewKey { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1000; diff --git a/console/account/src/view_key/serialize.rs b/console/account/src/view_key/serialize.rs index 03a6f28078..a49ebf3fea 100644 --- a/console/account/src/view_key/serialize.rs +++ b/console/account/src/view_key/serialize.rs @@ -41,9 +41,9 @@ impl<'de, N: Network> Deserialize<'de> for ViewKey { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1000; diff --git a/console/account/src/view_key/string.rs b/console/account/src/view_key/string.rs index cf7c93a56a..a341c0067d 100644 --- a/console/account/src/view_key/string.rs +++ b/console/account/src/view_key/string.rs @@ -48,9 +48,9 @@ impl fmt::Display for ViewKey { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1000; diff --git a/console/account/src/view_key/to_address.rs b/console/account/src/view_key/to_address.rs index 892064946c..055a040c84 100644 --- a/console/account/src/view_key/to_address.rs +++ b/console/account/src/view_key/to_address.rs @@ -24,9 +24,9 @@ impl ViewKey { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1000; diff --git a/console/account/src/view_key/try_from.rs b/console/account/src/view_key/try_from.rs index 6f11378a93..df148f0c66 100644 --- a/console/account/src/view_key/try_from.rs +++ b/console/account/src/view_key/try_from.rs @@ -51,9 +51,9 @@ impl TryFrom<(&PrivateKey, &ComputeKey)> for ViewKey { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1000; diff --git a/console/algorithms/Cargo.toml b/console/algorithms/Cargo.toml index 99291b7d20..575d0c8173 100644 --- a/console/algorithms/Cargo.toml +++ b/console/algorithms/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-console-algorithms" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Console algorithms for a decentralized virtual machine" license = "Apache-2.0" @@ -23,18 +23,18 @@ harness = false [dependencies.snarkvm-console-types] path = "../types" -version = "=0.16.15" +version = "=0.16.19" default-features = false features = [ "field", "group", "integers", "scalar" ] [dependencies.snarkvm-fields] path = "../../fields" -version = "=0.16.15" +version = "=0.16.19" default-features = false [dependencies.snarkvm-utilities] path = "../../utilities" -version = "=0.16.15" +version = "=0.16.19" [dependencies.blake2s_simd] version = "1.0" diff --git a/console/algorithms/src/poseidon/hash_many.rs b/console/algorithms/src/poseidon/hash_many.rs index d87a793348..fa789d900e 100644 --- a/console/algorithms/src/poseidon/hash_many.rs +++ b/console/algorithms/src/poseidon/hash_many.rs @@ -31,6 +31,6 @@ impl HashMany for Poseidon { let mut sponge = PoseidonSponge::::new(&self.parameters); sponge.absorb(&preimage); - sponge.squeeze(num_outputs).to_vec() + sponge.squeeze(num_outputs).into_vec() } } diff --git a/console/collections/Cargo.toml b/console/collections/Cargo.toml index 2566972c39..c853649f27 100644 --- a/console/collections/Cargo.toml +++ b/console/collections/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-console-collections" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Collections for a decentralized virtual machine" license = "Apache-2.0" @@ -18,16 +18,16 @@ harness = false [dependencies.snarkvm-console-algorithms] path = "../algorithms" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-types] path = "../types" -version = "=0.16.15" +version = "=0.16.19" default-features = false features = [ "field", "integers" ] [dependencies.aleo-std] -version = "0.1.18" +version = "0.1.24" default-features = false [dependencies.rayon] diff --git a/console/collections/benches/kary_merkle_tree.rs b/console/collections/benches/kary_merkle_tree.rs index f3610a0681..0ce72772c8 100644 --- a/console/collections/benches/kary_merkle_tree.rs +++ b/console/collections/benches/kary_merkle_tree.rs @@ -19,7 +19,7 @@ use snarkvm_console_algorithms::Sha3_256; use snarkvm_console_collections::kary_merkle_tree::KaryMerkleTree; use snarkvm_console_network::{ prelude::{TestRng, ToBits, Uniform}, - Testnet3, + MainnetV0, }; use snarkvm_console_types::Field; @@ -30,7 +30,7 @@ const ARITY: u8 = 8; /// Generates the specified number of random Merkle tree leaves. macro_rules! generate_leaves { - ($num_leaves:expr, $rng:expr) => {{ (0..$num_leaves).map(|_| Field::::rand($rng).to_bits_le()).collect::>() }}; + ($num_leaves:expr, $rng:expr) => {{ (0..$num_leaves).map(|_| Field::::rand($rng).to_bits_le()).collect::>() }}; } fn new(c: &mut Criterion) { diff --git a/console/collections/benches/merkle_tree.rs b/console/collections/benches/merkle_tree.rs index 01baa7fdbc..ec15aee461 100644 --- a/console/collections/benches/merkle_tree.rs +++ b/console/collections/benches/merkle_tree.rs @@ -17,8 +17,8 @@ extern crate criterion; use snarkvm_console_network::{ prelude::{TestRng, ToBits, Uniform}, + MainnetV0, Network, - Testnet3, }; use snarkvm_console_types::Field; @@ -34,7 +34,7 @@ const UPDATE_SIZES: &[usize] = &[1, 10, 100, 1_000, 10_000]; /// Generates the specified number of random Merkle tree leaves. macro_rules! generate_leaves { - ($num_leaves:expr, $rng:expr) => {{ (0..$num_leaves).map(|_| Field::::rand($rng).to_bits_le()).collect::>() }}; + ($num_leaves:expr, $rng:expr) => {{ (0..$num_leaves).map(|_| Field::::rand($rng).to_bits_le()).collect::>() }}; } fn new(c: &mut Criterion) { @@ -45,7 +45,7 @@ fn new(c: &mut Criterion) { // Benchmark the creation of a Merkle tree with the specified number of leaves. c.bench_function(&format!("MerkleTree/new/{num_leaves}"), |b| { b.iter(|| { - let _tree = Testnet3::merkle_tree_bhp::(&leaves[0..*num_leaves]).unwrap(); + let _tree = MainnetV0::merkle_tree_bhp::(&leaves[0..*num_leaves]).unwrap(); }) }); } @@ -61,7 +61,7 @@ fn append(c: &mut Criterion) { for num_leaves in NUM_LEAVES { for num_new_leaves in APPEND_SIZES { // Construct a Merkle tree with the specified number of leaves. - let merkle_tree = Testnet3::merkle_tree_bhp::(&leaves[..*num_leaves]).unwrap(); + let merkle_tree = MainnetV0::merkle_tree_bhp::(&leaves[..*num_leaves]).unwrap(); c.bench_function(&format!("MerkleTree/append/{num_leaves}/{num_new_leaves}"), |b| { b.iter_batched( || merkle_tree.clone(), @@ -93,7 +93,7 @@ fn update(c: &mut Criterion) { for num_new_leaves in UPDATE_SIZES { // Construct a Merkle tree with the specified number of leaves. - let merkle_tree = Testnet3::merkle_tree_bhp::(&leaves[..*num_leaves]).unwrap(); + let merkle_tree = MainnetV0::merkle_tree_bhp::(&leaves[..*num_leaves]).unwrap(); c.bench_function(&format!("MerkleTree/update/{num_leaves}/{num_new_leaves}"), |b| { b.iter_batched( @@ -131,7 +131,7 @@ fn update_many(c: &mut Criterion) { for num_new_leaves in UPDATE_SIZES { // Construct a Merkle tree with the specified number of leaves. - let merkle_tree = Testnet3::merkle_tree_bhp::(&leaves[..*num_leaves]).unwrap(); + let merkle_tree = MainnetV0::merkle_tree_bhp::(&leaves[..*num_leaves]).unwrap(); let num_new_leaves = std::cmp::min(*num_new_leaves, updates.len()); let updates = BTreeMap::from_iter(updates[..num_new_leaves].iter().cloned()); c.bench_function(&format!("MerkleTree/update_many/{num_leaves}/{num_new_leaves}",), |b| { @@ -157,7 +157,7 @@ fn update_vs_update_many(c: &mut Criterion) { // Compute the number of leaves at this depth. let num_leaves = 2usize.saturating_pow(depth as u32); // Construct a Merkle tree with the specified number of leaves. - let tree = Testnet3::merkle_tree_bhp::(&leaves[..num_leaves]).unwrap(); + let tree = MainnetV0::merkle_tree_bhp::(&leaves[..num_leaves]).unwrap(); // Generate a new leaf and select a random index to update. let index: usize = Uniform::rand(&mut rng); let index = index % num_leaves; diff --git a/console/network/Cargo.toml b/console/network/Cargo.toml index c86f68cca3..5ea82ad718 100644 --- a/console/network/Cargo.toml +++ b/console/network/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-console-network" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Network console library for a decentralized virtual machine" license = "Apache-2.0" @@ -15,45 +15,45 @@ wasm = [ [dependencies.snarkvm-algorithms] path = "../../algorithms" -version = "=0.16.15" +version = "=0.16.19" default-features = false features = [ "snark" ] [dependencies.snarkvm-console-algorithms] path = "../algorithms" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-collections] path = "../collections" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-network-environment] path = "./environment" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-types] path = "../types" -version = "=0.16.15" +version = "=0.16.19" default-features = false features = [ "field", "group", "scalar" ] [dependencies.snarkvm-curves] path = "../../curves" -version = "=0.16.15" +version = "=0.16.19" default-features = false [dependencies.snarkvm-fields] path = "../../fields" -version = "=0.16.15" +version = "=0.16.19" default-features = false [dependencies.snarkvm-parameters] path = "../../parameters" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-utilities] path = "../../utilities" -version = "=0.16.15" +version = "=0.16.19" [dependencies.anyhow] version = "1.0.73" diff --git a/console/network/environment/Cargo.toml b/console/network/environment/Cargo.toml index 279581b885..63b459700f 100644 --- a/console/network/environment/Cargo.toml +++ b/console/network/environment/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-console-network-environment" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Environment console library for a decentralized virtual machine" license = "Apache-2.0" @@ -8,17 +8,17 @@ edition = "2021" [dependencies.snarkvm-curves] path = "../../../curves" -version = "=0.16.15" +version = "=0.16.19" default-features = false [dependencies.snarkvm-fields] path = "../../../fields" -version = "=0.16.15" +version = "=0.16.19" default-features = false [dependencies.snarkvm-utilities] path = "../../../utilities" -version = "=0.16.15" +version = "=0.16.19" [dependencies.anyhow] version = "1.0.73" diff --git a/console/network/environment/src/lib.rs b/console/network/environment/src/lib.rs index bfd495d509..c7c54316ac 100644 --- a/console/network/environment/src/lib.rs +++ b/console/network/environment/src/lib.rs @@ -25,7 +25,37 @@ pub mod traits; pub use traits::*; pub mod prelude { - pub use crate::{environment::*, helpers::*, traits::*}; + pub use crate::{ + environment::*, + helpers::*, + traits::{ + algorithms::*, + arithmetic::*, + bitwise::*, + from_bits::*, + from_field::*, + parse::*, + parse_string::*, + to_bits_le, + to_field::*, + type_name::*, + types::{ + integer_magnitude::Magnitude, + integer_type::{ + CheckedPow, + CheckedShl, + IntegerProperties, + IntegerType, + WrappingDiv, + WrappingPow, + WrappingRem, + }, + *, + }, + visibility::*, + ToBits, + }, + }; pub use snarkvm_curves::{AffineCurve, MontgomeryParameters, ProjectiveCurve, TwistedEdwardsParameters}; pub use snarkvm_fields::{Field as _, PrimeField as _, SquareRootField as _, Zero as _}; diff --git a/console/network/environment/src/traits/mod.rs b/console/network/environment/src/traits/mod.rs index 7e03615c0d..aaeb41611f 100644 --- a/console/network/environment/src/traits/mod.rs +++ b/console/network/environment/src/traits/mod.rs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +pub use snarkvm_utilities::{to_bits_le, ToBits}; + pub mod algorithms; pub use algorithms::*; @@ -33,8 +35,6 @@ pub use parse::*; pub mod parse_string; pub use parse_string::string_parser; -pub use snarkvm_utilities::{to_bits_le, ToBits}; - pub mod to_field; pub use to_field::*; diff --git a/console/network/src/lib.rs b/console/network/src/lib.rs index 717946cba2..aa03a7cdfd 100644 --- a/console/network/src/lib.rs +++ b/console/network/src/lib.rs @@ -25,8 +25,8 @@ pub use snarkvm_console_network_environment::*; mod helpers; pub use helpers::*; -mod testnet3; -pub use testnet3::*; +mod mainnet_v0; +pub use mainnet_v0::*; pub mod prelude { pub use crate::{environment::prelude::*, Network}; @@ -98,6 +98,10 @@ pub trait Network: const STARTING_SUPPLY: u64 = 1_500_000_000_000_000; // 1.5B credits /// The cost in microcredits per byte for the deployment transaction. const DEPLOYMENT_FEE_MULTIPLIER: u64 = 1_000; // 1 millicredit per byte + /// The cost in microcredits per constraint for the deployment transaction. + const SYNTHESIS_FEE_MULTIPLIER: u64 = 25; // 25 microcredits per constraint + /// The maximum number of constraints in a deployment. + const MAX_DEPLOYMENT_LIMIT: u64 = 1 << 20; // 1,048,576 constraints /// The maximum number of microcredits that can be spent as a fee. const MAX_FEE: u64 = 1_000_000_000_000_000; diff --git a/console/network/src/testnet3.rs b/console/network/src/mainnet_v0.rs similarity index 89% rename from console/network/src/testnet3.rs rename to console/network/src/mainnet_v0.rs index e4f47594ca..edada2f3a0 100644 --- a/console/network/src/testnet3.rs +++ b/console/network/src/mainnet_v0.rs @@ -34,38 +34,38 @@ use snarkvm_console_algorithms::{ lazy_static! { /// The group bases for the Aleo signature and encryption schemes. - pub static ref GENERATOR_G: Vec> = Testnet3::new_bases("AleoAccountEncryptionAndSignatureScheme0"); + pub static ref GENERATOR_G: Vec> = MainnetV0::new_bases("AleoAccountEncryptionAndSignatureScheme0"); /// The Varuna sponge parameters. - pub static ref VARUNA_FS_PARAMETERS: FiatShamirParameters = FiatShamir::::sample_parameters(); + pub static ref VARUNA_FS_PARAMETERS: FiatShamirParameters = FiatShamir::::sample_parameters(); /// The encryption domain as a constant field element. - pub static ref ENCRYPTION_DOMAIN: Field = Field::::new_domain_separator("AleoSymmetricEncryption0"); + pub static ref ENCRYPTION_DOMAIN: Field = Field::::new_domain_separator("AleoSymmetricEncryption0"); /// The graph key domain as a constant field element. - pub static ref GRAPH_KEY_DOMAIN: Field = Field::::new_domain_separator("AleoGraphKey0"); + pub static ref GRAPH_KEY_DOMAIN: Field = Field::::new_domain_separator("AleoGraphKey0"); /// The serial number domain as a constant field element. - pub static ref SERIAL_NUMBER_DOMAIN: Field = Field::::new_domain_separator("AleoSerialNumber0"); + pub static ref SERIAL_NUMBER_DOMAIN: Field = Field::::new_domain_separator("AleoSerialNumber0"); /// The BHP hash function, which can take an input of up to 256 bits. - pub static ref BHP_256: BHP256 = BHP256::::setup("AleoBHP256").expect("Failed to setup BHP256"); + pub static ref BHP_256: BHP256 = BHP256::::setup("AleoBHP256").expect("Failed to setup BHP256"); /// The BHP hash function, which can take an input of up to 512 bits. - pub static ref BHP_512: BHP512 = BHP512::::setup("AleoBHP512").expect("Failed to setup BHP512"); + pub static ref BHP_512: BHP512 = BHP512::::setup("AleoBHP512").expect("Failed to setup BHP512"); /// The BHP hash function, which can take an input of up to 768 bits. - pub static ref BHP_768: BHP768 = BHP768::::setup("AleoBHP768").expect("Failed to setup BHP768"); + pub static ref BHP_768: BHP768 = BHP768::::setup("AleoBHP768").expect("Failed to setup BHP768"); /// The BHP hash function, which can take an input of up to 1024 bits. - pub static ref BHP_1024: BHP1024 = BHP1024::::setup("AleoBHP1024").expect("Failed to setup BHP1024"); + pub static ref BHP_1024: BHP1024 = BHP1024::::setup("AleoBHP1024").expect("Failed to setup BHP1024"); /// The Pedersen hash function, which can take an input of up to 64 bits. - pub static ref PEDERSEN_64: Pedersen64 = Pedersen64::::setup("AleoPedersen64"); + pub static ref PEDERSEN_64: Pedersen64 = Pedersen64::::setup("AleoPedersen64"); /// The Pedersen hash function, which can take an input of up to 128 bits. - pub static ref PEDERSEN_128: Pedersen128 = Pedersen128::::setup("AleoPedersen128"); + pub static ref PEDERSEN_128: Pedersen128 = Pedersen128::::setup("AleoPedersen128"); /// The Poseidon hash function, using a rate of 2. - pub static ref POSEIDON_2: Poseidon2 = Poseidon2::::setup("AleoPoseidon2").expect("Failed to setup Poseidon2"); + pub static ref POSEIDON_2: Poseidon2 = Poseidon2::::setup("AleoPoseidon2").expect("Failed to setup Poseidon2"); /// The Poseidon hash function, using a rate of 4. - pub static ref POSEIDON_4: Poseidon4 = Poseidon4::::setup("AleoPoseidon4").expect("Failed to setup Poseidon4"); + pub static ref POSEIDON_4: Poseidon4 = Poseidon4::::setup("AleoPoseidon4").expect("Failed to setup Poseidon4"); /// The Poseidon hash function, using a rate of 8. - pub static ref POSEIDON_8: Poseidon8 = Poseidon8::::setup("AleoPoseidon8").expect("Failed to setup Poseidon8"); + pub static ref POSEIDON_8: Poseidon8 = Poseidon8::::setup("AleoPoseidon8").expect("Failed to setup Poseidon8"); pub static ref CREDITS_PROVING_KEYS: IndexMap>> = { let mut map = IndexMap::new(); @@ -82,9 +82,9 @@ lazy_static! { pub const TRANSACTION_PREFIX: &str = "at"; #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] -pub struct Testnet3; +pub struct MainnetV0; -impl Testnet3 { +impl MainnetV0 { /// Initializes a new instance of group bases from a given input domain message. fn new_bases(message: &str) -> Vec> { // Hash the given message to a point on the curve, to initialize the starting base. @@ -101,7 +101,7 @@ impl Testnet3 { } } -impl Environment for Testnet3 { +impl Environment for MainnetV0 { type Affine = ::Affine; type BigInteger = ::BigInteger; type Field = ::Field; @@ -119,7 +119,7 @@ impl Environment for Testnet3 { const MONTGOMERY_B: Self::Field = Console::MONTGOMERY_B; } -impl Network for Testnet3 { +impl Network for MainnetV0 { /// The block hash type. type BlockHash = AleoID, { hrp2!("ab") }>; /// The ratification ID type. @@ -134,15 +134,15 @@ impl Network for Testnet3 { /// The network edition. const EDITION: u16 = 0; /// The network ID. - const ID: u16 = 3; + const ID: u16 = 0; /// The function name for the inclusion circuit. - const INCLUSION_FUNCTION_NAME: &'static str = snarkvm_parameters::testnet3::TESTNET3_INCLUSION_FUNCTION_NAME; + const INCLUSION_FUNCTION_NAME: &'static str = snarkvm_parameters::mainnet::NETWORK_INCLUSION_FUNCTION_NAME; /// The network name. - const NAME: &'static str = "Aleo Testnet 3"; + const NAME: &'static str = "Aleo Mainnet (v0)"; /// Returns the genesis block bytes. fn genesis_bytes() -> &'static [u8] { - snarkvm_parameters::testnet3::GenesisBytes::load_bytes() + snarkvm_parameters::mainnet::GenesisBytes::load_bytes() } /// Returns the proving key for the given function name in `credits.aleo`. @@ -165,7 +165,7 @@ impl Network for Testnet3 { INSTANCE.get_or_init(|| { // Skipping the first byte, which is the encoded version. Arc::new( - CircuitProvingKey::from_bytes_le(&snarkvm_parameters::testnet3::INCLUSION_PROVING_KEY[1..]) + CircuitProvingKey::from_bytes_le(&snarkvm_parameters::mainnet::INCLUSION_PROVING_KEY[1..]) .expect("Failed to load inclusion proving key."), ) }) @@ -177,7 +177,7 @@ impl Network for Testnet3 { INSTANCE.get_or_init(|| { // Skipping the first byte, which is the encoded version. Arc::new( - CircuitVerifyingKey::from_bytes_le(&snarkvm_parameters::testnet3::INCLUSION_VERIFYING_KEY[1..]) + CircuitVerifyingKey::from_bytes_le(&snarkvm_parameters::mainnet::INCLUSION_VERIFYING_KEY[1..]) .expect("Failed to load inclusion verifying key."), ) }) @@ -485,7 +485,7 @@ impl Network for Testnet3 { mod tests { use super::*; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_g_scalar_multiply() { diff --git a/console/program/Cargo.toml b/console/program/Cargo.toml index ba81988fc7..23df63249a 100644 --- a/console/program/Cargo.toml +++ b/console/program/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-console-program" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Program operations for a decentralized virtual machine" license = "Apache-2.0" @@ -12,27 +12,27 @@ test = [ ] [dependencies.snarkvm-console-account] path = "../account" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-algorithms] path = "../algorithms" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-collections] path = "../collections" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-network] path = "../network" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-types] path = "../types" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-utilities] path = "../../utilities" -version = "=0.16.15" +version = "=0.16.19" [dependencies.enum_index] version = "0.2" diff --git a/console/program/src/data/access/bytes.rs b/console/program/src/data/access/bytes.rs index f2a560b148..561c4c04e1 100644 --- a/console/program/src/data/access/bytes.rs +++ b/console/program/src/data/access/bytes.rs @@ -46,9 +46,9 @@ impl ToBytes for Access { mod tests { use super::*; use crate::data::identifier::tests::sample_identifier; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u32 = 1000; diff --git a/console/program/src/data/access/parse.rs b/console/program/src/data/access/parse.rs index 4d5801e336..8c5ff6c3a3 100644 --- a/console/program/src/data/access/parse.rs +++ b/console/program/src/data/access/parse.rs @@ -63,9 +63,9 @@ impl Display for Access { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() -> Result<()> { diff --git a/console/program/src/data/access/serialize.rs b/console/program/src/data/access/serialize.rs index 461f8c6d0c..8a48e236ea 100644 --- a/console/program/src/data/access/serialize.rs +++ b/console/program/src/data/access/serialize.rs @@ -37,9 +37,9 @@ impl<'de, N: Network> Deserialize<'de> for Access { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; fn check_serde_json< T: Serialize + for<'a> Deserialize<'a> + Debug + Display + PartialEq + Eq + FromStr + ToBytes + FromBytes, diff --git a/console/program/src/data/ciphertext/bytes.rs b/console/program/src/data/ciphertext/bytes.rs index d983d9bb71..80b0c2d6d8 100644 --- a/console/program/src/data/ciphertext/bytes.rs +++ b/console/program/src/data/ciphertext/bytes.rs @@ -49,9 +49,9 @@ impl ToBytes for Ciphertext { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u32 = 1000; diff --git a/console/program/src/data/ciphertext/decrypt.rs b/console/program/src/data/ciphertext/decrypt.rs index 1de811c4dc..5b10d4a9be 100644 --- a/console/program/src/data/ciphertext/decrypt.rs +++ b/console/program/src/data/ciphertext/decrypt.rs @@ -51,9 +51,9 @@ mod tests { use super::*; use crate::Literal; use snarkvm_console_account::{Address, PrivateKey}; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 100; diff --git a/console/program/src/data/ciphertext/parse.rs b/console/program/src/data/ciphertext/parse.rs index c3ca3f9b0a..185a8b2c29 100644 --- a/console/program/src/data/ciphertext/parse.rs +++ b/console/program/src/data/ciphertext/parse.rs @@ -74,9 +74,9 @@ impl Display for Ciphertext { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1_000; diff --git a/console/program/src/data/ciphertext/serialize.rs b/console/program/src/data/ciphertext/serialize.rs index 30070ead75..318fe2998b 100644 --- a/console/program/src/data/ciphertext/serialize.rs +++ b/console/program/src/data/ciphertext/serialize.rs @@ -37,9 +37,9 @@ impl<'de, N: Network> Deserialize<'de> for Ciphertext { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1000; diff --git a/console/program/src/data/future/bytes.rs b/console/program/src/data/future/bytes.rs index 95878055f1..b60b2ede0c 100644 --- a/console/program/src/data/future/bytes.rs +++ b/console/program/src/data/future/bytes.rs @@ -32,7 +32,8 @@ impl FromBytes for Future { // Read the argument (in 2 steps to prevent infinite recursion). let num_bytes = u16::read_le(&mut reader)?; // Read the argument bytes. - let bytes = (0..num_bytes).map(|_| u8::read_le(&mut reader)).collect::, _>>()?; + let mut bytes = Vec::new(); + (&mut reader).take(num_bytes as u64).read_to_end(&mut bytes)?; // Recover the argument. let entry = Argument::read_le(&mut bytes.as_slice())?; // Add the argument. @@ -71,9 +72,9 @@ impl ToBytes for Future { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_bytes() -> Result<()> { diff --git a/console/program/src/data/future/parse.rs b/console/program/src/data/future/parse.rs index c54356afed..6fd88bf6c2 100644 --- a/console/program/src/data/future/parse.rs +++ b/console/program/src/data/future/parse.rs @@ -213,9 +213,9 @@ impl Future { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse_future() -> Result<()> { diff --git a/console/program/src/data/identifier/bytes.rs b/console/program/src/data/identifier/bytes.rs index 757f27ba40..967feee7cc 100644 --- a/console/program/src/data/identifier/bytes.rs +++ b/console/program/src/data/identifier/bytes.rs @@ -56,9 +56,9 @@ impl ToBytes for Identifier { mod tests { use super::*; use crate::data::identifier::tests::sample_identifier; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1000; diff --git a/console/program/src/data/identifier/from_bits.rs b/console/program/src/data/identifier/from_bits.rs index e4a81c7811..c0c7e1d098 100644 --- a/console/program/src/data/identifier/from_bits.rs +++ b/console/program/src/data/identifier/from_bits.rs @@ -46,9 +46,9 @@ impl FromBits for Identifier { mod tests { use super::*; use crate::data::identifier::tests::sample_identifier; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: usize = 100; diff --git a/console/program/src/data/identifier/from_field.rs b/console/program/src/data/identifier/from_field.rs index f5b597b37f..e5ea3bede8 100644 --- a/console/program/src/data/identifier/from_field.rs +++ b/console/program/src/data/identifier/from_field.rs @@ -28,9 +28,9 @@ impl FromField for Identifier { mod tests { use super::*; use crate::data::identifier::tests::sample_identifier; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: usize = 100; diff --git a/console/program/src/data/identifier/mod.rs b/console/program/src/data/identifier/mod.rs index 22a1bec117..0dde199981 100644 --- a/console/program/src/data/identifier/mod.rs +++ b/console/program/src/data/identifier/mod.rs @@ -74,9 +74,9 @@ impl TryFrom<&str> for Identifier { #[cfg(test)] pub(crate) mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: usize = 100; diff --git a/console/program/src/data/identifier/parse.rs b/console/program/src/data/identifier/parse.rs index 94de468b24..daf02185fb 100644 --- a/console/program/src/data/identifier/parse.rs +++ b/console/program/src/data/identifier/parse.rs @@ -52,6 +52,12 @@ impl FromStr for Identifier { bail!("Identifier is too large. Identifiers must be <= {max_bytes} bytes long") } + // Ensure that the identifier is not a literal. + ensure!( + crate::LiteralType::from_str(identifier).is_err(), + "Identifier '{identifier}' is a reserved literal type" + ); + // Note: The string bytes themselves are **not** little-endian. Rather, they are order-preserving // for reconstructing the string when recovering the field element back into bytes. Ok(Self( @@ -93,9 +99,9 @@ impl Display for Identifier { mod tests { use super::*; use crate::data::identifier::tests::{sample_identifier, sample_identifier_as_string}; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: usize = 100; diff --git a/console/program/src/data/identifier/serialize.rs b/console/program/src/data/identifier/serialize.rs index eadddc2a9d..0d2e4ee766 100644 --- a/console/program/src/data/identifier/serialize.rs +++ b/console/program/src/data/identifier/serialize.rs @@ -38,9 +38,9 @@ impl<'de, N: Network> Deserialize<'de> for Identifier { mod tests { use super::*; use crate::data::identifier::tests::sample_identifier; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1000; diff --git a/console/program/src/data/identifier/size_in_bits.rs b/console/program/src/data/identifier/size_in_bits.rs index 506b253ae4..ec3c113b47 100644 --- a/console/program/src/data/identifier/size_in_bits.rs +++ b/console/program/src/data/identifier/size_in_bits.rs @@ -28,9 +28,9 @@ impl Identifier { mod tests { use super::*; use crate::data::identifier::tests::sample_identifier_as_string; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: usize = 100; diff --git a/console/program/src/data/identifier/to_bits.rs b/console/program/src/data/identifier/to_bits.rs index 2a22dc3234..efe0520ca7 100644 --- a/console/program/src/data/identifier/to_bits.rs +++ b/console/program/src/data/identifier/to_bits.rs @@ -46,9 +46,9 @@ impl ToBits for &Identifier { mod tests { use super::*; use crate::data::identifier::tests::sample_identifier_as_string; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: usize = 100; diff --git a/console/program/src/data/identifier/to_field.rs b/console/program/src/data/identifier/to_field.rs index 5eb11072b2..815e79d7b2 100644 --- a/console/program/src/data/identifier/to_field.rs +++ b/console/program/src/data/identifier/to_field.rs @@ -36,9 +36,9 @@ impl ToField for &Identifier { mod tests { use super::*; use crate::data::identifier::tests::sample_identifier_as_string; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: usize = 100; diff --git a/console/program/src/data/literal/bytes.rs b/console/program/src/data/literal/bytes.rs index 1f77bf3430..d5386a2aa2 100644 --- a/console/program/src/data/literal/bytes.rs +++ b/console/program/src/data/literal/bytes.rs @@ -122,9 +122,9 @@ impl ToBytes for Literal { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u32 = 1000; diff --git a/console/program/src/data/literal/from_bits.rs b/console/program/src/data/literal/from_bits.rs index e7b26f5f95..57bdbe1111 100644 --- a/console/program/src/data/literal/from_bits.rs +++ b/console/program/src/data/literal/from_bits.rs @@ -95,9 +95,9 @@ impl Literal { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u32 = 1000; diff --git a/console/program/src/data/literal/mod.rs b/console/program/src/data/literal/mod.rs index 5b904165ca..62777da9d8 100644 --- a/console/program/src/data/literal/mod.rs +++ b/console/program/src/data/literal/mod.rs @@ -24,6 +24,7 @@ mod parse; mod sample; mod serialize; mod size_in_bits; +mod size_in_bytes; mod to_bits; mod to_type; mod variant; diff --git a/console/program/src/data/literal/parse.rs b/console/program/src/data/literal/parse.rs index 0a02b7200d..bada3c011b 100644 --- a/console/program/src/data/literal/parse.rs +++ b/console/program/src/data/literal/parse.rs @@ -93,9 +93,9 @@ impl Display for Literal { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse_program_id() -> Result<()> { diff --git a/console/program/src/data/literal/serialize.rs b/console/program/src/data/literal/serialize.rs index 2bf01a9154..5bad54669a 100644 --- a/console/program/src/data/literal/serialize.rs +++ b/console/program/src/data/literal/serialize.rs @@ -37,9 +37,9 @@ impl<'de, N: Network> Deserialize<'de> for Literal { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1000; diff --git a/console/program/src/data/literal/size_in_bytes.rs b/console/program/src/data/literal/size_in_bytes.rs new file mode 100644 index 0000000000..cc3a434ec1 --- /dev/null +++ b/console/program/src/data/literal/size_in_bytes.rs @@ -0,0 +1,26 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the snarkVM library. + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use super::*; + +impl Literal { + /// Returns the size in bytes of this literal. + #[allow(clippy::cast_possible_truncation)] + pub fn size_in_bytes(&self) -> u16 { + // Note: This upcast to u32 and downcast to u16 is safe because the size of a literal is + // always less than or equal to u16::MAX bits, and we are dividing by 8, so the result will + // always fit in a u16. + (((self.size_in_bits() as u32) + 7) / 8) as u16 + } +} diff --git a/console/program/src/data/plaintext/bytes.rs b/console/program/src/data/plaintext/bytes.rs index 99cdd82ed4..73a4e7670e 100644 --- a/console/program/src/data/plaintext/bytes.rs +++ b/console/program/src/data/plaintext/bytes.rs @@ -33,7 +33,8 @@ impl FromBytes for Plaintext { // Read the plaintext value (in 2 steps to prevent infinite recursion). let num_bytes = u16::read_le(&mut reader)?; // Read the plaintext bytes. - let bytes = (0..num_bytes).map(|_| u8::read_le(&mut reader)).collect::, _>>()?; + let mut bytes = Vec::new(); + (&mut reader).take(num_bytes as u64).read_to_end(&mut bytes)?; // Recover the plaintext value. let plaintext = Plaintext::read_le(&mut bytes.as_slice())?; // Add the member. @@ -54,7 +55,8 @@ impl FromBytes for Plaintext { // Read the plaintext value (in 2 steps to prevent infinite recursion). let num_bytes = u16::read_le(&mut reader)?; // Read the plaintext bytes. - let bytes = (0..num_bytes).map(|_| u8::read_le(&mut reader)).collect::, _>>()?; + let mut bytes = Vec::new(); + (&mut reader).take(num_bytes as u64).read_to_end(&mut bytes)?; // Recover the plaintext value. let plaintext = Plaintext::read_le(&mut bytes.as_slice())?; // Add the element. @@ -121,9 +123,9 @@ impl ToBytes for Plaintext { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u32 = 1000; diff --git a/console/program/src/data/plaintext/equal.rs b/console/program/src/data/plaintext/equal.rs index 3432735d10..323feb8d84 100644 --- a/console/program/src/data/plaintext/equal.rs +++ b/console/program/src/data/plaintext/equal.rs @@ -84,9 +84,9 @@ impl Equal for Plaintext { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; fn sample_plaintext() -> Plaintext { Plaintext::::from_str( diff --git a/console/program/src/data/plaintext/mod.rs b/console/program/src/data/plaintext/mod.rs index be300e0a8c..8080557e4a 100644 --- a/console/program/src/data/plaintext/mod.rs +++ b/console/program/src/data/plaintext/mod.rs @@ -59,12 +59,12 @@ impl From<&Literal> for Plaintext { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; use snarkvm_console_types::Field; use core::str::FromStr; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_plaintext() -> Result<()> { @@ -93,102 +93,84 @@ mod tests { // Test a random struct with literal members. run_test(Plaintext::::Struct( - IndexMap::from_iter( - vec![ - (Identifier::from_str("a")?, Plaintext::::from_str("true")?), - ( - Identifier::from_str("b")?, - Plaintext::::Literal( - Literal::Field(Field::new(Uniform::rand(&mut rng))), - OnceCell::new(), - ), + IndexMap::from_iter(vec![ + (Identifier::from_str("a")?, Plaintext::::from_str("true")?), + ( + Identifier::from_str("b")?, + Plaintext::::Literal( + Literal::Field(Field::new(Uniform::rand(&mut rng))), + OnceCell::new(), ), - ] - .into_iter(), - ), + ), + ]), OnceCell::new(), )); // Test a random struct with array members. run_test(Plaintext::::Struct( - IndexMap::from_iter( - vec![ - (Identifier::from_str("a")?, Plaintext::::from_str("true")?), - ( - Identifier::from_str("b")?, - Plaintext::::Array( - vec![ - Plaintext::::from_str("true")?, - Plaintext::::from_str("false")?, - ], - OnceCell::new(), - ), + IndexMap::from_iter(vec![ + (Identifier::from_str("a")?, Plaintext::::from_str("true")?), + ( + Identifier::from_str("b")?, + Plaintext::::Array( + vec![ + Plaintext::::from_str("true")?, + Plaintext::::from_str("false")?, + ], + OnceCell::new(), ), - ] - .into_iter(), - ), + ), + ]), OnceCell::new(), )); // Test random deeply-nested struct. run_test(Plaintext::::Struct( - IndexMap::from_iter( - vec![ - (Identifier::from_str("a")?, Plaintext::::from_str("true")?), - ( - Identifier::from_str("b")?, - Plaintext::::Struct( - IndexMap::from_iter( - vec![ - (Identifier::from_str("c")?, Plaintext::::from_str("true")?), - ( - Identifier::from_str("d")?, - Plaintext::::Struct( - IndexMap::from_iter( - vec![ - ( - Identifier::from_str("e")?, - Plaintext::::from_str("true")?, - ), - ( - Identifier::from_str("f")?, - Plaintext::::Literal( - Literal::Field(Field::new(Uniform::rand(&mut rng))), - OnceCell::new(), - ), - ), - ] - .into_iter(), + IndexMap::from_iter(vec![ + (Identifier::from_str("a")?, Plaintext::::from_str("true")?), + ( + Identifier::from_str("b")?, + Plaintext::::Struct( + IndexMap::from_iter(vec![ + (Identifier::from_str("c")?, Plaintext::::from_str("true")?), + ( + Identifier::from_str("d")?, + Plaintext::::Struct( + IndexMap::from_iter(vec![ + (Identifier::from_str("e")?, Plaintext::::from_str("true")?), + ( + Identifier::from_str("f")?, + Plaintext::::Literal( + Literal::Field(Field::new(Uniform::rand(&mut rng))), + OnceCell::new(), ), - OnceCell::new(), ), - ), - ( - Identifier::from_str("g")?, - Plaintext::Array( - vec![ - Plaintext::::from_str("true")?, - Plaintext::::from_str("false")?, - ], - OnceCell::new(), - ), - ), - ] - .into_iter(), + ]), + OnceCell::new(), + ), + ), + ( + Identifier::from_str("g")?, + Plaintext::Array( + vec![ + Plaintext::::from_str("true")?, + Plaintext::::from_str("false")?, + ], + OnceCell::new(), + ), ), - OnceCell::new(), - ), + ]), + OnceCell::new(), ), - ( - Identifier::from_str("h")?, - Plaintext::::Literal( - Literal::Field(Field::new(Uniform::rand(&mut rng))), - OnceCell::new(), - ), + ), + ( + Identifier::from_str("h")?, + Plaintext::::Literal( + Literal::Field(Field::new(Uniform::rand(&mut rng))), + OnceCell::new(), ), - ] - .into_iter(), - ), + ), + ]), OnceCell::new(), )); diff --git a/console/program/src/data/plaintext/parse.rs b/console/program/src/data/plaintext/parse.rs index 01fb453595..594e38ce68 100644 --- a/console/program/src/data/plaintext/parse.rs +++ b/console/program/src/data/plaintext/parse.rs @@ -59,7 +59,7 @@ impl Parser for Plaintext { // Parse the '}' from the string. let (string, _) = tag("}")(string)?; // Output the plaintext. - Ok((string, Plaintext::Struct(IndexMap::from_iter(members.into_iter()), Default::default()))) + Ok((string, Plaintext::Struct(IndexMap::from_iter(members), Default::default()))) } /// Parses a plaintext as an array: `[plaintext_0, ..., plaintext_n]`. @@ -205,9 +205,9 @@ impl Plaintext { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse_literal() -> Result<()> { diff --git a/console/program/src/data/plaintext/serialize.rs b/console/program/src/data/plaintext/serialize.rs index 0ad4131272..82e7ac0b1c 100644 --- a/console/program/src/data/plaintext/serialize.rs +++ b/console/program/src/data/plaintext/serialize.rs @@ -37,9 +37,9 @@ impl<'de, N: Network> Deserialize<'de> for Plaintext { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 2; diff --git a/console/program/src/data/record/bytes.rs b/console/program/src/data/record/bytes.rs index a787040499..4e06c3abbf 100644 --- a/console/program/src/data/record/bytes.rs +++ b/console/program/src/data/record/bytes.rs @@ -29,7 +29,8 @@ impl FromBytes for Record { // Read the entry value (in 2 steps to prevent infinite recursion). let num_bytes = u16::read_le(&mut reader)?; // Read the entry bytes. - let bytes = (0..num_bytes).map(|_| u8::read_le(&mut reader)).collect::, _>>()?; + let mut bytes = Vec::new(); + (&mut reader).take(num_bytes as u64).read_to_end(&mut bytes)?; // Recover the entry value. let entry = Entry::read_le(&mut bytes.as_slice())?; // Add the entry. @@ -81,9 +82,9 @@ impl ToBytes for Record { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_bytes() -> Result<()> { diff --git a/console/program/src/data/record/decrypt.rs b/console/program/src/data/record/decrypt.rs index 4e9d5d15b2..d5d0f37b7f 100644 --- a/console/program/src/data/record/decrypt.rs +++ b/console/program/src/data/record/decrypt.rs @@ -96,10 +96,10 @@ mod tests { use super::*; use crate::Literal; use snarkvm_console_account::PrivateKey; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; use snarkvm_console_types::Field; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1000; @@ -112,13 +112,10 @@ mod tests { let randomizer = Scalar::rand(rng); let record = Record { owner, - data: IndexMap::from_iter( - vec![ - (Identifier::from_str("a")?, Entry::Private(Plaintext::from(Literal::Field(Field::rand(rng))))), - (Identifier::from_str("b")?, Entry::Private(Plaintext::from(Literal::Scalar(Scalar::rand(rng))))), - ] - .into_iter(), - ), + data: IndexMap::from_iter(vec![ + (Identifier::from_str("a")?, Entry::Private(Plaintext::from(Literal::Field(Field::rand(rng))))), + (Identifier::from_str("b")?, Entry::Private(Plaintext::from(Literal::Scalar(Scalar::rand(rng))))), + ]), nonce: N::g_scalar_multiply(&randomizer), }; // Encrypt the record. diff --git a/console/program/src/data/record/entry/parse.rs b/console/program/src/data/record/entry/parse.rs index af5c9491db..8ab61f6fa5 100644 --- a/console/program/src/data/record/entry/parse.rs +++ b/console/program/src/data/record/entry/parse.rs @@ -95,7 +95,7 @@ impl Parser for Entry> { // Parse the '}' from the string. let (string, _) = tag("}")(string)?; // Output the plaintext and visibility. - Ok((string, (Plaintext::Struct(IndexMap::from_iter(members.into_iter()), Default::default()), mode))) + Ok((string, (Plaintext::Struct(IndexMap::from_iter(members), Default::default()), mode))) } /// Parses an entry as an array: `[plaintext_0.visibility, ..., plaintext_n.visibility]`. @@ -288,9 +288,9 @@ impl Entry> { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() -> Result<()> { diff --git a/console/program/src/data/record/equal.rs b/console/program/src/data/record/equal.rs index 61bf58b714..c830b42b50 100644 --- a/console/program/src/data/record/equal.rs +++ b/console/program/src/data/record/equal.rs @@ -60,9 +60,9 @@ impl>> Equal for Reco #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; fn sample_record() -> Record> { Record::>::from_str( diff --git a/console/program/src/data/record/is_owner.rs b/console/program/src/data/record/is_owner.rs index 6ef8ef6dd2..06381ff9aa 100644 --- a/console/program/src/data/record/is_owner.rs +++ b/console/program/src/data/record/is_owner.rs @@ -62,10 +62,10 @@ mod tests { use super::*; use crate::Literal; use snarkvm_console_account::PrivateKey; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; use snarkvm_console_types::Field; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1_000; @@ -78,13 +78,10 @@ mod tests { let randomizer = Scalar::rand(rng); let record = Record { owner, - data: IndexMap::from_iter( - vec![ - (Identifier::from_str("a")?, Entry::Private(Plaintext::from(Literal::Field(Field::rand(rng))))), - (Identifier::from_str("b")?, Entry::Private(Plaintext::from(Literal::Scalar(Scalar::rand(rng))))), - ] - .into_iter(), - ), + data: IndexMap::from_iter(vec![ + (Identifier::from_str("a")?, Entry::Private(Plaintext::from(Literal::Field(Field::rand(rng))))), + (Identifier::from_str("b")?, Entry::Private(Plaintext::from(Literal::Scalar(Scalar::rand(rng))))), + ]), nonce: N::g_scalar_multiply(&randomizer), }; diff --git a/console/program/src/data/record/parse_plaintext.rs b/console/program/src/data/record/parse_plaintext.rs index c04a190d85..6179ac24a7 100644 --- a/console/program/src/data/record/parse_plaintext.rs +++ b/console/program/src/data/record/parse_plaintext.rs @@ -102,7 +102,7 @@ impl Parser for Record> { // Parse the '}' from the string. let (string, _) = tag("}")(string)?; // Output the record. - Ok((string, Record { owner, data: IndexMap::from_iter(entries.into_iter()), nonce })) + Ok((string, Record { owner, data: IndexMap::from_iter(entries), nonce })) } } @@ -178,9 +178,9 @@ impl Record> { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse_without_data_entries() -> Result<()> { diff --git a/console/program/src/data/record/serialize.rs b/console/program/src/data/record/serialize.rs index 00f4331007..c5da3d5670 100644 --- a/console/program/src/data/record/serialize.rs +++ b/console/program/src/data/record/serialize.rs @@ -57,9 +57,9 @@ impl<'de, N: Network> Deserialize<'de> for Record> { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1; diff --git a/console/program/src/data/register/mod.rs b/console/program/src/data/register/mod.rs index 7b17c38b90..d0839dffef 100644 --- a/console/program/src/data/register/mod.rs +++ b/console/program/src/data/register/mod.rs @@ -57,9 +57,9 @@ impl PartialOrd for Register { mod tests { use super::*; use crate::{Identifier, U32}; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_register_partial_ord() -> Result<()> { diff --git a/console/program/src/data/register/parse.rs b/console/program/src/data/register/parse.rs index 714bf0a700..d40a26a396 100644 --- a/console/program/src/data/register/parse.rs +++ b/console/program/src/data/register/parse.rs @@ -88,9 +88,9 @@ impl Display for Register { mod tests { use super::*; use crate::{Identifier, U32}; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_register_display() -> Result<()> { // Register::Locator diff --git a/console/program/src/data/register/serialize.rs b/console/program/src/data/register/serialize.rs index a2835884ff..f5efb62e6f 100644 --- a/console/program/src/data/register/serialize.rs +++ b/console/program/src/data/register/serialize.rs @@ -37,9 +37,9 @@ impl<'de, N: Network> Deserialize<'de> for Register { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; fn check_serde_json< T: Serialize + for<'a> Deserialize<'a> + Debug + Display + PartialEq + Eq + FromStr + ToBytes + FromBytes, diff --git a/console/program/src/data/value/bytes.rs b/console/program/src/data/value/bytes.rs index 50e8567f05..c4f673d89c 100644 --- a/console/program/src/data/value/bytes.rs +++ b/console/program/src/data/value/bytes.rs @@ -53,9 +53,9 @@ impl ToBytes for Value { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_value_plaintext_bytes() -> Result<()> { diff --git a/console/program/src/data/value/parse.rs b/console/program/src/data/value/parse.rs index 9186c5bae4..9c5dddf1f8 100644 --- a/console/program/src/data/value/parse.rs +++ b/console/program/src/data/value/parse.rs @@ -66,9 +66,9 @@ impl Display for Value { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_value_plaintext_parse() { diff --git a/console/program/src/data/value/serialize.rs b/console/program/src/data/value/serialize.rs index ed8d175b2c..61b94f0cba 100644 --- a/console/program/src/data/value/serialize.rs +++ b/console/program/src/data/value/serialize.rs @@ -37,9 +37,9 @@ impl<'de, N: Network> Deserialize<'de> for Value { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_serde_json() -> Result<()> { diff --git a/console/program/src/data_types/array_type/bytes.rs b/console/program/src/data_types/array_type/bytes.rs index b01482ad4d..3030b11635 100644 --- a/console/program/src/data_types/array_type/bytes.rs +++ b/console/program/src/data_types/array_type/bytes.rs @@ -103,7 +103,7 @@ impl ToBytes for ArrayType { mod tests { use super::*; - type CurrentNetwork = snarkvm_console_network::Testnet3; + type CurrentNetwork = snarkvm_console_network::MainnetV0; #[test] fn test_array_maximum_depth() { diff --git a/console/program/src/data_types/array_type/mod.rs b/console/program/src/data_types/array_type/mod.rs index 9680c28517..b3c781b744 100644 --- a/console/program/src/data_types/array_type/mod.rs +++ b/console/program/src/data_types/array_type/mod.rs @@ -91,11 +91,11 @@ impl ArrayType { mod tests { use super::*; use crate::{Identifier, LiteralType}; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; use core::str::FromStr; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_array_type() -> Result<()> { diff --git a/console/program/src/data_types/array_type/serialize.rs b/console/program/src/data_types/array_type/serialize.rs index 425b243f58..72869ae263 100644 --- a/console/program/src/data_types/array_type/serialize.rs +++ b/console/program/src/data_types/array_type/serialize.rs @@ -37,7 +37,7 @@ impl<'de, N: Network> Deserialize<'de> for ArrayType { #[cfg(test)] pub(crate) mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; /// Add test cases here to be checked for serialization. pub(crate) const TEST_CASES: &[&str] = &[ @@ -100,14 +100,14 @@ pub(crate) mod tests { #[test] fn test_serde_json() { for case in TEST_CASES.iter() { - check_serde_json(ArrayType::::from_str(case).unwrap()); + check_serde_json(ArrayType::::from_str(case).unwrap()); } } #[test] fn test_bincode() { for case in TEST_CASES.iter() { - check_bincode(ArrayType::::from_str(case).unwrap()); + check_bincode(ArrayType::::from_str(case).unwrap()); } } } diff --git a/console/program/src/data_types/finalize_type/parse.rs b/console/program/src/data_types/finalize_type/parse.rs index 7ab5ef9421..a60a7a3462 100644 --- a/console/program/src/data_types/finalize_type/parse.rs +++ b/console/program/src/data_types/finalize_type/parse.rs @@ -65,9 +65,9 @@ impl Display for FinalizeType { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() -> Result<()> { diff --git a/console/program/src/data_types/finalize_type/serialize.rs b/console/program/src/data_types/finalize_type/serialize.rs index db0e58dfd1..ef4794f47a 100644 --- a/console/program/src/data_types/finalize_type/serialize.rs +++ b/console/program/src/data_types/finalize_type/serialize.rs @@ -37,9 +37,9 @@ impl<'de, N: Network> Deserialize<'de> for FinalizeType { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Add test cases here to be checked for serialization. const TEST_CASES: &[&str] = &[ diff --git a/console/program/src/data_types/literal_type/mod.rs b/console/program/src/data_types/literal_type/mod.rs index cb5e4dae49..d6ddf2f5a0 100644 --- a/console/program/src/data_types/literal_type/mod.rs +++ b/console/program/src/data_types/literal_type/mod.rs @@ -15,8 +15,12 @@ mod bytes; mod parse; mod serialize; +mod size_in_bits; +mod size_in_bytes; +use snarkvm_console_account::Signature; use snarkvm_console_network::prelude::*; +use snarkvm_console_types::{prelude::*, Boolean}; use core::fmt::{self, Debug, Display}; use num_derive::FromPrimitive; diff --git a/console/program/src/data_types/literal_type/size_in_bits.rs b/console/program/src/data_types/literal_type/size_in_bits.rs new file mode 100644 index 0000000000..19db4593a7 --- /dev/null +++ b/console/program/src/data_types/literal_type/size_in_bits.rs @@ -0,0 +1,43 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the snarkVM library. + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use super::*; + +impl LiteralType { + /// Returns the number of bits of this literal type. + /// + /// For string literals, this method returns the maximum number of bits that can be stored in the string. + pub fn size_in_bits(&self) -> u16 { + let size = match self { + Self::Address => Address::::size_in_bits(), + Self::Boolean => Boolean::::size_in_bits(), + Self::Field => Field::::size_in_bits(), + Self::Group => Group::::size_in_bits(), + Self::I8 => I8::::size_in_bits(), + Self::I16 => I16::::size_in_bits(), + Self::I32 => I32::::size_in_bits(), + Self::I64 => I64::::size_in_bits(), + Self::I128 => I128::::size_in_bits(), + Self::U8 => U8::::size_in_bits(), + Self::U16 => U16::::size_in_bits(), + Self::U32 => U32::::size_in_bits(), + Self::U64 => U64::::size_in_bits(), + Self::U128 => U128::::size_in_bits(), + Self::Scalar => Scalar::::size_in_bits(), + Self::Signature => Signature::::size_in_bits(), + Self::String => N::MAX_STRING_BYTES.saturating_mul(8) as usize, + }; + u16::try_from(size).or_halt_with::("Literal exceeds u16::MAX bits.") + } +} diff --git a/console/program/src/data_types/literal_type/size_in_bytes.rs b/console/program/src/data_types/literal_type/size_in_bytes.rs new file mode 100644 index 0000000000..2862b0f218 --- /dev/null +++ b/console/program/src/data_types/literal_type/size_in_bytes.rs @@ -0,0 +1,28 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the snarkVM library. + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use super::*; + +impl LiteralType { + /// Returns the number of bytes of this literal. + /// + /// For string literals, this method returns the maximum number of bytes that can be stored in the string. + #[allow(clippy::cast_possible_truncation)] + pub fn size_in_bytes(&self) -> u16 { + // Note: This upcast to u32 and downcast to u16 is safe because the size of a literal is + // always less than or equal to u16::MAX bits, and we are dividing by 8, so the result will + // always fit in a u16. + (((self.size_in_bits::() as u32) + 7) / 8) as u16 + } +} diff --git a/console/program/src/data_types/plaintext_type/parse.rs b/console/program/src/data_types/plaintext_type/parse.rs index 21474fc5e6..4e55c6498b 100644 --- a/console/program/src/data_types/plaintext_type/parse.rs +++ b/console/program/src/data_types/plaintext_type/parse.rs @@ -21,8 +21,8 @@ impl Parser for PlaintextType { // Parse to determine the plaintext type (order matters). alt(( map(ArrayType::parse, |type_| Self::Array(type_)), - map(LiteralType::parse, |type_| Self::Literal(type_)), map(Identifier::parse, |identifier| Self::Struct(identifier)), + map(LiteralType::parse, |type_| Self::Literal(type_)), ))(string) } } @@ -68,9 +68,9 @@ impl Display for PlaintextType { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() -> Result<()> { @@ -86,6 +86,10 @@ mod tests { PlaintextType::parse("foo"), Ok(("", PlaintextType::::Struct(Identifier::from_str("foo")?))) ); + assert_eq!( + PlaintextType::parse("u8jdsklaj"), + Ok(("", PlaintextType::::Struct(Identifier::from_str("u8jdsklaj")?))) + ); assert_eq!( PlaintextType::parse("[field; 1u32]"), Ok(("", PlaintextType::::Array(ArrayType::from_str("[field; 1u32]")?))) diff --git a/console/program/src/data_types/plaintext_type/serialize.rs b/console/program/src/data_types/plaintext_type/serialize.rs index c9d602016c..f80a3862a8 100644 --- a/console/program/src/data_types/plaintext_type/serialize.rs +++ b/console/program/src/data_types/plaintext_type/serialize.rs @@ -37,9 +37,9 @@ impl<'de, N: Network> Deserialize<'de> for PlaintextType { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Add test cases here to be checked for serialization. const TEST_CASES: &[&str] = &[ diff --git a/console/program/src/data_types/record_type/bytes.rs b/console/program/src/data_types/record_type/bytes.rs index 0848fd93ef..172c41c631 100644 --- a/console/program/src/data_types/record_type/bytes.rs +++ b/console/program/src/data_types/record_type/bytes.rs @@ -88,9 +88,9 @@ impl ToBytes for RecordType { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_bytes() -> Result<()> { diff --git a/console/program/src/data_types/record_type/entry_type/parse.rs b/console/program/src/data_types/record_type/entry_type/parse.rs index 587517b1f0..36b153bdbc 100644 --- a/console/program/src/data_types/record_type/entry_type/parse.rs +++ b/console/program/src/data_types/record_type/entry_type/parse.rs @@ -65,9 +65,9 @@ impl Display for EntryType { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() -> Result<()> { diff --git a/console/program/src/data_types/record_type/entry_type/serialize.rs b/console/program/src/data_types/record_type/entry_type/serialize.rs index a042781a7f..00884ef302 100644 --- a/console/program/src/data_types/record_type/entry_type/serialize.rs +++ b/console/program/src/data_types/record_type/entry_type/serialize.rs @@ -37,9 +37,9 @@ impl<'de, N: Network> Deserialize<'de> for EntryType { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Add test cases here to be checked for serialization. const TEST_CASES: &[&str] = &[ diff --git a/console/program/src/data_types/record_type/parse.rs b/console/program/src/data_types/record_type/parse.rs index d6e78933ff..d995622e7c 100644 --- a/console/program/src/data_types/record_type/parse.rs +++ b/console/program/src/data_types/record_type/parse.rs @@ -94,7 +94,7 @@ impl Parser for RecordType { })(string)?; // Return the record type. - Ok((string, Self { name, owner, entries: IndexMap::from_iter(entries.into_iter()) })) + Ok((string, Self { name, owner, entries: IndexMap::from_iter(entries) })) } } @@ -134,18 +134,19 @@ impl Display for RecordType { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() -> Result<()> { let expected = RecordType:: { name: Identifier::from_str("message")?, owner: PublicOrPrivate::Private, - entries: IndexMap::from_iter( - vec![(Identifier::from_str("first")?, EntryType::from_str("field.constant")?)].into_iter(), - ), + entries: IndexMap::from_iter(vec![( + Identifier::from_str("first")?, + EntryType::from_str("field.constant")?, + )]), }; let (remainder, candidate) = RecordType::::parse( diff --git a/console/program/src/data_types/record_type/serialize.rs b/console/program/src/data_types/record_type/serialize.rs index ea56b08bee..40c94d2149 100644 --- a/console/program/src/data_types/record_type/serialize.rs +++ b/console/program/src/data_types/record_type/serialize.rs @@ -37,9 +37,9 @@ impl<'de, N: Network> Deserialize<'de> for RecordType { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Add test cases here to be checked for serialization. const TEST_CASES: &[&str] = diff --git a/console/program/src/data_types/register_type/parse.rs b/console/program/src/data_types/register_type/parse.rs index ec4bbcef58..6cd6f5b4fc 100644 --- a/console/program/src/data_types/register_type/parse.rs +++ b/console/program/src/data_types/register_type/parse.rs @@ -71,9 +71,9 @@ impl Display for RegisterType { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() -> Result<()> { @@ -88,6 +88,10 @@ mod tests { Ok(("", RegisterType::::Plaintext(PlaintextType::from_str("signature")?))), RegisterType::::parse("signature") ); + assert_eq!( + Ok(("", RegisterType::::Plaintext(PlaintextType::from_str("u8kldsafj")?))), + RegisterType::::parse("u8kldsafj") + ); // Record type. assert_eq!( diff --git a/console/program/src/data_types/register_type/serialize.rs b/console/program/src/data_types/register_type/serialize.rs index b4b526ef36..919e750256 100644 --- a/console/program/src/data_types/register_type/serialize.rs +++ b/console/program/src/data_types/register_type/serialize.rs @@ -37,9 +37,9 @@ impl<'de, N: Network> Deserialize<'de> for RegisterType { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Add test cases here to be checked for serialization. const TEST_CASES: &[&str] = &[ diff --git a/console/program/src/data_types/struct_type/bytes.rs b/console/program/src/data_types/struct_type/bytes.rs index e7b9c31856..cdee12b982 100644 --- a/console/program/src/data_types/struct_type/bytes.rs +++ b/console/program/src/data_types/struct_type/bytes.rs @@ -73,9 +73,9 @@ impl ToBytes for StructType { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_bytes() -> Result<()> { diff --git a/console/program/src/data_types/struct_type/parse.rs b/console/program/src/data_types/struct_type/parse.rs index 648203697f..42ad3b7ca0 100644 --- a/console/program/src/data_types/struct_type/parse.rs +++ b/console/program/src/data_types/struct_type/parse.rs @@ -70,7 +70,7 @@ impl Parser for StructType { Ok(members) })(string)?; // Return the struct. - Ok((string, Self { name, members: IndexMap::from_iter(members.into_iter()) })) + Ok((string, Self { name, members: IndexMap::from_iter(members) })) } } @@ -114,21 +114,18 @@ impl Display for StructType { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() -> Result<()> { let expected = StructType:: { name: Identifier::from_str("message")?, - members: IndexMap::from_iter( - vec![ - (Identifier::from_str("sender")?, PlaintextType::from_str("address")?), - (Identifier::from_str("amount")?, PlaintextType::from_str("u64")?), - ] - .into_iter(), - ), + members: IndexMap::from_iter(vec![ + (Identifier::from_str("sender")?, PlaintextType::from_str("address")?), + (Identifier::from_str("amount")?, PlaintextType::from_str("u64")?), + ]), }; let (remainder, candidate) = StructType::::parse( diff --git a/console/program/src/data_types/struct_type/serialize.rs b/console/program/src/data_types/struct_type/serialize.rs index 4d813a02f7..b5e0c2065c 100644 --- a/console/program/src/data_types/struct_type/serialize.rs +++ b/console/program/src/data_types/struct_type/serialize.rs @@ -37,9 +37,9 @@ impl<'de, N: Network> Deserialize<'de> for StructType { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Add test cases here to be checked for serialization. const TEST_CASES: &[&str] = &["struct message: owner as address; is_new as boolean; total_supply as u64;"]; diff --git a/console/program/src/data_types/value_type/parse.rs b/console/program/src/data_types/value_type/parse.rs index a9198179d4..e7ce5402a8 100644 --- a/console/program/src/data_types/value_type/parse.rs +++ b/console/program/src/data_types/value_type/parse.rs @@ -72,9 +72,9 @@ impl Display for ValueType { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() -> Result<()> { @@ -105,6 +105,10 @@ mod tests { Ok(("", ValueType::::from_str("signature.private")?)), ValueType::::parse("signature.private") ); + assert_eq!( + Ok(("", ValueType::::from_str("i8abc.constant")?)), + ValueType::::parse("i8abc.constant") + ); // Record type. assert_eq!( diff --git a/console/program/src/data_types/value_type/serialize.rs b/console/program/src/data_types/value_type/serialize.rs index d57c7c170f..fc6f779555 100644 --- a/console/program/src/data_types/value_type/serialize.rs +++ b/console/program/src/data_types/value_type/serialize.rs @@ -37,9 +37,9 @@ impl<'de, N: Network> Deserialize<'de> for ValueType { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Add test cases here to be checked for serialization. const TEST_CASES: &[&str] = &[ diff --git a/console/program/src/function_id/mod.rs b/console/program/src/function_id/mod.rs new file mode 100644 index 0000000000..91c17ec162 --- /dev/null +++ b/console/program/src/function_id/mod.rs @@ -0,0 +1,39 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the snarkVM library. + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use crate::{Identifier, ProgramID}; +use snarkvm_console_account::ToBits; +use snarkvm_console_algorithms::Result; +use snarkvm_console_network::Network; +use snarkvm_console_types::{Field, U16, U8}; + +/// Compute the function ID as `Hash(network_id, program_id.len(), program_id, function_name.len(), function_name)`. +pub fn compute_function_id( + network_id: &U16, + program_id: &ProgramID, + function_name: &Identifier, +) -> Result> { + N::hash_bhp1024( + &( + *network_id, + U8::::new(program_id.name().size_in_bits()), + program_id.name(), + U8::::new(program_id.network().size_in_bits()), + program_id.network(), + U8::::new(function_name.size_in_bits()), + function_name, + ) + .to_bits_le(), + ) +} diff --git a/console/program/src/id/mod.rs b/console/program/src/id/mod.rs index 4bab9a0886..da40170dda 100644 --- a/console/program/src/id/mod.rs +++ b/console/program/src/id/mod.rs @@ -151,9 +151,9 @@ impl Equal for ProgramID { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_partial_ord() -> Result<()> { diff --git a/console/program/src/id/parse.rs b/console/program/src/id/parse.rs index 86e3498fc0..8fa8a7f613 100644 --- a/console/program/src/id/parse.rs +++ b/console/program/src/id/parse.rs @@ -61,9 +61,9 @@ impl Display for ProgramID { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() -> Result<()> { diff --git a/console/program/src/id/serialize.rs b/console/program/src/id/serialize.rs index 76180a25a7..7857a201e1 100644 --- a/console/program/src/id/serialize.rs +++ b/console/program/src/id/serialize.rs @@ -37,9 +37,9 @@ impl<'de, N: Network> Deserialize<'de> for ProgramID { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Add test cases here to be checked for serialization. const TEST_CASES: &[&str] = &["testing.aleo", "hello.aleo", "abc_def.aleo", "a1234.aleo"]; diff --git a/console/program/src/id/to_bits.rs b/console/program/src/id/to_bits.rs index a34dcd689d..3817a537f1 100644 --- a/console/program/src/id/to_bits.rs +++ b/console/program/src/id/to_bits.rs @@ -44,9 +44,9 @@ impl ToBits for &ProgramID { mod tests { use super::*; use crate::data::identifier::tests::sample_lowercase_identifier_as_string; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: usize = 100; diff --git a/console/program/src/lib.rs b/console/program/src/lib.rs index 8547b46694..bb14280f53 100644 --- a/console/program/src/lib.rs +++ b/console/program/src/lib.rs @@ -30,6 +30,9 @@ pub use data::*; mod data_types; pub use data_types::*; +mod function_id; +pub use function_id::*; + mod id; pub use id::*; diff --git a/console/program/src/locator/parse.rs b/console/program/src/locator/parse.rs index 129bd89e0f..9f787423d1 100644 --- a/console/program/src/locator/parse.rs +++ b/console/program/src/locator/parse.rs @@ -62,9 +62,9 @@ impl Display for Locator { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_import_parse() -> Result<()> { diff --git a/console/program/src/locator/serialize.rs b/console/program/src/locator/serialize.rs index ab25677216..82dd9acb66 100644 --- a/console/program/src/locator/serialize.rs +++ b/console/program/src/locator/serialize.rs @@ -37,9 +37,9 @@ impl<'de, N: Network> Deserialize<'de> for Locator { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Add test cases here to be checked for serialization. const TEST_CASES: &[&str] = &["testing.aleo/abc", "hello.aleo/u1r02r", "hello_world.aleo/foo", "foo123.aleo/run"]; diff --git a/console/program/src/owner/bytes.rs b/console/program/src/owner/bytes.rs index edffec5844..c827ccfb64 100644 --- a/console/program/src/owner/bytes.rs +++ b/console/program/src/owner/bytes.rs @@ -49,9 +49,9 @@ impl ToBytes for ProgramOwner { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_bytes() -> Result<()> { diff --git a/console/program/src/owner/mod.rs b/console/program/src/owner/mod.rs index 96a532cd4c..4e7899b44d 100644 --- a/console/program/src/owner/mod.rs +++ b/console/program/src/owner/mod.rs @@ -63,11 +63,11 @@ impl ProgramOwner { #[cfg(test)] pub(crate) mod test_helpers { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; use once_cell::sync::OnceCell; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; pub(crate) fn sample_program_owner() -> ProgramOwner { static INSTANCE: OnceCell> = OnceCell::new(); diff --git a/console/program/src/request/bytes.rs b/console/program/src/request/bytes.rs index ec664b9c48..84cb5ea1dd 100644 --- a/console/program/src/request/bytes.rs +++ b/console/program/src/request/bytes.rs @@ -48,8 +48,22 @@ impl FromBytes for Request { let tvk = FromBytes::read_le(&mut reader)?; // Read the transition commitment. let tcm = FromBytes::read_le(&mut reader)?; - - Ok(Self::from((signer, network_id, program_id, function_name, input_ids, inputs, signature, sk_tag, tvk, tcm))) + // Read the signer commitment. + let scm = FromBytes::read_le(&mut reader)?; + + Ok(Self::from(( + signer, + network_id, + program_id, + function_name, + input_ids, + inputs, + signature, + sk_tag, + tvk, + tcm, + scm, + ))) } } @@ -93,7 +107,9 @@ impl ToBytes for Request { // Write the transition view key. self.tvk.write_le(&mut writer)?; // Write the transition commitment. - self.tcm.write_le(&mut writer) + self.tcm.write_le(&mut writer)?; + // Write the signer commitment. + self.scm.write_le(&mut writer) } } diff --git a/console/program/src/request/input_id/serialize.rs b/console/program/src/request/input_id/serialize.rs index 0a74b0874e..c4961f18a4 100644 --- a/console/program/src/request/input_id/serialize.rs +++ b/console/program/src/request/input_id/serialize.rs @@ -93,9 +93,9 @@ impl<'de, N: Network> Deserialize<'de> for InputID { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Add test cases here to be checked for serialization. const TEST_CASES: &[&str] = &[ diff --git a/console/program/src/request/mod.rs b/console/program/src/request/mod.rs index 9fa69a0d95..a04784b76b 100644 --- a/console/program/src/request/mod.rs +++ b/console/program/src/request/mod.rs @@ -21,7 +21,7 @@ mod sign; mod string; mod verify; -use crate::{Identifier, Plaintext, ProgramID, Record, Value, ValueType}; +use crate::{compute_function_id, Identifier, Plaintext, ProgramID, Record, Value, ValueType}; use snarkvm_console_account::{Address, ComputeKey, GraphKey, PrivateKey, Signature, ViewKey}; use snarkvm_console_network::Network; use snarkvm_console_types::prelude::*; @@ -48,6 +48,8 @@ pub struct Request { tvk: Field, /// The transition commitment. tcm: Field, + /// The signer commitment. + scm: Field, } impl @@ -62,11 +64,12 @@ impl Field, Field, Field, + Field, )> for Request { /// Note: See `Request::sign` to create the request. This method is used to eject from a circuit. fn from( - (signer, network_id, program_id, function_name, input_ids, inputs, signature, sk_tag, tvk, tcm): ( + (signer, network_id, program_id, function_name, input_ids, inputs, signature, sk_tag, tvk, tcm, scm): ( Address, U16, ProgramID, @@ -77,13 +80,14 @@ impl Field, Field, Field, + Field, ), ) -> Self { // Ensure the network ID is correct. if *network_id != N::ID { N::halt(format!("Invalid network ID. Expected {}, found {}", N::ID, *network_id)) } else { - Self { signer, network_id, program_id, function_name, input_ids, inputs, signature, sk_tag, tvk, tcm } + Self { signer, network_id, program_id, function_name, input_ids, inputs, signature, sk_tag, tvk, tcm, scm } } } } @@ -150,14 +154,19 @@ impl Request { pub const fn tcm(&self) -> &Field { &self.tcm } + + /// Returns the signer commitment `scm`. + pub const fn scm(&self) -> &Field { + &self.scm + } } #[cfg(test)] mod test_helpers { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1000; @@ -184,6 +193,9 @@ mod test_helpers { let input_external_record = Value::from_str(&record_string).unwrap(); let inputs = vec![input_constant, input_public, input_private, input_record, input_external_record]; + // Construct 'is_root'. + let is_root = false; + // Construct the input types. let input_types = [ ValueType::from_str("amount.constant").unwrap(), @@ -193,10 +205,13 @@ mod test_helpers { ValueType::from_str("token.aleo/token.record").unwrap(), ]; + // Sample root_tvk. + let root_tvk = None; + // Compute the signed request. let request = - Request::sign(&private_key, program_id, function_name, inputs.into_iter(), &input_types, rng).unwrap(); - assert!(request.verify(&input_types)); + Request::sign(&private_key, program_id, function_name, inputs.into_iter(), &input_types, root_tvk, is_root, rng).unwrap(); + assert!(request.verify(&input_types, is_root)); request }) .collect() diff --git a/console/program/src/request/serialize.rs b/console/program/src/request/serialize.rs index 905b67d991..34c8f73ace 100644 --- a/console/program/src/request/serialize.rs +++ b/console/program/src/request/serialize.rs @@ -21,7 +21,7 @@ impl Serialize for Request { fn serialize(&self, serializer: S) -> Result { match serializer.is_human_readable() { true => { - let mut transition = serializer.serialize_struct("Request", 10)?; + let mut transition = serializer.serialize_struct("Request", 11)?; transition.serialize_field("signer", &self.signer)?; transition.serialize_field("network", &self.network_id)?; transition.serialize_field("program", &self.program_id)?; @@ -32,6 +32,7 @@ impl Serialize for Request { transition.serialize_field("sk_tag", &self.sk_tag)?; transition.serialize_field("tvk", &self.tvk)?; transition.serialize_field("tcm", &self.tcm)?; + transition.serialize_field("scm", &self.scm)?; transition.end() } false => ToBytesSerializer::serialize_with_size_encoding(self, serializer), @@ -68,6 +69,8 @@ impl<'de, N: Network> Deserialize<'de> for Request { DeserializeExt::take_from_value::(&mut request, "tvk")?, // Retrieve the `tcm`. DeserializeExt::take_from_value::(&mut request, "tcm")?, + // Retrieve the `scm`. + DeserializeExt::take_from_value::(&mut request, "scm")?, ))) } false => FromBytesDeserializer::::deserialize_with_size_encoding(deserializer, "request"), diff --git a/console/program/src/request/sign.rs b/console/program/src/request/sign.rs index c71c7fa56a..47751b8bf7 100644 --- a/console/program/src/request/sign.rs +++ b/console/program/src/request/sign.rs @@ -24,6 +24,8 @@ impl Request { function_name: Identifier, inputs: impl ExactSizeIterator>>, input_types: &[ValueType], + root_tvk: Option>, + is_root: bool, rng: &mut R, ) -> Result { // Ensure the number of inputs matches the number of input types. @@ -63,16 +65,21 @@ impl Request { let tvk = (*signer * r).to_x_coordinate(); // Compute the transition commitment `tcm` as `Hash(tvk)`. let tcm = N::hash_psd2(&[tvk])?; + // Compute the signer commitment `scm` as `Hash(signer || root_tvk)`. + let root_tvk = root_tvk.unwrap_or(tvk); + let scm = N::hash_psd2(&[signer.deref().to_x_coordinate(), root_tvk])?; + // Compute 'is_root' as a field element. + let is_root = if is_root { Field::::one() } else { Field::::zero() }; - // Compute the function ID as `Hash(network_id, program_id, function_name)`. - let function_id = N::hash_bhp1024( - &(U16::::new(N::ID), program_id.name(), program_id.network(), function_name).to_bits_le(), - )?; + // Retrieve the network ID. + let network_id = U16::new(N::ID); + // Compute the function ID. + let function_id = compute_function_id(&network_id, &program_id, &function_name)?; // Construct the hash input as `(r * G, pk_sig, pr_sig, signer, [tvk, tcm, function ID, input IDs])`. let mut message = Vec::with_capacity(9 + 2 * inputs.len()); message.extend([g_r, pk_sig, pr_sig, *signer].map(|point| point.to_x_coordinate())); - message.extend([tvk, tcm, function_id]); + message.extend([tvk, tcm, function_id, is_root]); // Initialize a vector to store the prepared inputs. let mut prepared_inputs = Vec::with_capacity(inputs.len()); @@ -222,7 +229,7 @@ impl Request { Ok(Self { signer, - network_id: U16::new(N::ID), + network_id, program_id, function_name, input_ids, @@ -231,6 +238,7 @@ impl Request { sk_tag, tvk, tcm, + scm, }) } } diff --git a/console/program/src/request/verify.rs b/console/program/src/request/verify.rs index c1004818c4..d2f1f6739a 100644 --- a/console/program/src/request/verify.rs +++ b/console/program/src/request/verify.rs @@ -19,7 +19,7 @@ impl Request { /// /// Verifies (challenge == challenge') && (address == address') && (serial_numbers == serial_numbers') where: /// challenge' := HashToScalar(r * G, pk_sig, pr_sig, signer, \[tvk, tcm, function ID, input IDs\]) - pub fn verify(&self, input_types: &[ValueType]) -> bool { + pub fn verify(&self, input_types: &[ValueType], is_root: bool) -> bool { // Verify the transition public key, transition view key, and transition commitment are well-formed. { // Compute the transition commitment `tcm` as `Hash(tvk)`. @@ -43,11 +43,8 @@ impl Request { // Retrieve the response from the signature. let response = self.signature.response(); - // Compute the function ID as `Hash(network_id, program_id, function_name)`. - let function_id = match N::hash_bhp1024( - &(U16::::new(N::ID), self.program_id.name(), self.program_id.network(), &self.function_name) - .to_bits_le(), - ) { + // Compute the function ID. + let function_id = match compute_function_id(&self.network_id, &self.program_id, &self.function_name) { Ok(function_id) => function_id, Err(error) => { eprintln!("Failed to construct the function ID: {error}"); @@ -55,11 +52,15 @@ impl Request { } }; + // Compute the 'is_root' field. + let is_root = if is_root { Field::::one() } else { Field::::zero() }; + // Construct the signature message as `[tvk, tcm, function ID, input IDs]`. let mut message = Vec::with_capacity(3 + self.input_ids.len()); message.push(self.tvk); message.push(self.tcm); message.push(function_id); + message.push(is_root); if let Err(error) = self.input_ids.iter().zip_eq(&self.inputs).zip_eq(input_types).enumerate().try_for_each( |(index, ((input_id, input), input_type))| { @@ -210,9 +211,9 @@ impl Request { mod tests { use super::*; use snarkvm_console_account::PrivateKey; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; pub(crate) const ITERATIONS: usize = 1000; @@ -251,10 +252,24 @@ mod tests { ValueType::from_str("token.aleo/token.record").unwrap(), ]; + // Sample 'root_tvk'. + let root_tvk = None; + // Sample 'is_root'. + let is_root = Uniform::rand(rng); + // Compute the signed request. - let request = - Request::sign(&private_key, program_id, function_name, inputs.into_iter(), &input_types, rng).unwrap(); - assert!(request.verify(&input_types)); + let request = Request::sign( + &private_key, + program_id, + function_name, + inputs.into_iter(), + &input_types, + root_tvk, + is_root, + rng, + ) + .unwrap(); + assert!(request.verify(&input_types, is_root)); } } } diff --git a/console/program/src/response/mod.rs b/console/program/src/response/mod.rs index 1c3d774b0b..f54e7f9dca 100644 --- a/console/program/src/response/mod.rs +++ b/console/program/src/response/mod.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::{Identifier, ProgramID, Register, Value, ValueType}; +use crate::{compute_function_id, Identifier, ProgramID, Register, Value, ValueType}; use snarkvm_console_network::Network; use snarkvm_console_types::prelude::*; @@ -60,9 +60,8 @@ impl Response { output_types: &[ValueType], output_operands: &[Option>], ) -> Result { - // Compute the function ID as `Hash(network_id, program_id, function_name)`. - let function_id = - N::hash_bhp1024(&(*network_id, program_id.name(), program_id.network(), function_name).to_bits_le())?; + // Compute the function ID. + let function_id = compute_function_id(network_id, program_id, function_name)?; // Compute the output IDs. let output_ids = outputs diff --git a/console/program/src/state_path/bytes.rs b/console/program/src/state_path/bytes.rs index 13a42f96ff..4b4334fadd 100644 --- a/console/program/src/state_path/bytes.rs +++ b/console/program/src/state_path/bytes.rs @@ -94,9 +94,9 @@ impl ToBytes for StatePath { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: usize = 100; diff --git a/console/program/src/state_path/configuration/mod.rs b/console/program/src/state_path/configuration/mod.rs index b8ddef30cf..80b920510f 100644 --- a/console/program/src/state_path/configuration/mod.rs +++ b/console/program/src/state_path/configuration/mod.rs @@ -19,14 +19,18 @@ use snarkvm_console_network::BHPMerkleTree; pub const BLOCKS_DEPTH: u8 = 32; /// The depth of the Merkle tree for the block header. pub const HEADER_DEPTH: u8 = 3; +/// The depth of the Merkle tree for finalize operations in a transaction. +pub const FINALIZE_ID_DEPTH: u8 = TRANSACTION_DEPTH + 4; // '+ 4' is to support 16 finalize operations per transition. /// The depth of the Merkle tree for finalize operations in a block. -pub const FINALIZE_OPERATIONS_DEPTH: u8 = 20; +pub const FINALIZE_OPERATIONS_DEPTH: u8 = TRANSACTIONS_DEPTH; /// The depth of the Merkle tree for the ratifications in a block. pub const RATIFICATIONS_DEPTH: u8 = 16; /// The depth the Merkle tree for the subdag certificates in a block. pub const SUBDAG_CERTIFICATES_DEPTH: u8 = 16; /// The depth of the Merkle tree for transactions in a block. -pub const TRANSACTIONS_DEPTH: u8 = 16; +/// Note: The technical limit is 2^20 - 1 transactions, to allow compatibility with the +/// finalize operations tree, which requires 1 leaf for the ratified finalize ID. +pub const TRANSACTIONS_DEPTH: u8 = 20; /// The depth of the Merkle tree for the transaction. pub const TRANSACTION_DEPTH: u8 = 5; /// The depth of the Merkle tree for the transition. @@ -67,7 +71,7 @@ mod tests { use super::*; use snarkvm_console_network::Network; - type CurrentNetwork = snarkvm_console_network::Testnet3; + type CurrentNetwork = snarkvm_console_network::MainnetV0; #[test] fn test_transaction_depth_is_correct() { diff --git a/console/program/src/state_path/header_leaf/mod.rs b/console/program/src/state_path/header_leaf/mod.rs index 1768af8046..ecfc8fc53f 100644 --- a/console/program/src/state_path/header_leaf/mod.rs +++ b/console/program/src/state_path/header_leaf/mod.rs @@ -49,9 +49,9 @@ impl HeaderLeaf { #[cfg(test)] mod test_helpers { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; pub(super) fn sample_leaf(rng: &mut TestRng) -> HeaderLeaf { // Construct a new leaf. diff --git a/console/program/src/state_path/mod.rs b/console/program/src/state_path/mod.rs index 2ff02b04b4..ce3b719d88 100644 --- a/console/program/src/state_path/mod.rs +++ b/console/program/src/state_path/mod.rs @@ -280,7 +280,7 @@ pub mod test_helpers { let header_path = header_tree.prove(1, &header_leaf.to_bits_le())?; let previous_block_hash: N::BlockHash = Field::::rand(rng).into(); - let preimage = (*previous_block_hash).to_bits_le().into_iter().chain(header_root.to_bits_le().into_iter()); + let preimage = (*previous_block_hash).to_bits_le().into_iter().chain(header_root.to_bits_le()); let block_hash = N::hash_bhp1024(&preimage.collect::>())?; // Construct the global state root and block path. diff --git a/console/program/src/state_path/parse.rs b/console/program/src/state_path/parse.rs index de701da6b7..cff85c3bdd 100644 --- a/console/program/src/state_path/parse.rs +++ b/console/program/src/state_path/parse.rs @@ -74,9 +74,9 @@ impl Display for StatePath { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: usize = 100; diff --git a/console/program/src/state_path/serialize.rs b/console/program/src/state_path/serialize.rs index 119104105a..6ec1821db4 100644 --- a/console/program/src/state_path/serialize.rs +++ b/console/program/src/state_path/serialize.rs @@ -37,9 +37,9 @@ impl<'de, N: Network> Deserialize<'de> for StatePath { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: usize = 100; diff --git a/console/program/src/state_path/transaction_leaf/mod.rs b/console/program/src/state_path/transaction_leaf/mod.rs index 1f3da92793..ef824af4d2 100644 --- a/console/program/src/state_path/transaction_leaf/mod.rs +++ b/console/program/src/state_path/transaction_leaf/mod.rs @@ -71,9 +71,9 @@ impl TransactionLeaf { #[cfg(test)] mod test_helpers { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; pub(super) fn sample_leaf(rng: &mut TestRng) -> TransactionLeaf { // Construct a new leaf. diff --git a/console/program/src/state_path/transition_leaf/mod.rs b/console/program/src/state_path/transition_leaf/mod.rs index 53e84eac0b..edd79d5e61 100644 --- a/console/program/src/state_path/transition_leaf/mod.rs +++ b/console/program/src/state_path/transition_leaf/mod.rs @@ -71,9 +71,9 @@ impl TransitionLeaf { #[cfg(test)] mod test_helpers { use super::*; - use snarkvm_console_network::Testnet3; + use snarkvm_console_network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; pub(super) fn sample_leaf(rng: &mut TestRng) -> TransitionLeaf { // Construct a new leaf. diff --git a/console/program/src/state_path/verify.rs b/console/program/src/state_path/verify.rs index fe44638b89..8b93397e2d 100644 --- a/console/program/src/state_path/verify.rs +++ b/console/program/src/state_path/verify.rs @@ -133,9 +133,9 @@ impl StatePath { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::{prelude::TestRng, Testnet3}; + use snarkvm_console_network::{prelude::TestRng, MainnetV0}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: usize = 100; diff --git a/console/types/Cargo.toml b/console/types/Cargo.toml index 17dc90de05..f2b0d934ed 100644 --- a/console/types/Cargo.toml +++ b/console/types/Cargo.toml @@ -1,50 +1,61 @@ [package] name = "snarkvm-console-types" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Console types for a decentralized virtual machine" license = "Apache-2.0" edition = "2021" +[[bench]] +name = "group" +path = "benches/group.rs" +harness = false + [dependencies.snarkvm-console-network-environment] path = "../network/environment" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-types-address] path = "./address" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-console-types-boolean] path = "./boolean" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-console-types-field] path = "./field" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-console-types-group] path = "./group" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-console-types-integers] path = "./integers" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-console-types-scalar] path = "./scalar" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-console-types-string] path = "./string" -version = "=0.16.15" +version = "=0.16.19" optional = true +[dev-dependencies.criterion] +version = "0.5.1" + +[dev-dependencies.snarkvm-console-network] +path = "../network" + [features] default = [ "address", diff --git a/console/types/address/Cargo.toml b/console/types/address/Cargo.toml index 2c17e364a5..92fa744b6d 100644 --- a/console/types/address/Cargo.toml +++ b/console/types/address/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-console-types-address" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Type operations for a decentralized virtual machine" license = "Apache-2.0" @@ -8,19 +8,19 @@ edition = "2021" [dependencies.snarkvm-console-network-environment] path = "../../network/environment" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-types-boolean] path = "../boolean" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-types-field] path = "../field" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-types-group] path = "../group" -version = "=0.16.15" +version = "=0.16.19" [dev-dependencies.bincode] version = "1.3" diff --git a/console/types/address/src/from_bits.rs b/console/types/address/src/from_bits.rs index 6b7df16c23..f344d1252c 100644 --- a/console/types/address/src/from_bits.rs +++ b/console/types/address/src/from_bits.rs @@ -49,7 +49,7 @@ mod tests { assert_eq!(expected, candidate); // Add excess zero bits. - let candidate = vec![given_bits, vec![false; i]].concat(); + let candidate = [given_bits, vec![false; i]].concat(); let candidate = Address::::from_bits_le(&candidate)?; assert_eq!(expected, candidate); @@ -72,7 +72,7 @@ mod tests { assert_eq!(expected, candidate); // Add excess zero bits. - let candidate = vec![vec![false; i], given_bits].concat(); + let candidate = [vec![false; i], given_bits].concat(); let candidate = Address::::from_bits_be(&candidate)?; assert_eq!(expected, candidate); diff --git a/console/types/benches/group.rs b/console/types/benches/group.rs new file mode 100644 index 0000000000..4bd36e6b31 --- /dev/null +++ b/console/types/benches/group.rs @@ -0,0 +1,84 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the snarkVM library. + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[macro_use] +extern crate criterion; + +use criterion::Criterion; +use snarkvm_console_network::{environment::prelude::*, MainnetV0}; +use snarkvm_console_types::{Field, Group}; + +type CurrentNetwork = MainnetV0; + +fn group_from_field(c: &mut Criterion) { + let rng = &mut TestRng::default(); + + c.bench_function("group_from_field", move |b| { + let fields: Vec> = (0..1000).map(|_| rng.gen()).collect(); + + b.iter(|| { + for field in &fields { + let group = Group::from_field(field); + let _ = std::hint::black_box(group); + } + }) + }); +} + +fn group_from_field_on_curve(c: &mut Criterion) { + let rng = &mut TestRng::default(); + + c.bench_function("group_from_field_on_curve", move |b| { + type Projective = ::Projective; + + let fields: Vec> = + (0..1000).map(|_| rng.gen::().to_affine().to_x_coordinate()).map(Field::new).collect(); + + b.iter(|| { + for field in &fields { + let group = Group::from_field(field); + let _ = std::hint::black_box(group); + } + }) + }); +} + +fn group_from_field_off_curve(c: &mut Criterion) { + let rng = &mut TestRng::default(); + + c.bench_function("group_from_field_off_curve", move |b| { + type Affine = ::Affine; + + let fields: Vec<_> = std::iter::repeat(()) + .map(|_| rng.gen::>()) + .filter(|&field| Affine::from_x_coordinate(*field, true).is_none()) + .take(1000) + .collect(); + + b.iter(|| { + for field in &fields { + let group = Group::from_field(field); + let _ = std::hint::black_box(group); + } + }) + }); +} + +criterion_group! { + name = group; + config = Criterion::default().sample_size(20); + targets = group_from_field, group_from_field_on_curve, group_from_field_off_curve +} + +criterion_main!(group); diff --git a/console/types/boolean/Cargo.toml b/console/types/boolean/Cargo.toml index be2c33dbee..7403db92e6 100644 --- a/console/types/boolean/Cargo.toml +++ b/console/types/boolean/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-console-types-boolean" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Type operations for a decentralized virtual machine" license = "Apache-2.0" @@ -8,7 +8,7 @@ edition = "2021" [dependencies.snarkvm-console-network-environment] path = "../../network/environment" -version = "=0.16.15" +version = "=0.16.19" [dev-dependencies.bincode] version = "1.3" diff --git a/console/types/boolean/src/from_bits.rs b/console/types/boolean/src/from_bits.rs index 3cf131b005..173572f188 100644 --- a/console/types/boolean/src/from_bits.rs +++ b/console/types/boolean/src/from_bits.rs @@ -54,7 +54,7 @@ mod tests { assert_eq!(expected, candidate); // Add excess zero bits. - let candidate = vec![given_bits, vec![false; i]].concat(); + let candidate = [given_bits, vec![false; i]].concat(); assert!(Boolean::::from_bits_le(&candidate).is_err()); } Ok(()) @@ -73,7 +73,7 @@ mod tests { assert_eq!(expected, candidate); // Add excess zero bits. - let candidate = vec![vec![false; i], given_bits].concat(); + let candidate = [vec![false; i], given_bits].concat(); assert!(Boolean::::from_bits_be(&candidate).is_err()); } Ok(()) diff --git a/console/types/field/Cargo.toml b/console/types/field/Cargo.toml index bc29ee8fde..c8be7daf1d 100644 --- a/console/types/field/Cargo.toml +++ b/console/types/field/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-console-types-field" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Type operations for a decentralized virtual machine" license = "Apache-2.0" @@ -8,11 +8,11 @@ edition = "2021" [dependencies.snarkvm-console-network-environment] path = "../../network/environment" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-types-boolean] path = "../boolean" -version = "=0.16.15" +version = "=0.16.19" [dependencies.zeroize] version = "1" diff --git a/console/types/field/src/from_bits.rs b/console/types/field/src/from_bits.rs index 18e1ea02a5..ad79a3685e 100644 --- a/console/types/field/src/from_bits.rs +++ b/console/types/field/src/from_bits.rs @@ -45,12 +45,14 @@ impl FromBits for Field { // Return the field. Ok(Field { field: E::Field::from_bigint(field).ok_or_else(|| anyhow!("Invalid field from bits"))? }) } else { - // Construct the sanitized list of bits, resizing up if necessary. - let mut bits_le = bits_le.iter().take(size_in_bits).cloned().collect::>(); - bits_le.resize(size_in_bits, false); + // Construct the sanitized list of bits padded with `false` + let mut sanitized_bits = vec![false; size_in_bits]; + // Note: This is safe, because we just checked that the length of bits isn't bigger + // than `size_in_data_bits` which is equal to `size_in_bits - 1`. + sanitized_bits[..num_bits].copy_from_slice(bits_le); // Recover the native field. - let field = E::Field::from_bigint(E::BigInteger::from_bits_le(&bits_le)?) + let field = E::Field::from_bigint(E::BigInteger::from_bits_le(&sanitized_bits)?) .ok_or_else(|| anyhow!("Invalid field from bits"))?; // Return the field. @@ -91,7 +93,7 @@ mod tests { assert_eq!(expected, candidate); // Add excess zero bits. - let candidate = vec![given_bits, vec![false; i]].concat(); + let candidate = [given_bits, vec![false; i]].concat(); let candidate = Field::::from_bits_le(&candidate)?; assert_eq!(expected, candidate); @@ -113,7 +115,7 @@ mod tests { assert_eq!(expected, candidate); // Add excess zero bits. - let candidate = vec![vec![false; i], given_bits].concat(); + let candidate = [vec![false; i], given_bits].concat(); let candidate = Field::::from_bits_be(&candidate)?; assert_eq!(expected, candidate); diff --git a/console/types/group/Cargo.toml b/console/types/group/Cargo.toml index 4fc8365c8f..fd4bfc7611 100644 --- a/console/types/group/Cargo.toml +++ b/console/types/group/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-console-types-group" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Type operations for a decentralized virtual machine" license = "Apache-2.0" @@ -8,19 +8,19 @@ edition = "2021" [dependencies.snarkvm-console-network-environment] path = "../../network/environment" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-types-boolean] path = "../boolean" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-types-field] path = "../field" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-types-scalar] path = "../scalar" -version = "=0.16.15" +version = "=0.16.19" [dev-dependencies.bincode] version = "1.3" diff --git a/console/types/group/src/from_bits.rs b/console/types/group/src/from_bits.rs index c8eafc873a..d5c9188d54 100644 --- a/console/types/group/src/from_bits.rs +++ b/console/types/group/src/from_bits.rs @@ -48,7 +48,7 @@ mod tests { assert_eq!(expected, candidate); // Add excess zero bits. - let candidate = vec![given_bits, vec![false; i]].concat(); + let candidate = [given_bits, vec![false; i]].concat(); let candidate = Group::::from_bits_le(&candidate)?; assert_eq!(expected, candidate); @@ -70,7 +70,7 @@ mod tests { assert_eq!(expected, candidate); // Add excess zero bits. - let candidate = vec![vec![false; i], given_bits].concat(); + let candidate = [vec![false; i], given_bits].concat(); let candidate = Group::::from_bits_be(&candidate)?; assert_eq!(expected, candidate); diff --git a/console/types/group/src/from_x_coordinate.rs b/console/types/group/src/from_x_coordinate.rs index 62a075b42a..f8be208f71 100644 --- a/console/types/group/src/from_x_coordinate.rs +++ b/console/types/group/src/from_x_coordinate.rs @@ -18,14 +18,11 @@ impl Group { /// Attempts to recover an affine group element from a given x-coordinate field element. /// For safety, the resulting point is always enforced to be on the curve and in the correct subgroup. pub fn from_x_coordinate(x_coordinate: Field) -> Result { - if let Some(point) = E::Affine::from_x_coordinate(*x_coordinate, true) { - if point.is_in_correct_subgroup_assuming_on_curve() { - return Ok(Self::new(point)); - } - } - if let Some(point) = E::Affine::from_x_coordinate(*x_coordinate, false) { - if point.is_in_correct_subgroup_assuming_on_curve() { - return Ok(Self::new(point)); + if let Some((p1, p2)) = E::Affine::pair_from_x_coordinate(*x_coordinate) { + for point in [p2, p1] { + if point.is_in_correct_subgroup_assuming_on_curve() { + return Ok(Self::new(point)); + } } } bail!("Failed to recover an affine group from an x-coordinate of {x_coordinate}") diff --git a/console/types/integers/Cargo.toml b/console/types/integers/Cargo.toml index 0b35f6f1a8..1da2502c68 100644 --- a/console/types/integers/Cargo.toml +++ b/console/types/integers/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-console-types-integers" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Type operations for a decentralized virtual machine" license = "Apache-2.0" @@ -8,19 +8,19 @@ edition = "2021" [dependencies.snarkvm-console-network-environment] path = "../../network/environment" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-types-boolean] path = "../boolean" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-types-field] path = "../field" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-types-scalar] path = "../scalar" -version = "=0.16.15" +version = "=0.16.19" [dev-dependencies.bincode] version = "1.3" diff --git a/console/types/integers/src/from_bits.rs b/console/types/integers/src/from_bits.rs index 98381be72b..87290176de 100644 --- a/console/types/integers/src/from_bits.rs +++ b/console/types/integers/src/from_bits.rs @@ -48,7 +48,7 @@ mod tests { assert_eq!(expected, candidate); // Add excess zero bits. - let candidate = vec![given_bits, vec![false; i]].concat(); + let candidate = [given_bits, vec![false; i]].concat(); let candidate = Integer::::from_bits_le(&candidate)?; assert_eq!(expected, candidate); @@ -70,7 +70,7 @@ mod tests { assert_eq!(expected, candidate); // Add excess zero bits. - let candidate = vec![vec![false; i], given_bits].concat(); + let candidate = [vec![false; i], given_bits].concat(); let candidate = Integer::::from_bits_be(&candidate)?; assert_eq!(expected, candidate); diff --git a/console/types/integers/src/lib.rs b/console/types/integers/src/lib.rs index 2142ae50de..bfc0d0b2b7 100644 --- a/console/types/integers/src/lib.rs +++ b/console/types/integers/src/lib.rs @@ -38,9 +38,7 @@ mod zero; pub use snarkvm_console_network_environment::prelude::*; pub use snarkvm_console_types_boolean::Boolean; pub use snarkvm_console_types_field::Field; - -use snarkvm_console_network_environment::traits::types::{integer_magnitude::Magnitude, integer_type::IntegerType}; -use snarkvm_console_types_scalar::Scalar; +pub use snarkvm_console_types_scalar::Scalar; use core::marker::PhantomData; diff --git a/console/types/scalar/Cargo.toml b/console/types/scalar/Cargo.toml index 03db6c53ec..944a20d5d4 100644 --- a/console/types/scalar/Cargo.toml +++ b/console/types/scalar/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-console-types-scalar" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Type operations for a decentralized virtual machine" license = "Apache-2.0" @@ -8,15 +8,15 @@ edition = "2021" [dependencies.snarkvm-console-network-environment] path = "../../network/environment" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-types-boolean] path = "../boolean" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-types-field] path = "../field" -version = "=0.16.15" +version = "=0.16.19" [dependencies.zeroize] version = "1" diff --git a/console/types/scalar/src/from_bits.rs b/console/types/scalar/src/from_bits.rs index 25b98715b7..4f9a123bfb 100644 --- a/console/types/scalar/src/from_bits.rs +++ b/console/types/scalar/src/from_bits.rs @@ -48,12 +48,14 @@ impl FromBits for Scalar { // Return the scalar. Ok(Scalar { scalar: E::Scalar::from_bigint(scalar).ok_or_else(|| anyhow!("Invalid scalar from bits"))? }) } else { - // Construct the sanitized list of bits, resizing up if necessary. - let mut bits_le = bits_le.iter().take(size_in_bits).cloned().collect::>(); - bits_le.resize(size_in_bits, false); + // Construct the sanitized list of bits padded with `false` + let mut sanitized_bits = vec![false; size_in_bits]; + // Note: This is safe, because we just checked that the length of bits isn't bigger + // than `size_in_data_bits` which is equal to `size_in_bits - 1`. + sanitized_bits[..num_bits].copy_from_slice(bits_le); // Recover the native scalar. - let scalar = E::Scalar::from_bigint(E::BigInteger::from_bits_le(&bits_le)?) + let scalar = E::Scalar::from_bigint(E::BigInteger::from_bits_le(&sanitized_bits)?) .ok_or_else(|| anyhow!("Invalid scalar from bits"))?; // Return the scalar. @@ -94,7 +96,7 @@ mod tests { assert_eq!(expected, candidate); // Add excess zero bits. - let candidate = vec![given_bits, vec![false; i]].concat(); + let candidate = [given_bits, vec![false; i]].concat(); let candidate = Scalar::::from_bits_le(&candidate)?; assert_eq!(expected, candidate); @@ -116,7 +118,7 @@ mod tests { assert_eq!(expected, candidate); // Add excess zero bits. - let candidate = vec![vec![false; i], given_bits].concat(); + let candidate = [vec![false; i], given_bits].concat(); let candidate = Scalar::::from_bits_be(&candidate)?; assert_eq!(expected, candidate); diff --git a/console/types/string/Cargo.toml b/console/types/string/Cargo.toml index 4e98ffd9e0..aea2da4af3 100644 --- a/console/types/string/Cargo.toml +++ b/console/types/string/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-console-types-string" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Type operations for a decentralized virtual machine" license = "Apache-2.0" @@ -8,19 +8,19 @@ edition = "2021" [dependencies.snarkvm-console-network-environment] path = "../../network/environment" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-types-boolean] path = "../boolean" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-types-field] path = "../field" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-console-types-integers] path = "../integers" -version = "=0.16.15" +version = "=0.16.19" [dev-dependencies.bincode] version = "1.3" diff --git a/curves/Cargo.toml b/curves/Cargo.toml index 369622d10e..8d4c7c3dd0 100644 --- a/curves/Cargo.toml +++ b/curves/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-curves" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Curves for a decentralized virtual machine" homepage = "https://aleo.org" @@ -36,12 +36,12 @@ harness = false [dependencies.snarkvm-fields] path = "../fields" -version = "=0.16.15" +version = "=0.16.19" default-features = false [dependencies.snarkvm-utilities] path = "../utilities" -version = "=0.16.15" +version = "=0.16.19" default-features = false [dependencies.rand] diff --git a/curves/src/bls12_377/fq.rs b/curves/src/bls12_377/fq.rs index fa333b8217..1bcd522597 100644 --- a/curves/src/bls12_377/fq.rs +++ b/curves/src/bls12_377/fq.rs @@ -24,6 +24,7 @@ use snarkvm_utilities::biginteger::BigInteger384 as BigInteger; pub type Fq = Fp384; +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)] pub struct FqParameters; impl Fp384Parameters for FqParameters {} diff --git a/curves/src/bls12_377/fq12.rs b/curves/src/bls12_377/fq12.rs index a94da8470f..165599a37f 100644 --- a/curves/src/bls12_377/fq12.rs +++ b/curves/src/bls12_377/fq12.rs @@ -19,7 +19,7 @@ use crate::bls12_377::{Fq, Fq2, Fq6Parameters}; pub type Fq12 = Fp12; -#[derive(Clone, Copy)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)] pub struct Fq12Parameters; impl Fp12Parameters for Fq12Parameters { diff --git a/curves/src/bls12_377/fq2.rs b/curves/src/bls12_377/fq2.rs index 649cf6d33b..fbaffb2c7e 100644 --- a/curves/src/bls12_377/fq2.rs +++ b/curves/src/bls12_377/fq2.rs @@ -21,7 +21,7 @@ use crate::bls12_377::Fq; pub type Fq2 = Fp2; -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct Fq2Parameters; impl Fp2Parameters for Fq2Parameters { diff --git a/curves/src/bls12_377/fq6.rs b/curves/src/bls12_377/fq6.rs index 35a420d298..841c81dabc 100644 --- a/curves/src/bls12_377/fq6.rs +++ b/curves/src/bls12_377/fq6.rs @@ -23,7 +23,7 @@ use crate::bls12_377::{Fq, Fq2, Fq2Parameters}; pub type Fq6 = Fp6; -#[derive(Clone, Copy)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)] pub struct Fq6Parameters; impl Fp6Parameters for Fq6Parameters { diff --git a/curves/src/bls12_377/fr.rs b/curves/src/bls12_377/fr.rs index 9756f51950..67de1ab1ad 100644 --- a/curves/src/bls12_377/fr.rs +++ b/curves/src/bls12_377/fr.rs @@ -47,6 +47,7 @@ use snarkvm_utilities::biginteger::BigInteger256 as BigInteger; /// ``` pub type Fr = Fp256; +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)] pub struct FrParameters; impl Fp256Parameters for FrParameters {} diff --git a/curves/src/edwards_bls12/fr.rs b/curves/src/edwards_bls12/fr.rs index 1e8f9c1b85..0ed9d8e233 100644 --- a/curves/src/edwards_bls12/fr.rs +++ b/curves/src/edwards_bls12/fr.rs @@ -24,6 +24,7 @@ use snarkvm_utilities::biginteger::BigInteger256 as BigInteger; pub type Fr = Fp256; +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)] pub struct FrParameters; impl Fp256Parameters for FrParameters {} diff --git a/curves/src/templates/short_weierstrass_jacobian/affine.rs b/curves/src/templates/short_weierstrass_jacobian/affine.rs index 49799cb7ea..d5cbe730f5 100644 --- a/curves/src/templates/short_weierstrass_jacobian/affine.rs +++ b/curves/src/templates/short_weierstrass_jacobian/affine.rs @@ -148,6 +148,18 @@ impl AffineCurve for Affine

{ }) } + /// Attempts to construct both possible affine points given an x-coordinate. + /// Points are not guaranteed to be in the prime order subgroup. + /// + /// The affine points returned should be in lexicographically growing order. + /// + /// Calling this should be equivalent (but likely more performant) to + /// `(AffineCurve::from_x_coordinate(x, false), AffineCurve::from_x_coordinate(x, true))`. + #[inline] + fn pair_from_x_coordinate(x: Self::BaseField) -> Option<(Self, Self)> { + Self::from_x_coordinate(x, false).map(|p1| (p1, Self::new(p1.x, -p1.y, false))) + } + /// Attempts to construct an affine point given a y-coordinate. The /// point is not guaranteed to be in the prime order subgroup. /// diff --git a/curves/src/templates/short_weierstrass_jacobian/tests.rs b/curves/src/templates/short_weierstrass_jacobian/tests.rs index 623d7fc026..b8f94bbd23 100644 --- a/curves/src/templates/short_weierstrass_jacobian/tests.rs +++ b/curves/src/templates/short_weierstrass_jacobian/tests.rs @@ -29,6 +29,7 @@ pub const ITERATIONS: usize = 10; pub fn sw_tests(rng: &mut TestRng) { sw_curve_serialization_test::

(rng); sw_from_random_bytes::

(rng); + sw_from_x_coordinate::

(rng); } pub fn sw_curve_serialization_test(rng: &mut TestRng) { @@ -138,3 +139,23 @@ pub fn sw_from_random_bytes(rng: &mut TestRng) { } } } + +pub fn sw_from_x_coordinate(rng: &mut TestRng) { + for _ in 0..ITERATIONS { + let a = Projective::

::rand(rng); + let a = a.to_affine(); + { + let x = a.x; + + let a1 = Affine::

::from_x_coordinate(x, true).unwrap(); + let a2 = Affine::

::from_x_coordinate(x, false).unwrap(); + + assert!(a == a1 || a == a2); + + let (b2, b1) = Affine::

::pair_from_x_coordinate(x).unwrap(); + + assert_eq!(a1, b1); + assert_eq!(a2, b2); + } + } +} diff --git a/curves/src/templates/twisted_edwards_extended/affine.rs b/curves/src/templates/twisted_edwards_extended/affine.rs index 1be2c48122..d850729e4b 100644 --- a/curves/src/templates/twisted_edwards_extended/affine.rs +++ b/curves/src/templates/twisted_edwards_extended/affine.rs @@ -148,6 +148,18 @@ impl AffineCurve for Affine

{ }) } + /// Attempts to construct both possible affine points given an x-coordinate. + /// Points are not guaranteed to be in the prime order subgroup. + /// + /// The affine points returned should be in lexicographically growing order. + /// + /// Calling this should be equivalent (but likely more performant) to + /// `(AffineCurve::from_x_coordinate(x, false), AffineCurve::from_x_coordinate(x, true))`. + #[inline] + fn pair_from_x_coordinate(x: Self::BaseField) -> Option<(Self, Self)> { + Self::from_x_coordinate(x, false).map(|p1| (p1, Self::new(p1.x, -p1.y, -p1.t))) + } + /// Attempts to construct an affine point given a y-coordinate. The /// point is not guaranteed to be in the prime order subgroup. /// @@ -168,6 +180,7 @@ impl AffineCurve for Affine

{ }) } + #[inline] fn mul_bits(&self, bits: impl Iterator) -> Projective

{ let mut res = Projective::zero(); for i in bits { diff --git a/curves/src/templates/twisted_edwards_extended/tests.rs b/curves/src/templates/twisted_edwards_extended/tests.rs index f8cee43f9d..e1ccbded0d 100644 --- a/curves/src/templates/twisted_edwards_extended/tests.rs +++ b/curves/src/templates/twisted_edwards_extended/tests.rs @@ -201,6 +201,11 @@ where let a2 = Affine::

::from_x_coordinate(x, false).unwrap(); assert!(a == a1 || a == a2); + + let (b2, b1) = Affine::

::pair_from_x_coordinate(x).unwrap(); + + assert_eq!(a1, b1); + assert_eq!(a2, b2); } { let y = a.y; diff --git a/curves/src/traits/group.rs b/curves/src/traits/group.rs index a913134f6b..47f8bdcc69 100644 --- a/curves/src/traits/group.rs +++ b/curves/src/traits/group.rs @@ -164,6 +164,15 @@ pub trait AffineCurve: /// largest y-coordinate be selected. fn from_x_coordinate(x: Self::BaseField, greatest: bool) -> Option; + /// Attempts to construct both possible affine points given an x-coordinate. + /// Points are not guaranteed to be in the prime order subgroup. + /// + /// The affine points returned should be in lexicographically growing order. + /// + /// Calling this should be equivalent (but likely more performant) to + /// `(AffineCurve::from_x_coordinate(x, false), AffineCurve::from_x_coordinate(x, true))`. + fn pair_from_x_coordinate(x: Self::BaseField) -> Option<(Self, Self)>; + /// Attempts to construct an affine point given a y-coordinate. The /// point is not guaranteed to be in the prime order subgroup. /// diff --git a/curves/src/traits/tests_projective.rs b/curves/src/traits/tests_projective.rs index 6b8da06408..b48d55d9a3 100644 --- a/curves/src/traits/tests_projective.rs +++ b/curves/src/traits/tests_projective.rs @@ -44,7 +44,7 @@ fn random_addition_test(rng: &mut TestRng) { assert_eq!(aplusa, aplusamixed); } - let mut tmp = vec![G::zero(); 6]; + let mut tmp = [G::zero(); 6]; // (a + b) + c tmp[0] = (a + b) + c; diff --git a/fields/Cargo.toml b/fields/Cargo.toml index 9f15b2f15c..df9474d09e 100644 --- a/fields/Cargo.toml +++ b/fields/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-fields" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Fields for a decentralized virtual machine" homepage = "https://aleo.org" @@ -23,21 +23,23 @@ include = [ "Cargo.toml", "src", "README.md", "LICENSE.md" ] license = "Apache-2.0" edition = "2021" +[[bench]] +name = "fields" +path = "benches/fields.rs" +harness = false + [dependencies.snarkvm-utilities] path = "../utilities" -version = "=0.16.15" +version = "=0.16.19" default-features = false [dependencies.aleo-std] -version = "0.1.18" +version = "0.1.24" default-features = false [dependencies.anyhow] version = "1.0" -[dependencies.derivative] -version = "2" - [dependencies.itertools] version = "0.11.0" @@ -63,6 +65,13 @@ version = "1.0" version = "1" features = [ "derive" ] +[dev-dependencies.criterion] +version = "0.5" + +[dev-dependencies.snarkvm-curves] +path = "../curves" +default-features = false + [features] default = [ "snarkvm-utilities/default" ] profiler = [ "aleo-std/profiler" ] diff --git a/fields/benches/fields.rs b/fields/benches/fields.rs new file mode 100644 index 0000000000..f58e4f6a64 --- /dev/null +++ b/fields/benches/fields.rs @@ -0,0 +1,163 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the snarkVM library. + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Silences the false positives caused by black_box. +#![allow(clippy::unit_arg)] + +use snarkvm_fields::{Field, Fp256, Fp384, PrimeField}; +use snarkvm_utilities::TestRng; + +use criterion::*; +use rand::Rng; +use std::{ + hint::black_box, + ops::{AddAssign, MulAssign, SubAssign}, +}; + +fn fp256(c: &mut Criterion) { + let rng = &mut TestRng::default(); + + const N: usize = 1_000; + + let mut values = Vec::with_capacity(N); + let mut arr = [0u8; 32]; + + while values.len() < N { + rng.fill(&mut arr); + if let Some(v) = Fp256::::from_random_bytes(&arr) { + values.push(v); + } + } + + c.bench_function("fp256_add_assign", |b| { + b.iter(|| { + for (mut v1, v2) in values.iter().cloned().zip(values.iter().skip(1)) { + black_box(v1.add_assign(v2)); + } + }) + }); + + c.bench_function("fp256_sub_assign", |b| { + b.iter(|| { + for (mut v1, v2) in values.iter().cloned().zip(values.iter().skip(1)) { + black_box(v1.sub_assign(v2)); + } + }) + }); + + c.bench_function("fp256_mul_assign", |b| { + b.iter(|| { + for (mut v1, v2) in values.iter().cloned().zip(values.iter().skip(1)) { + black_box(v1.mul_assign(v2)); + } + }) + }); + + c.bench_function("fp256_inverse", |b| { + b.iter(|| { + for v in values.iter() { + black_box(v.inverse()); + } + }) + }); + + c.bench_function("fp256_square_in_place", |b| { + b.iter(|| { + for mut v in values.iter().cloned() { + black_box(v.square_in_place()); + } + }) + }); + + c.bench_function("fp256_to_bigint", |b| { + b.iter(|| { + for v in values.iter() { + black_box(v.to_bigint()); + } + }) + }); +} + +fn fp384(c: &mut Criterion) { + let rng = &mut TestRng::default(); + + const N: usize = 1_000; + + let mut values = Vec::with_capacity(N); + let mut arr = [0u8; 48]; + + while values.len() < N { + rng.fill(&mut arr[..32]); + rng.fill(&mut arr[32..]); + if let Some(v) = Fp384::::from_random_bytes(&arr) { + values.push(v); + } + } + + c.bench_function("fp384_add_assign", |b| { + b.iter(|| { + for (mut v1, v2) in values.iter().cloned().zip(values.iter().skip(1)) { + black_box(v1.add_assign(v2)); + } + }) + }); + + c.bench_function("fp384_sub_assign", |b| { + b.iter(|| { + for (mut v1, v2) in values.iter().cloned().zip(values.iter().skip(1)) { + black_box(v1.sub_assign(v2)); + } + }) + }); + + c.bench_function("fp384_mul_assign", |b| { + b.iter(|| { + for (mut v1, v2) in values.iter().cloned().zip(values.iter().skip(1)) { + black_box(v1.mul_assign(v2)); + } + }) + }); + + c.bench_function("fp384_inverse", |b| { + b.iter(|| { + for v in values.iter() { + black_box(v.inverse()); + } + }) + }); + + c.bench_function("fp384_square_in_place", |b| { + b.iter(|| { + for mut v in values.iter().cloned() { + black_box(v.square_in_place()); + } + }) + }); + + c.bench_function("fp384_to_bigint", |b| { + b.iter(|| { + for v in values.iter() { + black_box(v.to_bigint()); + } + }) + }); +} + +criterion_group! { + name = fields; + config = Criterion::default(); + targets = fp256, fp384 +} + +criterion_main!(fields); diff --git a/fields/src/fp12_2over3over2.rs b/fields/src/fp12_2over3over2.rs index 7659c781a1..e7da3be7cd 100644 --- a/fields/src/fp12_2over3over2.rs +++ b/fields/src/fp12_2over3over2.rs @@ -22,48 +22,38 @@ use rand::{ use serde::{Deserialize, Serialize}; use std::{ cmp::Ordering, + fmt::Debug, + hash::Hash, io::{Read, Result as IoResult, Write}, ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}, }; -pub trait Fp12Parameters: 'static + Send + Sync + Copy { +pub trait Fp12Parameters: 'static + Copy + Clone + Debug + Default + PartialEq + Eq + Hash + Send + Sync { type Fp6Params: Fp6Parameters; /// Coefficients for the Frobenius automorphism. const FROBENIUS_COEFF_FP12_C1: [Fp2>; 12]; } +type Fp2Params

= <

::Fp6Params as Fp6Parameters>::Fp2Params; + /// An element of Fp12, represented by c0 + c1 * v -#[derive(Derivative, Serialize, Deserialize)] -#[derivative( - Default(bound = "P: Fp12Parameters"), - Hash(bound = "P: Fp12Parameters"), - Clone(bound = "P: Fp12Parameters"), - Copy(bound = "P: Fp12Parameters"), - Debug(bound = "P: Fp12Parameters"), - PartialEq(bound = "P: Fp12Parameters"), - Eq(bound = "P: Fp12Parameters") -)] -#[must_use] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct Fp12 { pub c0: Fp6, pub c1: Fp6, } -type Fp2Params

= <

::Fp6Params as Fp6Parameters>::Fp2Params; - impl Fp12

{ - /// Multiply by quadratic nonresidue v. - #[inline(always)] - pub(crate) fn mul_fp6_by_nonresidue(fe: &Fp6) -> Fp6 { - let new_c0 = P::Fp6Params::mul_fp2_by_nonresidue(&fe.c2); - let new_c1 = fe.c0; - let new_c2 = fe.c1; - Fp6::new(new_c0, new_c1, new_c2) + /// Initializes an element of `Fp12` from two `Fp6` elements. + pub const fn new(c0: Fp6, c1: Fp6) -> Self { + Self { c0, c1 } } +} - pub fn new(c0: Fp6, c1: Fp6) -> Self { - Self { c0, c1 } +impl Fp12

{ + pub fn conjugate(&mut self) { + self.c1 = self.c1.neg(); } pub fn mul_by_fp(&mut self, element: &<::Fp2Params as Fp2Parameters>::Fp) { @@ -71,8 +61,13 @@ impl Fp12

{ self.c1.mul_by_fp(element); } - pub fn conjugate(&mut self) { - self.c1 = self.c1.neg(); + /// Multiply by quadratic nonresidue v. + #[inline(always)] + pub(crate) fn mul_fp6_by_nonresidue(fe: &Fp6) -> Fp6 { + let new_c0 = P::Fp6Params::mul_fp2_by_nonresidue(&fe.c2); + let new_c1 = fe.c0; + let new_c2 = fe.c1; + Fp6::new(new_c0, new_c1, new_c2) } pub fn mul_by_034(&mut self, c0: &Fp2>, c3: &Fp2>, c4: &Fp2>) { diff --git a/fields/src/fp2.rs b/fields/src/fp2.rs index 19841a359e..528e5c3be7 100644 --- a/fields/src/fp2.rs +++ b/fields/src/fp2.rs @@ -28,11 +28,15 @@ use rand::{ use serde::{Deserialize, Serialize}; use std::{ cmp::{Ord, Ordering, PartialOrd}, + fmt::Debug, + hash::Hash, io::{Read, Result as IoResult, Write}, ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}, }; -pub trait Fp2Parameters: 'static + Send + Sync + Serialize + for<'a> Deserialize<'a> { +pub trait Fp2Parameters: + 'static + Copy + Clone + Default + Debug + PartialEq + Eq + Hash + Serialize + for<'a> Deserialize<'a> + Send + Sync +{ type Fp: PrimeField; /// Coefficients for the Frobenius automorphism. @@ -48,26 +52,20 @@ pub trait Fp2Parameters: 'static + Send + Sync + Serialize + for<'a> Deserialize } } -#[derive(Derivative, Serialize, Deserialize)] -#[derivative( - Default(bound = "P: Fp2Parameters"), - Hash(bound = "P: Fp2Parameters"), - Clone(bound = "P: Fp2Parameters"), - Copy(bound = "P: Fp2Parameters"), - Debug(bound = "P: Fp2Parameters"), - PartialEq(bound = "P: Fp2Parameters"), - Eq(bound = "P: Fp2Parameters") -)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct Fp2 { pub c0: P::Fp, pub c1: P::Fp, } impl Fp2

{ - pub fn new(c0: P::Fp, c1: P::Fp) -> Self { + /// Initializes a `Fp2` element from two `Fp` elements. + pub const fn new(c0: P::Fp, c1: P::Fp) -> Self { Fp2 { c0, c1 } } +} +impl Fp2

{ /// Norm of Fp2 over Fp: Norm(a) = a.x^2 - beta * a.y^2 pub fn norm(&self) -> P::Fp { let t0 = self.c0.square(); diff --git a/fields/src/fp6_3over2.rs b/fields/src/fp6_3over2.rs index 859e5a6613..5699630195 100644 --- a/fields/src/fp6_3over2.rs +++ b/fields/src/fp6_3over2.rs @@ -28,11 +28,13 @@ use rand::{ use serde::{Deserialize, Serialize}; use std::{ cmp::Ordering, + fmt::Debug, + hash::Hash, io::{Read, Result as IoResult, Write}, ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}, }; -pub trait Fp6Parameters: 'static + Send + Sync + Copy { +pub trait Fp6Parameters: 'static + Copy + Clone + Default + Debug + PartialEq + Eq + Hash + Send + Sync { type Fp2Params: Fp2Parameters; /// Coefficients for the Frobenius automorphism. @@ -48,16 +50,7 @@ pub trait Fp6Parameters: 'static + Send + Sync + Copy { } /// An element of Fp6, represented by c0 + c1 * v + c2 * v^(2). -#[derive(Derivative, Serialize, Deserialize)] -#[derivative( - Default(bound = "P: Fp6Parameters"), - Hash(bound = "P: Fp6Parameters"), - Clone(bound = "P: Fp6Parameters"), - Copy(bound = "P: Fp6Parameters"), - Debug(bound = "P: Fp6Parameters"), - PartialEq(bound = "P: Fp6Parameters"), - Eq(bound = "P: Fp6Parameters") -)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct Fp6 { pub c0: Fp2, pub c1: Fp2, @@ -65,7 +58,8 @@ pub struct Fp6 { } impl Fp6

{ - pub fn new(c0: Fp2, c1: Fp2, c2: Fp2) -> Self { + /// Initializes an element of `Fp6` from 3 `Fp2` elements. + pub const fn new(c0: Fp2, c1: Fp2, c2: Fp2) -> Self { Self { c0, c1, c2 } } diff --git a/fields/src/fp_256.rs b/fields/src/fp_256.rs index 15af78a1e1..80f69a635b 100644 --- a/fields/src/fp_256.rs +++ b/fields/src/fp_256.rs @@ -47,21 +47,8 @@ use zeroize::Zeroize; pub trait Fp256Parameters: FieldParameters {} -#[derive(Derivative, Zeroize)] -#[derivative( - Default(bound = ""), - Hash(bound = ""), - Clone(bound = ""), - Copy(bound = ""), - PartialEq(bound = ""), - Eq(bound = "") -)] -pub struct Fp256

( - pub BigInteger, - #[derivative(Debug = "ignore")] - #[doc(hidden)] - pub PhantomData

, -); +#[derive(Copy, Clone, Default, PartialEq, Eq, Hash, Zeroize)] +pub struct Fp256(pub BigInteger, #[doc(hidden)] pub PhantomData

); impl Fp256

{ #[inline] @@ -135,7 +122,7 @@ impl Fp256

{ impl Zero for Fp256

{ #[inline] fn zero() -> Self { - Fp256::

(BigInteger::from(0), PhantomData) + Self(BigInteger::from(0), PhantomData) } #[inline] @@ -147,12 +134,12 @@ impl Zero for Fp256

{ impl One for Fp256

{ #[inline] fn one() -> Self { - Fp256::

(P::R, PhantomData) + Self(P::R, PhantomData) } #[inline] fn is_one(&self) -> bool { - self == &Self::one() + self.0 == P::R } } @@ -312,7 +299,7 @@ impl Field for Fp256

{ let mut u = self.0; let mut v = P::MODULUS; - let mut b = Fp256::

(P::R2, PhantomData); // Avoids unnecessary reduction step. + let mut b = Self(P::R2, PhantomData); // Avoids unnecessary reduction step. let mut c = Self::zero(); while u != one && v != one { @@ -549,12 +536,25 @@ impl SquareRootField for Fp256

{ } fn sqrt_in_place(&mut self) -> Option<&mut Self> { - if let Some(sqrt) = self.sqrt() { + (*self).sqrt().map(|sqrt| { *self = sqrt; - Some(self) - } else { - None - } + self + }) + } +} + +/// `Fp` elements are ordered lexicographically. +impl Ord for Fp256

{ + #[inline(always)] + fn cmp(&self, other: &Self) -> Ordering { + self.to_bigint().cmp(&other.to_bigint()) + } +} + +impl PartialOrd for Fp256

{ + #[inline(always)] + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) } } @@ -606,21 +606,6 @@ impl FromBytes for Fp256

{ } } -/// `Fp` elements are ordered lexicographically. -impl Ord for Fp256

{ - #[inline(always)] - fn cmp(&self, other: &Self) -> Ordering { - self.to_bigint().cmp(&other.to_bigint()) - } -} - -impl PartialOrd for Fp256

{ - #[inline(always)] - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - impl FromStr for Fp256

{ type Err = FieldError; @@ -690,7 +675,7 @@ impl Neg for Fp256

{ if !self.is_zero() { let mut tmp = P::MODULUS; tmp.sub_noborrow(&self.0); - Fp256::

(tmp, PhantomData) + Self(tmp, PhantomData) } else { self } diff --git a/fields/src/fp_384.rs b/fields/src/fp_384.rs index 596ef055c2..1e60a18c2f 100644 --- a/fields/src/fp_384.rs +++ b/fields/src/fp_384.rs @@ -47,21 +47,8 @@ use zeroize::Zeroize; pub trait Fp384Parameters: FieldParameters {} -#[derive(Derivative, Zeroize)] -#[derivative( - Default(bound = "P: Fp384Parameters"), - Hash(bound = "P: Fp384Parameters"), - Clone(bound = "P: Fp384Parameters"), - Copy(bound = "P: Fp384Parameters"), - PartialEq(bound = "P: Fp384Parameters"), - Eq(bound = "P: Fp384Parameters") -)] -pub struct Fp384( - pub BigInteger, - #[derivative(Debug = "ignore")] - #[doc(hidden)] - pub PhantomData

, -); +#[derive(Copy, Clone, Default, PartialEq, Eq, Hash, Zeroize)] +pub struct Fp384(pub BigInteger, #[doc(hidden)] pub PhantomData

); impl Fp384

{ #[inline] @@ -169,7 +156,7 @@ impl Fp384

{ impl Zero for Fp384

{ #[inline] fn zero() -> Self { - Fp384::

(BigInteger::from(0), PhantomData) + Self(BigInteger::from(0), PhantomData) } #[inline] @@ -181,7 +168,7 @@ impl Zero for Fp384

{ impl One for Fp384

{ #[inline] fn one() -> Self { - Fp384::

(P::R, PhantomData) + Self(P::R, PhantomData) } #[inline] @@ -370,7 +357,7 @@ impl Field for Fp384

{ let mut u = self.0; let mut v = P::MODULUS; - let mut b = Fp384::

(P::R2, PhantomData); // Avoids unnecessary reduction step. + let mut b = Self(P::R2, PhantomData); // Avoids unnecessary reduction step. let mut c = Self::zero(); while u != one && v != one { @@ -446,7 +433,6 @@ impl PrimeField for Fp384

{ let mut tmp = self.0; let mut r = tmp.0; // Montgomery Reduction - // Iteration 0 let k = r[0].wrapping_mul(P::INV); let mut carry = 0; fa::mac_with_carry(r[0], k, P::MODULUS.0[0], &mut carry); @@ -551,6 +537,7 @@ impl SquareRootField for Fp384

{ // s = self^((MODULUS - 1) // 2) let s = self.pow(P::MODULUS_MINUS_ONE_DIV_TWO); + if s.is_zero() { Zero } else if s.is_one() { @@ -573,6 +560,7 @@ impl SquareRootField for Fp384

{ } } +/// `Fp` elements are ordered lexicographically. impl Ord for Fp384

{ #[inline(always)] fn cmp(&self, other: &Self) -> Ordering { @@ -704,7 +692,7 @@ impl Neg for Fp384

{ if !self.is_zero() { let mut tmp = P::MODULUS; tmp.sub_noborrow(&self.0); - Fp384::

(tmp, PhantomData) + Self(tmp, PhantomData) } else { self } @@ -760,7 +748,7 @@ impl<'a, P: Fp384Parameters> AddAssign<&'a Self> for Fp384

{ fn add_assign(&mut self, other: &Self) { // This cannot exceed the backing capacity. self.0.add_nocarry(&other.0); - // However, it may need to be reduced + // However, it may need to be reduced. self.reduce(); } } @@ -784,6 +772,7 @@ impl<'a, P: Fp384Parameters> MulAssign<&'a Self> for Fp384

{ let mut carry1 = 0u64; let mut carry2 = 0u64; + // Iteration 0. r[0] = fa::mac(r[0], (self.0).0[0], (other.0).0[0], &mut carry1); let k = r[0].wrapping_mul(P::INV); fa::mac_discard(r[0], k, P::MODULUS.0[0], &mut carry2); diff --git a/fields/src/lib.rs b/fields/src/lib.rs index 1a5e5be332..52b1ac0c3d 100644 --- a/fields/src/lib.rs +++ b/fields/src/lib.rs @@ -15,9 +15,6 @@ #![allow(clippy::module_inception)] #![forbid(unsafe_code)] -#[macro_use] -extern crate derivative; - #[macro_use] extern crate thiserror; @@ -45,6 +42,7 @@ mod legendre; pub use legendre::*; mod to_field_vec; +#[allow(unused_imports)] pub use to_field_vec::*; pub mod traits; diff --git a/fields/src/macros.rs b/fields/src/macros.rs index 8084e7c218..493745348a 100644 --- a/fields/src/macros.rs +++ b/fields/src/macros.rs @@ -104,12 +104,12 @@ macro_rules! sqrt_impl { let l_minus_one_times_k = n - 1 - k_2; let l_minus_one = l_minus_one_times_k / k; let l = l_minus_one + 1; - let mut l_s: Vec = Vec::with_capacity(k as usize); - l_s.resize(l_s.len() + k_1 as usize, l_minus_one); - l_s.resize(l_s.len() + k_2 as usize, l); + + let l_s = + || std::iter::repeat(l_minus_one).take(k_1 as usize).chain(std::iter::repeat(l).take(k_2 as usize)); let mut l_sum = 0; - let x_s = l_s.iter().take((k as usize) - 1).map(|l| { + let x_s = l_s().take((k as usize) - 1).map(|l| { l_sum += l; x.pow(BigInteger::from(2u64.pow((n - 1 - l_sum) as u32))) }); @@ -140,20 +140,16 @@ macro_rules! sqrt_impl { s }; - let calculate_kappa = |i: usize, j: usize, l_s: &[u64]| -> u64 { - l_s.iter().take(j).sum::() + 1 + l_s.iter().skip(i + 1).sum::() - }; - let calculate_gamma = |i: usize, q_s: &[u64], last: bool| -> $Self { let mut gamma = $Self::one(); if i != 0 { - q_s.iter().zip(l_s.iter()).enumerate().for_each(|(j, (q, l))| { - let mut kappa = calculate_kappa(i, j, &l_s); + q_s.iter().zip(l_s()).enumerate().for_each(|(j, (q, l))| { + let mut kappa = l_s().take(j).sum::() + 1 + l_s().skip(i + 1).sum::(); if last { kappa -= 1; } let mut value = *q; - (0..*l as usize).for_each(|k| { + (0..l as usize).for_each(|k| { let bit = value & 1 == 1; if bit { gamma *= $Self($P::POWERS_OF_ROOTS_OF_UNITY[(kappa as usize) + k], PhantomData); diff --git a/fields/src/traits/field_parameters.rs b/fields/src/traits/field_parameters.rs index 280b72f124..ba0c4a186a 100644 --- a/fields/src/traits/field_parameters.rs +++ b/fields/src/traits/field_parameters.rs @@ -14,8 +14,12 @@ use crate::traits::{FftParameters, PoseidonDefaultParameters}; +use core::{fmt::Debug, hash::Hash}; + /// A trait that defines parameters for a prime field. -pub trait FieldParameters: 'static + FftParameters + PoseidonDefaultParameters { +pub trait FieldParameters: + 'static + FftParameters + PoseidonDefaultParameters + Copy + Clone + Debug + Default + PartialEq + Eq + Hash +{ /// The modulus of the field. const MODULUS: Self::BigInteger; diff --git a/ledger/Cargo.toml b/ledger/Cargo.toml index 8258be5fc0..6451d7b364 100644 --- a/ledger/Cargo.toml +++ b/ledger/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-ledger" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "A node ledger for a decentralized virtual machine" homepage = "https://aleo.org" @@ -57,57 +57,57 @@ timer = [ "aleo-std/timer" ] [dependencies.console] package = "snarkvm-console" path = "../console" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-authority] package = "snarkvm-ledger-authority" path = "./authority" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-block] package = "snarkvm-ledger-block" path = "./block" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-coinbase] package = "snarkvm-ledger-coinbase" path = "./coinbase" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-committee] package = "snarkvm-ledger-committee" path = "./committee" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-narwhal] package = "snarkvm-ledger-narwhal" path = "./narwhal" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-query] package = "snarkvm-ledger-query" path = "./query" -version = "=0.16.15" +version = "=0.16.19" features = [ "query" ] [dependencies.ledger-store] package = "snarkvm-ledger-store" path = "./store" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-test-helpers] package = "snarkvm-ledger-test-helpers" path = "./test-helpers" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.synthesizer] package = "snarkvm-synthesizer" path = "../synthesizer" -version = "=0.16.15" +version = "=0.16.19" [dependencies.aleo-std] -version = "0.1.18" +version = "0.1.24" default-features = false [dependencies.anyhow] diff --git a/ledger/authority/Cargo.toml b/ledger/authority/Cargo.toml index 2be5317994..bf1ce00d77 100644 --- a/ledger/authority/Cargo.toml +++ b/ledger/authority/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-ledger-authority" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Data structures for a block authority in a decentralized virtual machine" homepage = "https://aleo.org" @@ -32,12 +32,12 @@ test-helpers = [ "narwhal-subdag/test-helpers" ] [dependencies.console] package = "snarkvm-console" path = "../../console" -version = "=0.16.15" +version = "=0.16.19" [dependencies.narwhal-subdag] package = "snarkvm-ledger-narwhal-subdag" path = "../narwhal/subdag" -version = "=0.16.15" +version = "=0.16.19" [dependencies.anyhow] version = "1" diff --git a/ledger/authority/src/lib.rs b/ledger/authority/src/lib.rs index a3fcf38adf..5d6c8e5736 100644 --- a/ledger/authority/src/lib.rs +++ b/ledger/authority/src/lib.rs @@ -119,7 +119,7 @@ pub mod test_helpers { use super::*; use console::prelude::{TestRng, Uniform}; - pub type CurrentNetwork = console::network::Testnet3; + pub type CurrentNetwork = console::network::MainnetV0; /// Returns a sample beacon authority. pub fn sample_beacon_authority(rng: &mut TestRng) -> Authority { diff --git a/ledger/benches/block.rs b/ledger/benches/block.rs index 1ddacaf8ad..710c96661f 100644 --- a/ledger/benches/block.rs +++ b/ledger/benches/block.rs @@ -15,12 +15,12 @@ #[macro_use] extern crate criterion; -use console::{network::Testnet3, prelude::*}; +use console::{network::MainnetV0, prelude::*}; use ledger_block::Block; use criterion::Criterion; -type CurrentNetwork = Testnet3; +type CurrentNetwork = MainnetV0; /// Loads the genesis block. fn load_genesis_block() -> Block { diff --git a/ledger/benches/transaction.rs b/ledger/benches/transaction.rs index 233e15aa37..17f241f99c 100644 --- a/ledger/benches/transaction.rs +++ b/ledger/benches/transaction.rs @@ -19,7 +19,7 @@ extern crate criterion; use console::{ account::*, - network::Testnet3, + network::MainnetV0, program::{Plaintext, Record, Value}, }; use ledger_block::Transition; @@ -30,9 +30,9 @@ use criterion::Criterion; use indexmap::IndexMap; fn initialize_vm( - private_key: &PrivateKey, + private_key: &PrivateKey, rng: &mut R, -) -> (VM>, Vec>>) { +) -> (VM>, Vec>>) { let vm = VM::from(ConsensusStore::open(None).unwrap()).unwrap(); // Initialize the genesis block. @@ -55,13 +55,13 @@ fn deploy(c: &mut Criterion) { let rng = &mut TestRng::default(); // Sample a new private key and address. - let private_key = PrivateKey::::new(rng).unwrap(); + let private_key = PrivateKey::::new(rng).unwrap(); // Initialize the VM. let (vm, records) = initialize_vm(&private_key, rng); // Create a sample program. - let program = Program::::from_str( + let program = Program::::from_str( r" program helloworld.aleo; @@ -88,7 +88,7 @@ fn execute(c: &mut Criterion) { let rng = &mut TestRng::default(); // Sample a new private key and address. - let private_key = PrivateKey::::new(rng).unwrap(); + let private_key = PrivateKey::::new(rng).unwrap(); let address = Address::try_from(&private_key).unwrap(); // Initialize the VM. @@ -96,9 +96,11 @@ fn execute(c: &mut Criterion) { { // Prepare the inputs. - let inputs = - [Value::::from_str(&address.to_string()).unwrap(), Value::::from_str("1u64").unwrap()] - .into_iter(); + let inputs = [ + Value::::from_str(&address.to_string()).unwrap(), + Value::::from_str("1u64").unwrap(), + ] + .into_iter(); // Authorize the execution. let execute_authorization = vm.authorize(&private_key, "credits.aleo", "transfer_public", inputs, rng).unwrap(); @@ -131,9 +133,9 @@ fn execute(c: &mut Criterion) { { // Prepare the inputs. let inputs = [ - Value::::Record(records[0].clone()), - Value::::from_str(&address.to_string()).unwrap(), - Value::::from_str("1u64").unwrap(), + Value::::Record(records[0].clone()), + Value::::from_str(&address.to_string()).unwrap(), + Value::::from_str("1u64").unwrap(), ] .into_iter(); diff --git a/ledger/block/Cargo.toml b/ledger/block/Cargo.toml index c3dff51f0e..7174c09fbc 100644 --- a/ledger/block/Cargo.toml +++ b/ledger/block/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-ledger-block" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "A block for a decentralized virtual machine" homepage = "https://aleo.org" @@ -39,42 +39,47 @@ test = [ ] [dependencies.console] package = "snarkvm-console" path = "../../console" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-authority] package = "snarkvm-ledger-authority" path = "../authority" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-coinbase] package = "snarkvm-ledger-coinbase" path = "../../ledger/coinbase" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-committee] package = "snarkvm-ledger-committee" path = "../../ledger/committee" -version = "=0.16.15" +version = "=0.16.19" + +[dependencies.ledger-narwhal-batch-header] +package = "snarkvm-ledger-narwhal-batch-header" +path = "../narwhal/batch-header" +version = "=0.16.19" [dependencies.ledger-narwhal-subdag] package = "snarkvm-ledger-narwhal-subdag" path = "../narwhal/subdag" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-narwhal-transmission-id] package = "snarkvm-ledger-narwhal-transmission-id" path = "../narwhal/transmission-id" -version = "=0.16.15" +version = "=0.16.19" [dependencies.synthesizer-program] package = "snarkvm-synthesizer-program" path = "../../synthesizer/program" -version = "=0.16.15" +version = "=0.16.19" [dependencies.synthesizer-snark] package = "snarkvm-synthesizer-snark" path = "../../synthesizer/snark" -version = "=0.16.15" +version = "=0.16.19" [dependencies.indexmap] version = "2.0" diff --git a/ledger/block/src/bytes.rs b/ledger/block/src/bytes.rs index 448c24cc3d..9a33f1f2d2 100644 --- a/ledger/block/src/bytes.rs +++ b/ledger/block/src/bytes.rs @@ -39,25 +39,32 @@ impl FromBytes for Block { let ratifications = Ratifications::read_le(&mut reader)?; // Read the solutions. - let solutions_variant = u8::read_le(&mut reader)?; - let solutions = match solutions_variant { - 0 => None, - 1 => Some(FromBytes::read_le(&mut reader)?), - _ => return Err(error("Invalid solutions variant in the block")), - }; + let solutions: Solutions = FromBytes::read_le(&mut reader)?; + + // Read the number of aborted solution IDs. + let num_aborted_solutions = u32::read_le(&mut reader)?; + // Ensure the number of aborted solutions IDs is within bounds (this is an early safety check). + if num_aborted_solutions as usize > Solutions::::MAX_ABORTED_SOLUTIONS { + return Err(error("Invalid number of aborted solutions IDs in the block")); + } + // Read the aborted solution IDs. + let mut aborted_solution_ids = Vec::with_capacity(num_aborted_solutions as usize); + for _ in 0..num_aborted_solutions { + aborted_solution_ids.push(FromBytes::read_le(&mut reader)?); + } // Read the transactions. let transactions = FromBytes::read_le(&mut reader)?; // Read the number of aborted transaction IDs. - let num_aborted = u32::read_le(&mut reader)?; + let num_aborted_transactions = u32::read_le(&mut reader)?; // Ensure the number of aborted transaction IDs is within bounds (this is an early safety check). - if num_aborted as usize > Transactions::::MAX_TRANSACTIONS { + if num_aborted_transactions as usize > Transactions::::MAX_ABORTED_TRANSACTIONS { return Err(error("Invalid number of aborted transaction IDs in the block")); } // Read the aborted transaction IDs. - let mut aborted_transaction_ids = Vec::with_capacity(num_aborted as usize); - for _ in 0..num_aborted { + let mut aborted_transaction_ids = Vec::with_capacity(num_aborted_transactions as usize); + for _ in 0..num_aborted_transactions { aborted_transaction_ids.push(FromBytes::read_le(&mut reader)?); } @@ -68,6 +75,7 @@ impl FromBytes for Block { authority, ratifications, solutions, + aborted_solution_ids, transactions, aborted_transaction_ids, ) @@ -102,13 +110,11 @@ impl ToBytes for Block { self.ratifications.write_le(&mut writer)?; // Write the solutions. - match self.solutions { - None => 0u8.write_le(&mut writer)?, - Some(ref solutions) => { - 1u8.write_le(&mut writer)?; - solutions.write_le(&mut writer)?; - } - } + self.solutions.write_le(&mut writer)?; + + // Write the aborted solution IDs. + (u32::try_from(self.aborted_solution_ids.len()).map_err(error))?.write_le(&mut writer)?; + self.aborted_solution_ids.write_le(&mut writer)?; // Write the transactions. self.transactions.write_le(&mut writer)?; @@ -122,9 +128,9 @@ impl ToBytes for Block { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_bytes() -> Result<()> { diff --git a/ledger/block/src/genesis.rs b/ledger/block/src/genesis.rs index 061c8ec370..1370598a08 100644 --- a/ledger/block/src/genesis.rs +++ b/ledger/block/src/genesis.rs @@ -29,7 +29,7 @@ impl Block { // Ensure there is the correct number of ratification operations in the genesis block. && self.ratifications.len() == 1 // Ensure there are no solutions in the genesis block. - && self.solutions.is_none() + && self.solutions.is_empty() // Ensure there is the correct number of accepted transaction in the genesis block. && self.transactions.num_accepted() == Self::NUM_GENESIS_TRANSACTIONS // Ensure there is the correct number of rejected transaction in the genesis block. @@ -44,9 +44,9 @@ impl Block { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_genesis() { diff --git a/ledger/block/src/header/bytes.rs b/ledger/block/src/header/bytes.rs index 3ea781cfc2..a906e6a4ab 100644 --- a/ledger/block/src/header/bytes.rs +++ b/ledger/block/src/header/bytes.rs @@ -69,9 +69,9 @@ impl ToBytes for Header { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_bytes() -> Result<()> { diff --git a/ledger/block/src/header/genesis.rs b/ledger/block/src/header/genesis.rs index 87952914d4..5d653b4671 100644 --- a/ledger/block/src/header/genesis.rs +++ b/ledger/block/src/header/genesis.rs @@ -22,9 +22,7 @@ impl Header { ratified_finalize_operations: Vec>, ) -> Result { #[cfg(not(debug_assertions))] - ensure!(!ratifications.is_empty(), "The genesis block must not contain ratifications"); - #[cfg(not(debug_assertions))] - ensure!(ratifications.len() == 1, "The genesis block must not contain 1 ratification"); + ensure!(ratifications.len() == 1, "The genesis block must contain exactly 1 ratification"); #[cfg(not(debug_assertions))] ensure!(!ratified_finalize_operations.is_empty(), "The genesis block must contain ratify-finalize operations"); @@ -71,9 +69,9 @@ impl Header { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Returns the expected block header size by summing its subcomponent sizes. /// Update this method if the contents of a block header have changed. diff --git a/ledger/block/src/header/merkle.rs b/ledger/block/src/header/merkle.rs index bef088944f..0c8f1c1ac1 100644 --- a/ledger/block/src/header/merkle.rs +++ b/ledger/block/src/header/merkle.rs @@ -89,9 +89,9 @@ impl Header { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1_000; diff --git a/ledger/block/src/header/metadata/bytes.rs b/ledger/block/src/header/metadata/bytes.rs index f89a9046e3..f458935906 100644 --- a/ledger/block/src/header/metadata/bytes.rs +++ b/ledger/block/src/header/metadata/bytes.rs @@ -78,9 +78,9 @@ impl ToBytes for Metadata { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_bytes() -> Result<()> { diff --git a/ledger/block/src/header/metadata/genesis.rs b/ledger/block/src/header/metadata/genesis.rs index a3a107b228..dc34250c0c 100644 --- a/ledger/block/src/header/metadata/genesis.rs +++ b/ledger/block/src/header/metadata/genesis.rs @@ -72,9 +72,9 @@ impl Metadata { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Returns the expected metadata size by summing its subcomponent sizes. /// Update this method if the contents of the metadata have changed. diff --git a/ledger/block/src/header/metadata/mod.rs b/ledger/block/src/header/metadata/mod.rs index 842ecdccf7..9bb7e2dcab 100644 --- a/ledger/block/src/header/metadata/mod.rs +++ b/ledger/block/src/header/metadata/mod.rs @@ -172,7 +172,7 @@ impl Metadata { pub mod test_helpers { use super::*; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; /// Samples a block metadata. pub(crate) fn sample_block_metadata(rng: &mut TestRng) -> Metadata { diff --git a/ledger/block/src/header/mod.rs b/ledger/block/src/header/mod.rs index 0d29c81721..2f963090d3 100644 --- a/ledger/block/src/header/mod.rs +++ b/ledger/block/src/header/mod.rs @@ -186,7 +186,7 @@ impl Header { pub mod test_helpers { use super::*; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; /// Samples a block header. pub(crate) fn sample_block_header(rng: &mut TestRng) -> Header { diff --git a/ledger/block/src/helpers/target.rs b/ledger/block/src/helpers/target.rs index ffb6265bd2..40b2c9f461 100644 --- a/ledger/block/src/helpers/target.rs +++ b/ledger/block/src/helpers/target.rs @@ -226,9 +226,9 @@ fn retarget( #[cfg(test)] mod tests { use super::*; - use console::network::{prelude::*, Testnet3}; + use console::network::{prelude::*, MainnetV0}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u32 = 1000; diff --git a/ledger/block/src/lib.rs b/ledger/block/src/lib.rs index ff495b2ade..596de24a6c 100644 --- a/ledger/block/src/lib.rs +++ b/ledger/block/src/lib.rs @@ -29,6 +29,9 @@ pub use ratifications::*; pub mod ratify; pub use ratify::*; +pub mod solutions; +pub use solutions::*; + pub mod transaction; pub use transaction::*; @@ -69,7 +72,9 @@ pub struct Block { /// The ratifications in this block. ratifications: Ratifications, /// The solutions in the block. - solutions: Option>, + solutions: Solutions, + /// The aborted solution IDs in this block. + aborted_solution_ids: Vec>, /// The transactions in this block. transactions: Transactions, /// The aborted transaction IDs in this block. @@ -84,7 +89,8 @@ impl Block { previous_hash: N::BlockHash, header: Header, ratifications: Ratifications, - solutions: Option>, + solutions: Solutions, + aborted_solution_ids: Vec>, transactions: Transactions, aborted_transaction_ids: Vec, rng: &mut R, @@ -94,7 +100,16 @@ impl Block { // Construct the beacon authority. let authority = Authority::new_beacon(private_key, block_hash, rng)?; // Construct the block. - Self::from(previous_hash, header, authority, ratifications, solutions, transactions, aborted_transaction_ids) + Self::from( + previous_hash, + header, + authority, + ratifications, + solutions, + aborted_solution_ids, + transactions, + aborted_transaction_ids, + ) } /// Initializes a new quorum block from the given previous block hash, block header, @@ -104,14 +119,24 @@ impl Block { header: Header, subdag: Subdag, ratifications: Ratifications, - solutions: Option>, + solutions: Solutions, + aborted_solution_ids: Vec>, transactions: Transactions, aborted_transaction_ids: Vec, ) -> Result { // Construct the beacon authority. let authority = Authority::new_quorum(subdag); // Construct the block. - Self::from(previous_hash, header, authority, ratifications, solutions, transactions, aborted_transaction_ids) + Self::from( + previous_hash, + header, + authority, + ratifications, + solutions, + aborted_solution_ids, + transactions, + aborted_transaction_ids, + ) } /// Initializes a new block from the given previous block hash, block header, @@ -121,12 +146,18 @@ impl Block { header: Header, authority: Authority, ratifications: Ratifications, - solutions: Option>, + solutions: Solutions, + aborted_solution_ids: Vec>, transactions: Transactions, aborted_transaction_ids: Vec, ) -> Result { - // Ensure the block contains transactions. - ensure!(!transactions.is_empty(), "Cannot create a block with zero transactions"); + // Ensure the number of aborted solutions IDs is within the allowed range. + if aborted_solution_ids.len() > Solutions::::MAX_ABORTED_SOLUTIONS { + bail!( + "Cannot initialize a block with more than {} aborted solutions IDs", + Solutions::::MAX_ABORTED_SOLUTIONS + ); + } // Ensure the number of transactions is within the allowed range. if transactions.len() > Transactions::::MAX_TRANSACTIONS { @@ -137,10 +168,10 @@ impl Block { } // Ensure the number of aborted transaction IDs is within the allowed range. - if aborted_transaction_ids.len() > Transactions::::MAX_TRANSACTIONS { + if aborted_transaction_ids.len() > Transactions::::MAX_ABORTED_TRANSACTIONS { bail!( "Cannot initialize a block with more than {} aborted transaction IDs", - Transactions::::MAX_TRANSACTIONS + Transactions::::MAX_ABORTED_TRANSACTIONS ); } @@ -157,16 +188,18 @@ impl Block { } Authority::Quorum(subdag) => { // Ensure the transmission IDs from the subdag correspond to the block. - Self::check_subdag_transmissions(subdag, &solutions, &transactions, &aborted_transaction_ids)?; + Self::check_subdag_transmissions( + subdag, + &solutions, + &aborted_solution_ids, + &transactions, + &aborted_transaction_ids, + )?; } } // Ensure that coinbase accumulator matches the solutions. - let solutions_root = match &solutions { - Some(coinbase_solution) => coinbase_solution.to_accumulator_point()?, - None => Field::::zero(), - }; - if header.solutions_root() != solutions_root { + if header.solutions_root() != solutions.to_solutions_root()? { bail!("The solutions root in the block does not correspond to the solutions"); } @@ -187,6 +220,7 @@ impl Block { authority, ratifications, solutions, + aborted_solution_ids, transactions, aborted_transaction_ids, ) @@ -200,7 +234,8 @@ impl Block { header: Header, authority: Authority, ratifications: Ratifications, - solutions: Option>, + solutions: Solutions, + aborted_solution_ids: Vec>, transactions: Transactions, aborted_transaction_ids: Vec, ) -> Result { @@ -210,9 +245,10 @@ impl Block { previous_hash, header, authority, - transactions, ratifications, solutions, + aborted_solution_ids, + transactions, aborted_transaction_ids, }) } @@ -240,8 +276,13 @@ impl Block { } /// Returns the solutions in the block. - pub const fn solutions(&self) -> Option<&CoinbaseSolution> { - self.solutions.as_ref() + pub const fn solutions(&self) -> &Solutions { + &self.solutions + } + + /// Returns the aborted solution IDs in this block. + pub const fn aborted_solution_ids(&self) -> &Vec> { + &self.aborted_solution_ids } /// Returns the transactions in this block. @@ -567,7 +608,7 @@ pub mod test_helpers { use once_cell::sync::OnceCell; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; type CurrentAleo = circuit::network::AleoV0; /// Samples a random genesis block. @@ -636,7 +677,7 @@ pub mod test_helpers { // Prepare the confirmed transaction. let confirmed = ConfirmedTransaction::accepted_execute(0, transaction.clone(), vec![]).unwrap(); // Prepare the transactions. - let transactions = Transactions::from_iter([confirmed].into_iter()); + let transactions = Transactions::from_iter([confirmed]); // Construct the ratifications. let ratifications = Ratifications::try_from(vec![]).unwrap(); @@ -647,9 +688,18 @@ pub mod test_helpers { let previous_hash = ::BlockHash::default(); // Construct the block. - let block = - Block::new_beacon(&private_key, previous_hash, header, ratifications, None, transactions, vec![], rng) - .unwrap(); + let block = Block::new_beacon( + &private_key, + previous_hash, + header, + ratifications, + None.into(), + vec![], + transactions, + vec![], + rng, + ) + .unwrap(); assert!(block.header().is_genesis(), "Failed to initialize a genesis block"); // Return the block, transaction, and private key. (block, transaction, private_key) diff --git a/ledger/block/src/ratifications/merkle.rs b/ledger/block/src/ratifications/merkle.rs index 806e4eb7ad..6d229abed2 100644 --- a/ledger/block/src/ratifications/merkle.rs +++ b/ledger/block/src/ratifications/merkle.rs @@ -54,9 +54,9 @@ impl Ratifications { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_ratifications_depth() { diff --git a/ledger/block/src/ratifications/mod.rs b/ledger/block/src/ratifications/mod.rs index 884c09d6f6..4e6778e26e 100644 --- a/ledger/block/src/ratifications/mod.rs +++ b/ledger/block/src/ratifications/mod.rs @@ -51,7 +51,7 @@ impl TryFrom>> for Ratifications { /// Initializes from a given ratifications list. fn try_from(ratifications: Vec>) -> Result { - Self::try_from_iter(ratifications.into_iter()) + Self::try_from_iter(ratifications) } } @@ -137,7 +137,7 @@ impl Ratifications { pub mod test_helpers { use super::*; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; /// Samples a block ratifications. pub(crate) fn sample_block_ratifications(rng: &mut TestRng) -> Ratifications { diff --git a/ledger/block/src/ratifications/serialize.rs b/ledger/block/src/ratifications/serialize.rs index df252a8bbd..7322772076 100644 --- a/ledger/block/src/ratifications/serialize.rs +++ b/ledger/block/src/ratifications/serialize.rs @@ -66,9 +66,9 @@ impl<'de, N: Network> Deserialize<'de> for Ratifications { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u32 = 100; diff --git a/ledger/block/src/ratify/mod.rs b/ledger/block/src/ratify/mod.rs index c9a468c229..0cc1c6f377 100644 --- a/ledger/block/src/ratify/mod.rs +++ b/ledger/block/src/ratify/mod.rs @@ -45,9 +45,9 @@ impl Ratify { #[cfg(test)] pub(crate) mod test_helpers { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; pub(crate) fn sample_ratifications(rng: &mut TestRng) -> Vec> { let committee = ledger_committee::test_helpers::sample_committee(rng); diff --git a/ledger/block/src/serialize.rs b/ledger/block/src/serialize.rs index 24edfa8687..d440b450b6 100644 --- a/ledger/block/src/serialize.rs +++ b/ledger/block/src/serialize.rs @@ -19,17 +19,14 @@ impl Serialize for Block { fn serialize(&self, serializer: S) -> Result { match serializer.is_human_readable() { true => { - let mut block = serializer.serialize_struct("Block", 7 + self.solutions.is_some() as usize)?; + let mut block = serializer.serialize_struct("Block", 9)?; block.serialize_field("block_hash", &self.block_hash)?; block.serialize_field("previous_hash", &self.previous_hash)?; block.serialize_field("header", &self.header)?; block.serialize_field("authority", &self.authority)?; block.serialize_field("ratifications", &self.ratifications)?; - - if let Some(solutions) = &self.solutions { - block.serialize_field("solutions", solutions)?; - } - + block.serialize_field("solutions", &self.solutions)?; + block.serialize_field("aborted_solution_ids", &self.aborted_solution_ids)?; block.serialize_field("transactions", &self.transactions)?; block.serialize_field("aborted_transaction_ids", &self.aborted_transaction_ids)?; block.end() @@ -47,16 +44,14 @@ impl<'de, N: Network> Deserialize<'de> for Block { let mut block = serde_json::Value::deserialize(deserializer)?; let block_hash: N::BlockHash = DeserializeExt::take_from_value::(&mut block, "block_hash")?; - // Retrieve the solutions. - let solutions = block.get_mut("solutions").unwrap_or(&mut serde_json::Value::Null).take(); - // Recover the block. let block = Self::from( DeserializeExt::take_from_value::(&mut block, "previous_hash")?, DeserializeExt::take_from_value::(&mut block, "header")?, DeserializeExt::take_from_value::(&mut block, "authority")?, DeserializeExt::take_from_value::(&mut block, "ratifications")?, - serde_json::from_value(solutions).map_err(de::Error::custom)?, + DeserializeExt::take_from_value::(&mut block, "solutions")?, + DeserializeExt::take_from_value::(&mut block, "aborted_solution_ids")?, DeserializeExt::take_from_value::(&mut block, "transactions")?, DeserializeExt::take_from_value::(&mut block, "aborted_transaction_ids")?, ) @@ -76,9 +71,9 @@ impl<'de, N: Network> Deserialize<'de> for Block { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_serde_json() -> Result<()> { diff --git a/ledger/block/src/solutions/bytes.rs b/ledger/block/src/solutions/bytes.rs new file mode 100644 index 0000000000..aa92c63114 --- /dev/null +++ b/ledger/block/src/solutions/bytes.rs @@ -0,0 +1,84 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the snarkVM library. + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use super::*; + +impl FromBytes for Solutions { + /// Reads the solutions from the buffer. + fn read_le(mut reader: R) -> IoResult { + // Read the version. + let version: u8 = FromBytes::read_le(&mut reader)?; + // Ensure the version is valid. + if version != 1 { + return Err(error(format!("Invalid solutions version ({version})"))); + } + + // Read the variant. + let variant: u8 = FromBytes::read_le(&mut reader)?; + // Parse the variant. + match variant { + 0 => { + // Return the solutions. + Ok(Self { solutions: None }) + } + 1 => { + // Read the solutions. + let solutions: CoinbaseSolution = FromBytes::read_le(&mut reader)?; + // Return the solutions. + Self::new(solutions).map_err(error) + } + _ => Err(error(format!("Invalid solutions variant ({variant})"))), + } + } +} + +impl ToBytes for Solutions { + /// Writes the solutions to the buffer. + fn write_le(&self, mut writer: W) -> IoResult<()> { + // Write the version. + 1u8.write_le(&mut writer)?; + + match &self.solutions { + None => { + // Write the variant. + 0u8.write_le(&mut writer)?; + } + Some(solutions) => { + // Write the variant. + 1u8.write_le(&mut writer)?; + // Write the solutions. + solutions.write_le(&mut writer)?; + } + } + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_bytes() -> Result<()> { + let mut rng = TestRng::default(); + + // Sample random solutions. + let expected = crate::solutions::serialize::tests::sample_solutions(&mut rng); + + // Check the byte representation. + let expected_bytes = expected.to_bytes_le()?; + assert_eq!(expected, Solutions::read_le(&expected_bytes[..])?); + Ok(()) + } +} diff --git a/ledger/block/src/solutions/merkle.rs b/ledger/block/src/solutions/merkle.rs new file mode 100644 index 0000000000..7b655dd759 --- /dev/null +++ b/ledger/block/src/solutions/merkle.rs @@ -0,0 +1,25 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the snarkVM library. + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use super::*; + +impl Solutions { + /// Returns the solutions root. + pub fn to_solutions_root(&self) -> Result> { + match &self.solutions { + Some(solutions) => solutions.to_accumulator_point(), + None => Ok(Field::::zero()), + } + } +} diff --git a/ledger/block/src/solutions/mod.rs b/ledger/block/src/solutions/mod.rs new file mode 100644 index 0000000000..7cdbd1d8a8 --- /dev/null +++ b/ledger/block/src/solutions/mod.rs @@ -0,0 +1,94 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the snarkVM library. + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +mod bytes; +mod merkle; +mod serialize; +mod string; + +use console::{network::prelude::*, types::Field}; +use ledger_coinbase::{CoinbaseSolution, PuzzleCommitment}; +use ledger_committee::Committee; +use ledger_narwhal_batch_header::BatchHeader; + +#[derive(Clone, Eq, PartialEq)] +pub struct Solutions { + /// The prover solutions for the coinbase puzzle. + solutions: Option>, +} + +impl Solutions { + /// The maximum number of aborted solutions allowed in a block. + pub const MAX_ABORTED_SOLUTIONS: usize = BatchHeader::::MAX_TRANSMISSIONS_PER_BATCH + * BatchHeader::::MAX_GC_ROUNDS + * Committee::::MAX_COMMITTEE_SIZE as usize; +} + +impl From>> for Solutions { + /// Initializes a new instance of the solutions. + fn from(solutions: Option>) -> Self { + // Return the solutions. + Self { solutions } + } +} + +impl Solutions { + /// Initializes a new instance of the solutions. + pub fn new(solutions: CoinbaseSolution) -> Result { + // Return the solutions. + Ok(Self { solutions: Some(solutions) }) + } + + /// Returns `true` if the solutions are empty. + pub fn is_empty(&self) -> bool { + self.solutions.is_none() + } + + /// Returns the number of solutions. + pub fn len(&self) -> usize { + match &self.solutions { + Some(solutions) => solutions.len(), + None => 0, + } + } +} + +impl Solutions { + /// Returns an iterator over the solution IDs. + pub fn solution_ids<'a>(&'a self) -> Box> + 'a> { + match &self.solutions { + Some(solutions) => Box::new(solutions.keys()), + None => Box::new(std::iter::empty::<&PuzzleCommitment>()), + } + } +} + +impl Solutions { + /// Returns the combined sum of the prover solutions. + pub fn to_combined_proof_target(&self) -> Result { + match &self.solutions { + Some(solutions) => solutions.to_combined_proof_target(), + None => Ok(0), + } + } +} + +impl Deref for Solutions { + type Target = Option>; + + /// Returns the solutions. + fn deref(&self) -> &Self::Target { + &self.solutions + } +} diff --git a/ledger/block/src/solutions/serialize.rs b/ledger/block/src/solutions/serialize.rs new file mode 100644 index 0000000000..712d624e91 --- /dev/null +++ b/ledger/block/src/solutions/serialize.rs @@ -0,0 +1,122 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the snarkVM library. + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use super::*; + +impl Serialize for Solutions { + /// Serializes the solutions to a JSON-string or buffer. + fn serialize(&self, serializer: S) -> Result { + match serializer.is_human_readable() { + true => { + let mut solutions = serializer.serialize_struct("Solutions", 1 + self.solutions.is_some() as usize)?; + solutions.serialize_field("version", &1u8)?; + if let Some(s) = &self.solutions { + solutions.serialize_field("solutions", s)?; + } + solutions.end() + } + false => ToBytesSerializer::serialize_with_size_encoding(self, serializer), + } + } +} + +impl<'de, N: Network> Deserialize<'de> for Solutions { + /// Deserializes the solutions from a JSON-string or buffer. + fn deserialize>(deserializer: D) -> Result { + match deserializer.is_human_readable() { + true => { + // Deserialize the solutions into a JSON value. + let mut solutions = serde_json::Value::deserialize(deserializer)?; + + // Retrieve the version. + let version: u8 = DeserializeExt::take_from_value::(&mut solutions, "version")?; + // Ensure the version is valid. + if version != 1 { + return Err(de::Error::custom(format!("Invalid solutions version ({version})"))); + } + + // Retrieve the solutions, if it exists. + Ok(Self { + solutions: serde_json::from_value( + solutions.get_mut("solutions").unwrap_or(&mut serde_json::Value::Null).take(), + ) + .map_err(de::Error::custom)?, + }) + } + false => FromBytesDeserializer::::deserialize_with_size_encoding(deserializer, "solutions"), + } + } +} + +#[cfg(test)] +pub(super) mod tests { + use super::*; + use console::account::{Address, PrivateKey}; + use ledger_coinbase::{PartialSolution, ProverSolution, PuzzleCommitment, PuzzleProof}; + + type CurrentNetwork = console::network::MainnetV0; + + pub(crate) fn sample_solutions(rng: &mut TestRng) -> Solutions { + // Sample a new solutions. + let mut prover_solutions = vec![]; + for _ in 0..rng.gen_range(1..10) { + let private_key = PrivateKey::::new(rng).unwrap(); + let address = Address::try_from(private_key).unwrap(); + + let commitment = PuzzleCommitment::from_g1_affine(rng.gen()); + let partial_solution = PartialSolution::new(address, u64::rand(rng), commitment); + let proof = PuzzleProof:: { w: rng.gen(), random_v: None }; + prover_solutions.push(ProverSolution::new(partial_solution, proof)); + } + Solutions::new(CoinbaseSolution::new(prover_solutions).unwrap()).unwrap() + } + + #[test] + fn test_serde_json() -> Result<()> { + let rng = &mut TestRng::default(); + + // Sample a new solutions. + let expected = sample_solutions(rng); + + // Serialize + let expected_string = &expected.to_string(); + let candidate_string = serde_json::to_string(&expected)?; + assert_eq!(expected, serde_json::from_str(&candidate_string)?); + + // Deserialize + assert_eq!(expected, Solutions::from_str(expected_string)?); + assert_eq!(expected, serde_json::from_str(&candidate_string)?); + + Ok(()) + } + + #[test] + fn test_bincode() -> Result<()> { + let rng = &mut TestRng::default(); + + // Sample a new solutions. + let expected = sample_solutions(rng); + + // Serialize + let expected_bytes = expected.to_bytes_le()?; + let expected_bytes_with_size_encoding = bincode::serialize(&expected)?; + assert_eq!(&expected_bytes[..], &expected_bytes_with_size_encoding[8..]); + + // Deserialize + assert_eq!(expected, Solutions::read_le(&expected_bytes[..])?); + assert_eq!(expected, bincode::deserialize(&expected_bytes_with_size_encoding[..])?); + + Ok(()) + } +} diff --git a/ledger/block/src/solutions/string.rs b/ledger/block/src/solutions/string.rs new file mode 100644 index 0000000000..b4dfe9b954 --- /dev/null +++ b/ledger/block/src/solutions/string.rs @@ -0,0 +1,57 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the snarkVM library. + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use super::*; + +impl FromStr for Solutions { + type Err = Error; + + /// Initializes the solutions from a JSON-string. + fn from_str(solutions: &str) -> Result { + Ok(serde_json::from_str(solutions)?) + } +} + +impl Debug for Solutions { + /// Prints the solutions as a JSON-string. + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + Display::fmt(self, f) + } +} + +impl Display for Solutions { + /// Displays the solutions as a JSON-string. + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + write!(f, "{}", serde_json::to_string(self).map_err::(ser::Error::custom)?) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_string() -> Result<()> { + let mut rng = TestRng::default(); + + // Sample random solutions. + let expected = crate::solutions::serialize::tests::sample_solutions(&mut rng); + + // Check the string representation. + let candidate = format!("{expected}"); + assert_eq!(expected, Solutions::from_str(&candidate)?); + + Ok(()) + } +} diff --git a/ledger/block/src/transaction/deployment/mod.rs b/ledger/block/src/transaction/deployment/mod.rs index 01d4cac081..bf898b41ba 100644 --- a/ledger/block/src/transaction/deployment/mod.rs +++ b/ledger/block/src/transaction/deployment/mod.rs @@ -124,6 +124,23 @@ impl Deployment { &self.verifying_keys } + /// Returns the sum of the constraint counts for all functions in this deployment. + pub fn num_combined_constraints(&self) -> Result { + // Initialize the accumulator. + let mut num_combined_constraints = 0u64; + // Iterate over the functions. + for (_, (vk, _)) in &self.verifying_keys { + // Add the number of constraints. + // Note: This method must be *checked* because the claimed constraint count + // is from the user, not the synthesizer. + num_combined_constraints = num_combined_constraints + .checked_add(vk.circuit_info.num_constraints as u64) + .ok_or_else(|| anyhow!("Overflow when counting constraints for '{}'", self.program_id()))?; + } + // Return the number of combined constraints. + Ok(num_combined_constraints) + } + /// Returns the deployment ID. pub fn to_deployment_id(&self) -> Result> { Ok(*Transaction::deployment_tree(self, None)?.root()) @@ -133,12 +150,12 @@ impl Deployment { #[cfg(test)] pub mod test_helpers { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; use synthesizer_process::Process; use once_cell::sync::OnceCell; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; type CurrentAleo = circuit::network::AleoV0; pub(crate) fn sample_deployment(rng: &mut TestRng) -> Deployment { diff --git a/ledger/block/src/transaction/execution/mod.rs b/ledger/block/src/transaction/execution/mod.rs index cfcbb26c51..7bd7d34ef2 100644 --- a/ledger/block/src/transaction/execution/mod.rs +++ b/ledger/block/src/transaction/execution/mod.rs @@ -147,7 +147,7 @@ impl Execution { pub mod test_helpers { use super::*; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; /// Samples a random execution. pub(crate) fn sample_execution(rng: &mut TestRng) -> Execution { diff --git a/ledger/block/src/transaction/fee/mod.rs b/ledger/block/src/transaction/fee/mod.rs index 233704fca4..5bd90737ee 100644 --- a/ledger/block/src/transaction/fee/mod.rs +++ b/ledger/block/src/transaction/fee/mod.rs @@ -207,7 +207,7 @@ pub mod test_helpers { use once_cell::sync::OnceCell; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; type CurrentAleo = circuit::network::AleoV0; /// Samples a random hardcoded private fee. diff --git a/ledger/block/src/transaction/mod.rs b/ledger/block/src/transaction/mod.rs index fe1ace4c76..3115d7a866 100644 --- a/ledger/block/src/transaction/mod.rs +++ b/ledger/block/src/transaction/mod.rs @@ -407,9 +407,9 @@ impl Transaction { #[cfg(test)] pub mod test_helpers { use super::*; - use console::{account::PrivateKey, network::Testnet3, program::ProgramOwner}; + use console::{account::PrivateKey, network::MainnetV0, program::ProgramOwner}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Samples a random deployment transaction with a private or public fee. pub fn sample_deployment_transaction(is_fee_private: bool, rng: &mut TestRng) -> Transaction { diff --git a/ledger/block/src/transactions/confirmed/mod.rs b/ledger/block/src/transactions/confirmed/mod.rs index 9d16b7915d..b1d4164d9a 100644 --- a/ledger/block/src/transactions/confirmed/mod.rs +++ b/ledger/block/src/transactions/confirmed/mod.rs @@ -17,7 +17,7 @@ mod serialize; mod string; use crate::{rejected::Rejected, Transaction}; -use console::{network::prelude::*, types::Field}; +use console::{network::prelude::*, program::FINALIZE_ID_DEPTH, types::Field}; use synthesizer_program::FinalizeOperation; pub type NumFinalizeSize = u16; @@ -261,6 +261,16 @@ impl ConfirmedTransaction { } } + /// Returns the finalize ID, by computing the root of a (small) Merkle tree comprised of + /// the ordered finalize operations for the transaction. + pub fn to_finalize_id(&self) -> Result> { + // Prepare the leaves. + let leaves = self.finalize_operations().iter().map(ToBits::to_bits_le).collect::>(); + // Compute the finalize ID. + // Note: This call will ensure the number of finalize operations is within the size of the Merkle tree. + Ok(*N::merkle_tree_bhp::(&leaves)?.root()) + } + /// Returns the rejected ID, if the confirmed transaction is rejected. pub fn to_rejected_id(&self) -> Result>> { match self { @@ -328,9 +338,9 @@ impl Deref for ConfirmedTransaction { #[cfg(test)] pub mod test_helpers { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Samples an accepted deploy transaction at the given index. pub(crate) fn sample_accepted_deploy( @@ -439,7 +449,7 @@ mod test { use super::*; use crate::transactions::confirmed::test_helpers; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; #[test] fn test_accepted_execute() { diff --git a/ledger/block/src/transactions/merkle.rs b/ledger/block/src/transactions/merkle.rs index 4efc914ba5..74c4fd9006 100644 --- a/ledger/block/src/transactions/merkle.rs +++ b/ledger/block/src/transactions/merkle.rs @@ -17,13 +17,23 @@ use super::*; impl Transactions { /// Returns the finalize root of the transactions. pub fn to_finalize_root(&self, ratified_finalize_operations: Vec>) -> Result> { - // Prepare the leaves. - let leaves = self.finalize_operations().chain(&ratified_finalize_operations).map(ToBits::to_bits_le); - // Compute the finalize tree. - // Note: This call will check the number of finalize operations is within the size of the Merkle tree. - let tree = N::merkle_tree_bhp::(&leaves.collect::>())?; - // Return the finalize root. - Ok(*tree.root()) + // Prepare the ratified finalize ID - a Merkle tree composed of the ratified finalize operations. + let ratified_finalize_id = *N::merkle_tree_bhp::( + &ratified_finalize_operations.iter().map(ToBits::to_bits_le).collect::>(), + )? + .root(); + + // Prepare the leaves, composed of: + // | transaction_0 finalize ID, ..., transaction_n finalize ID | ratified finalize ID | + let leaves = self + .iter() + .map(|tx| tx.to_finalize_id().map(|id| id.to_bits_le())) + .chain(std::iter::once(Ok(ratified_finalize_id.to_bits_le()))) + .collect::>>()?; + + // Compute the finalize root. + // Note: This call will ensure the number of finalize operations is within the size of the Merkle tree. + Ok(*N::merkle_tree_bhp::(&leaves)?.root()) } } @@ -67,13 +77,17 @@ impl Transactions { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_transactions_depth() { // Ensure the log2 relationship between depth and the maximum number of transactions. - assert_eq!(2usize.pow(TRANSACTIONS_DEPTH as u32), Transactions::::MAX_TRANSACTIONS); + // Note: This test uses 'checked_sub' to ensure the depth is not zero. + assert_eq!( + 2usize.pow(TRANSACTIONS_DEPTH as u32).checked_sub(1).expect("Invalid depth"), + Transactions::::MAX_TRANSACTIONS + ); } } diff --git a/ledger/block/src/transactions/mod.rs b/ledger/block/src/transactions/mod.rs index 2eb3a31372..90bd1ec721 100644 --- a/ledger/block/src/transactions/mod.rs +++ b/ledger/block/src/transactions/mod.rs @@ -32,11 +32,14 @@ use console::{ Record, TransactionsPath, TransactionsTree, + FINALIZE_ID_DEPTH, FINALIZE_OPERATIONS_DEPTH, TRANSACTIONS_DEPTH, }, types::{Field, Group, U64}, }; +use ledger_committee::Committee; +use ledger_narwhal_batch_header::BatchHeader; use synthesizer_program::FinalizeOperation; use indexmap::IndexMap; @@ -166,8 +169,12 @@ impl Transactions { } impl Transactions { + /// The maximum number of aborted transactions allowed in a block. + pub const MAX_ABORTED_TRANSACTIONS: usize = BatchHeader::::MAX_TRANSMISSIONS_PER_BATCH + * BatchHeader::::MAX_GC_ROUNDS + * Committee::::MAX_COMMITTEE_SIZE as usize; /// The maximum number of transactions allowed in a block. - pub const MAX_TRANSACTIONS: usize = usize::pow(2, TRANSACTIONS_DEPTH as u32); + pub const MAX_TRANSACTIONS: usize = usize::pow(2, TRANSACTIONS_DEPTH as u32).saturating_sub(1); /// Returns an iterator over all transactions, for all transactions in `self`. pub fn iter(&self) -> impl '_ + ExactSizeIterator> { @@ -176,7 +183,7 @@ impl Transactions { /// Returns a parallel iterator over all transactions, for all transactions in `self`. #[cfg(not(feature = "serial"))] - pub fn par_iter(&self) -> impl '_ + ParallelIterator> { + pub fn par_iter(&self) -> impl '_ + IndexedParallelIterator> { self.transactions.par_values() } @@ -332,7 +339,7 @@ impl Transactions { pub mod test_helpers { use super::*; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; /// Samples a block transactions. pub(crate) fn sample_block_transactions(rng: &mut TestRng) -> Transactions { @@ -343,14 +350,23 @@ pub mod test_helpers { #[cfg(test)] mod tests { use super::*; + use ledger_narwhal_batch_header::BatchHeader; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; #[test] - fn test_max_transactions() { - assert_eq!( - Transactions::::MAX_TRANSACTIONS, - ledger_narwhal_batch_header::BatchHeader::::MAX_TRANSACTIONS + fn test_max_transmissions() { + // Determine the maximum number of transmissions in a block. + let max_transmissions_per_block = BatchHeader::::MAX_TRANSMISSIONS_PER_BATCH + * BatchHeader::::MAX_GC_ROUNDS + * BatchHeader::::MAX_CERTIFICATES as usize; + + // Note: The maximum number of *transmissions* in a block cannot exceed the maximum number of *transactions* in a block. + // If you intended to change the number of 'MAX_TRANSACTIONS', note that this will break the inclusion proof, + // and you will need to migrate all users to a new circuit for the inclusion proof. + assert!( + max_transmissions_per_block <= Transactions::::MAX_TRANSACTIONS, + "The maximum number of transmissions in a block is too large" ); } } diff --git a/ledger/block/src/transactions/rejected/mod.rs b/ledger/block/src/transactions/rejected/mod.rs index c730935c4d..6ce9886201 100644 --- a/ledger/block/src/transactions/rejected/mod.rs +++ b/ledger/block/src/transactions/rejected/mod.rs @@ -94,9 +94,9 @@ impl Rejected { #[cfg(test)] pub mod test_helpers { use super::*; - use console::{account::PrivateKey, network::Testnet3}; + use console::{account::PrivateKey, network::MainnetV0}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Samples a rejected deployment. pub(crate) fn sample_rejected_deployment(is_fee_private: bool, rng: &mut TestRng) -> Rejected { diff --git a/ledger/block/src/transactions/serialize.rs b/ledger/block/src/transactions/serialize.rs index f1a264e611..a1e5d3b92e 100644 --- a/ledger/block/src/transactions/serialize.rs +++ b/ledger/block/src/transactions/serialize.rs @@ -65,9 +65,9 @@ impl<'de, N: Network> Deserialize<'de> for Transactions { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u32 = 6; diff --git a/ledger/block/src/transition/bytes.rs b/ledger/block/src/transition/bytes.rs index dacc875df8..3654b7de17 100644 --- a/ledger/block/src/transition/bytes.rs +++ b/ledger/block/src/transition/bytes.rs @@ -53,10 +53,12 @@ impl FromBytes for Transition { let tpk = FromBytes::read_le(&mut reader)?; // Read the transition commitment. let tcm = FromBytes::read_le(&mut reader)?; + // Read the signer commitment. + let scm = FromBytes::read_le(&mut reader)?; // Construct the candidate transition. let transition = - Self::new(program_id, function_name, inputs, outputs, tpk, tcm).map_err(|e| error(e.to_string()))?; + Self::new(program_id, function_name, inputs, outputs, tpk, tcm, scm).map_err(|e| error(e.to_string()))?; // Ensure the transition ID matches the expected ID. match transition_id == *transition.id() { true => Ok(transition), @@ -91,7 +93,9 @@ impl ToBytes for Transition { // Write the transition public key. self.tpk.write_le(&mut writer)?; // Write the transition commitment. - self.tcm.write_le(&mut writer) + self.tcm.write_le(&mut writer)?; + // Write the signer commitment. + self.scm.write_le(&mut writer) } } diff --git a/ledger/block/src/transition/input/mod.rs b/ledger/block/src/transition/input/mod.rs index 284af88f76..c49beb2c11 100644 --- a/ledger/block/src/transition/input/mod.rs +++ b/ledger/block/src/transition/input/mod.rs @@ -180,9 +180,9 @@ impl Input { #[cfg(test)] pub(crate) mod test_helpers { use super::*; - use console::{network::Testnet3, program::Literal}; + use console::{network::MainnetV0, program::Literal}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Sample the transition inputs. pub(crate) fn sample_inputs() -> Vec<(::TransitionID, Input)> { diff --git a/ledger/block/src/transition/merkle.rs b/ledger/block/src/transition/merkle.rs index d5a8fb33b1..4874a675e0 100644 --- a/ledger/block/src/transition/merkle.rs +++ b/ledger/block/src/transition/merkle.rs @@ -36,7 +36,7 @@ impl Transition { // Check if the input ID matches the given ID. if id == input.id() { // Return the transition leaf. - return Ok(input.to_transition_leaf(index as u8)); + return Ok(input.to_transition_leaf(u8::try_from(index)?)); } } // Error if the input ID was not found. @@ -48,7 +48,7 @@ impl Transition { // Check if the output ID matches the given ID. if id == output.id() { // Return the transition leaf. - return Ok(output.to_transition_leaf((self.inputs.len() + index) as u8)); + return Ok(output.to_transition_leaf(u8::try_from(self.inputs.len() + index)?)); } } // Error if the output ID was not found. @@ -97,9 +97,9 @@ impl Transition { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_transition_depth() { diff --git a/ledger/block/src/transition/mod.rs b/ledger/block/src/transition/mod.rs index 26ee80ac41..0856e20cf4 100644 --- a/ledger/block/src/transition/mod.rs +++ b/ledger/block/src/transition/mod.rs @@ -26,6 +26,7 @@ mod string; use console::{ network::prelude::*, program::{ + compute_function_id, Ciphertext, Identifier, InputID, @@ -61,6 +62,8 @@ pub struct Transition { tpk: Group, /// The transition commitment. tcm: Field, + /// The transition signer commitment. + scm: Field, } impl Transition { @@ -73,12 +76,13 @@ impl Transition { outputs: Vec>, tpk: Group, tcm: Field, + scm: Field, ) -> Result { // Compute the transition ID. let function_tree = Self::function_tree(&inputs, &outputs)?; let id = N::hash_bhp512(&(*function_tree.root(), tcm).to_bits_le())?; // Return the transition. - Ok(Self { id: id.into(), program_id, function_name, inputs, outputs, tpk, tcm }) + Ok(Self { id: id.into(), program_id, function_name, inputs, outputs, tpk, tcm, scm }) } /// Initializes a new transition from a request and response. @@ -93,9 +97,8 @@ impl Transition { let function_name = *request.function_name(); let num_inputs = request.inputs().len(); - // Compute the function ID as `Hash(network_id, program_id, function_name)`. - let function_id = - N::hash_bhp1024(&(network_id, program_id.name(), program_id.network(), function_name).to_bits_le())?; + // Compute the function ID. + let function_id = compute_function_id(&network_id, &program_id, &function_name)?; let inputs = request .input_ids() @@ -255,8 +258,10 @@ impl Transition { let tpk = request.to_tpk(); // Retrieve the `tcm`. let tcm = *request.tcm(); + // Retrieve the `scm`. + let scm = *request.scm(); // Return the transition. - Self::new(program_id, function_name, inputs, outputs, tpk, tcm) + Self::new(program_id, function_name, inputs, outputs, tpk, tcm, scm) } } @@ -295,19 +300,30 @@ impl Transition { pub const fn tcm(&self) -> &Field { &self.tcm } + + /// Returns the signer commitment. + pub const fn scm(&self) -> &Field { + &self.scm + } } impl Transition { - /// Returns `true` if this is a `bond` transition. + /// Returns `true` if this is a `bond_public` transition. #[inline] - pub fn is_bond(&self) -> bool { - self.program_id.to_string() == "credits.aleo" && self.function_name.to_string() == "bond" + pub fn is_bond_public(&self) -> bool { + self.inputs.len() == 2 + && self.outputs.is_empty() + && self.program_id.to_string() == "credits.aleo" + && self.function_name.to_string() == "bond_public" } - /// Returns `true` if this is an `unbond` transition. + /// Returns `true` if this is an `unbond_public` transition. #[inline] - pub fn is_unbond(&self) -> bool { - self.program_id.to_string() == "credits.aleo" && self.function_name.to_string() == "unbond" + pub fn is_unbond_public(&self) -> bool { + self.inputs.len() == 2 + && self.outputs.is_empty() + && self.program_id.to_string() == "credits.aleo" + && self.function_name.to_string() == "unbond_public" } /// Returns `true` if this is a `fee_private` transition. @@ -465,7 +481,7 @@ pub mod test_helpers { use super::*; use crate::Transaction; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; /// Samples a random transition. pub(crate) fn sample_transition(rng: &mut TestRng) -> Transition { diff --git a/ledger/block/src/transition/output/mod.rs b/ledger/block/src/transition/output/mod.rs index 3f0f5ff7a4..84a7b5c594 100644 --- a/ledger/block/src/transition/output/mod.rs +++ b/ledger/block/src/transition/output/mod.rs @@ -257,9 +257,9 @@ impl Output { #[cfg(test)] pub(crate) mod test_helpers { use super::*; - use console::{network::Testnet3, program::Literal}; + use console::{network::MainnetV0, program::Literal}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Sample the transition outputs. pub(crate) fn sample_outputs() -> Vec<(::TransitionID, Output)> { diff --git a/ledger/block/src/transition/serialize.rs b/ledger/block/src/transition/serialize.rs index 47e5e4b4f4..a9c1c31dae 100644 --- a/ledger/block/src/transition/serialize.rs +++ b/ledger/block/src/transition/serialize.rs @@ -27,6 +27,7 @@ impl Serialize for Transition { transition.serialize_field("outputs", &self.outputs)?; transition.serialize_field("tpk", &self.tpk)?; transition.serialize_field("tcm", &self.tcm)?; + transition.serialize_field("scm", &self.scm)?; transition.end() } false => ToBytesSerializer::serialize_with_size_encoding(self, serializer), @@ -58,6 +59,8 @@ impl<'de, N: Network> Deserialize<'de> for Transition { DeserializeExt::take_from_value::(&mut transition, "tpk")?, // Retrieve the `tcm`. DeserializeExt::take_from_value::(&mut transition, "tcm")?, + // Retrieve the `scm`. + DeserializeExt::take_from_value::(&mut transition, "scm")?, ) .map_err(de::Error::custom)?; diff --git a/ledger/block/src/verify.rs b/ledger/block/src/verify.rs index 6a278897b9..5517f81001 100644 --- a/ledger/block/src/verify.rs +++ b/ledger/block/src/verify.rs @@ -30,18 +30,23 @@ impl Block { &self, previous_block: &Block, current_state_root: N::StateRoot, - current_committee: &Committee, + current_committee_lookback: &Committee, current_puzzle: &CoinbasePuzzle, current_epoch_challenge: &EpochChallenge, current_timestamp: i64, ratified_finalize_operations: Vec>, - ) -> Result<()> { + ) -> Result<(Vec>, Vec)> { // Ensure the block hash is correct. self.verify_hash(previous_block.height(), previous_block.hash())?; // Ensure the block authority is correct. - let (expected_round, expected_height, expected_timestamp) = - self.verify_authority(previous_block.round(), previous_block.height(), current_committee)?; + let ( + expected_round, + expected_height, + expected_timestamp, + expected_existing_solution_ids, + expected_existing_transaction_ids, + ) = self.verify_authority(previous_block.round(), previous_block.height(), current_committee_lookback)?; // Ensure the block solutions are correct. let ( @@ -92,7 +97,10 @@ impl Block { expected_last_coinbase_timestamp, expected_timestamp, current_timestamp, - ) + )?; + + // Return the expected existing solution IDs and transaction IDs. + Ok((expected_existing_solution_ids, expected_existing_transaction_ids)) } } @@ -135,8 +143,9 @@ impl Block { &self, previous_round: u64, previous_height: u32, - current_committee: &Committee, - ) -> Result<(u64, u32, i64)> { + current_committee_lookback: &Committee, + ) -> Result<(u64, u32, i64, Vec>, Vec)> { + // Note: Do not remove this. This ensures that all blocks after genesis are quorum blocks. #[cfg(not(any(test, feature = "test")))] ensure!(self.authority.is_quorum(), "The next block must be a quorum block"); @@ -161,22 +170,24 @@ impl Block { subdag.anchor_round() } }; - // Ensure the block round is at least the starting round of the committee. + // Ensure the block round minus the committee lookback range is at least the starting round of the committee lookback. ensure!( - expected_round >= current_committee.starting_round(), - "Block {} has an invalid round (found '{expected_round}', expected at least '{}')", - expected_height, - current_committee.starting_round() + expected_round.saturating_sub(Committee::::COMMITTEE_LOOKBACK_RANGE) + >= current_committee_lookback.starting_round(), + "Block {expected_height} has an invalid round (found '{}', expected at least '{}')", + expected_round.saturating_sub(Committee::::COMMITTEE_LOOKBACK_RANGE), + current_committee_lookback.starting_round() ); // Ensure the block authority is correct. - match &self.authority { + // Determine the solution IDs and transaction IDs that are expected to be in previous blocks. + let (expected_existing_solution_ids, expected_existing_transaction_ids) = match &self.authority { Authority::Beacon(signature) => { // Retrieve the signer. let signer = signature.to_address(); // Ensure the block is signed by a committee member. ensure!( - current_committee.members().contains_key(&signer), + current_committee_lookback.members().contains_key(&signer), "Beacon block {expected_height} has a signer not in the committee (found '{signer}')", ); // Ensure the signature is valid. @@ -184,10 +195,12 @@ impl Block { signature.verify(&signer, &[*self.block_hash]), "Signature is invalid in block {expected_height}" ); + + (vec![], vec![]) } Authority::Quorum(subdag) => { // Compute the expected leader. - let expected_leader = current_committee.get_leader(expected_round)?; + let expected_leader = current_committee_lookback.get_leader(expected_round)?; // Ensure the block is authored by the expected leader. ensure!( subdag.leader_address() == expected_leader, @@ -198,22 +211,29 @@ impl Block { Self::check_subdag_transmissions( subdag, &self.solutions, + &self.aborted_solution_ids, &self.transactions, &self.aborted_transaction_ids, - )?; + )? } - } + }; // Determine the expected timestamp. let expected_timestamp = match &self.authority { // Beacon blocks do not have a timestamp check. Authority::Beacon(..) => self.timestamp(), - // Quorum blocks use the median timestamp from the subdag. - Authority::Quorum(subdag) => subdag.timestamp(), + // Quorum blocks use the weighted median timestamp from the subdag. + Authority::Quorum(subdag) => subdag.timestamp(current_committee_lookback), }; // Return success. - Ok((expected_round, expected_height, expected_timestamp)) + Ok(( + expected_round, + expected_height, + expected_timestamp, + expected_existing_solution_ids, + expected_existing_transaction_ids, + )) } /// Ensures the block ratifications are correct. @@ -260,22 +280,43 @@ impl Block { let height = self.height(); let timestamp = self.timestamp(); - let (combined_proof_target, expected_cumulative_proof_target, is_coinbase_target_reached) = match &self - .solutions - { - Some(coinbase) => { - // Ensure the number of solutions is within the allowed range. - ensure!( - coinbase.len() <= N::MAX_SOLUTIONS, - "Block {height} contains too many prover solutions (found '{}', expected '{}')", - coinbase.len(), - N::MAX_SOLUTIONS - ); - // Ensure the solutions are not accepted after the block height at year 10. - if height > block_height_at_year(N::BLOCK_TIME, 10) { - bail!("Solutions are no longer accepted after the block height at year 10."); - } + // Ensure the solutions are not accepted after the block height at year 10. + if !self.solutions.is_empty() && height > block_height_at_year(N::BLOCK_TIME, 10) { + bail!("Solutions are no longer accepted after the block height at year 10."); + } + + // Ensure the number of solutions is within the allowed range. + ensure!( + self.solutions.len() <= N::MAX_SOLUTIONS, + "Block {height} contains too many prover solutions (found '{}', expected '{}')", + self.solutions.len(), + N::MAX_SOLUTIONS + ); + // Ensure the number of aborted solution IDs is within the allowed range. + ensure!( + self.aborted_solution_ids.len() <= Solutions::::MAX_ABORTED_SOLUTIONS, + "Block {height} contains too many aborted solution IDs (found '{}', expected '{}')", + self.aborted_solution_ids.len(), + Solutions::::MAX_ABORTED_SOLUTIONS + ); + // Ensure there are no duplicate solution IDs. + if has_duplicates( + self.solutions + .as_ref() + .map(CoinbaseSolution::puzzle_commitments) + .into_iter() + .flatten() + .chain(self.aborted_solution_ids()), + ) { + bail!("Found a duplicate solution in block {height}"); + } + + // Compute the combined proof target. + let combined_proof_target = self.solutions.to_combined_proof_target()?; + + let (expected_cumulative_proof_target, is_coinbase_target_reached) = match self.solutions.deref() { + Some(coinbase) => { // Ensure the puzzle proof is valid. if let Err(e) = current_puzzle.check_solutions(coinbase, current_epoch_challenge, previous_block.proof_target()) @@ -283,9 +324,6 @@ impl Block { bail!("Block {height} contains an invalid puzzle proof - {e}"); } - // Compute the combined proof target. - let combined_proof_target = coinbase.to_combined_proof_target()?; - // Ensure that the block cumulative proof target is less than the previous block's coinbase target. // Note: This is a sanity check, as the cumulative proof target resets to 0 if the // coinbase target was reached in this block. @@ -306,15 +344,13 @@ impl Block { false => cumulative_proof_target, }; - (combined_proof_target, expected_cumulative_proof_target, is_coinbase_target_reached) + (expected_cumulative_proof_target, is_coinbase_target_reached) } None => { - // Set the combined proof target. - let combined_proof_target = 0; // Determine the cumulative proof target. let expected_cumulative_proof_target = previous_block.cumulative_proof_target(); - (combined_proof_target, expected_cumulative_proof_target, false) + (expected_cumulative_proof_target, false) } }; @@ -393,10 +429,10 @@ impl Block { } // Ensure the number of aborted transaction IDs is within the allowed range. - if self.aborted_transaction_ids.len() > Transactions::::MAX_TRANSACTIONS { + if self.aborted_transaction_ids.len() > Transactions::::MAX_ABORTED_TRANSACTIONS { bail!( "Cannot validate a block with more than {} aborted transaction IDs", - Transactions::::MAX_TRANSACTIONS + Transactions::::MAX_ABORTED_TRANSACTIONS ); } @@ -487,10 +523,7 @@ impl Block { /// Computes the solutions root for the block. fn compute_solutions_root(&self) -> Result> { - match self.solutions { - Some(ref coinbase) => coinbase.to_accumulator_point(), - None => Ok(Field::zero()), - } + self.solutions.to_solutions_root() } /// Computes the subdag root for the block. @@ -502,12 +535,14 @@ impl Block { } /// Checks that the transmission IDs in the given subdag matches the solutions and transactions in the block. + /// Returns the IDs of the transactions and solutions that should already exist in the ledger. pub(super) fn check_subdag_transmissions( subdag: &Subdag, solutions: &Option>, + aborted_solution_ids: &[PuzzleCommitment], transactions: &Transactions, aborted_transaction_ids: &[N::TransactionID], - ) -> Result<()> { + ) -> Result<(Vec>, Vec)> { // Prepare an iterator over the solution IDs. let mut solutions = solutions.as_ref().map(|s| s.deref()).into_iter().flatten().peekable(); // Prepare an iterator over the unconfirmed transaction IDs. @@ -516,13 +551,13 @@ impl Block { .collect::>>()?; let mut unconfirmed_transaction_ids = unconfirmed_transaction_ids.iter().peekable(); - // Initialize a list of already seen transmission IDs. + // Initialize a set of already seen transmission IDs. let mut seen_transmission_ids = HashSet::new(); - // Initialize a list of aborted or already-existing solution IDs. - let mut aborted_or_existing_solution_ids = Vec::new(); - // Initialize a list of aborted or already-existing transaction IDs. - let mut aborted_or_existing_transaction_ids = Vec::new(); + // Initialize a set of aborted or already-existing solution IDs. + let mut aborted_or_existing_solution_ids = HashSet::new(); + // Initialize a set of aborted or already-existing transaction IDs. + let mut aborted_or_existing_transaction_ids = HashSet::new(); // Iterate over the transmission IDs. for transmission_id in subdag.transmission_ids() { @@ -534,15 +569,19 @@ impl Block { // Process the transmission ID. match transmission_id { TransmissionID::Ratification => {} - TransmissionID::Solution(commitment) => { + TransmissionID::Solution(solution_id) => { match solutions.peek() { - // Check the next solution matches the expected commitment. - Some((_, solution)) if solution.commitment() == *commitment => { + // Check the next solution matches the expected solution ID. + Some((_, solution)) if solution.commitment() == *solution_id => { // Increment the solution iterator. solutions.next(); } // Otherwise, add the solution ID to the aborted or existing list. - _ => aborted_or_existing_solution_ids.push(commitment), + _ => { + if !aborted_or_existing_solution_ids.insert(*solution_id) { + bail!("Block contains a duplicate aborted solution ID (found '{solution_id}')"); + } + } } } TransmissionID::Transaction(transaction_id) => { @@ -553,7 +592,11 @@ impl Block { unconfirmed_transaction_ids.next(); } // Otherwise, add the transaction ID to the aborted or existing list. - _ => aborted_or_existing_transaction_ids.push(*transaction_id), + _ => { + if !aborted_or_existing_transaction_ids.insert(*transaction_id) { + bail!("Block contains a duplicate aborted transaction ID (found '{transaction_id}')"); + } + } } } } @@ -564,9 +607,15 @@ impl Block { // Ensure there are no more transactions in the block. ensure!(unconfirmed_transaction_ids.next().is_none(), "There exists more transactions than expected."); - // TODO: Move this check to be outside of this method, and check against the ledger for existence. - // Ensure there are no aborted or existing solution IDs. - // ensure!(aborted_or_existing_solution_ids.is_empty(), "Block contains aborted or already-existing solutions."); + // Ensure the aborted solution IDs match. + for aborted_solution_id in aborted_solution_ids { + // If the aborted transaction ID is not found, throw an error. + if !aborted_or_existing_solution_ids.contains(aborted_solution_id) { + bail!( + "Block contains an aborted solution ID that is not found in the subdag (found '{aborted_solution_id}')" + ); + } + } // Ensure the aborted transaction IDs match. for aborted_transaction_id in aborted_transaction_ids { // If the aborted transaction ID is not found, throw an error. @@ -577,6 +626,17 @@ impl Block { } } - Ok(()) + // Retrieve the solution IDs that should already exist in the ledger. + let existing_solution_ids: Vec<_> = aborted_or_existing_solution_ids + .difference(&aborted_solution_ids.iter().copied().collect()) + .copied() + .collect(); + // Retrieve the transaction IDs that should already exist in the ledger. + let existing_transaction_ids: Vec<_> = aborted_or_existing_transaction_ids + .difference(&aborted_transaction_ids.iter().copied().collect()) + .copied() + .collect(); + + Ok((existing_solution_ids, existing_transaction_ids)) } } diff --git a/ledger/coinbase/Cargo.toml b/ledger/coinbase/Cargo.toml index 4af319fcec..dbb5b6ce3f 100644 --- a/ledger/coinbase/Cargo.toml +++ b/ledger/coinbase/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-ledger-coinbase" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Coinbase puzzle for a decentralized virtual machine" homepage = "https://aleo.org" @@ -50,31 +50,31 @@ wasm = [ [dependencies.console] package = "snarkvm-console" path = "../../console" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-algorithms] path = "../../algorithms" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-curves] path = "../../curves" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-fields] path = "../../fields" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-synthesizer-snark] path = "../../synthesizer/snark" -version = "=0.16.15" +version = "=0.16.19" [dependencies.snarkvm-utilities] path = "../../utilities" -version = "=0.16.15" +version = "=0.16.19" default-features = false [dependencies.aleo-std] -version = "0.1.18" +version = "0.1.24" default-features = false [dependencies.anyhow] diff --git a/ledger/coinbase/benches/coinbase_puzzle.rs b/ledger/coinbase/benches/coinbase_puzzle.rs index fe8c86c4ca..d48757930a 100644 --- a/ledger/coinbase/benches/coinbase_puzzle.rs +++ b/ledger/coinbase/benches/coinbase_puzzle.rs @@ -19,29 +19,29 @@ extern crate criterion; use console::{ account::*, - network::{Network, Testnet3}, + network::{MainnetV0, Network}, }; use snarkvm_ledger_coinbase::{CoinbasePuzzle, CoinbaseSolution, EpochChallenge, PuzzleConfig}; use criterion::Criterion; use rand::{self, thread_rng, CryptoRng, RngCore}; -type CoinbasePuzzleInst = CoinbasePuzzle; +type CoinbasePuzzleInst = CoinbasePuzzle; fn sample_inputs( degree: u32, rng: &mut (impl CryptoRng + RngCore), -) -> (EpochChallenge, Address, u64) { +) -> (EpochChallenge, Address, u64) { let epoch_challenge = sample_epoch_challenge(degree, rng); let (address, nonce) = sample_address_and_nonce(rng); (epoch_challenge, address, nonce) } -fn sample_epoch_challenge(degree: u32, rng: &mut (impl CryptoRng + RngCore)) -> EpochChallenge { +fn sample_epoch_challenge(degree: u32, rng: &mut (impl CryptoRng + RngCore)) -> EpochChallenge { EpochChallenge::new(rng.next_u32(), Default::default(), degree).unwrap() } -fn sample_address_and_nonce(rng: &mut (impl CryptoRng + RngCore)) -> (Address, u64) { +fn sample_address_and_nonce(rng: &mut (impl CryptoRng + RngCore)) -> (Address, u64) { let private_key = PrivateKey::new(rng).unwrap(); let address = Address::try_from(private_key).unwrap(); let nonce = rng.next_u64(); @@ -52,7 +52,7 @@ fn sample_address_and_nonce(rng: &mut (impl CryptoRng + RngCore)) -> (Address::setup(max_config).unwrap(); + let universal_srs = CoinbasePuzzle::::setup(max_config).unwrap(); for degree in [(1 << 13) - 1] { let config = PuzzleConfig { degree }; @@ -69,7 +69,7 @@ fn coinbase_puzzle_prove(c: &mut Criterion) { let max_degree = 1 << 15; let max_config = PuzzleConfig { degree: max_degree }; - let universal_srs = CoinbasePuzzle::::setup(max_config).unwrap(); + let universal_srs = CoinbasePuzzle::::setup(max_config).unwrap(); for degree in [(1 << 13) - 1] { let config = PuzzleConfig { degree }; @@ -88,14 +88,14 @@ fn coinbase_puzzle_verify(c: &mut Criterion) { let max_degree = 1 << 15; let max_config = PuzzleConfig { degree: max_degree }; - let universal_srs = CoinbasePuzzle::::setup(max_config).unwrap(); + let universal_srs = CoinbasePuzzle::::setup(max_config).unwrap(); for degree in [(1 << 13) - 1] { let config = PuzzleConfig { degree }; let puzzle = CoinbasePuzzleInst::trim(&universal_srs, config).unwrap(); let epoch_challenge = sample_epoch_challenge(degree, rng); - for batch_size in [10, 100, ::MAX_SOLUTIONS] { + for batch_size in [10, 100, ::MAX_SOLUTIONS] { let solutions = (0..batch_size) .map(|_| { let (address, nonce) = sample_address_and_nonce(rng); diff --git a/ledger/coinbase/src/helpers/coinbase_solution/serialize.rs b/ledger/coinbase/src/helpers/coinbase_solution/serialize.rs index ac973aee78..ab461e7023 100644 --- a/ledger/coinbase/src/helpers/coinbase_solution/serialize.rs +++ b/ledger/coinbase/src/helpers/coinbase_solution/serialize.rs @@ -48,7 +48,7 @@ pub(super) mod tests { use super::*; use console::account::PrivateKey; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; pub(crate) fn sample_solutions(rng: &mut TestRng) -> CoinbaseSolution { // Sample a new solutions. diff --git a/ledger/coinbase/src/helpers/epoch_challenge/bytes.rs b/ledger/coinbase/src/helpers/epoch_challenge/bytes.rs index e9e250ca9f..45398c0956 100644 --- a/ledger/coinbase/src/helpers/epoch_challenge/bytes.rs +++ b/ledger/coinbase/src/helpers/epoch_challenge/bytes.rs @@ -43,11 +43,11 @@ impl ToBytes for EpochChallenge { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; use rand::RngCore; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: usize = 100; diff --git a/ledger/coinbase/src/helpers/partial_solution/bytes.rs b/ledger/coinbase/src/helpers/partial_solution/bytes.rs index 7b919d93d5..57ef315034 100644 --- a/ledger/coinbase/src/helpers/partial_solution/bytes.rs +++ b/ledger/coinbase/src/helpers/partial_solution/bytes.rs @@ -37,9 +37,9 @@ impl ToBytes for PartialSolution { #[cfg(test)] mod tests { use super::*; - use console::{account::PrivateKey, network::Testnet3}; + use console::{account::PrivateKey, network::MainnetV0}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_bytes() -> Result<()> { diff --git a/ledger/coinbase/src/helpers/partial_solution/serialize.rs b/ledger/coinbase/src/helpers/partial_solution/serialize.rs index 322b0b155a..c71cfdb89e 100644 --- a/ledger/coinbase/src/helpers/partial_solution/serialize.rs +++ b/ledger/coinbase/src/helpers/partial_solution/serialize.rs @@ -52,9 +52,9 @@ impl<'de, N: Network> Deserialize<'de> for PartialSolution { #[cfg(test)] mod tests { use super::*; - use console::{account::PrivateKey, network::Testnet3}; + use console::{account::PrivateKey, network::MainnetV0}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_serde_json() -> Result<()> { diff --git a/ledger/coinbase/src/helpers/partial_solution/string.rs b/ledger/coinbase/src/helpers/partial_solution/string.rs index 4b21975538..d194cc2121 100644 --- a/ledger/coinbase/src/helpers/partial_solution/string.rs +++ b/ledger/coinbase/src/helpers/partial_solution/string.rs @@ -40,9 +40,9 @@ impl Display for PartialSolution { #[cfg(test)] mod tests { use super::*; - use console::{account::PrivateKey, network::Testnet3}; + use console::{account::PrivateKey, network::MainnetV0}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_string() -> Result<()> { diff --git a/ledger/coinbase/src/helpers/prover_solution/bytes.rs b/ledger/coinbase/src/helpers/prover_solution/bytes.rs index f5c5bdacf8..20e846b5f5 100644 --- a/ledger/coinbase/src/helpers/prover_solution/bytes.rs +++ b/ledger/coinbase/src/helpers/prover_solution/bytes.rs @@ -35,9 +35,9 @@ impl ToBytes for ProverSolution { #[cfg(test)] mod tests { use super::*; - use console::{account::PrivateKey, network::Testnet3}; + use console::{account::PrivateKey, network::MainnetV0}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_bytes() -> Result<()> { diff --git a/ledger/coinbase/src/helpers/prover_solution/serialize.rs b/ledger/coinbase/src/helpers/prover_solution/serialize.rs index 564cba8bed..0b737310b0 100644 --- a/ledger/coinbase/src/helpers/prover_solution/serialize.rs +++ b/ledger/coinbase/src/helpers/prover_solution/serialize.rs @@ -60,9 +60,9 @@ impl<'de, N: Network> Deserialize<'de> for ProverSolution { #[cfg(test)] mod tests { use super::*; - use console::{account::PrivateKey, network::Testnet3}; + use console::{account::PrivateKey, network::MainnetV0}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_serde_json() -> Result<()> { diff --git a/ledger/coinbase/src/helpers/prover_solution/string.rs b/ledger/coinbase/src/helpers/prover_solution/string.rs index 66f6a79275..1c96dcb4ed 100644 --- a/ledger/coinbase/src/helpers/prover_solution/string.rs +++ b/ledger/coinbase/src/helpers/prover_solution/string.rs @@ -40,9 +40,9 @@ impl Display for ProverSolution { #[cfg(test)] mod tests { use super::*; - use console::{account::PrivateKey, network::Testnet3}; + use console::{account::PrivateKey, network::MainnetV0}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_string() -> Result<()> { diff --git a/ledger/coinbase/src/helpers/puzzle_commitment/bytes.rs b/ledger/coinbase/src/helpers/puzzle_commitment/bytes.rs index 1f83beb97d..f76cca0553 100644 --- a/ledger/coinbase/src/helpers/puzzle_commitment/bytes.rs +++ b/ledger/coinbase/src/helpers/puzzle_commitment/bytes.rs @@ -33,9 +33,9 @@ impl ToBytes for PuzzleCommitment { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_bytes() -> Result<()> { diff --git a/ledger/coinbase/src/helpers/puzzle_commitment/serialize.rs b/ledger/coinbase/src/helpers/puzzle_commitment/serialize.rs index 3f753fc143..61283b5551 100644 --- a/ledger/coinbase/src/helpers/puzzle_commitment/serialize.rs +++ b/ledger/coinbase/src/helpers/puzzle_commitment/serialize.rs @@ -37,9 +37,9 @@ impl<'de, N: Network> Deserialize<'de> for PuzzleCommitment { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_serde_json() -> Result<()> { diff --git a/ledger/coinbase/src/helpers/puzzle_commitment/string.rs b/ledger/coinbase/src/helpers/puzzle_commitment/string.rs index d01cac5802..3560889e60 100644 --- a/ledger/coinbase/src/helpers/puzzle_commitment/string.rs +++ b/ledger/coinbase/src/helpers/puzzle_commitment/string.rs @@ -57,9 +57,9 @@ impl Display for PuzzleCommitment { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const ITERATIONS: u64 = 1_000; diff --git a/ledger/coinbase/src/tests.rs b/ledger/coinbase/src/tests.rs index 15a39fc6a3..54311253e4 100644 --- a/ledger/coinbase/src/tests.rs +++ b/ledger/coinbase/src/tests.rs @@ -13,7 +13,7 @@ // limitations under the License. use super::*; -use console::{account::*, network::Testnet3}; +use console::{account::*, network::MainnetV0}; use snarkvm_utilities::Uniform; use rand::RngCore; @@ -26,18 +26,18 @@ fn test_coinbase_puzzle() { let max_degree = 1 << 15; let max_config = PuzzleConfig { degree: max_degree }; - let srs = CoinbasePuzzle::::setup(max_config).unwrap(); + let srs = CoinbasePuzzle::::setup(max_config).unwrap(); for log_degree in 5..10 { let degree = (1 << log_degree) - 1; let config = PuzzleConfig { degree }; - let puzzle = CoinbasePuzzle::::trim(&srs, config).unwrap(); + let puzzle = CoinbasePuzzle::::trim(&srs, config).unwrap(); let epoch_challenge = EpochChallenge::new(rng.next_u32(), Default::default(), degree).unwrap(); for batch_size in 1..10 { let solutions = (0..batch_size) .map(|_| { - let private_key = PrivateKey::::new(&mut rng).unwrap(); + let private_key = PrivateKey::::new(&mut rng).unwrap(); let address = Address::try_from(private_key).unwrap(); let nonce = u64::rand(&mut rng); puzzle.prove(&epoch_challenge, address, nonce, None).unwrap() @@ -58,16 +58,16 @@ fn test_prover_solution_minimum_target() { let max_degree = 1 << 15; let max_config = PuzzleConfig { degree: max_degree }; - let srs = CoinbasePuzzle::::setup(max_config).unwrap(); + let srs = CoinbasePuzzle::::setup(max_config).unwrap(); for log_degree in 5..10 { let degree = (1 << log_degree) - 1; let config = PuzzleConfig { degree }; - let puzzle = CoinbasePuzzle::::trim(&srs, config).unwrap(); + let puzzle = CoinbasePuzzle::::trim(&srs, config).unwrap(); let epoch_challenge = EpochChallenge::new(rng.next_u32(), Default::default(), degree).unwrap(); for _ in 0..ITERATIONS { - let private_key = PrivateKey::::new(&mut rng).unwrap(); + let private_key = PrivateKey::::new(&mut rng).unwrap(); let address = Address::try_from(private_key).unwrap(); let nonce = u64::rand(&mut rng); @@ -90,14 +90,14 @@ fn test_edge_case_for_degree() { // Generate srs. let max_degree = 1 << 15; let max_config = PuzzleConfig { degree: max_degree }; - let srs = CoinbasePuzzle::::setup(max_config).unwrap(); + let srs = CoinbasePuzzle::::setup(max_config).unwrap(); // Generate PK and VK. let degree = (1 << 13) - 1; - let puzzle = CoinbasePuzzle::::trim(&srs, PuzzleConfig { degree }).unwrap(); + let puzzle = CoinbasePuzzle::::trim(&srs, PuzzleConfig { degree }).unwrap(); // Generate proof inputs - let private_key = PrivateKey::::new(&mut rng).unwrap(); + let private_key = PrivateKey::::new(&mut rng).unwrap(); let address = Address::try_from(private_key).unwrap(); let epoch_challenge = EpochChallenge::new(rng.gen(), Default::default(), degree).unwrap(); @@ -111,7 +111,7 @@ fn test_edge_case_for_degree() { #[ignore] #[test] fn test_profiler() -> Result<()> { - fn sample_address_and_nonce(rng: &mut (impl CryptoRng + RngCore)) -> (Address, u64) { + fn sample_address_and_nonce(rng: &mut (impl CryptoRng + RngCore)) -> (Address, u64) { let private_key = PrivateKey::new(rng).unwrap(); let address = Address::try_from(private_key).unwrap(); let nonce = rng.next_u64(); @@ -123,7 +123,7 @@ fn test_profiler() -> Result<()> { // Generate srs. let max_degree = 1 << 15; let max_config = PuzzleConfig { degree: max_degree }; - let universal_srs = CoinbasePuzzle::::setup(max_config).unwrap(); + let universal_srs = CoinbasePuzzle::::setup(max_config).unwrap(); // Generate PK and VK. let degree = (1 << 13) - 1; @@ -133,7 +133,7 @@ fn test_profiler() -> Result<()> { // Generate proof inputs let epoch_challenge = EpochChallenge::new(rng.next_u32(), Default::default(), degree).unwrap(); - for batch_size in [10, 100, ::MAX_SOLUTIONS] { + for batch_size in [10, 100, ::MAX_SOLUTIONS] { // Generate the solutions. let solutions = (0..batch_size) .map(|_| { diff --git a/ledger/committee/Cargo.toml b/ledger/committee/Cargo.toml index 2bfae2c3f0..a9cb6dad8c 100644 --- a/ledger/committee/Cargo.toml +++ b/ledger/committee/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-ledger-committee" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "A committee for a decentralized virtual machine" homepage = "https://aleo.org" @@ -34,7 +34,11 @@ test-helpers = [ "prop-tests", "rand_distr" ] [dependencies.console] package = "snarkvm-console" path = "../../console" -version = "=0.16.15" +version = "=0.16.19" + +[dependencies.ledger-narwhal-batch-header] +package = "snarkvm-ledger-narwhal-batch-header" +path = "../narwhal/batch-header" [dependencies.indexmap] version = "2.0" @@ -43,7 +47,7 @@ features = [ "serde", "rayon" ] [dependencies.metrics] package = "snarkvm-metrics" path = "../../metrics" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.serde_json] diff --git a/ledger/committee/src/lib.rs b/ledger/committee/src/lib.rs index 9ba7843dcd..b360cf3e29 100644 --- a/ledger/committee/src/lib.rs +++ b/ledger/committee/src/lib.rs @@ -29,6 +29,7 @@ use console::{ }; use indexmap::IndexMap; +use ledger_narwhal_batch_header::BatchHeader; use std::collections::HashSet; /// The minimum amount of stake required for a validator to bond. @@ -47,8 +48,10 @@ pub struct Committee { } impl Committee { + /// The committee lookback range. + pub const COMMITTEE_LOOKBACK_RANGE: u64 = BatchHeader::::MAX_GC_ROUNDS as u64; /// The maximum number of members that may be in a committee. - pub const MAX_COMMITTEE_SIZE: u16 = 200; + pub const MAX_COMMITTEE_SIZE: u16 = BatchHeader::::MAX_CERTIFICATES; /// Initializes a new `Committee` instance. pub fn new_genesis(members: IndexMap, (u64, bool)>) -> Result { @@ -201,7 +204,8 @@ impl Committee { /// Note: This ensures the method returns a deterministic result that is SNARK-friendly. fn sorted_members(&self) -> indexmap::map::IntoIter, (u64, bool)> { let members = self.members.clone(); - members.sorted_unstable_by(|address1, stake1, address2, stake2| { + // Note: The use of 'sorted_unstable_by' is safe here because the addresses are guaranteed to be unique. + members.sorted_unstable_by(|address1, (stake1, _), address2, (stake2, _)| { // Sort by stake in decreasing order. let cmp = stake2.cmp(stake1); // If the stakes are equal, sort by x-coordinate in decreasing order. @@ -233,7 +237,7 @@ pub mod test_helpers { use indexmap::IndexMap; use rand_distr::{Distribution, Exp}; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; /// Samples a list of random committees. pub fn sample_committees(rng: &mut TestRng) -> Vec> { @@ -285,6 +289,22 @@ pub mod test_helpers { Committee::::new(round, committee_members).unwrap() } + /// Samples a committee where all validators have the same stake. + pub fn sample_committee_equal_stake_committee(num_members: u16, rng: &mut TestRng) -> Committee { + assert!(num_members >= 4); + // Sample the members. + let mut members = IndexMap::new(); + // Add in the minimum and maximum staked nodes. + members.insert(Address::::new(rng.gen()), (MIN_VALIDATOR_STAKE, false)); + while members.len() < num_members as usize - 1 { + let stake = MIN_VALIDATOR_STAKE; + let is_open = rng.gen(); + members.insert(Address::::new(rng.gen()), (stake, is_open)); + } + // Return the committee. + Committee::::new(1, members).unwrap() + } + /// Samples a random committee. #[allow(clippy::cast_possible_truncation)] pub fn sample_committee_custom(num_members: u16, rng: &mut TestRng) -> Committee { @@ -324,7 +344,7 @@ mod tests { use rayon::prelude::*; use std::sync::Arc; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; /// Checks the leader distribution. fn check_leader_distribution(committee: Committee, num_rounds: u64, tolerance_percent: f64) { @@ -410,11 +430,30 @@ mod tests { } } + #[test] + fn test_sorted_members_with_equal_stake() { + // Initialize the RNG. + let rng = &mut TestRng::default(); + // Sample a committee. + let committee = crate::test_helpers::sample_committee_equal_stake_committee(200, rng); + // Start a timer. + let timer = std::time::Instant::now(); + // Sort the members. + let sorted_members = committee.sorted_members().collect::>(); + println!("sorted_members: {}ms", timer.elapsed().as_millis()); + // Check that the members are sorted based on our sorting criteria. + for i in 0..sorted_members.len() - 1 { + let (address1, (stake1, _)) = sorted_members[i]; + let (address2, (stake2, _)) = sorted_members[i + 1]; + assert!(stake1 >= stake2); + if stake1 == stake2 { + assert!(address1.to_x_coordinate() > address2.to_x_coordinate()); + } + } + } + #[test] fn test_maximum_committee_size() { - assert_eq!( - Committee::::MAX_COMMITTEE_SIZE as usize, - ledger_narwhal_batch_header::BatchHeader::::MAX_CERTIFICATES - ); + assert_eq!(Committee::::MAX_COMMITTEE_SIZE, BatchHeader::::MAX_CERTIFICATES); } } diff --git a/ledger/committee/src/prop_tests.rs b/ledger/committee/src/prop_tests.rs index f0aa2e7bb2..992be5e216 100644 --- a/ledger/committee/src/prop_tests.rs +++ b/ledger/committee/src/prop_tests.rs @@ -29,7 +29,7 @@ use std::{ }; use test_strategy::proptest; -type CurrentNetwork = console::network::Testnet3; +type CurrentNetwork = console::network::MainnetV0; #[derive(Debug, Clone)] pub struct Validator { diff --git a/ledger/narwhal/Cargo.toml b/ledger/narwhal/Cargo.toml index 014a7a0599..f1b5238232 100644 --- a/ledger/narwhal/Cargo.toml +++ b/ledger/narwhal/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-ledger-narwhal" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Data structures for a Narwhal-style memory pool in a decentralized virtual machine" homepage = "https://aleo.org" @@ -64,37 +64,37 @@ transmission-id = [ "narwhal-transmission-id" ] [dependencies.narwhal-batch-certificate] package = "snarkvm-ledger-narwhal-batch-certificate" path = "./batch-certificate" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.narwhal-batch-header] package = "snarkvm-ledger-narwhal-batch-header" path = "./batch-header" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.narwhal-data] package = "snarkvm-ledger-narwhal-data" path = "./data" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.narwhal-subdag] package = "snarkvm-ledger-narwhal-subdag" path = "./subdag" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.narwhal-transmission] package = "snarkvm-ledger-narwhal-transmission" path = "./transmission" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.narwhal-transmission-id] package = "snarkvm-ledger-narwhal-transmission-id" path = "./transmission-id" -version = "=0.16.15" +version = "=0.16.19" optional = true [dev-dependencies.snarkvm-ledger-narwhal] diff --git a/ledger/narwhal/batch-certificate/Cargo.toml b/ledger/narwhal/batch-certificate/Cargo.toml index 0e91b4f2e5..63d18a6237 100644 --- a/ledger/narwhal/batch-certificate/Cargo.toml +++ b/ledger/narwhal/batch-certificate/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-ledger-narwhal-batch-certificate" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "A batch certificate for a Narwhal-style memory pool in a decentralized virtual machine" homepage = "https://aleo.org" @@ -32,17 +32,17 @@ test-helpers = [ "narwhal-batch-header/test-helpers" ] [dependencies.console] package = "snarkvm-console" path = "../../../console" -version = "=0.16.15" +version = "=0.16.19" [dependencies.narwhal-batch-header] package = "snarkvm-ledger-narwhal-batch-header" path = "../batch-header" -version = "=0.16.15" +version = "=0.16.19" [dependencies.narwhal-transmission-id] package = "snarkvm-ledger-narwhal-transmission-id" path = "../transmission-id" -version = "=0.16.15" +version = "=0.16.19" [dependencies.indexmap] version = "2.0" diff --git a/ledger/narwhal/batch-certificate/src/bytes.rs b/ledger/narwhal/batch-certificate/src/bytes.rs index 446a0d4193..baa793c1ff 100644 --- a/ledger/narwhal/batch-certificate/src/bytes.rs +++ b/ledger/narwhal/batch-certificate/src/bytes.rs @@ -32,7 +32,7 @@ impl FromBytes for BatchCertificate { // Read the number of signatures. let num_signatures = u32::read_le(&mut reader)?; // Ensure the number of signatures is within bounds. - if num_signatures as usize > Self::MAX_SIGNATURES { + if num_signatures > Self::MAX_SIGNATURES as u32 { return Err(error(format!( "Number of signatures ({num_signatures}) exceeds the maximum ({})", Self::MAX_SIGNATURES @@ -56,7 +56,7 @@ impl FromBytes for BatchCertificate { // Read the number of signatures. let num_signatures = u16::read_le(&mut reader)?; // Ensure the number of signatures is within bounds. - if num_signatures as usize > Self::MAX_SIGNATURES { + if num_signatures > Self::MAX_SIGNATURES { return Err(error(format!( "Number of signatures ({num_signatures}) exceeds the maximum ({})", Self::MAX_SIGNATURES diff --git a/ledger/narwhal/batch-certificate/src/lib.rs b/ledger/narwhal/batch-certificate/src/lib.rs index 3e9fede619..f3d8d42dca 100644 --- a/ledger/narwhal/batch-certificate/src/lib.rs +++ b/ledger/narwhal/batch-certificate/src/lib.rs @@ -29,6 +29,7 @@ use narwhal_transmission_id::TransmissionID; use core::hash::{Hash, Hasher}; use indexmap::{IndexMap, IndexSet}; +use std::collections::HashSet; #[cfg(not(feature = "serial"))] use rayon::prelude::*; @@ -54,7 +55,7 @@ pub enum BatchCertificate { impl BatchCertificate { /// The maximum number of signatures in a batch certificate. - pub const MAX_SIGNATURES: usize = BatchHeader::::MAX_CERTIFICATES; + pub const MAX_SIGNATURES: u16 = BatchHeader::::MAX_CERTIFICATES; } impl BatchCertificate { @@ -84,7 +85,7 @@ impl BatchCertificate { N::hash_bhp1024(&preimage.to_bits_le()) } // Ensure that the number of signatures is within bounds. - ensure!(signatures.len() <= Self::MAX_SIGNATURES, "Invalid number of signatures"); + ensure!(signatures.len() <= Self::MAX_SIGNATURES as usize, "Invalid number of signatures"); // Compute the certificate ID. if certificate_id != compute_certificate_id(batch_header.batch_id(), &signatures)? { bail!("Invalid batch certificate ID") @@ -103,7 +104,15 @@ impl BatchCertificate { /// Initializes a new batch certificate. pub fn from(batch_header: BatchHeader, signatures: IndexSet>) -> Result { // Ensure that the number of signatures is within bounds. - ensure!(signatures.len() <= Self::MAX_SIGNATURES, "Invalid number of signatures"); + ensure!(signatures.len() <= Self::MAX_SIGNATURES as usize, "Invalid number of signatures"); + + // Ensure that the signature is from a unique signer and not from the author. + let signature_authors = signatures.iter().map(|signature| signature.to_address()).collect::>(); + ensure!( + !signature_authors.contains(&batch_header.author()), + "The author's signature was included in the signers" + ); + ensure!(signature_authors.len() == signatures.len(), "A duplicate author was found in the set of signatures"); // Verify the signatures are valid. cfg_iter!(signatures).try_for_each(|signature| { @@ -197,8 +206,7 @@ impl BatchCertificate { match self { Self::V1 { batch_header, signatures, .. } => { // Return the median timestamp. - let mut timestamps = - signatures.values().copied().chain([batch_header.timestamp()].into_iter()).collect::>(); + let mut timestamps = signatures.values().copied().chain([batch_header.timestamp()]).collect::>(); timestamps.sort_unstable(); timestamps[timestamps.len() / 2] } @@ -218,11 +226,11 @@ impl BatchCertificate { #[cfg(any(test, feature = "test-helpers"))] pub mod test_helpers { use super::*; - use console::{account::PrivateKey, network::Testnet3, prelude::TestRng, types::Field}; + use console::{account::PrivateKey, network::MainnetV0, prelude::TestRng, types::Field}; use indexmap::IndexSet; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Returns a sample batch certificate, sampled at random. pub fn sample_batch_certificate(rng: &mut TestRng) -> BatchCertificate { @@ -297,7 +305,7 @@ pub mod test_helpers { // Sample the leader certificate. let certificate = sample_batch_certificate_for_round_with_previous_certificate_ids( current_round, - previous_certificate_ids.clone(), + previous_certificate_ids, rng, ); @@ -309,7 +317,7 @@ pub mod test_helpers { mod tests { use super::*; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; #[test] fn test_maximum_signatures() { diff --git a/ledger/narwhal/batch-header/Cargo.toml b/ledger/narwhal/batch-header/Cargo.toml index 2469093f4f..8ec3fd22cd 100644 --- a/ledger/narwhal/batch-header/Cargo.toml +++ b/ledger/narwhal/batch-header/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-ledger-narwhal-batch-header" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "A batch header for a Narwhal-style memory pool in a decentralized virtual machine" homepage = "https://aleo.org" @@ -32,12 +32,12 @@ test-helpers = [ "narwhal-transmission-id/test-helpers", "time" ] [dependencies.console] package = "snarkvm-console" path = "../../../console" -version = "=0.16.15" +version = "=0.16.19" [dependencies.narwhal-transmission-id] package = "snarkvm-ledger-narwhal-transmission-id" path = "../transmission-id" -version = "=0.16.15" +version = "=0.16.19" [dependencies.indexmap] version = "2.0" diff --git a/ledger/narwhal/batch-header/src/bytes.rs b/ledger/narwhal/batch-header/src/bytes.rs index c46a1f140a..37474eb118 100644 --- a/ledger/narwhal/batch-header/src/bytes.rs +++ b/ledger/narwhal/batch-header/src/bytes.rs @@ -20,8 +20,7 @@ impl FromBytes for BatchHeader { // Read the version. let version = u8::read_le(&mut reader)?; // Ensure the version is valid. - // TODO (howardwu): For mainnet - Change the version back to 1. - if version != 1 && version != 2 { + if version != 1 { return Err(error("Invalid batch header version")); } @@ -37,10 +36,10 @@ impl FromBytes for BatchHeader { // Read the number of transmission IDs. let num_transmission_ids = u32::read_le(&mut reader)?; // Ensure the number of transmission IDs is within bounds. - if num_transmission_ids as usize > Self::MAX_TRANSMISSIONS { + if num_transmission_ids as usize > Self::MAX_TRANSMISSIONS_PER_BATCH { return Err(error(format!( "Number of transmission IDs ({num_transmission_ids}) exceeds the maximum ({})", - Self::MAX_TRANSMISSIONS, + Self::MAX_TRANSMISSIONS_PER_BATCH, ))); } // Read the transmission IDs. @@ -51,9 +50,9 @@ impl FromBytes for BatchHeader { } // Read the number of previous certificate IDs. - let num_previous_certificate_ids = u32::read_le(&mut reader)?; + let num_previous_certificate_ids = u16::read_le(&mut reader)?; // Ensure the number of previous certificate IDs is within bounds. - if num_previous_certificate_ids as usize > Self::MAX_CERTIFICATES { + if num_previous_certificate_ids > Self::MAX_CERTIFICATES { return Err(error(format!( "Number of previous certificate IDs ({num_previous_certificate_ids}) exceeds the maximum ({})", Self::MAX_CERTIFICATES @@ -66,44 +65,12 @@ impl FromBytes for BatchHeader { previous_certificate_ids.insert(Field::read_le(&mut reader)?); } - // TODO (howardwu): For mainnet - Change this to always encode the number of committed certificate IDs. - // We currently only encode the size and certificates in the new version, for backwards compatibility. - let num_last_election_certificate_ids = if version == 2 { - // Read the number of last election certificate IDs. - u16::read_le(&mut reader)? - } else { - // Set the number of last election certificate IDs to zero. - 0 - }; - // Ensure the number of last election certificate IDs is within bounds. - if num_last_election_certificate_ids as usize > Self::MAX_CERTIFICATES { - return Err(error(format!( - "Number of last election certificate IDs ({num_last_election_certificate_ids}) exceeds the maximum ({})", - Self::MAX_CERTIFICATES - ))); - } - // Read the last election certificate IDs. - let mut last_election_certificate_ids = IndexSet::new(); - for _ in 0..num_last_election_certificate_ids { - // Read the certificate ID. - last_election_certificate_ids.insert(Field::read_le(&mut reader)?); - } - // Read the signature. let signature = Signature::read_le(&mut reader)?; // Construct the batch. - let batch = Self::from( - version, - author, - round, - timestamp, - transmission_ids, - previous_certificate_ids, - last_election_certificate_ids, - signature, - ) - .map_err(|e| error(e.to_string()))?; + let batch = Self::from(author, round, timestamp, transmission_ids, previous_certificate_ids, signature) + .map_err(error)?; // Return the batch. match batch.batch_id == batch_id { @@ -117,8 +84,7 @@ impl ToBytes for BatchHeader { /// Writes the batch header to the buffer. fn write_le(&self, mut writer: W) -> IoResult<()> { // Write the version. - // TODO (howardwu): For mainnet - Change this back to '1u8.write_le(&mut writer)?'; - self.version.write_le(&mut writer)?; + 1u8.write_le(&mut writer)?; // Write the batch ID. self.batch_id.write_le(&mut writer)?; // Write the author. @@ -135,25 +101,12 @@ impl ToBytes for BatchHeader { transmission_id.write_le(&mut writer)?; } // Write the number of previous certificate IDs. - u32::try_from(self.previous_certificate_ids.len()).map_err(|e| error(e.to_string()))?.write_le(&mut writer)?; + u16::try_from(self.previous_certificate_ids.len()).map_err(|e| error(e.to_string()))?.write_le(&mut writer)?; // Write the previous certificate IDs. for certificate_id in &self.previous_certificate_ids { // Write the certificate ID. certificate_id.write_le(&mut writer)?; } - // TODO (howardwu): For mainnet - Change this to always encode the number of committed certificate IDs. - // We currently only encode the size and certificates in the new version, for backwards compatibility. - if self.version != 1 { - // Write the number of last election certificate IDs. - u16::try_from(self.last_election_certificate_ids.len()) - .map_err(|e| error(e.to_string()))? - .write_le(&mut writer)?; - // Write the last election certificate IDs. - for certificate_id in &self.last_election_certificate_ids { - // Write the certificate ID. - certificate_id.write_le(&mut writer)?; - } - } // Write the signature. self.signature.write_le(&mut writer) } diff --git a/ledger/narwhal/batch-header/src/lib.rs b/ledger/narwhal/batch-header/src/lib.rs index 64f4bc7b30..d50ea0f7f3 100644 --- a/ledger/narwhal/batch-header/src/lib.rs +++ b/ledger/narwhal/batch-header/src/lib.rs @@ -31,10 +31,6 @@ use narwhal_transmission_id::TransmissionID; #[derive(Clone, PartialEq, Eq)] pub struct BatchHeader { - /// The version of the batch header. - /// TODO (howardwu): For mainnet - Remove this version from the struct, we only use it here for backwards compatibility. - /// NOTE: You must keep the version encoding in the byte serialization, just remove it from the struct in memory. - version: u8, /// The batch ID, defined as the hash of the author, round number, timestamp, transmission IDs, /// previous batch certificate IDs, and last election certificate IDs. batch_id: Field, @@ -48,21 +44,20 @@ pub struct BatchHeader { transmission_ids: IndexSet>, /// The batch certificate IDs of the previous round. previous_certificate_ids: IndexSet>, - /// The last election batch certificate IDs. - last_election_certificate_ids: IndexSet>, /// The signature of the batch ID from the creator. signature: Signature, } impl BatchHeader { /// The maximum number of certificates in a batch. - pub const MAX_CERTIFICATES: usize = 200; - /// The maximum number of solutions in a batch. - pub const MAX_SOLUTIONS: usize = N::MAX_SOLUTIONS; - /// The maximum number of transactions in a batch. - pub const MAX_TRANSACTIONS: usize = usize::pow(2, console::program::TRANSACTIONS_DEPTH as u32); + pub const MAX_CERTIFICATES: u16 = 200; + /// The maximum number of rounds to store before garbage collecting. + pub const MAX_GC_ROUNDS: usize = 100; /// The maximum number of transmissions in a batch. - pub const MAX_TRANSMISSIONS: usize = Self::MAX_SOLUTIONS + Self::MAX_TRANSACTIONS; + /// Note: This limit is set to 50 as part of safety measures to prevent DoS attacks. + /// This limit can be increased in the future as performance improves. Alternatively, + /// the rate of block production can be sped up to compensate for the limit set here. + pub const MAX_TRANSMISSIONS_PER_BATCH: usize = 50; } impl BatchHeader { @@ -73,121 +68,79 @@ impl BatchHeader { timestamp: i64, transmission_ids: IndexSet>, previous_certificate_ids: IndexSet>, - last_election_certificate_ids: IndexSet>, rng: &mut R, ) -> Result { - // Set the version. - // TODO (howardwu): For mainnet - Remove this version from the struct, we only use it here for backwards compatibility. - // NOTE: You must keep the version encoding in the byte serialization, just remove it from the struct in memory. - let version = 2u8; - match round { 0 | 1 => { // If the round is zero or one, then there should be no previous certificate IDs. ensure!(previous_certificate_ids.is_empty(), "Invalid round number, must not have certificates"); - // If the round is zero or one, then there should be no last election certificate IDs. - ensure!(last_election_certificate_ids.is_empty(), "Invalid batch, contains election certificates"); } // If the round is not zero and not one, then there should be at least one previous certificate ID. _ => ensure!(!previous_certificate_ids.is_empty(), "Invalid round number, must have certificates"), } // Ensure that the number of transmissions is within bounds. - ensure!(transmission_ids.len() <= Self::MAX_TRANSMISSIONS, "Invalid number of transmission ids"); + ensure!( + transmission_ids.len() <= Self::MAX_TRANSMISSIONS_PER_BATCH, + "Invalid number of transmission IDs ({})", + transmission_ids.len() + ); // Ensure that the number of previous certificate IDs is within bounds. - ensure!(previous_certificate_ids.len() <= Self::MAX_CERTIFICATES, "Invalid number of previous certificate IDs"); - // Ensure the number of last election certificate IDs is within bounds. ensure!( - last_election_certificate_ids.len() <= Self::MAX_CERTIFICATES, - "Invalid number of last election certificate IDs" + previous_certificate_ids.len() <= Self::MAX_CERTIFICATES as usize, + "Invalid number of previous certificate IDs ({})", + previous_certificate_ids.len() ); // Retrieve the address. let author = Address::try_from(private_key)?; // Compute the batch ID. - let batch_id = Self::compute_batch_id( - version, - author, - round, - timestamp, - &transmission_ids, - &previous_certificate_ids, - &last_election_certificate_ids, - )?; + let batch_id = Self::compute_batch_id(author, round, timestamp, &transmission_ids, &previous_certificate_ids)?; // Sign the preimage. let signature = private_key.sign(&[batch_id], rng)?; // Return the batch header. - Ok(Self { - version, - author, - batch_id, - round, - timestamp, - transmission_ids, - previous_certificate_ids, - last_election_certificate_ids, - signature, - }) + Ok(Self { author, batch_id, round, timestamp, transmission_ids, previous_certificate_ids, signature }) } /// Initializes a new batch header. pub fn from( - version: u8, author: Address, round: u64, timestamp: i64, transmission_ids: IndexSet>, previous_certificate_ids: IndexSet>, - last_election_certificate_ids: IndexSet>, signature: Signature, ) -> Result { match round { 0 | 1 => { // If the round is zero or one, then there should be no previous certificate IDs. ensure!(previous_certificate_ids.is_empty(), "Invalid round number, must not have certificates"); - // If the round is zero or one, then there should be no last election certificate IDs. - ensure!(last_election_certificate_ids.is_empty(), "Invalid batch, contains election certificates"); } // If the round is not zero and not one, then there should be at least one previous certificate ID. _ => ensure!(!previous_certificate_ids.is_empty(), "Invalid round number, must have certificates"), } // Ensure that the number of transmissions is within bounds. - ensure!(transmission_ids.len() <= Self::MAX_TRANSMISSIONS, "Invalid number of transmission ids"); + ensure!( + transmission_ids.len() <= Self::MAX_TRANSMISSIONS_PER_BATCH, + "Invalid number of transmission IDs ({})", + transmission_ids.len() + ); // Ensure that the number of previous certificate IDs is within bounds. - ensure!(previous_certificate_ids.len() <= Self::MAX_CERTIFICATES, "Invalid number of previous certificate IDs"); - // Ensure the number of last election certificate IDs is within bounds. ensure!( - last_election_certificate_ids.len() <= Self::MAX_CERTIFICATES, - "Invalid number of last election certificate IDs" + previous_certificate_ids.len() <= Self::MAX_CERTIFICATES as usize, + "Invalid number of previous certificate IDs ({})", + previous_certificate_ids.len() ); // Compute the batch ID. - let batch_id = Self::compute_batch_id( - version, - author, - round, - timestamp, - &transmission_ids, - &previous_certificate_ids, - &last_election_certificate_ids, - )?; + let batch_id = Self::compute_batch_id(author, round, timestamp, &transmission_ids, &previous_certificate_ids)?; // Verify the signature. if !signature.verify(&author, &[batch_id]) { bail!("Invalid signature for the batch header"); } // Return the batch header. - Ok(Self { - version, - author, - batch_id, - round, - timestamp, - transmission_ids, - previous_certificate_ids, - last_election_certificate_ids, - signature, - }) + Ok(Self { author, batch_id, round, timestamp, transmission_ids, previous_certificate_ids, signature }) } } @@ -222,11 +175,6 @@ impl BatchHeader { &self.previous_certificate_ids } - /// Returns the last election batch certificate IDs. - pub const fn last_election_certificate_ids(&self) -> &IndexSet> { - &self.last_election_certificate_ids - } - /// Returns the signature. pub const fn signature(&self) -> &Signature { &self.signature @@ -253,11 +201,11 @@ impl BatchHeader { #[cfg(any(test, feature = "test-helpers"))] pub mod test_helpers { use super::*; - use console::{account::PrivateKey, network::Testnet3, prelude::TestRng}; + use console::{account::PrivateKey, network::MainnetV0, prelude::TestRng}; use time::OffsetDateTime; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Returns a sample batch header, sampled at random. pub fn sample_batch_header(rng: &mut TestRng) -> BatchHeader { @@ -285,19 +233,8 @@ pub mod test_helpers { narwhal_transmission_id::test_helpers::sample_transmission_ids(rng).into_iter().collect::>(); // Checkpoint the timestamp for the batch. let timestamp = OffsetDateTime::now_utc().unix_timestamp(); - // Sample the last election certificate IDs. - let last_election_certificate_ids = (0..5).map(|_| Field::::rand(rng)).collect::>(); // Return the batch header. - BatchHeader::new( - &private_key, - round, - timestamp, - transmission_ids, - previous_certificate_ids, - last_election_certificate_ids, - rng, - ) - .unwrap() + BatchHeader::new(&private_key, round, timestamp, transmission_ids, previous_certificate_ids, rng).unwrap() } /// Returns a list of sample batch headers, sampled at random. diff --git a/ledger/narwhal/batch-header/src/serialize.rs b/ledger/narwhal/batch-header/src/serialize.rs index 15cefd3a70..6acddaead2 100644 --- a/ledger/narwhal/batch-header/src/serialize.rs +++ b/ledger/narwhal/batch-header/src/serialize.rs @@ -19,16 +19,13 @@ impl Serialize for BatchHeader { fn serialize(&self, serializer: S) -> Result { match serializer.is_human_readable() { true => { - let mut header = serializer.serialize_struct("BatchHeader", 9)?; - // TODO (howardwu): For mainnet - Remove the version field, and update the 'len' above to 8. - header.serialize_field("version", &self.version)?; + let mut header = serializer.serialize_struct("BatchHeader", 7)?; header.serialize_field("batch_id", &self.batch_id)?; header.serialize_field("author", &self.author)?; header.serialize_field("round", &self.round)?; header.serialize_field("timestamp", &self.timestamp)?; header.serialize_field("transmission_ids", &self.transmission_ids)?; header.serialize_field("previous_certificate_ids", &self.previous_certificate_ids)?; - header.serialize_field("last_election_certificate_ids", &self.last_election_certificate_ids)?; header.serialize_field("signature", &self.signature)?; header.end() } @@ -45,31 +42,13 @@ impl<'de, N: Network> Deserialize<'de> for BatchHeader { let mut header = serde_json::Value::deserialize(deserializer)?; let batch_id: Field = DeserializeExt::take_from_value::(&mut header, "batch_id")?; - // TODO (howardwu): For mainnet - Remove the version parsing. - // If the version field is present, then parse the version. - let version = DeserializeExt::take_from_value::(&mut header, "version").unwrap_or(1); - // TODO (howardwu): For mainnet - Remove the version checking. - // Ensure the version is valid. - if version != 1 && version != 2 { - return Err(error("Invalid batch header version")).map_err(de::Error::custom); - } - // TODO (howardwu): For mainnet - Always take from the 'header', no need to use this match case anymore. - // If the version is not 1, then parse the last election certificate IDs. - let last_election_certificate_ids = match version { - 1 => IndexSet::new(), - 2 => DeserializeExt::take_from_value::(&mut header, "last_election_certificate_ids")?, - _ => unreachable!(), - }; - // Recover the header. let batch_header = Self::from( - version, DeserializeExt::take_from_value::(&mut header, "author")?, DeserializeExt::take_from_value::(&mut header, "round")?, DeserializeExt::take_from_value::(&mut header, "timestamp")?, DeserializeExt::take_from_value::(&mut header, "transmission_ids")?, DeserializeExt::take_from_value::(&mut header, "previous_certificate_ids")?, - last_election_certificate_ids, DeserializeExt::take_from_value::(&mut header, "signature")?, ) .map_err(de::Error::custom)?; diff --git a/ledger/narwhal/batch-header/src/to_id.rs b/ledger/narwhal/batch-header/src/to_id.rs index 1d3eea042b..1d99cbda77 100644 --- a/ledger/narwhal/batch-header/src/to_id.rs +++ b/ledger/narwhal/batch-header/src/to_id.rs @@ -18,13 +18,11 @@ impl BatchHeader { /// Returns the batch ID. pub fn to_id(&self) -> Result> { Self::compute_batch_id( - self.version, self.author, self.round, self.timestamp, &self.transmission_ids, &self.previous_certificate_ids, - &self.last_election_certificate_ids, ) } } @@ -32,13 +30,11 @@ impl BatchHeader { impl BatchHeader { /// Returns the batch ID. pub fn compute_batch_id( - version: u8, author: Address, round: u64, timestamp: i64, transmission_ids: &IndexSet>, previous_certificate_ids: &IndexSet>, - last_election_certificate_ids: &IndexSet>, ) -> Result> { let mut preimage = Vec::new(); // Insert the author. @@ -60,17 +56,6 @@ impl BatchHeader { // Insert the certificate ID. certificate_id.write_le(&mut preimage)?; } - // TODO (howardwu): For mainnet - Change this to always encode the number of committed certificate IDs. - // We currently only encode the size and certificates only in the new version, for backwards compatibility. - if version != 1 { - // Insert the number of last election certificate IDs. - u32::try_from(last_election_certificate_ids.len())?.write_le(&mut preimage)?; - // Insert the last election certificate IDs. - for certificate_id in last_election_certificate_ids { - // Insert the certificate ID. - certificate_id.write_le(&mut preimage)?; - } - } // Hash the preimage. N::hash_bhp1024(&preimage.to_bits_le()) } diff --git a/ledger/narwhal/data/Cargo.toml b/ledger/narwhal/data/Cargo.toml index 0605db8cd8..a8172b12d9 100644 --- a/ledger/narwhal/data/Cargo.toml +++ b/ledger/narwhal/data/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-ledger-narwhal-data" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "A batch certificate for a Narwhal-style memory pool in a decentralized virtual machine" homepage = "https://aleo.org" @@ -29,7 +29,7 @@ async = [ "tokio" ] [dependencies.console] package = "snarkvm-console" path = "../../../console" -version = "=0.16.15" +version = "=0.16.19" [dependencies.bytes] version = "1" diff --git a/ledger/narwhal/data/src/lib.rs b/ledger/narwhal/data/src/lib.rs index 76b7ccd1d5..28508ecc54 100644 --- a/ledger/narwhal/data/src/lib.rs +++ b/ledger/narwhal/data/src/lib.rs @@ -119,7 +119,8 @@ impl FromBytes for Data { return Err(error(format!("Failed to deserialize data ({num_bytes} bytes)"))); } // Read the bytes. - let bytes = (0..num_bytes).map(|_| u8::read_le(&mut reader)).collect::>>()?; + let mut bytes = Vec::new(); + (&mut reader).take(num_bytes as u64).read_to_end(&mut bytes)?; // Return the data. Ok(Self::Buffer(Bytes::from(bytes))) } @@ -134,9 +135,9 @@ impl ToBytes for Data { // Write the data. match self { Self::Object(object) => { - // FIXME(ljedrz): see if we can omit this intermediate allocation. - let mut buffer = Vec::new(); - object.write_le(&mut buffer)?; + // Serialize the object. + let buffer = + object.to_bytes_le().map_err(|e| error(format!("Failed to serialize 'Data::Object' - {e}")))?; // Write the object. u32::try_from(buffer.len()).map_err(error)?.write_le(&mut writer)?; // Write the object. diff --git a/ledger/narwhal/subdag/Cargo.toml b/ledger/narwhal/subdag/Cargo.toml index 34c72d5888..f91a199478 100644 --- a/ledger/narwhal/subdag/Cargo.toml +++ b/ledger/narwhal/subdag/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-ledger-narwhal-subdag" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "A subdag for a Narwhal-style memory pool in a decentralized virtual machine" homepage = "https://aleo.org" @@ -32,22 +32,27 @@ test-helpers = [ "narwhal-batch-certificate/test-helpers" ] [dependencies.console] package = "snarkvm-console" path = "../../../console" -version = "=0.16.15" +version = "=0.16.19" [dependencies.narwhal-batch-certificate] package = "snarkvm-ledger-narwhal-batch-certificate" path = "../batch-certificate" -version = "=0.16.15" +version = "=0.16.19" [dependencies.narwhal-batch-header] package = "snarkvm-ledger-narwhal-batch-header" path = "../batch-header" -version = "=0.16.15" +version = "=0.16.19" + +[dependencies.ledger-committee] +package = "snarkvm-ledger-committee" +path = "../../committee" +version = "=0.16.19" [dependencies.narwhal-transmission-id] package = "snarkvm-ledger-narwhal-transmission-id" path = "../transmission-id" -version = "=0.16.15" +version = "=0.16.19" [dependencies.indexmap] version = "2.0" diff --git a/ledger/narwhal/subdag/src/bytes.rs b/ledger/narwhal/subdag/src/bytes.rs index b805dabecb..5b7aef35a9 100644 --- a/ledger/narwhal/subdag/src/bytes.rs +++ b/ledger/narwhal/subdag/src/bytes.rs @@ -20,15 +20,14 @@ impl FromBytes for Subdag { // Read the version. let version = u8::read_le(&mut reader)?; // Ensure the version is valid. - // TODO (howardwu): For mainnet - Change the version back to 1. - if version != 1 && version != 2 { + if version != 1 { return Err(error(format!("Invalid subdag version ({version})"))); } // Read the number of rounds. let num_rounds = u32::read_le(&mut reader)?; // Ensure the number of rounds is within bounds. - if num_rounds as usize > Self::MAX_ROUNDS { + if num_rounds as u64 > Self::MAX_ROUNDS { return Err(error(format!("Number of rounds ({num_rounds}) exceeds the maximum ({})", Self::MAX_ROUNDS))); } // Read the round certificates. @@ -37,9 +36,9 @@ impl FromBytes for Subdag { // Read the round. let round = u64::read_le(&mut reader)?; // Read the number of certificates. - let num_certificates = u32::read_le(&mut reader)?; + let num_certificates = u16::read_le(&mut reader)?; // Ensure the number of certificates is within bounds. - if num_certificates as usize > BatchHeader::::MAX_CERTIFICATES { + if num_certificates > BatchHeader::::MAX_CERTIFICATES { return Err(error(format!( "Number of certificates ({num_certificates}) exceeds the maximum ({})", BatchHeader::::MAX_CERTIFICATES @@ -55,27 +54,8 @@ impl FromBytes for Subdag { subdag.insert(round, certificates); } - // Read the election certificate IDs. - let mut election_certificate_ids = IndexSet::new(); - // TODO (howardwu): For mainnet - Always attempt to deserialize the election certificate IDs. - if version != 1 { - // Read the number of election certificate IDs. - let num_election_certificate_ids = u16::read_le(&mut reader)?; - // Ensure the number of election certificate IDs is within bounds. - if num_election_certificate_ids as usize > BatchHeader::::MAX_CERTIFICATES { - return Err(error(format!( - "Number of election certificate IDs ({num_election_certificate_ids}) exceeds the maximum ({})", - BatchHeader::::MAX_CERTIFICATES - ))); - } - for _ in 0..num_election_certificate_ids { - // Read the election certificate ID. - election_certificate_ids.insert(Field::read_le(&mut reader)?); - } - } - // Return the subdag. - Self::from(subdag, election_certificate_ids).map_err(error) + Self::from(subdag).map_err(error) } } @@ -83,8 +63,7 @@ impl ToBytes for Subdag { /// Writes the subdag to the buffer. fn write_le(&self, mut writer: W) -> IoResult<()> { // Write the version. - // TODO (howardwu): For mainnet - Change the version back to 1. - 2u8.write_le(&mut writer)?; + 1u8.write_le(&mut writer)?; // Write the number of rounds. u32::try_from(self.subdag.len()).map_err(error)?.write_le(&mut writer)?; // Write the round certificates. @@ -92,20 +71,13 @@ impl ToBytes for Subdag { // Write the round. round.write_le(&mut writer)?; // Write the number of certificates. - u32::try_from(certificates.len()).map_err(error)?.write_le(&mut writer)?; + u16::try_from(certificates.len()).map_err(error)?.write_le(&mut writer)?; // Write the certificates. for certificate in certificates { // Write the certificate. certificate.write_le(&mut writer)?; } } - // Write the number of election certificate IDs. - u16::try_from(self.election_certificate_ids.len()).map_err(error)?.write_le(&mut writer)?; - // Write the election certificate IDs. - for election_certificate_id in &self.election_certificate_ids { - // Write the election certificate ID. - election_certificate_id.write_le(&mut writer)?; - } Ok(()) } } diff --git a/ledger/narwhal/subdag/src/lib.rs b/ledger/narwhal/subdag/src/lib.rs index 3026a094b3..5bb62b203f 100644 --- a/ledger/narwhal/subdag/src/lib.rs +++ b/ledger/narwhal/subdag/src/lib.rs @@ -20,6 +20,7 @@ mod serialize; mod string; use console::{account::Address, prelude::*, program::SUBDAG_CERTIFICATES_DEPTH, types::Field}; +use ledger_committee::Committee; use narwhal_batch_certificate::BatchCertificate; use narwhal_batch_header::BatchHeader; use narwhal_transmission_id::TransmissionID; @@ -78,12 +79,40 @@ fn sanity_check_subdag_with_dfs(subdag: &BTreeMap) -> i64 { + let mut timestamps_and_stake = timestamps_and_stake; + + // Sort the timestamps. + #[cfg(not(feature = "serial"))] + timestamps_and_stake.par_sort_unstable_by_key(|(timestamp, _)| *timestamp); + #[cfg(feature = "serial")] + timestamps_and_stake.sort_unstable_by_key(|(timestamp, _)| *timestamp); + + // Calculate the total stake of the authors. + let total_stake = timestamps_and_stake.iter().map(|(_, stake)| *stake).sum::(); + + // Initialize the current timestamp and accumulated stake. + let mut current_timestamp: i64 = 0; + let mut accumulated_stake: u64 = 0; + + // Find the weighted median timestamp. + for (timestamp, stake) in timestamps_and_stake.iter() { + accumulated_stake = accumulated_stake.saturating_add(*stake); + current_timestamp = *timestamp; + if accumulated_stake.saturating_mul(2) >= total_stake { + break; + } + } + + // Return the weighted median timestamp + current_timestamp +} + #[derive(Clone)] pub struct Subdag { /// The subdag of round certificates. subdag: BTreeMap>>, - /// The election certificate IDs. - election_certificate_ids: IndexSet>, } impl PartialEq for Subdag { @@ -97,35 +126,30 @@ impl Eq for Subdag {} impl Subdag { /// Initializes a new subdag. - pub fn from( - subdag: BTreeMap>>, - election_certificate_ids: IndexSet>, - ) -> Result { + pub fn from(subdag: BTreeMap>>) -> Result { // Ensure the subdag is not empty. ensure!(!subdag.is_empty(), "Subdag cannot be empty"); // Ensure the subdag does not exceed the maximum number of rounds. - ensure!(subdag.len() <= Self::MAX_ROUNDS, "Subdag cannot exceed the maximum number of rounds"); + ensure!( + subdag.len() <= usize::try_from(Self::MAX_ROUNDS)?, + "Subdag cannot exceed the maximum number of rounds" + ); // Ensure the anchor round is even. ensure!(subdag.iter().next_back().map_or(0, |(r, _)| *r) % 2 == 0, "Anchor round must be even"); // Ensure there is only one leader certificate. ensure!(subdag.iter().next_back().map_or(0, |(_, c)| c.len()) == 1, "Subdag cannot have multiple leaders"); - // Ensure the number of election certificate IDs is within bounds. - ensure!( - election_certificate_ids.len() <= BatchHeader::::MAX_CERTIFICATES, - "Number of election certificate IDs exceeds the maximum" - ); // Ensure the rounds are sequential. ensure!(is_sequential(&subdag), "Subdag rounds must be sequential"); // Ensure the subdag structure matches the commit. ensure!(sanity_check_subdag_with_dfs(&subdag), "Subdag structure does not match commit"); // Ensure the leader certificate is an even round. - Ok(Self { subdag, election_certificate_ids }) + Ok(Self { subdag }) } } impl Subdag { /// The maximum number of rounds in a subdag (bounded up to GC depth). - pub const MAX_ROUNDS: usize = 50; + pub const MAX_ROUNDS: u64 = BatchHeader::::MAX_GC_ROUNDS as u64; } impl Subdag { @@ -162,30 +186,28 @@ impl Subdag { self.values().flatten().flat_map(BatchCertificate::transmission_ids) } - /// Returns the timestamp of the anchor round, defined as the median timestamp of the subdag. - pub fn timestamp(&self) -> i64 { + /// Returns the timestamp of the anchor round, defined as the weighted median timestamp of the subdag. + pub fn timestamp(&self, committee: &Committee) -> i64 { match self.leader_certificate() { BatchCertificate::V1 { .. } => self.leader_certificate().timestamp(), BatchCertificate::V2 { .. } => { - // Retrieve the timestamps of the certificates. - let mut timestamps = self.values().flatten().map(BatchCertificate::timestamp).collect::>(); - // Sort the timestamps. - #[cfg(not(feature = "serial"))] - timestamps.par_sort_unstable(); - #[cfg(feature = "serial")] - timestamps.sort_unstable(); - // Return the median timestamp. - timestamps[timestamps.len() / 2] + // Retrieve the anchor round. + let anchor_round = self.anchor_round(); + // Retrieve the timestamps and stakes of the certificates for `anchor_round` - 1. + let timestamps_and_stakes = self + .values() + .flatten() + .filter(|certificate| certificate.round() == anchor_round.saturating_sub(1)) + .map(|certificate| (certificate.timestamp(), committee.get_stake(certificate.author()))) + .collect::>(); + + // Return the weighted median timestamp. + weighted_median(timestamps_and_stakes) } } } - /// Returns the election certificate IDs. - pub fn election_certificate_ids(&self) -> &IndexSet> { - &self.election_certificate_ids - } - - /// Returns the subdag root of the transactions. + /// Returns the subdag root of the certificates. pub fn to_subdag_root(&self) -> Result> { // Prepare the leaves. let leaves = cfg_iter!(self.subdag) @@ -194,10 +216,8 @@ impl Subdag { }) .collect::>(); - // Compute the subdag tree. - let tree = N::merkle_tree_bhp::(&leaves)?; - // Return the subdag root. - Ok(*tree.root()) + // Compute the subdag root. + Ok(*N::merkle_tree_bhp::(&leaves)?.root()) } } @@ -213,11 +233,11 @@ impl Deref for Subdag { #[cfg(any(test, feature = "test-helpers"))] pub mod test_helpers { use super::*; - use console::{network::Testnet3, prelude::TestRng}; + use console::{network::MainnetV0, prelude::TestRng}; use indexmap::{indexset, IndexSet}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Returns a sample subdag, sampled at random. pub fn sample_subdag(rng: &mut TestRng) -> Subdag { @@ -265,14 +285,8 @@ pub mod test_helpers { ); subdag.insert(starting_round + 2, indexset![certificate]); - // Initialize the election certificate IDs. - let mut election_certificate_ids = IndexSet::new(); - for _ in 0..AVAILABILITY_THRESHOLD { - election_certificate_ids.insert(rng.gen()); - } - // Return the subdag. - Subdag::from(subdag, election_certificate_ids).unwrap() + Subdag::from(subdag).unwrap() } /// Returns a list of sample subdags, sampled at random. @@ -287,3 +301,85 @@ pub mod test_helpers { sample } } + +#[cfg(test)] +mod tests { + use super::*; + use narwhal_batch_header::BatchHeader; + + type CurrentNetwork = console::network::MainnetV0; + + const ITERATIONS: u64 = 100; + + #[test] + fn test_max_certificates() { + // Determine the maximum number of certificates in a block. + let max_certificates_per_block = + BatchHeader::::MAX_GC_ROUNDS * BatchHeader::::MAX_CERTIFICATES as usize; + + // Note: The maximum number of certificates in a block must be able to be Merklized. + assert!( + max_certificates_per_block <= 2u32.checked_pow(SUBDAG_CERTIFICATES_DEPTH as u32).unwrap() as usize, + "The maximum number of certificates in a block is too large" + ); + } + + #[test] + fn test_weighted_median_simple() { + // Test a simple case with equal weights. + let data = vec![(1, 10), (2, 10), (3, 10)]; + assert_eq!(weighted_median(data), 2); + + // Test a case with a single element. + let data = vec![(5, 10)]; + assert_eq!(weighted_median(data), 5); + + // Test a case with an even number of elements + let data = vec![(1, 10), (2, 30), (3, 20), (4, 40)]; + assert_eq!(weighted_median(data), 3); + + // Test a case with a skewed weight. + let data = vec![(100, 100), (200, 10000), (300, 500)]; + assert_eq!(weighted_median(data), 200); + + // Test a case with a empty set. + assert_eq!(weighted_median(vec![]), 0); + + // Test a case where there is possible truncation. + let data = vec![(1, 1), (2, 1), (3, 1), (4, 1), (5, 1)]; + assert_eq!(weighted_median(data), 3); + + // Test a case where weights of 0 do not affect the median. + let data = vec![(1, 10), (2, 0), (3, 0), (4, 0), (5, 20), (6, 0), (7, 10)]; + assert_eq!(weighted_median(data), 5); + } + + #[test] + fn test_weighted_median_range() { + let mut rng = TestRng::default(); + + for _ in 0..ITERATIONS { + let data: Vec<(i64, u64)> = (0..10).map(|_| (rng.gen_range(1..100), rng.gen_range(10..100))).collect(); + let min = data.iter().min_by_key(|x| x.0).unwrap().0; + let max = data.iter().max_by_key(|x| x.0).unwrap().0; + let median = weighted_median(data); + assert!(median >= min && median <= max); + } + } + + #[test] + fn test_weighted_median_scaled_weights() { + let mut rng = TestRng::default(); + + for _ in 0..ITERATIONS { + let data: Vec<(i64, u64)> = (0..10).map(|_| (rng.gen_range(1..100), rng.gen_range(10..100) * 2)).collect(); + let scaled_data: Vec<(i64, u64)> = data.iter().map(|&(t, s)| (t, s * 10)).collect(); + + if weighted_median(data.clone()) != weighted_median(scaled_data.clone()) { + println!("data: {:?}", data); + println!("scaled_data: {:?}", scaled_data); + } + assert_eq!(weighted_median(data), weighted_median(scaled_data)); + } + } +} diff --git a/ledger/narwhal/subdag/src/serialize.rs b/ledger/narwhal/subdag/src/serialize.rs index fb73011d91..f02389871e 100644 --- a/ledger/narwhal/subdag/src/serialize.rs +++ b/ledger/narwhal/subdag/src/serialize.rs @@ -19,9 +19,8 @@ impl Serialize for Subdag { fn serialize(&self, serializer: S) -> Result { match serializer.is_human_readable() { true => { - let mut certificate = serializer.serialize_struct("Subdag", 2)?; + let mut certificate = serializer.serialize_struct("Subdag", 1)?; certificate.serialize_field("subdag", &self.subdag)?; - certificate.serialize_field("election_certificate_ids", &self.election_certificate_ids)?; certificate.end() } false => ToBytesSerializer::serialize_with_size_encoding(self, serializer), @@ -36,11 +35,7 @@ impl<'de, N: Network> Deserialize<'de> for Subdag { true => { let mut value = serde_json::Value::deserialize(deserializer)?; - // TODO (howardwu): For mainnet - Directly take the value, do not check if its missing. - let election_certificate_ids = - DeserializeExt::take_from_value::(&mut value, "election_certificate_ids").unwrap_or_default(); - - Ok(Self::from(DeserializeExt::take_from_value::(&mut value, "subdag")?, election_certificate_ids) + Ok(Self::from(DeserializeExt::take_from_value::(&mut value, "subdag")?) .map_err(de::Error::custom)?) } false => FromBytesDeserializer::::deserialize_with_size_encoding(deserializer, "subdag"), diff --git a/ledger/narwhal/transmission-id/Cargo.toml b/ledger/narwhal/transmission-id/Cargo.toml index 337d55df0a..9ab29797eb 100644 --- a/ledger/narwhal/transmission-id/Cargo.toml +++ b/ledger/narwhal/transmission-id/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-ledger-narwhal-transmission-id" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "A transmission ID for a Narwhal-style memory pool in a decentralized virtual machine" homepage = "https://aleo.org" @@ -32,12 +32,12 @@ test-helpers = [ ] [dependencies.console] package = "snarkvm-console" path = "../../../console" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-coinbase] package = "snarkvm-ledger-coinbase" path = "../../coinbase" -version = "=0.16.15" +version = "=0.16.19" [dev-dependencies.bincode] version = "1.3" diff --git a/ledger/narwhal/transmission-id/src/lib.rs b/ledger/narwhal/transmission-id/src/lib.rs index 43ffea0191..285b58ff53 100644 --- a/ledger/narwhal/transmission-id/src/lib.rs +++ b/ledger/narwhal/transmission-id/src/lib.rs @@ -68,12 +68,12 @@ impl TransmissionID { pub mod test_helpers { use super::*; use console::{ - network::Testnet3, + network::MainnetV0, prelude::{Rng, TestRng, Uniform}, types::Field, }; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Returns a list of sample transmission IDs, sampled at random. pub fn sample_transmission_ids(rng: &mut TestRng) -> Vec> { diff --git a/ledger/narwhal/transmission-id/src/string.rs b/ledger/narwhal/transmission-id/src/string.rs index 167ad781ef..e2e0b8ce86 100644 --- a/ledger/narwhal/transmission-id/src/string.rs +++ b/ledger/narwhal/transmission-id/src/string.rs @@ -52,9 +52,9 @@ impl Display for TransmissionID { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_string() { diff --git a/ledger/narwhal/transmission/Cargo.toml b/ledger/narwhal/transmission/Cargo.toml index e50f7952c5..c209403679 100644 --- a/ledger/narwhal/transmission/Cargo.toml +++ b/ledger/narwhal/transmission/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-ledger-narwhal-transmission" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "A transmission for a Narwhal-style memory pool in a decentralized virtual machine" homepage = "https://aleo.org" @@ -32,22 +32,22 @@ test-helpers = [ ] [dependencies.console] package = "snarkvm-console" path = "../../../console" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-block] package = "snarkvm-ledger-block" path = "../../block" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-coinbase] package = "snarkvm-ledger-coinbase" path = "../../coinbase" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-narwhal-data] package = "snarkvm-ledger-narwhal-data" path = "../data" -version = "=0.16.15" +version = "=0.16.19" [dependencies.bytes] version = "1" diff --git a/ledger/narwhal/transmission/src/lib.rs b/ledger/narwhal/transmission/src/lib.rs index a18d096241..a7e7950c21 100644 --- a/ledger/narwhal/transmission/src/lib.rs +++ b/ledger/narwhal/transmission/src/lib.rs @@ -68,13 +68,13 @@ impl From>> for Transmission { pub mod test_helpers { use super::*; use console::{ - network::Testnet3, + network::MainnetV0, prelude::{Rng, TestRng}, }; use ::bytes::Bytes; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Returns a list of sample transmissions, sampled at random. pub fn sample_transmissions(rng: &mut TestRng) -> Vec> { diff --git a/ledger/query/Cargo.toml b/ledger/query/Cargo.toml index 5feb1fba04..979555c7e4 100644 --- a/ledger/query/Cargo.toml +++ b/ledger/query/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-ledger-query" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "A query for a decentralized virtual machine" homepage = "https://aleo.org" @@ -34,18 +34,18 @@ query = [ "ledger-store", "synthesizer-program", "ureq" ] [dependencies.console] package = "snarkvm-console" path = "../../console" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-store] package = "snarkvm-ledger-store" path = "../store" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.synthesizer-program] package = "snarkvm-synthesizer-program" path = "../../synthesizer/program" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.async-trait] @@ -59,4 +59,5 @@ optional = true [dependencies.ureq] version = "2.7.1" features = [ "json" ] +default-features = false optional = true diff --git a/ledger/query/src/query.rs b/ledger/query/src/query.rs index e4fbfd29e3..f925c51b39 100644 --- a/ledger/query/src/query.rs +++ b/ledger/query/src/query.rs @@ -66,7 +66,7 @@ impl> QueryTrait for Query { match self { Self::VM(block_store) => Ok(block_store.current_state_root()), Self::REST(url) => match N::ID { - 3 => Ok(Self::get_request(&format!("{url}/testnet3/latest/stateRoot"))?.into_json()?), + 3 => Ok(Self::get_request(&format!("{url}/mainnet/latest/stateRoot"))?.into_json()?), _ => bail!("Unsupported network ID in inclusion query"), }, } @@ -78,7 +78,7 @@ impl> QueryTrait for Query { match self { Self::VM(block_store) => Ok(block_store.current_state_root()), Self::REST(url) => match N::ID { - 3 => Ok(Self::get_request_async(&format!("{url}/testnet3/latest/stateRoot")).await?.json().await?), + 3 => Ok(Self::get_request_async(&format!("{url}/mainnet/latest/stateRoot")).await?.json().await?), _ => bail!("Unsupported network ID in inclusion query"), }, } @@ -89,7 +89,7 @@ impl> QueryTrait for Query { match self { Self::VM(block_store) => block_store.get_state_path_for_commitment(commitment), Self::REST(url) => match N::ID { - 3 => Ok(Self::get_request(&format!("{url}/testnet3/statePath/{commitment}"))?.into_json()?), + 3 => Ok(Self::get_request(&format!("{url}/mainnet/statePath/{commitment}"))?.into_json()?), _ => bail!("Unsupported network ID in inclusion query"), }, } @@ -102,7 +102,7 @@ impl> QueryTrait for Query { Self::VM(block_store) => block_store.get_state_path_for_commitment(commitment), Self::REST(url) => match N::ID { 3 => { - Ok(Self::get_request_async(&format!("{url}/testnet3/statePath/{commitment}")).await?.json().await?) + Ok(Self::get_request_async(&format!("{url}/mainnet/statePath/{commitment}")).await?.json().await?) } _ => bail!("Unsupported network ID in inclusion query"), }, @@ -118,7 +118,7 @@ impl> Query { block_store.get_program(program_id)?.ok_or_else(|| anyhow!("Program {program_id} not found in storage")) } Self::REST(url) => match N::ID { - 3 => Ok(Self::get_request(&format!("{url}/testnet3/program/{program_id}"))?.into_json()?), + 3 => Ok(Self::get_request(&format!("{url}/mainnet/program/{program_id}"))?.into_json()?), _ => bail!("Unsupported network ID in inclusion query"), }, } @@ -132,7 +132,7 @@ impl> Query { block_store.get_program(program_id)?.ok_or_else(|| anyhow!("Program {program_id} not found in storage")) } Self::REST(url) => match N::ID { - 3 => Ok(Self::get_request_async(&format!("{url}/testnet3/program/{program_id}")).await?.json().await?), + 3 => Ok(Self::get_request_async(&format!("{url}/mainnet/program/{program_id}")).await?.json().await?), _ => bail!("Unsupported network ID in inclusion query"), }, } diff --git a/ledger/src/advance.rs b/ledger/src/advance.rs index ee49488d93..ba8de721ff 100644 --- a/ledger/src/advance.rs +++ b/ledger/src/advance.rs @@ -29,7 +29,7 @@ impl> Ledger { // Currently, we do not support ratifications from the memory pool. ensure!(ratifications.is_empty(), "Ratifications are currently unsupported from the memory pool"); // Construct the block template. - let (header, ratifications, solutions, transactions, aborted_transaction_ids) = + let (header, ratifications, solutions, aborted_solution_ids, transactions, aborted_transaction_ids) = self.construct_block_template(&previous_block, Some(&subdag), ratifications, solutions, transactions)?; // Construct the new quorum block. @@ -39,6 +39,7 @@ impl> Ledger { subdag, ratifications, solutions, + aborted_solution_ids, transactions, aborted_transaction_ids, ) @@ -60,13 +61,14 @@ impl> Ledger { let previous_block = self.latest_block(); // Construct the block template. - let (header, ratifications, solutions, transactions, aborted_transaction_ids) = self.construct_block_template( - &previous_block, - None, - candidate_ratifications, - candidate_solutions, - candidate_transactions, - )?; + let (header, ratifications, solutions, aborted_solution_ids, transactions, aborted_transaction_ids) = self + .construct_block_template( + &previous_block, + None, + candidate_ratifications, + candidate_solutions, + candidate_transactions, + )?; // Construct the new beacon block. Block::new_beacon( @@ -75,6 +77,7 @@ impl> Ledger { header, ratifications, solutions, + aborted_solution_ids, transactions, aborted_transaction_ids, rng, @@ -107,6 +110,61 @@ impl> Ledger { } } +/// Splits candidate solutions into a collection of accepted ones and aborted ones. +pub fn split_candidate_solutions( + mut candidate_solutions: Vec, + max_solutions: usize, + verification_fn: F, +) -> (Vec, Vec) +where + T: Sized + Send, + F: Fn(&T) -> bool + Send + Sync, +{ + // Separate the candidate solutions into valid and aborted solutions. + let mut valid_candidate_solutions = Vec::with_capacity(max_solutions); + let mut aborted_candidate_solutions = Vec::new(); + // Reverse the candidate solutions in order to be able to chunk them more efficiently. + candidate_solutions.reverse(); + // Verify the candidate solutions in chunks. This is done so that we can potentially + // perform these operations in parallel while keeping the end result deterministic. + let chunk_size = 16; + while !candidate_solutions.is_empty() { + // Check if the collection of valid solutions is full. + if valid_candidate_solutions.len() >= max_solutions { + // If that's the case, mark the rest of the candidates as aborted. + aborted_candidate_solutions.extend(candidate_solutions.into_iter().rev()); + break; + } + + // Split off a chunk of the candidate solutions. + let candidates_chunk = if candidate_solutions.len() > chunk_size { + candidate_solutions.split_off(candidate_solutions.len() - chunk_size) + } else { + std::mem::take(&mut candidate_solutions) + }; + + // Verify the solutions in the chunk. + let verification_results: Vec<_> = cfg_into_iter!(candidates_chunk) + .rev() + .map(|solution| { + let verified = verification_fn(&solution); + (solution, verified) + }) + .collect(); + + // Process the results of the verification. + for (solution, is_valid) in verification_results.into_iter() { + if is_valid && valid_candidate_solutions.len() < max_solutions { + valid_candidate_solutions.push(solution); + } else { + aborted_candidate_solutions.push(solution); + } + } + } + + (valid_candidate_solutions, aborted_candidate_solutions) +} + impl> Ledger { /// Constructs a block template for the next block in the ledger. #[allow(clippy::type_complexity)] @@ -117,42 +175,34 @@ impl> Ledger { candidate_ratifications: Vec>, candidate_solutions: Vec>, candidate_transactions: Vec>, - ) -> Result<(Header, Ratifications, Option>, Transactions, Vec)> - { + ) -> Result<( + Header, + Ratifications, + Solutions, + Vec>, + Transactions, + Vec, + )> { // Construct the solutions. - let (solutions, solutions_root, combined_proof_target) = match candidate_solutions.is_empty() { - true => (None, Field::::zero(), 0u128), + let (solutions, aborted_solutions, solutions_root, combined_proof_target) = match candidate_solutions.is_empty() + { + true => (None, vec![], Field::::zero(), 0u128), false => { // Retrieve the coinbase verifying key. let coinbase_verifying_key = self.coinbase_puzzle.coinbase_verifying_key(); // Retrieve the latest epoch challenge. let latest_epoch_challenge = self.latest_epoch_challenge()?; - // TODO: For mainnet - Add `aborted_solution_ids` to the block. And optimize this logic. - // Verify the candidate solutions. - let verification_results: Vec<_> = cfg_into_iter!(candidate_solutions) - .map(|solution| { - ( - solution, - solution - .verify(coinbase_verifying_key, &latest_epoch_challenge, self.latest_proof_target()) - .unwrap_or(false), - ) - }) - .collect(); // Separate the candidate solutions into valid and aborted solutions. - let mut valid_candidate_solutions = Vec::with_capacity(N::MAX_SOLUTIONS); - let mut aborted_candidate_solutions = Vec::new(); - for (solution, is_valid) in verification_results.into_iter() { - if is_valid && valid_candidate_solutions.len() < N::MAX_SOLUTIONS { - valid_candidate_solutions.push(solution); - } else { - aborted_candidate_solutions.push(solution); - } - } + let (valid_candidate_solutions, aborted_candidate_solutions) = + split_candidate_solutions(candidate_solutions, N::MAX_SOLUTIONS, |solution| { + solution + .verify(coinbase_verifying_key, &latest_epoch_challenge, self.latest_proof_target()) + .unwrap_or(false) + }); // Check if there are any valid solutions. match valid_candidate_solutions.is_empty() { - true => (None, Field::::zero(), 0u128), + true => (None, aborted_candidate_solutions, Field::::zero(), 0u128), false => { // Construct the solutions. let solutions = CoinbaseSolution::new(valid_candidate_solutions)?; @@ -161,11 +211,17 @@ impl> Ledger { // Compute the combined proof target. let combined_proof_target = solutions.to_combined_proof_target()?; // Output the solutions, solutions root, and combined proof target. - (Some(solutions), solutions_root, combined_proof_target) + (Some(solutions), aborted_candidate_solutions, solutions_root, combined_proof_target) } } } }; + // Prepare the solutions. + let solutions = Solutions::from(solutions); + + // Construct the aborted solution IDs. + let aborted_solution_ids = + aborted_solutions.into_iter().map(|solution| solution.commitment()).collect::>(); // Retrieve the latest state root. let latest_state_root = self.latest_state_root(); @@ -183,7 +239,7 @@ impl> Ledger { let next_height = previous_block.height().saturating_add(1); // Determine the timestamp for the next block. let next_timestamp = match subdag { - Some(subdag) => subdag.timestamp(), + Some(subdag) => subdag.timestamp(&self.latest_committee()?), None => OffsetDateTime::now_utc().unix_timestamp(), }; // Compute the next cumulative weight. @@ -239,7 +295,7 @@ impl> Ledger { state, Some(coinbase_reward), candidate_ratifications, - solutions.as_ref(), + &solutions, candidate_transactions.iter(), )?; @@ -278,6 +334,6 @@ impl> Ledger { )?; // Return the block template. - Ok((header, ratifications, solutions, transactions, aborted_transaction_ids)) + Ok((header, ratifications, solutions, aborted_solution_ids, transactions, aborted_transaction_ids)) } } diff --git a/ledger/src/check_next_block.rs b/ledger/src/check_next_block.rs index 18a1ee2544..3f282f660b 100644 --- a/ledger/src/check_next_block.rs +++ b/ledger/src/check_next_block.rs @@ -32,20 +32,17 @@ impl> Ledger { } // Ensure the solutions do not already exist. - if let Some(solutions) = block.solutions() { - for puzzle_commitment in solutions.puzzle_commitments() { - if self.contains_puzzle_commitment(puzzle_commitment)? { - bail!("Puzzle commitment {puzzle_commitment} already exists in the ledger"); - } + for solution_id in block.solutions().solution_ids() { + if self.contains_puzzle_commitment(solution_id)? { + bail!("Solution ID {solution_id} already exists in the ledger"); } } // Ensure each transaction is well-formed and unique. - // TODO: this intermediate allocation shouldn't be necessary; this is most likely https://github.com/rust-lang/rust/issues/89418. - let transactions = block.transactions().iter().collect::>(); + let transactions = block.transactions(); let rngs = (0..transactions.len()).map(|_| StdRng::from_seed(rng.gen())).collect::>(); cfg_iter!(transactions).zip(rngs).try_for_each(|(transaction, mut rng)| { - self.check_transaction_basic(*transaction, transaction.to_rejected_id()?, &mut rng) + self.check_transaction_basic(transaction, transaction.to_rejected_id()?, &mut rng) .map_err(|e| anyhow!("Invalid transaction found in the transactions list: {e}")) })?; @@ -85,17 +82,44 @@ impl> Ledger { let ratified_finalize_operations = self.vm.check_speculate(state, block.ratifications(), block.solutions(), block.transactions())?; + // Get the round number for the previous committee. Note, we subtract 2 from odd rounds, + // because committees are updated in even rounds. + let previous_round = match block.round() % 2 == 0 { + true => block.round().saturating_sub(1), + false => block.round().saturating_sub(2), + }; + // Get the committee lookback round. + let committee_lookback_round = previous_round.saturating_sub(Committee::::COMMITTEE_LOOKBACK_RANGE); + // Retrieve the committee lookback. + let committee_lookback = self + .get_committee_for_round(committee_lookback_round)? + .ok_or(anyhow!("Failed to fetch committee for round {committee_lookback_round}"))?; + // Ensure the block is correct. - block.verify( + let (expected_existing_solution_ids, expected_existing_transaction_ids) = block.verify( &self.latest_block(), self.latest_state_root(), - &self.latest_committee()?, + &committee_lookback, self.coinbase_puzzle(), &self.latest_epoch_challenge()?, OffsetDateTime::now_utc().unix_timestamp(), ratified_finalize_operations, )?; + // Ensure that each existing solution ID from the block exists in the ledger. + for existing_solution_id in expected_existing_solution_ids { + if !self.contains_puzzle_commitment(&existing_solution_id)? { + bail!("Solution ID '{existing_solution_id}' does not exist in the ledger"); + } + } + + // Ensure that each existing transaction ID from the block exists in the ledger. + for existing_transaction_id in expected_existing_transaction_ids { + if !self.contains_transaction_id(&existing_transaction_id)? { + bail!("Transaction ID '{existing_transaction_id}' does not exist in the ledger"); + } + } + Ok(()) } } diff --git a/ledger/src/contains.rs b/ledger/src/contains.rs index 64a52bbda5..7b5500f434 100644 --- a/ledger/src/contains.rs +++ b/ledger/src/contains.rs @@ -44,14 +44,14 @@ impl> Ledger { pub fn contains_transmission(&self, transmission_id: &TransmissionID) -> Result { match transmission_id { TransmissionID::Ratification => Ok(false), - TransmissionID::Solution(puzzle_commitment) => self.contains_puzzle_commitment(puzzle_commitment), + TransmissionID::Solution(solution_id) => self.contains_puzzle_commitment(solution_id), TransmissionID::Transaction(transaction_id) => self.contains_transaction_id(transaction_id), } } /// Returns `true` if the given puzzle commitment exists. - pub fn contains_puzzle_commitment(&self, puzzle_commitment: &PuzzleCommitment) -> Result { - self.vm.block_store().contains_puzzle_commitment(puzzle_commitment) + pub fn contains_puzzle_commitment(&self, solution_id: &PuzzleCommitment) -> Result { + self.vm.block_store().contains_puzzle_commitment(solution_id) } /* Transaction */ diff --git a/ledger/src/get.rs b/ledger/src/get.rs index 9058f89d4b..06263a4841 100644 --- a/ledger/src/get.rs +++ b/ledger/src/get.rs @@ -200,10 +200,10 @@ impl> Ledger { } /// Returns the block solutions for the given block height. - pub fn get_solutions(&self, height: u32) -> Result>> { + pub fn get_solutions(&self, height: u32) -> Result> { // If the height is 0, return the genesis block solutions. if height == 0 { - return Ok(self.genesis_block.solutions().cloned()); + return Ok(self.genesis_block.solutions().clone()); } // Retrieve the block hash. let block_hash = match self.vm.block_store().get_block_hash(height)? { @@ -247,9 +247,9 @@ impl> Ledger { mod tests { use super::*; use crate::test_helpers::CurrentLedger; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_get_block() { @@ -257,7 +257,7 @@ mod tests { let genesis = Block::from_bytes_le(CurrentNetwork::genesis_bytes()).unwrap(); // Initialize a new ledger. - let ledger = CurrentLedger::load(genesis.clone(), None).unwrap(); + let ledger = CurrentLedger::load(genesis.clone(), StorageMode::Production).unwrap(); // Retrieve the genesis block. let candidate = ledger.get_block(0).unwrap(); // Ensure the genesis block matches. diff --git a/ledger/src/iterators.rs b/ledger/src/iterators.rs index 976de7393a..1c6880e56c 100644 --- a/ledger/src/iterators.rs +++ b/ledger/src/iterators.rs @@ -20,9 +20,9 @@ impl> Ledger { self.vm.block_store().state_roots() } - /// Returns an iterator over the puzzle commitments, for all blocks in `self`. - pub fn puzzle_commitments(&self) -> impl '_ + Iterator>> { - self.vm.block_store().puzzle_commitments() + /// Returns an iterator over the solution IDs, for all blocks in `self`. + pub fn solution_ids(&self) -> impl '_ + Iterator>> { + self.vm.block_store().solution_ids() } /* Transaction */ diff --git a/ledger/src/lib.rs b/ledger/src/lib.rs index ecb5c9c59d..d7928b9581 100644 --- a/ledger/src/lib.rs +++ b/ledger/src/lib.rs @@ -52,7 +52,6 @@ use console::{ types::{Field, Group}, }; use ledger_authority::Authority; -use ledger_block::{Block, ConfirmedTransaction, Header, Metadata, Ratify, Transaction, Transactions}; use ledger_coinbase::{CoinbasePuzzle, CoinbaseSolution, EpochChallenge, ProverSolution, PuzzleCommitment}; use ledger_committee::Committee; use ledger_narwhal::{BatchCertificate, Subdag, Transmission, TransmissionID}; @@ -63,7 +62,10 @@ use synthesizer::{ vm::VM, }; -use aleo_std::prelude::{finish, lap, timer}; +use aleo_std::{ + prelude::{finish, lap, timer}, + StorageMode, +}; use anyhow::Result; use core::ops::Range; use indexmap::IndexMap; @@ -109,13 +111,13 @@ pub struct Ledger> { impl> Ledger { /// Loads the ledger from storage. - pub fn load(genesis_block: Block, dev: Option) -> Result { + pub fn load(genesis_block: Block, storage_mode: StorageMode) -> Result { let timer = timer!("Ledger::load"); // Retrieve the genesis hash. let genesis_hash = genesis_block.hash(); // Initialize the ledger. - let ledger = Self::load_unchecked(genesis_block, dev)?; + let ledger = Self::load_unchecked(genesis_block, storage_mode)?; // Ensure the ledger contains the correct genesis block. if !ledger.contains_block_hash(&genesis_hash)? { @@ -141,12 +143,12 @@ impl> Ledger { } /// Loads the ledger from storage, without performing integrity checks. - pub fn load_unchecked(genesis_block: Block, dev: Option) -> Result { + pub fn load_unchecked(genesis_block: Block, storage_mode: StorageMode) -> Result { let timer = timer!("Ledger::load_unchecked"); info!("Loading the ledger from storage..."); // Initialize the consensus store. - let store = match ConsensusStore::::open(dev) { + let store = match ConsensusStore::::open(storage_mode) { Ok(store) => store, Err(e) => bail!("Failed to load ledger (run 'snarkos clean' and try again)\n\n{e}\n"), }; @@ -384,16 +386,17 @@ impl> Ledger { #[cfg(test)] pub(crate) mod test_helpers { use crate::Ledger; + use aleo_std::StorageMode; use console::{ account::{Address, PrivateKey, ViewKey}, - network::Testnet3, + network::MainnetV0, prelude::*, }; use ledger_block::Block; use ledger_store::ConsensusStore; use synthesizer::vm::VM; - pub(crate) type CurrentNetwork = Testnet3; + pub(crate) type CurrentNetwork = MainnetV0; #[cfg(not(feature = "rocks"))] pub(crate) type CurrentLedger = @@ -440,7 +443,7 @@ pub(crate) mod test_helpers { // Create a genesis block. let genesis = VM::from(store).unwrap().genesis_beacon(&private_key, rng).unwrap(); // Initialize the ledger with the genesis block. - let ledger = CurrentLedger::load(genesis.clone(), None).unwrap(); + let ledger = CurrentLedger::load(genesis.clone(), StorageMode::Production).unwrap(); // Ensure the genesis block is correct. assert_eq!(genesis, ledger.get_block(0).unwrap()); // Return the ledger. diff --git a/ledger/src/tests.rs b/ledger/src/tests.rs index 273394ac95..be02b08392 100644 --- a/ledger/src/tests.rs +++ b/ledger/src/tests.rs @@ -13,9 +13,11 @@ // limitations under the License. use crate::{ + advance::split_candidate_solutions, test_helpers::{CurrentLedger, CurrentNetwork}, RecordsFilter, }; +use aleo_std::StorageMode; use console::{ account::{Address, PrivateKey}, network::prelude::*, @@ -37,7 +39,7 @@ fn test_load() { let genesis = VM::from(store).unwrap().genesis_beacon(&private_key, rng).unwrap(); // Initialize the ledger with the genesis block. - let ledger = CurrentLedger::load(genesis.clone(), None).unwrap(); + let ledger = CurrentLedger::load(genesis.clone(), StorageMode::Production).unwrap(); assert_eq!(ledger.latest_hash(), genesis.hash()); assert_eq!(ledger.latest_height(), genesis.height()); assert_eq!(ledger.latest_round(), genesis.round()); @@ -50,14 +52,14 @@ fn test_load_unchecked() { let genesis = crate::test_helpers::sample_genesis_block(); // Initialize the ledger without checks. - let ledger = CurrentLedger::load_unchecked(genesis.clone(), None).unwrap(); + let ledger = CurrentLedger::load_unchecked(genesis.clone(), StorageMode::Production).unwrap(); assert_eq!(ledger.latest_hash(), genesis.hash()); assert_eq!(ledger.latest_height(), genesis.height()); assert_eq!(ledger.latest_round(), genesis.round()); assert_eq!(ledger.latest_block(), genesis); // Initialize the ledger with the genesis block. - let ledger = CurrentLedger::load(genesis.clone(), None).unwrap(); + let ledger = CurrentLedger::load(genesis.clone(), StorageMode::Production).unwrap(); assert_eq!(ledger.latest_hash(), genesis.hash()); assert_eq!(ledger.latest_height(), genesis.height()); assert_eq!(ledger.latest_round(), genesis.round()); @@ -110,8 +112,7 @@ fn test_insufficient_private_fees() { { // Prepare a `split` execution without a fee. let inputs = [Value::Record(record_1.clone()), Value::from_str("100u64").unwrap()]; - let authorization = - ledger.vm.authorize(&private_key, "credits.aleo", "split", inputs.into_iter(), rng).unwrap(); + let authorization = ledger.vm.authorize(&private_key, "credits.aleo", "split", inputs, rng).unwrap(); let split_transaction_without_fee = ledger.vm.execute_authorization(authorization, None, None, rng).unwrap(); assert!(ledger.check_transaction_basic(&split_transaction_without_fee, None, rng).is_ok()); } @@ -124,8 +125,7 @@ fn test_insufficient_private_fees() { Value::from_str(&format!("{address}")).unwrap(), Value::from_str("100u64").unwrap(), ]; - let authorization = - ledger.vm.authorize(&private_key, "credits.aleo", "transfer_private", inputs.into_iter(), rng).unwrap(); + let authorization = ledger.vm.authorize(&private_key, "credits.aleo", "transfer_private", inputs, rng).unwrap(); let transaction_without_fee = ledger.vm.execute_authorization(authorization, None, None, rng).unwrap(); let execution = transaction_without_fee.execution().unwrap(); @@ -637,6 +637,53 @@ fn test_aborted_transaction_indexing() { ledger.advance_to_next_block(&block).unwrap(); } +#[test] +fn test_aborted_solution_ids() { + let rng = &mut TestRng::default(); + + // Initialize the test environment. + let crate::test_helpers::TestEnv { ledger, private_key, address, .. } = crate::test_helpers::sample_test_env(rng); + + // Retrieve the coinbase puzzle parameters. + let coinbase_puzzle = ledger.coinbase_puzzle(); + let epoch_challenge = ledger.latest_epoch_challenge().unwrap(); + let minimum_proof_target = ledger.latest_proof_target(); + + // Create a solution that is less than the minimum proof target. + let mut invalid_solution = coinbase_puzzle.prove(&epoch_challenge, address, rng.gen(), None).unwrap(); + while invalid_solution.to_target().unwrap() >= minimum_proof_target { + invalid_solution = coinbase_puzzle.prove(&epoch_challenge, address, rng.gen(), None).unwrap(); + } + + // Create a valid transaction for the block. + let inputs = [Value::from_str(&format!("{address}")).unwrap(), Value::from_str("10u64").unwrap()]; + let transfer_transaction = ledger + .vm + .execute(&private_key, ("credits.aleo", "transfer_public"), inputs.iter(), None, 0, None, rng) + .unwrap(); + + // Create a block. + let block = ledger + .prepare_advance_to_next_beacon_block( + &private_key, + vec![], + vec![invalid_solution], + vec![transfer_transaction], + rng, + ) + .unwrap(); + + // Check that the next block is valid. + ledger.check_next_block(&block, rng).unwrap(); + + // Add the deployment block to the ledger. + ledger.advance_to_next_block(&block).unwrap(); + + // Enforce that the block solution was aborted properly. + assert!(block.solutions().is_empty()); + assert_eq!(block.aborted_solution_ids(), &vec![invalid_solution.commitment()]); +} + #[test] fn test_execute_duplicate_input_ids() { let rng = &mut TestRng::default(); @@ -758,6 +805,415 @@ fn test_execute_duplicate_input_ids() { assert_eq!(block.aborted_transaction_ids(), &vec![transfer_4_id]); } +#[test] +fn test_execute_duplicate_output_ids() { + let rng = &mut TestRng::default(); + + // Initialize the test environment. + let crate::test_helpers::TestEnv { ledger, private_key, address, .. } = crate::test_helpers::sample_test_env(rng); + + // Deploy a test program to the ledger. + let program = Program::::from_str( + " +program dummy_program.aleo; + +record dummy_program: + owner as address.private; + rand_var as u64.private; + +function create_duplicate_record: + input r0 as u64.private; + cast self.caller 1u64 into r1 as dummy_program.record; + output r1 as dummy_program.record;", + ) + .unwrap(); + + // Deploy. + let deployment_transaction = ledger.vm.deploy(&private_key, &program, None, 0, None, rng).unwrap(); + // Verify. + ledger.vm().check_transaction(&deployment_transaction, None, rng).unwrap(); + + // Construct the next block. + let block = ledger + .prepare_advance_to_next_beacon_block(&private_key, vec![], vec![], vec![deployment_transaction], rng) + .unwrap(); + + // Check that the next block is valid. + ledger.check_next_block(&block, rng).unwrap(); + // Add the block to the ledger. + ledger.advance_to_next_block(&block).unwrap(); + + // Create a transaction with different transition ids, but with a fixed output record (output ID). + let mut create_transaction_with_duplicate_output_id = |x: u64| -> Transaction { + // Use a fixed seed RNG. + let fixed_rng = &mut TestRng::from_seed(1); + + // Create a transaction with a fixed rng. + let inputs = [Value::from_str(&format!("{x}u64")).unwrap()]; + let transaction = ledger + .vm + .execute( + &private_key, + ("dummy_program.aleo", "create_duplicate_record"), + inputs.into_iter(), + None, + 0, + None, + fixed_rng, + ) + .unwrap(); + // Extract the execution. + let execution = transaction.execution().unwrap().clone(); + + // Create a new fee for the execution. + let fee_authorization = ledger + .vm + .authorize_fee_public( + &private_key, + *transaction.fee_amount().unwrap(), + 0, + execution.to_execution_id().unwrap(), + rng, + ) + .unwrap(); + let fee = ledger.vm.execute_fee_authorization(fee_authorization, None, rng).unwrap(); + + Transaction::from_execution(execution, Some(fee)).unwrap() + }; + + // Create the first transfer. + let transfer_1 = create_transaction_with_duplicate_output_id(1); + let transfer_1_id = transfer_1.id(); + + // Create a second transfer with the same output id. + let transfer_2 = create_transaction_with_duplicate_output_id(2); + let transfer_2_id = transfer_2.id(); + + // Create a third transfer with the same output id. + let transfer_3 = create_transaction_with_duplicate_output_id(3); + let transfer_3_id = transfer_3.id(); + + // Ensure that each transaction has a duplicate output id. + let tx_1_output_id = transfer_1.output_ids().next().unwrap(); + let tx_2_output_id = transfer_2.output_ids().next().unwrap(); + let tx_3_output_id = transfer_3.output_ids().next().unwrap(); + assert_eq!(tx_1_output_id, tx_2_output_id); + assert_eq!(tx_1_output_id, tx_3_output_id); + + // Create a block. + let block = ledger + .prepare_advance_to_next_beacon_block(&private_key, vec![], vec![], vec![transfer_1, transfer_2], rng) + .unwrap(); + + // Check that the next block is valid. + ledger.check_next_block(&block, rng).unwrap(); + + // Add the block to the ledger. + ledger.advance_to_next_block(&block).unwrap(); + + // Enforce that the block transactions were correct. + assert_eq!(block.transactions().num_accepted(), 1); + assert_eq!(block.transactions().transaction_ids().collect::>(), vec![&transfer_1_id]); + assert_eq!(block.aborted_transaction_ids(), &vec![transfer_2_id]); + + // Prepare a transfer that will succeed for the subsequent block. + let inputs = [Value::from_str(&format!("{address}")).unwrap(), Value::from_str("1000u64").unwrap()]; + let transfer_4 = ledger + .vm + .execute(&private_key, ("credits.aleo", "transfer_public"), inputs.into_iter(), None, 0, None, rng) + .unwrap(); + let transfer_4_id = transfer_4.id(); + + // Create a block. + let block = ledger + .prepare_advance_to_next_beacon_block(&private_key, vec![], vec![], vec![transfer_3, transfer_4], rng) + .unwrap(); + + // Check that the next block is valid. + ledger.check_next_block(&block, rng).unwrap(); + + // Add the block to the ledger. + ledger.advance_to_next_block(&block).unwrap(); + + // Enforce that the block transactions were correct. + assert_eq!(block.transactions().num_accepted(), 1); + assert_eq!(block.transactions().transaction_ids().collect::>(), vec![&transfer_4_id]); + assert_eq!(block.aborted_transaction_ids(), &vec![transfer_3_id]); +} + +#[test] +fn test_execute_duplicate_transition_ids() { + let rng = &mut TestRng::default(); + + // Initialize the test environment. + let crate::test_helpers::TestEnv { ledger, private_key, address, .. } = crate::test_helpers::sample_test_env(rng); + + // Deploy a test program to the ledger. + let program = Program::::from_str( + " +program dummy_program.aleo; + +function empty_function: + ", + ) + .unwrap(); + + // Deploy. + let deployment_transaction = ledger.vm.deploy(&private_key, &program, None, 0, None, rng).unwrap(); + // Verify. + ledger.vm().check_transaction(&deployment_transaction, None, rng).unwrap(); + + // Construct the next block. + let block = ledger + .prepare_advance_to_next_beacon_block(&private_key, vec![], vec![], vec![deployment_transaction], rng) + .unwrap(); + + // Check that the next block is valid. + ledger.check_next_block(&block, rng).unwrap(); + // Add the block to the ledger. + ledger.advance_to_next_block(&block).unwrap(); + + // Create a transaction with different transaction IDs, but with a fixed transition ID. + let mut create_transaction_with_duplicate_transition_id = || -> Transaction { + // Use a fixed seed RNG. + let fixed_rng = &mut TestRng::from_seed(1); + + // Create a transaction with a fixed rng. + let inputs: [Value<_>; 0] = []; + let transaction = ledger + .vm + .execute( + &private_key, + ("dummy_program.aleo", "empty_function"), + inputs.into_iter(), + None, + 0, + None, + fixed_rng, + ) + .unwrap(); + // Extract the execution. + let execution = transaction.execution().unwrap().clone(); + + // Create a new fee for the execution. + let fee_authorization = ledger + .vm + .authorize_fee_public( + &private_key, + *transaction.fee_amount().unwrap(), + 0, + execution.to_execution_id().unwrap(), + rng, + ) + .unwrap(); + let fee = ledger.vm.execute_fee_authorization(fee_authorization, None, rng).unwrap(); + + Transaction::from_execution(execution, Some(fee)).unwrap() + }; + + // Create the first transaction. + let transaction_1 = create_transaction_with_duplicate_transition_id(); + let transaction_1_id = transaction_1.id(); + + // Create a second transaction with the same transition id. + let transaction_2 = create_transaction_with_duplicate_transition_id(); + let transaction_2_id = transaction_2.id(); + + // Create a third transaction with the same transition_id + let transaction_3 = create_transaction_with_duplicate_transition_id(); + let transaction_3_id = transaction_3.id(); + + // Ensure that each transaction has a duplicate transition id. + let tx_1_transition_id = transaction_1.transition_ids().next().unwrap(); + let tx_2_transition_id = transaction_2.transition_ids().next().unwrap(); + let tx_3_transition_id = transaction_3.transition_ids().next().unwrap(); + assert_eq!(tx_1_transition_id, tx_2_transition_id); + assert_eq!(tx_1_transition_id, tx_3_transition_id); + + // Create a block. + let block = ledger + .prepare_advance_to_next_beacon_block(&private_key, vec![], vec![], vec![transaction_1, transaction_2], rng) + .unwrap(); + + // Check that the next block is valid. + ledger.check_next_block(&block, rng).unwrap(); + + // Add the block to the ledger. + ledger.advance_to_next_block(&block).unwrap(); + + // Enforce that the block transactions were correct. + assert_eq!(block.transactions().num_accepted(), 1); + assert_eq!(block.transactions().transaction_ids().collect::>(), vec![&transaction_1_id]); + assert_eq!(block.aborted_transaction_ids(), &vec![transaction_2_id]); + + // Prepare a transfer that will succeed for the subsequent block. + let inputs = [Value::from_str(&format!("{address}")).unwrap(), Value::from_str("1000u64").unwrap()]; + let transfer_transaction = ledger + .vm + .execute(&private_key, ("credits.aleo", "transfer_public"), inputs.into_iter(), None, 0, None, rng) + .unwrap(); + let transfer_transaction_id = transfer_transaction.id(); + + // Create a block. + let block = ledger + .prepare_advance_to_next_beacon_block( + &private_key, + vec![], + vec![], + vec![transaction_3, transfer_transaction], + rng, + ) + .unwrap(); + + // Check that the next block is valid. + ledger.check_next_block(&block, rng).unwrap(); + + // Add the block to the ledger. + ledger.advance_to_next_block(&block).unwrap(); + + // Enforce that the block transactions were correct. + assert_eq!(block.transactions().num_accepted(), 1); + assert_eq!(block.transactions().transaction_ids().collect::>(), vec![&transfer_transaction_id]); + assert_eq!(block.aborted_transaction_ids(), &vec![transaction_3_id]); +} + +#[test] +fn test_execute_duplicate_transition_public_keys() { + let rng = &mut TestRng::default(); + + // Initialize the test environment. + let crate::test_helpers::TestEnv { ledger, private_key, address, .. } = crate::test_helpers::sample_test_env(rng); + + // Deploy a test program to the ledger. + let program = Program::::from_str( + " +program dummy_program.aleo; + +function empty_function: + +function simple_output: + output 1u64 as u64.public; + ", + ) + .unwrap(); + + // Deploy. + let deployment_transaction = ledger.vm.deploy(&private_key, &program, None, 0, None, rng).unwrap(); + // Verify. + ledger.vm().check_transaction(&deployment_transaction, None, rng).unwrap(); + + // Construct the next block. + let block = ledger + .prepare_advance_to_next_beacon_block(&private_key, vec![], vec![], vec![deployment_transaction], rng) + .unwrap(); + + // Check that the next block is valid. + ledger.check_next_block(&block, rng).unwrap(); + // Add the block to the ledger. + ledger.advance_to_next_block(&block).unwrap(); + + // Create a transaction with different transaction ids, but with a TPK. + let mut create_transaction_with_duplicate_tpk = |function: &str| -> Transaction { + // Use a fixed seed RNG. + let fixed_rng = &mut TestRng::from_seed(1); + + // Create a transaction with a fixed rng. + let inputs: [Value<_>; 0] = []; + let transaction = ledger + .vm + .execute(&private_key, ("dummy_program.aleo", function), inputs.into_iter(), None, 0, None, fixed_rng) + .unwrap(); + // Extract the execution. + let execution = transaction.execution().unwrap().clone(); + + // Create a new fee for the execution. + let fee_authorization = ledger + .vm + .authorize_fee_public( + &private_key, + *transaction.fee_amount().unwrap(), + 0, + execution.to_execution_id().unwrap(), + rng, + ) + .unwrap(); + let fee = ledger.vm.execute_fee_authorization(fee_authorization, None, rng).unwrap(); + + Transaction::from_execution(execution, Some(fee)).unwrap() + }; + + // Create the first transaction. + let transaction_1 = create_transaction_with_duplicate_tpk("empty_function"); + let transaction_1_id = transaction_1.id(); + + // Create a second transaction with the same tpk and tcm. + let transaction_2 = create_transaction_with_duplicate_tpk("simple_output"); + let transaction_2_id = transaction_2.id(); + + // Create a third transaction with the same tpk and tcm. + let transaction_3 = create_transaction_with_duplicate_tpk("simple_output"); + let transaction_3_id = transaction_3.id(); + + // Ensure that each transaction has a duplicate tcm and tpk. + let tx_1_tpk = transaction_1.transitions().next().unwrap().tpk(); + let tx_2_tpk = transaction_2.transitions().next().unwrap().tpk(); + let tx_3_tpk = transaction_3.transitions().next().unwrap().tpk(); + assert_eq!(tx_1_tpk, tx_2_tpk); + assert_eq!(tx_1_tpk, tx_3_tpk); + + let tx_1_tcm = transaction_1.transitions().next().unwrap().tcm(); + let tx_2_tcm = transaction_2.transitions().next().unwrap().tcm(); + let tx_3_tcm = transaction_3.transitions().next().unwrap().tcm(); + assert_eq!(tx_1_tcm, tx_2_tcm); + assert_eq!(tx_1_tcm, tx_3_tcm); + + // Create a block. + let block = ledger + .prepare_advance_to_next_beacon_block(&private_key, vec![], vec![], vec![transaction_1, transaction_2], rng) + .unwrap(); + + // Check that the next block is valid. + ledger.check_next_block(&block, rng).unwrap(); + + // Add the block to the ledger. + ledger.advance_to_next_block(&block).unwrap(); + + // Enforce that the block transactions were correct. + assert_eq!(block.transactions().num_accepted(), 1); + assert_eq!(block.transactions().transaction_ids().collect::>(), vec![&transaction_1_id]); + assert_eq!(block.aborted_transaction_ids(), &vec![transaction_2_id]); + + // Prepare a transfer that will succeed for the subsequent block. + let inputs = [Value::from_str(&format!("{address}")).unwrap(), Value::from_str("1000u64").unwrap()]; + let transfer_transaction = ledger + .vm + .execute(&private_key, ("credits.aleo", "transfer_public"), inputs.into_iter(), None, 0, None, rng) + .unwrap(); + let transfer_transaction_id = transfer_transaction.id(); + + // Create a block. + let block = ledger + .prepare_advance_to_next_beacon_block( + &private_key, + vec![], + vec![], + vec![transaction_3, transfer_transaction], + rng, + ) + .unwrap(); + + // Check that the next block is valid. + ledger.check_next_block(&block, rng).unwrap(); + + // Add the block to the ledger. + ledger.advance_to_next_block(&block).unwrap(); + + // Enforce that the block transactions were correct. + assert_eq!(block.transactions().num_accepted(), 1); + assert_eq!(block.transactions().transaction_ids().collect::>(), vec![&transfer_transaction_id]); + assert_eq!(block.aborted_transaction_ids(), &vec![transaction_3_id]); +} + #[test] fn test_deployment_duplicate_program_id() { let rng = &mut TestRng::default(); @@ -828,3 +1284,20 @@ finalize foo2: assert!(ledger.vm.transaction_store().contains_transaction_id(&deployment_1_id).unwrap()); assert!(ledger.vm.block_store().contains_rejected_or_aborted_transaction_id(&deployment_2_id).unwrap()); } + +#[test] +fn test_split_candidate_solutions() { + let rng = &mut TestRng::default(); + + let max_solutions = CurrentNetwork::MAX_SOLUTIONS; + + const ITERATIONS: usize = 1_000; + + for _ in 0..ITERATIONS { + let num_candidates = rng.gen_range(0..max_solutions * 2); + let candidate_solutions: Vec = rng.sample_iter(Standard).take(num_candidates).collect(); + + let (_accepted, _aborted) = + split_candidate_solutions(candidate_solutions, max_solutions, |candidate| candidate % 2 == 0); + } +} diff --git a/ledger/store/Cargo.toml b/ledger/store/Cargo.toml index e17fa0900f..2491a5ae1b 100644 --- a/ledger/store/Cargo.toml +++ b/ledger/store/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-ledger-store" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "A data store for a decentralized virtual machine" homepage = "https://aleo.org" @@ -18,7 +18,7 @@ edition = "2021" [features] default = [ "indexmap/rayon", "rayon" ] -rocks = [ "aleo-std", "once_cell", "rocksdb", "tracing" ] +rocks = [ "once_cell", "rocksdb", "tracing" ] serial = [ "console/serial", "ledger-block/serial", @@ -42,47 +42,46 @@ test = [ ] [dependencies.console] package = "snarkvm-console" path = "../../console" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-authority] package = "snarkvm-ledger-authority" path = "../authority" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-block] package = "snarkvm-ledger-block" path = "../block" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-coinbase] package = "snarkvm-ledger-coinbase" path = "../coinbase" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-committee] package = "snarkvm-ledger-committee" path = "../committee" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-narwhal-batch-certificate] package = "snarkvm-ledger-narwhal-batch-certificate" path = "../narwhal/batch-certificate" -version = "=0.16.15" +version = "=0.16.19" [dependencies.synthesizer-program] package = "snarkvm-synthesizer-program" path = "../../synthesizer/program" -version = "=0.16.15" +version = "=0.16.19" [dependencies.synthesizer-snark] package = "snarkvm-synthesizer-snark" path = "../../synthesizer/snark" -version = "=0.16.15" +version = "=0.16.19" -[dependencies.aleo-std] -version = "0.1.18" +[dependencies.aleo-std-storage] +version = "0.1.7" default-features = false -optional = true [dependencies.anyhow] version = "1.0.73" diff --git a/ledger/store/src/block/mod.rs b/ledger/store/src/block/mod.rs index 4ffb292fec..38d67af76d 100644 --- a/ledger/store/src/block/mod.rs +++ b/ledger/store/src/block/mod.rs @@ -35,13 +35,15 @@ use ledger_block::{ NumFinalizeSize, Ratifications, Rejected, + Solutions, Transaction, Transactions, }; -use ledger_coinbase::{CoinbaseSolution, ProverSolution, PuzzleCommitment}; +use ledger_coinbase::{ProverSolution, PuzzleCommitment}; use ledger_narwhal_batch_certificate::BatchCertificate; use synthesizer_program::Program; +use aleo_std_storage::StorageMode; use anyhow::Result; use parking_lot::RwLock; use std::{borrow::Cow, io::Cursor, sync::Arc}; @@ -186,9 +188,13 @@ pub trait BlockStorage: 'static + Clone + Send + Sync { /// The mapping of `block hash` to `block ratifications`. type RatificationsMap: for<'a> Map<'a, N::BlockHash, Ratifications>; /// The mapping of `block hash` to `block solutions`. - type SolutionsMap: for<'a> Map<'a, N::BlockHash, Option>>; + type SolutionsMap: for<'a> Map<'a, N::BlockHash, Solutions>; /// The mapping of `puzzle commitment` to `block height`. type PuzzleCommitmentsMap: for<'a> Map<'a, PuzzleCommitment, u32>; + /// The mapping of `block hash` to `[aborted solution ID]`. + type AbortedSolutionIDsMap: for<'a> Map<'a, N::BlockHash, Vec>>; + /// The mapping of aborted `solution ID` to `block height`. + type AbortedSolutionHeightsMap: for<'a> Map<'a, PuzzleCommitment, u32>; /// The mapping of `block hash` to `[transaction ID]`. type TransactionsMap: for<'a> Map<'a, N::BlockHash, Vec>; /// The mapping of `block hash` to `[aborted transaction ID]`. @@ -207,7 +213,7 @@ pub trait BlockStorage: 'static + Clone + Send + Sync { type TransitionStorage: TransitionStorage; /// Initializes the block storage. - fn open(dev: Option) -> Result; + fn open>(storage: S) -> Result; /// Returns the state root map. fn state_root_map(&self) -> &Self::StateRootMap; @@ -229,6 +235,10 @@ pub trait BlockStorage: 'static + Clone + Send + Sync { fn solutions_map(&self) -> &Self::SolutionsMap; /// Returns the puzzle commitments map. fn puzzle_commitments_map(&self) -> &Self::PuzzleCommitmentsMap; + /// Returns the aborted solution IDs map. + fn aborted_solution_ids_map(&self) -> &Self::AbortedSolutionIDsMap; + /// Returns the aborted solution heights map. + fn aborted_solution_heights_map(&self) -> &Self::AbortedSolutionHeightsMap; /// Returns the accepted transactions map. fn transactions_map(&self) -> &Self::TransactionsMap; /// Returns the aborted transaction IDs map. @@ -246,10 +256,10 @@ pub trait BlockStorage: 'static + Clone + Send + Sync { fn transition_store(&self) -> &TransitionStore { self.transaction_store().transition_store() } - /// Returns the optional development ID. - fn dev(&self) -> Option { - debug_assert!(self.transaction_store().dev() == self.transition_store().dev()); - self.transition_store().dev() + /// Returns the storage mode. + fn storage_mode(&self) -> &StorageMode { + debug_assert!(self.transaction_store().storage_mode() == self.transition_store().storage_mode()); + self.transition_store().storage_mode() } /// Starts an atomic batch write operation. @@ -264,6 +274,8 @@ pub trait BlockStorage: 'static + Clone + Send + Sync { self.ratifications_map().start_atomic(); self.solutions_map().start_atomic(); self.puzzle_commitments_map().start_atomic(); + self.aborted_solution_ids_map().start_atomic(); + self.aborted_solution_heights_map().start_atomic(); self.transactions_map().start_atomic(); self.aborted_transaction_ids_map().start_atomic(); self.rejected_or_aborted_transaction_id_map().start_atomic(); @@ -284,6 +296,8 @@ pub trait BlockStorage: 'static + Clone + Send + Sync { || self.ratifications_map().is_atomic_in_progress() || self.solutions_map().is_atomic_in_progress() || self.puzzle_commitments_map().is_atomic_in_progress() + || self.aborted_solution_ids_map().is_atomic_in_progress() + || self.aborted_solution_heights_map().is_atomic_in_progress() || self.transactions_map().is_atomic_in_progress() || self.aborted_transaction_ids_map().is_atomic_in_progress() || self.rejected_or_aborted_transaction_id_map().is_atomic_in_progress() @@ -304,6 +318,8 @@ pub trait BlockStorage: 'static + Clone + Send + Sync { self.ratifications_map().atomic_checkpoint(); self.solutions_map().atomic_checkpoint(); self.puzzle_commitments_map().atomic_checkpoint(); + self.aborted_solution_ids_map().atomic_checkpoint(); + self.aborted_solution_heights_map().atomic_checkpoint(); self.transactions_map().atomic_checkpoint(); self.aborted_transaction_ids_map().atomic_checkpoint(); self.rejected_or_aborted_transaction_id_map().atomic_checkpoint(); @@ -324,6 +340,8 @@ pub trait BlockStorage: 'static + Clone + Send + Sync { self.ratifications_map().clear_latest_checkpoint(); self.solutions_map().clear_latest_checkpoint(); self.puzzle_commitments_map().clear_latest_checkpoint(); + self.aborted_solution_ids_map().clear_latest_checkpoint(); + self.aborted_solution_heights_map().clear_latest_checkpoint(); self.transactions_map().clear_latest_checkpoint(); self.aborted_transaction_ids_map().clear_latest_checkpoint(); self.rejected_or_aborted_transaction_id_map().clear_latest_checkpoint(); @@ -344,6 +362,8 @@ pub trait BlockStorage: 'static + Clone + Send + Sync { self.ratifications_map().atomic_rewind(); self.solutions_map().atomic_rewind(); self.puzzle_commitments_map().atomic_rewind(); + self.aborted_solution_ids_map().atomic_rewind(); + self.aborted_solution_heights_map().atomic_rewind(); self.transactions_map().atomic_rewind(); self.aborted_transaction_ids_map().atomic_rewind(); self.rejected_or_aborted_transaction_id_map().atomic_rewind(); @@ -364,6 +384,8 @@ pub trait BlockStorage: 'static + Clone + Send + Sync { self.ratifications_map().abort_atomic(); self.solutions_map().abort_atomic(); self.puzzle_commitments_map().abort_atomic(); + self.aborted_solution_ids_map().abort_atomic(); + self.aborted_solution_heights_map().abort_atomic(); self.transactions_map().abort_atomic(); self.aborted_transaction_ids_map().abort_atomic(); self.rejected_or_aborted_transaction_id_map().abort_atomic(); @@ -384,6 +406,8 @@ pub trait BlockStorage: 'static + Clone + Send + Sync { self.ratifications_map().finish_atomic()?; self.solutions_map().finish_atomic()?; self.puzzle_commitments_map().finish_atomic()?; + self.aborted_solution_ids_map().finish_atomic()?; + self.aborted_solution_heights_map().finish_atomic()?; self.transactions_map().finish_atomic()?; self.aborted_transaction_ids_map().finish_atomic()?; self.rejected_or_aborted_transaction_id_map().finish_atomic()?; @@ -443,13 +467,19 @@ pub trait BlockStorage: 'static + Clone + Send + Sync { self.ratifications_map().insert(block.hash(), block.ratifications().clone())?; // Store the block solutions. - self.solutions_map().insert(block.hash(), block.solutions().cloned())?; + self.solutions_map().insert(block.hash(), block.solutions().clone())?; - // Store the block puzzle commitments. - if let Some(solutions) = block.solutions() { - for puzzle_commitment in solutions.keys() { - self.puzzle_commitments_map().insert(*puzzle_commitment, block.height())?; - } + // Store the block solution IDs. + for solution_id in block.solutions().solution_ids() { + self.puzzle_commitments_map().insert(*solution_id, block.height())?; + } + + // Store the aborted solution IDs. + self.aborted_solution_ids_map().insert(block.hash(), block.aborted_solution_ids().clone())?; + + // Store the block aborted solution heights. + for solution_id in block.aborted_solution_ids() { + self.aborted_solution_heights_map().insert(*solution_id, block.height())?; } // Store the transaction IDs. @@ -507,6 +537,12 @@ pub trait BlockStorage: 'static + Clone + Send + Sync { } }; + // Retrieve the aborted solution IDs. + let aborted_solution_ids = match self.get_block_aborted_solution_ids(block_hash)? { + Some(solution_ids) => solution_ids, + None => Vec::new(), + }; + // Retrieve the aborted transaction IDs. let aborted_transaction_ids = match self.get_block_aborted_transaction_ids(block_hash)? { Some(transaction_ids) => transaction_ids, @@ -561,11 +597,17 @@ pub trait BlockStorage: 'static + Clone + Send + Sync { // Remove the block solutions. self.solutions_map().remove(block_hash)?; - // Remove the block puzzle commitments. - if let Some(solutions) = solutions { - for puzzle_commitment in solutions.keys() { - self.puzzle_commitments_map().remove(puzzle_commitment)?; - } + // Remove the block solution IDs. + for solution_id in solutions.solution_ids() { + self.puzzle_commitments_map().remove(solution_id)?; + } + + // Remove the aborted solution IDs. + self.aborted_solution_ids_map().remove(block_hash)?; + + // Remove the aborted solution heights. + for solution_id in aborted_solution_ids { + self.aborted_solution_heights_map().remove(&solution_id)?; } // Remove the transaction IDs. @@ -637,10 +679,13 @@ pub trait BlockStorage: 'static + Clone + Send + Sync { } /// Returns the block height that contains the given `puzzle commitment`. - fn find_block_height_from_puzzle_commitment(&self, puzzle_commitment: &PuzzleCommitment) -> Result> { - match self.puzzle_commitments_map().get_confirmed(puzzle_commitment)? { + fn find_block_height_from_puzzle_commitment(&self, solution_id: &PuzzleCommitment) -> Result> { + match self.puzzle_commitments_map().get_confirmed(solution_id)? { Some(block_height) => Ok(Some(cow_to_copied!(block_height))), - None => Ok(None), + None => match self.aborted_solution_heights_map().get_confirmed(solution_id)? { + Some(block_height) => Ok(Some(cow_to_copied!(block_height))), + None => Ok(None), + }, } } @@ -824,7 +869,7 @@ pub trait BlockStorage: 'static + Clone + Send + Sync { } /// Returns the block solutions for the given `block hash`. - fn get_block_solutions(&self, block_hash: &N::BlockHash) -> Result>> { + fn get_block_solutions(&self, block_hash: &N::BlockHash) -> Result> { match self.solutions_map().get_confirmed(block_hash)? { Some(solutions) => Ok(cow_to_cloned!(solutions)), None => bail!("Missing solutions for block ('{block_hash}')"), @@ -832,10 +877,10 @@ pub trait BlockStorage: 'static + Clone + Send + Sync { } /// Returns the prover solution for the given solution ID. - fn get_solution(&self, puzzle_commitment: &PuzzleCommitment) -> Result> { - // Retrieve the block height for the puzzle commitment. - let Some(block_height) = self.find_block_height_from_puzzle_commitment(puzzle_commitment)? else { - bail!("The block height for puzzle commitment '{puzzle_commitment}' is missing in block storage") + fn get_solution(&self, solution_id: &PuzzleCommitment) -> Result> { + // Retrieve the block height for the solution ID. + let Some(block_height) = self.find_block_height_from_puzzle_commitment(solution_id)? else { + bail!("The block height for solution ID '{solution_id}' is missing in block storage") }; // Retrieve the block hash. let Some(block_hash) = self.get_block_hash(block_height)? else { @@ -846,15 +891,19 @@ pub trait BlockStorage: 'static + Clone + Send + Sync { bail!("The solutions for block '{block_height}' are missing in block storage") }; // Retrieve the prover solution. - match solutions { - Cow::Owned(Some(ref solutions)) | Cow::Borrowed(Some(ref solutions)) => { - solutions.get(puzzle_commitment).cloned().ok_or_else(|| { - anyhow!( - "The prover solution for puzzle commitment '{puzzle_commitment}' is missing in block storage" - ) - }) - } - _ => bail!("The prover solution for puzzle commitment '{puzzle_commitment}' is missing in block storage"), + match solutions.deref().deref() { + Some(ref solutions) => solutions.get(solution_id).cloned().ok_or_else(|| { + anyhow!("The prover solution for solution ID '{solution_id}' is missing in block storage") + }), + _ => bail!("The prover solution for solution ID '{solution_id}' is missing in block storage"), + } + } + + /// Returns the block aborted solution IDs for the given `block hash`. + fn get_block_aborted_solution_ids(&self, block_hash: &N::BlockHash) -> Result>>> { + match self.aborted_solution_ids_map().get_confirmed(block_hash)? { + Some(aborted_solution_ids) => Ok(Some(cow_to_cloned!(aborted_solution_ids))), + None => Ok(None), } } @@ -971,6 +1020,10 @@ pub trait BlockStorage: 'static + Clone + Send + Sync { let Ok(solutions) = self.get_block_solutions(block_hash) else { bail!("Missing solutions for block {height} ('{block_hash}')"); }; + // Retrieve the block aborted solution IDs. + let Some(aborted_solution_ids) = self.get_block_aborted_solution_ids(block_hash)? else { + bail!("Missing aborted solutions IDs for block {height} ('{block_hash}')"); + }; // Retrieve the block transactions. let Some(transactions) = self.get_block_transactions(block_hash)? else { bail!("Missing transactions for block {height} ('{block_hash}')"); @@ -987,6 +1040,7 @@ pub trait BlockStorage: 'static + Clone + Send + Sync { authority, ratifications, solutions, + aborted_solution_ids, transactions, aborted_transaction_ids, )?)) @@ -1004,9 +1058,9 @@ pub struct BlockStore> { impl> BlockStore { /// Initializes the block store. - pub fn open(dev: Option) -> Result { + pub fn open>(storage: S) -> Result { // Initialize the block storage. - let storage = B::open(dev)?; + let storage = B::open(storage)?; // Compute the block tree. let tree = { @@ -1143,9 +1197,9 @@ impl> BlockStore { self.storage.finish_atomic() } - /// Returns the optional development ID. - pub fn dev(&self) -> Option { - self.storage.dev() + /// Returns the storage mode. + pub fn storage_mode(&self) -> &StorageMode { + self.storage.storage_mode() } } @@ -1216,7 +1270,7 @@ impl> BlockStore { } /// Returns the block solutions for the given `block hash`. - pub fn get_block_solutions(&self, block_hash: &N::BlockHash) -> Result>> { + pub fn get_block_solutions(&self, block_hash: &N::BlockHash) -> Result> { self.storage.get_block_solutions(block_hash) } @@ -1308,9 +1362,15 @@ impl> BlockStore { self.storage.certificate_map().contains_key_confirmed(certificate_id) } - /// Returns `true` if the given puzzle commitment exists. - pub fn contains_puzzle_commitment(&self, puzzle_commitment: &PuzzleCommitment) -> Result { - self.storage.puzzle_commitments_map().contains_key_confirmed(puzzle_commitment) + /// Returns `true` if the given solution ID exists. + pub fn contains_puzzle_commitment(&self, solution_id: &PuzzleCommitment) -> Result { + Ok(self.storage.puzzle_commitments_map().contains_key_confirmed(solution_id)? + || self.contains_aborted_puzzle_commitment(solution_id)?) + } + + /// Returns `true` if the given aborted solution ID exists. + fn contains_aborted_puzzle_commitment(&self, solution_id: &PuzzleCommitment) -> Result { + self.storage.aborted_solution_heights_map().contains_key_confirmed(solution_id) } } @@ -1330,8 +1390,8 @@ impl> BlockStore { self.storage.reverse_id_map().keys_confirmed() } - /// Returns an iterator over the puzzle commitments, for all blocks in `self`. - pub fn puzzle_commitments(&self) -> impl '_ + Iterator>> { + /// Returns an iterator over the solution IDs, for all blocks in `self`. + pub fn solution_ids(&self) -> impl '_ + Iterator>> { self.storage.puzzle_commitments_map().keys_confirmed() } } @@ -1341,7 +1401,7 @@ mod tests { use super::*; use crate::helpers::memory::BlockMemory; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; #[test] fn test_insert_get_remove() { diff --git a/ledger/store/src/consensus/mod.rs b/ledger/store/src/consensus/mod.rs index c8524bcee7..d4672f7414 100644 --- a/ledger/store/src/consensus/mod.rs +++ b/ledger/store/src/consensus/mod.rs @@ -24,6 +24,7 @@ use crate::{ }; use console::network::prelude::*; +use aleo_std_storage::StorageMode; use anyhow::Result; use core::marker::PhantomData; @@ -39,7 +40,7 @@ pub trait ConsensusStorage: 'static + Clone + Send + Sync { type TransitionStorage: TransitionStorage; /// Initializes the consensus storage. - fn open(dev: Option) -> Result; + fn open>(storage: S) -> Result; /// Returns the finalize storage. fn finalize_store(&self) -> &FinalizeStore; @@ -53,11 +54,11 @@ pub trait ConsensusStorage: 'static + Clone + Send + Sync { fn transition_store(&self) -> &TransitionStore { self.block_store().transition_store() } - /// Returns the optional development ID. - fn dev(&self) -> Option { - debug_assert!(self.block_store().dev() == self.transaction_store().dev()); - debug_assert!(self.transaction_store().dev() == self.transition_store().dev()); - self.transition_store().dev() + /// Returns the storage mode. + fn storage_mode(&self) -> &StorageMode { + debug_assert!(self.block_store().storage_mode() == self.transaction_store().storage_mode()); + debug_assert!(self.transaction_store().storage_mode() == self.transition_store().storage_mode()); + self.transition_store().storage_mode() } /// Starts an atomic batch write operation. @@ -113,9 +114,9 @@ pub struct ConsensusStore> { impl> ConsensusStore { /// Initializes the consensus store. - pub fn open(dev: Option) -> Result { + pub fn open>(storage: S) -> Result { // Initialize the consensus storage. - let storage = C::open(dev)?; + let storage = C::open(storage.clone())?; // Return the consensus store. Ok(Self { storage, _phantom: PhantomData }) } @@ -180,8 +181,8 @@ impl> ConsensusStore { self.storage.finish_atomic() } - /// Returns the optional development ID. - pub fn dev(&self) -> Option { - self.storage.dev() + /// Returns the storage mode. + pub fn storage_mode(&self) -> &StorageMode { + self.storage.storage_mode() } } diff --git a/ledger/store/src/helpers/memory/block.rs b/ledger/store/src/helpers/memory/block.rs index c09fa09f2e..7c515ba5b3 100644 --- a/ledger/store/src/helpers/memory/block.rs +++ b/ledger/store/src/helpers/memory/block.rs @@ -21,8 +21,10 @@ use crate::{ }; use console::{prelude::*, types::Field}; use ledger_authority::Authority; -use ledger_block::{Header, Ratifications, Rejected}; -use ledger_coinbase::{CoinbaseSolution, PuzzleCommitment}; +use ledger_block::{Header, Ratifications, Rejected, Solutions}; +use ledger_coinbase::PuzzleCommitment; + +use aleo_std_storage::StorageMode; /// An in-memory block storage. #[derive(Clone)] @@ -44,9 +46,13 @@ pub struct BlockMemory { /// The ratifications map. ratifications_map: MemoryMap>, /// The solutions map. - solutions_map: MemoryMap>>, + solutions_map: MemoryMap>, /// The puzzle commitments map. puzzle_commitments_map: MemoryMap, u32>, + /// The aborted solution IDs map. + aborted_solution_ids_map: MemoryMap>>, + /// The aborted solution heights map. + aborted_solution_heights_map: MemoryMap, u32>, /// The transactions map. transactions_map: MemoryMap>, /// The aborted transaction IDs map. @@ -71,8 +77,10 @@ impl BlockStorage for BlockMemory { type AuthorityMap = MemoryMap>; type CertificateMap = MemoryMap, (u32, u64)>; type RatificationsMap = MemoryMap>; - type SolutionsMap = MemoryMap>>; + type SolutionsMap = MemoryMap>; type PuzzleCommitmentsMap = MemoryMap, u32>; + type AbortedSolutionIDsMap = MemoryMap>>; + type AbortedSolutionHeightsMap = MemoryMap, u32>; type TransactionsMap = MemoryMap>; type AbortedTransactionIDsMap = MemoryMap>; type RejectedOrAbortedTransactionIDMap = MemoryMap; @@ -82,9 +90,9 @@ impl BlockStorage for BlockMemory { type TransitionStorage = TransitionMemory; /// Initializes the block storage. - fn open(dev: Option) -> Result { + fn open>(storage: S) -> Result { // Initialize the transition store. - let transition_store = TransitionStore::>::open(dev)?; + let transition_store = TransitionStore::>::open(storage)?; // Initialize the transaction store. let transaction_store = TransactionStore::>::open(transition_store)?; // Return the block storage. @@ -99,6 +107,8 @@ impl BlockStorage for BlockMemory { ratifications_map: MemoryMap::default(), solutions_map: MemoryMap::default(), puzzle_commitments_map: MemoryMap::default(), + aborted_solution_ids_map: MemoryMap::default(), + aborted_solution_heights_map: MemoryMap::default(), transactions_map: MemoryMap::default(), aborted_transaction_ids_map: MemoryMap::default(), rejected_or_aborted_transaction_id_map: MemoryMap::default(), @@ -158,6 +168,16 @@ impl BlockStorage for BlockMemory { &self.puzzle_commitments_map } + /// Returns the aborted solution IDs map. + fn aborted_solution_ids_map(&self) -> &Self::AbortedSolutionIDsMap { + &self.aborted_solution_ids_map + } + + /// Returns the aborted solution heights map. + fn aborted_solution_heights_map(&self) -> &Self::AbortedSolutionHeightsMap { + &self.aborted_solution_heights_map + } + /// Returns the transactions map. fn transactions_map(&self) -> &Self::TransactionsMap { &self.transactions_map diff --git a/ledger/store/src/helpers/memory/consensus.rs b/ledger/store/src/helpers/memory/consensus.rs index 2160160ef6..d5adf20141 100644 --- a/ledger/store/src/helpers/memory/consensus.rs +++ b/ledger/store/src/helpers/memory/consensus.rs @@ -20,6 +20,8 @@ use crate::{ }; use console::prelude::*; +use aleo_std_storage::StorageMode; + /// An in-memory consensus storage. #[derive(Clone)] pub struct ConsensusMemory { @@ -37,11 +39,11 @@ impl ConsensusStorage for ConsensusMemory { type TransitionStorage = TransitionMemory; /// Initializes the consensus storage. - fn open(dev: Option) -> Result { + fn open>(storage: S) -> Result { // Initialize the finalize store. - let finalize_store = FinalizeStore::>::open(dev)?; + let finalize_store = FinalizeStore::>::open(storage.clone())?; // Initialize the block store. - let block_store = BlockStore::>::open(dev)?; + let block_store = BlockStore::>::open(storage)?; // Return the consensus storage. Ok(Self { finalize_store, diff --git a/ledger/store/src/helpers/memory/internal/map.rs b/ledger/store/src/helpers/memory/internal/map.rs index 6c0e838db0..892555f27d 100644 --- a/ledger/store/src/helpers/memory/internal/map.rs +++ b/ledger/store/src/helpers/memory/internal/map.rs @@ -194,7 +194,7 @@ impl< let operations = core::mem::take(&mut *self.atomic_batch.lock()); // Insert the operations into an index map to remove any operations that would have been overwritten anyways. - let operations: IndexMap<_, _> = IndexMap::from_iter(operations.into_iter()); + let operations: IndexMap<_, _> = IndexMap::from_iter(operations); if !operations.is_empty() { // Acquire a write lock on the map. @@ -321,7 +321,7 @@ impl< /// Returns an iterator visiting each key-value pair in the atomic batch. /// fn iter_pending(&'a self) -> Self::PendingIterator { - let filtered_atomic_batch: IndexMap<_, _> = IndexMap::from_iter(self.atomic_batch.lock().clone().into_iter()); + let filtered_atomic_batch: IndexMap<_, _> = IndexMap::from_iter(self.atomic_batch.lock().clone()); filtered_atomic_batch.into_iter().map(|(k, v)| (Cow::Owned(k), v.map(|v| Cow::Owned(v)))) } @@ -365,9 +365,9 @@ impl< mod tests { use super::*; use crate::{atomic_batch_scope, atomic_finalize, FinalizeMode}; - use console::{account::Address, network::Testnet3}; + use console::{account::Address, network::MainnetV0}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_contains_key_sanity_check() { diff --git a/ledger/store/src/helpers/memory/internal/nested_map.rs b/ledger/store/src/helpers/memory/internal/nested_map.rs index 2ad1ccdaf2..11d265ce21 100644 --- a/ledger/store/src/helpers/memory/internal/nested_map.rs +++ b/ledger/store/src/helpers/memory/internal/nested_map.rs @@ -591,9 +591,9 @@ fn to_map_key(m: &[u8], k: &[u8]) -> Vec { mod tests { use super::*; use crate::{atomic_batch_scope, atomic_finalize, FinalizeMode}; - use console::{account::Address, network::Testnet3}; + use console::{account::Address, network::MainnetV0}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_contains_key_sanity_check() { diff --git a/ledger/store/src/helpers/memory/program.rs b/ledger/store/src/helpers/memory/program.rs index 85a5ac5d3e..04675cff7d 100644 --- a/ledger/store/src/helpers/memory/program.rs +++ b/ledger/store/src/helpers/memory/program.rs @@ -26,6 +26,7 @@ use console::{ }; use ledger_committee::Committee; +use aleo_std_storage::StorageMode; use indexmap::IndexSet; /// An in-memory finalize storage. @@ -37,8 +38,8 @@ pub struct FinalizeMemory { program_id_map: MemoryMap, IndexSet>>, /// The key-value map. key_value_map: NestedMemoryMap<(ProgramID, Identifier), Plaintext, Value>, - /// The optional development ID. - dev: Option, + /// The storage mode. + storage_mode: StorageMode, } #[rustfmt::skip] @@ -48,15 +49,15 @@ impl FinalizeStorage for FinalizeMemory { type KeyValueMap = NestedMemoryMap<(ProgramID, Identifier), Plaintext, Value>; /// Initializes the finalize storage. - fn open(dev: Option) -> Result { + fn open>(storage: S) -> Result { // Initialize the committee store. - let committee_store = CommitteeStore::>::open(dev)?; + let committee_store = CommitteeStore::>::open(storage.clone())?; // Return the finalize store. Ok(Self { committee_store, program_id_map: MemoryMap::default(), key_value_map: NestedMemoryMap::default(), - dev, + storage_mode: storage.into(), }) } @@ -81,9 +82,9 @@ impl FinalizeStorage for FinalizeMemory { &self.key_value_map } - /// Returns the optional development ID. - fn dev(&self) -> Option { - self.dev + /// Returns the storage mode. + fn storage_mode(&self) -> &StorageMode { + &self.storage_mode } } @@ -96,8 +97,8 @@ pub struct CommitteeMemory { round_to_height_map: MemoryMap, /// The committee map. committee_map: MemoryMap>, - /// The optional development ID. - dev: Option, + /// The storage mode. + storage_mode: StorageMode, } #[rustfmt::skip] @@ -107,12 +108,12 @@ impl CommitteeStorage for CommitteeMemory { type CommitteeMap = MemoryMap>; /// Initializes the committee storage. - fn open(dev: Option) -> Result { + fn open>(storage: S) -> Result { Ok(Self { current_round_map: MemoryMap::default(), round_to_height_map: MemoryMap::default(), committee_map: MemoryMap::default(), - dev, + storage_mode: storage.into(), }) } @@ -137,8 +138,8 @@ impl CommitteeStorage for CommitteeMemory { &self.committee_map } - /// Returns the optional development ID. - fn dev(&self) -> Option { - self.dev + /// Returns the storage mode. + fn storage_mode(&self) -> &StorageMode { + &self.storage_mode } } diff --git a/ledger/store/src/helpers/memory/transition.rs b/ledger/store/src/helpers/memory/transition.rs index 651181fd34..ee5e90b1c4 100644 --- a/ledger/store/src/helpers/memory/transition.rs +++ b/ledger/store/src/helpers/memory/transition.rs @@ -19,6 +19,8 @@ use console::{ types::{Field, Group}, }; +use aleo_std_storage::StorageMode; + /// An in-memory transition storage. #[derive(Clone)] pub struct TransitionMemory { @@ -36,6 +38,8 @@ pub struct TransitionMemory { tcm_map: MemoryMap>, /// The reverse `tcm` map. reverse_tcm_map: MemoryMap, N::TransitionID>, + /// The signer commitments. + scm_map: MemoryMap>, } #[rustfmt::skip] @@ -47,17 +51,19 @@ impl TransitionStorage for TransitionMemory { type ReverseTPKMap = MemoryMap, N::TransitionID>; type TCMMap = MemoryMap>; type ReverseTCMMap = MemoryMap, N::TransitionID>; + type SCMMap = MemoryMap>; /// Initializes the transition storage. - fn open(dev: Option) -> Result { + fn open>(storage: S) -> Result { Ok(Self { locator_map: MemoryMap::default(), - input_store: InputStore::open(dev)?, - output_store: OutputStore::open(dev)?, + input_store: InputStore::open(storage.clone())?, + output_store: OutputStore::open(storage)?, tpk_map: MemoryMap::default(), reverse_tpk_map: MemoryMap::default(), tcm_map: MemoryMap::default(), reverse_tcm_map: MemoryMap::default(), + scm_map: MemoryMap::default(), }) } @@ -95,6 +101,11 @@ impl TransitionStorage for TransitionMemory { fn reverse_tcm_map(&self) -> &Self::ReverseTCMMap { &self.reverse_tcm_map } + + /// Returns the signer commitments. + fn scm_map(&self) -> &Self::SCMMap { + &self.scm_map + } } /// An in-memory transition input storage. @@ -116,8 +127,8 @@ pub struct InputMemory { record_tag: MemoryMap, Field>, /// The mapping of `external hash` to `()`. Note: This is **not** the record commitment. external_record: MemoryMap, ()>, - /// The optional development ID. - dev: Option, + /// The storage mode. + storage_mode: StorageMode, } #[rustfmt::skip] @@ -132,7 +143,7 @@ impl InputStorage for InputMemory { type ExternalRecordMap = MemoryMap, ()>; /// Initializes the transition input storage. - fn open(dev: Option) -> Result { + fn open>(storage: S) -> Result { Ok(Self { id_map: MemoryMap::default(), reverse_id_map: MemoryMap::default(), @@ -142,7 +153,7 @@ impl InputStorage for InputMemory { record: MemoryMap::default(), record_tag: MemoryMap::default(), external_record: MemoryMap::default(), - dev, + storage_mode: storage.into(), }) } @@ -186,9 +197,9 @@ impl InputStorage for InputMemory { &self.external_record } - /// Returns the optional development ID. - fn dev(&self) -> Option { - self.dev + /// Returns the storage mode. + fn storage_mode(&self) -> &StorageMode { + &self.storage_mode } } @@ -214,8 +225,8 @@ pub struct OutputMemory { external_record: MemoryMap, ()>, /// The mapping of `future hash` to `(optional) future`. future: MemoryMap, Option>>, - /// The optional development ID. - dev: Option, + /// The storage mode. + storage_mode: StorageMode, } #[rustfmt::skip] @@ -231,7 +242,7 @@ impl OutputStorage for OutputMemory { type FutureMap = MemoryMap, Option>>; /// Initializes the transition output storage. - fn open(dev: Option) -> Result { + fn open>(storage: S) -> Result { Ok(Self { id_map: Default::default(), reverse_id_map: Default::default(), @@ -242,7 +253,7 @@ impl OutputStorage for OutputMemory { record_nonce: Default::default(), external_record: Default::default(), future: Default::default(), - dev, + storage_mode: storage.into(), }) } @@ -291,8 +302,8 @@ impl OutputStorage for OutputMemory { &self.future } - /// Returns the optional development ID. - fn dev(&self) -> Option { - self.dev + /// Returns the storage mode. + fn storage_mode(&self) -> &StorageMode { + &self.storage_mode } } diff --git a/ledger/store/src/helpers/mod.rs b/ledger/store/src/helpers/mod.rs index 994fe0638f..deb8926700 100644 --- a/ledger/store/src/helpers/mod.rs +++ b/ledger/store/src/helpers/mod.rs @@ -85,6 +85,7 @@ macro_rules! atomic_finalize { // // Wrap the operations that should be batched in a closure to be able to abort the entire // write batch if any of them fails. + #[allow(clippy::redundant_closure_call)] match ($finalize_mode, || -> Result<_, String> { $ops }()) { // If this is a successful real run, commit the atomic batch. (FinalizeMode::RealRun, Ok(result)) => { diff --git a/ledger/store/src/helpers/rocksdb/block.rs b/ledger/store/src/helpers/rocksdb/block.rs index 121ae2a994..5fae5e2cf4 100644 --- a/ledger/store/src/helpers/rocksdb/block.rs +++ b/ledger/store/src/helpers/rocksdb/block.rs @@ -27,8 +27,10 @@ use crate::{ }; use console::{prelude::*, types::Field}; use ledger_authority::Authority; -use ledger_block::{Header, Ratifications, Rejected}; -use ledger_coinbase::{CoinbaseSolution, PuzzleCommitment}; +use ledger_block::{Header, Ratifications, Rejected, Solutions}; +use ledger_coinbase::PuzzleCommitment; + +use aleo_std_storage::StorageMode; /// A RocksDB block storage. #[derive(Clone)] @@ -50,9 +52,13 @@ pub struct BlockDB { /// The ratifications map. ratifications_map: DataMap>, /// The solutions map. - solutions_map: DataMap>>, + solutions_map: DataMap>, /// The puzzle commitments map. puzzle_commitments_map: DataMap, u32>, + /// The aborted solution IDs map. + aborted_solution_ids_map: DataMap>>, + /// The aborted solution heights map. + aborted_solution_heights_map: DataMap, u32>, /// The transactions map. transactions_map: DataMap>, /// The aborted transaction IDs map. @@ -77,8 +83,10 @@ impl BlockStorage for BlockDB { type AuthorityMap = DataMap>; type CertificateMap = DataMap, (u32, u64)>; type RatificationsMap = DataMap>; - type SolutionsMap = DataMap>>; + type SolutionsMap = DataMap>; type PuzzleCommitmentsMap = DataMap, u32>; + type AbortedSolutionIDsMap = DataMap>>; + type AbortedSolutionHeightsMap = DataMap, u32>; type TransactionsMap = DataMap>; type AbortedTransactionIDsMap = DataMap>; type RejectedOrAbortedTransactionIDMap = DataMap; @@ -88,28 +96,30 @@ impl BlockStorage for BlockDB { type TransitionStorage = TransitionDB; /// Initializes the block storage. - fn open(dev: Option) -> Result { + fn open>(storage: S) -> Result { // Initialize the transition store. - let transition_store = TransitionStore::>::open(dev)?; + let transition_store = TransitionStore::>::open(storage.clone())?; // Initialize the transaction store. let transaction_store = TransactionStore::>::open(transition_store)?; // Return the block storage. Ok(Self { - state_root_map: internal::RocksDB::open_map(N::ID, dev, MapID::Block(BlockMap::StateRoot))?, - reverse_state_root_map: internal::RocksDB::open_map(N::ID, dev, MapID::Block(BlockMap::ReverseStateRoot))?, - id_map: internal::RocksDB::open_map(N::ID, dev, MapID::Block(BlockMap::ID))?, - reverse_id_map: internal::RocksDB::open_map(N::ID, dev, MapID::Block(BlockMap::ReverseID))?, - header_map: internal::RocksDB::open_map(N::ID, dev, MapID::Block(BlockMap::Header))?, - authority_map: internal::RocksDB::open_map(N::ID, dev, MapID::Block(BlockMap::Authority))?, - certificate_map: internal::RocksDB::open_map(N::ID, dev, MapID::Block(BlockMap::Certificate))?, - ratifications_map: internal::RocksDB::open_map(N::ID, dev, MapID::Block(BlockMap::Ratifications))?, - solutions_map: internal::RocksDB::open_map(N::ID, dev, MapID::Block(BlockMap::Solutions))?, - puzzle_commitments_map: internal::RocksDB::open_map(N::ID, dev, MapID::Block(BlockMap::PuzzleCommitments))?, - transactions_map: internal::RocksDB::open_map(N::ID, dev, MapID::Block(BlockMap::Transactions))?, - aborted_transaction_ids_map: internal::RocksDB::open_map(N::ID, dev, MapID::Block(BlockMap::AbortedTransactionIDs))?, - rejected_or_aborted_transaction_id_map: internal::RocksDB::open_map(N::ID, dev, MapID::Block(BlockMap::RejectedOrAbortedTransactionID))?, - confirmed_transactions_map: internal::RocksDB::open_map(N::ID, dev, MapID::Block(BlockMap::ConfirmedTransactions))?, - rejected_deployment_or_execution_map: internal::RocksDB::open_map(N::ID, dev, MapID::Block(BlockMap::RejectedDeploymentOrExecution))?, + state_root_map: internal::RocksDB::open_map(N::ID, storage.clone(), MapID::Block(BlockMap::StateRoot))?, + reverse_state_root_map: internal::RocksDB::open_map(N::ID, storage.clone(), MapID::Block(BlockMap::ReverseStateRoot))?, + id_map: internal::RocksDB::open_map(N::ID, storage.clone(), MapID::Block(BlockMap::ID))?, + reverse_id_map: internal::RocksDB::open_map(N::ID, storage.clone(), MapID::Block(BlockMap::ReverseID))?, + header_map: internal::RocksDB::open_map(N::ID, storage.clone(), MapID::Block(BlockMap::Header))?, + authority_map: internal::RocksDB::open_map(N::ID, storage.clone(), MapID::Block(BlockMap::Authority))?, + certificate_map: internal::RocksDB::open_map(N::ID, storage.clone(), MapID::Block(BlockMap::Certificate))?, + ratifications_map: internal::RocksDB::open_map(N::ID, storage.clone(), MapID::Block(BlockMap::Ratifications))?, + solutions_map: internal::RocksDB::open_map(N::ID, storage.clone(), MapID::Block(BlockMap::Solutions))?, + puzzle_commitments_map: internal::RocksDB::open_map(N::ID, storage.clone(), MapID::Block(BlockMap::PuzzleCommitments))?, + aborted_solution_ids_map: internal::RocksDB::open_map(N::ID, storage.clone(), MapID::Block(BlockMap::AbortedSolutionIDs))?, + aborted_solution_heights_map: internal::RocksDB::open_map(N::ID, storage.clone(), MapID::Block(BlockMap::AbortedSolutionHeights))?, + transactions_map: internal::RocksDB::open_map(N::ID, storage.clone(), MapID::Block(BlockMap::Transactions))?, + aborted_transaction_ids_map: internal::RocksDB::open_map(N::ID, storage.clone(), MapID::Block(BlockMap::AbortedTransactionIDs))?, + rejected_or_aborted_transaction_id_map: internal::RocksDB::open_map(N::ID, storage.clone(), MapID::Block(BlockMap::RejectedOrAbortedTransactionID))?, + confirmed_transactions_map: internal::RocksDB::open_map(N::ID, storage.clone(), MapID::Block(BlockMap::ConfirmedTransactions))?, + rejected_deployment_or_execution_map: internal::RocksDB::open_map(N::ID, storage, MapID::Block(BlockMap::RejectedDeploymentOrExecution))?, transaction_store, }) } @@ -164,6 +174,16 @@ impl BlockStorage for BlockDB { &self.puzzle_commitments_map } + /// Returns the aborted solution IDs map. + fn aborted_solution_ids_map(&self) -> &Self::AbortedSolutionIDsMap { + &self.aborted_solution_ids_map + } + + /// Returns the aborted solution heights map. + fn aborted_solution_heights_map(&self) -> &Self::AbortedSolutionHeightsMap { + &self.aborted_solution_heights_map + } + /// Returns the transactions map. fn transactions_map(&self) -> &Self::TransactionsMap { &self.transactions_map diff --git a/ledger/store/src/helpers/rocksdb/consensus.rs b/ledger/store/src/helpers/rocksdb/consensus.rs index 346b97058b..3735a31e67 100644 --- a/ledger/store/src/helpers/rocksdb/consensus.rs +++ b/ledger/store/src/helpers/rocksdb/consensus.rs @@ -20,6 +20,8 @@ use crate::{ }; use console::prelude::*; +use aleo_std_storage::StorageMode; + /// An RocksDB consensus storage. #[derive(Clone)] pub struct ConsensusDB { @@ -37,11 +39,11 @@ impl ConsensusStorage for ConsensusDB { type TransitionStorage = TransitionDB; /// Initializes the consensus storage. - fn open(dev: Option) -> Result { + fn open>(storage: S) -> Result { // Initialize the finalize store. - let finalize_store = FinalizeStore::>::open(dev)?; + let finalize_store = FinalizeStore::>::open(storage.clone())?; // Initialize the block store. - let block_store = BlockStore::>::open(dev)?; + let block_store = BlockStore::>::open(storage)?; // Return the consensus storage. Ok(Self { finalize_store, diff --git a/ledger/store/src/helpers/rocksdb/internal/id.rs b/ledger/store/src/helpers/rocksdb/internal/id.rs index 4a8dd7d3ad..3fad6aceec 100644 --- a/ledger/store/src/helpers/rocksdb/internal/id.rs +++ b/ledger/store/src/helpers/rocksdb/internal/id.rs @@ -77,6 +77,8 @@ pub enum BlockMap { Ratifications = DataID::BlockRatificationsMap as u16, Solutions = DataID::BlockSolutionsMap as u16, PuzzleCommitments = DataID::BlockPuzzleCommitmentsMap as u16, + AbortedSolutionIDs = DataID::BlockAbortedSolutionIDsMap as u16, + AbortedSolutionHeights = DataID::BlockAbortedSolutionHeightsMap as u16, Transactions = DataID::BlockTransactionsMap as u16, AbortedTransactionIDs = DataID::BlockAbortedTransactionIDsMap as u16, RejectedOrAbortedTransactionID = DataID::BlockRejectedOrAbortedTransactionIDMap as u16, @@ -184,6 +186,7 @@ pub enum TransitionMap { ReverseTPK = DataID::TransitionReverseTPKMap as u16, TCM = DataID::TransitionTCMMap as u16, ReverseTCM = DataID::TransitionReverseTCMMap as u16, + SCM = DataID::TransitionSCMMap as u16, } /// The RocksDB map prefix for program-related entries. @@ -228,6 +231,8 @@ enum DataID { BlockRatificationsMap, BlockSolutionsMap, BlockPuzzleCommitmentsMap, + BlockAbortedSolutionIDsMap, + BlockAbortedSolutionHeightsMap, BlockTransactionsMap, BlockAbortedTransactionIDsMap, BlockRejectedOrAbortedTransactionIDMap, @@ -278,6 +283,7 @@ enum DataID { TransitionReverseTPKMap, TransitionTCMMap, TransitionReverseTCMMap, + TransitionSCMMap, // Program ProgramIDMap, KeyValueMap, diff --git a/ledger/store/src/helpers/rocksdb/internal/map.rs b/ledger/store/src/helpers/rocksdb/internal/map.rs index 2dc677ad07..558559f97d 100644 --- a/ledger/store/src/helpers/rocksdb/internal/map.rs +++ b/ledger/store/src/helpers/rocksdb/internal/map.rs @@ -177,7 +177,7 @@ impl< if !operations.is_empty() { // Insert the operations into an index map to remove any operations that would have been overwritten anyways. - let operations: IndexMap<_, _> = IndexMap::from_iter(operations.into_iter()); + let operations: IndexMap<_, _> = IndexMap::from_iter(operations); // Prepare the key and value for each queued operation. // @@ -346,7 +346,7 @@ impl< /// Returns an iterator visiting each key-value pair in the atomic batch. /// fn iter_pending(&'a self) -> Self::PendingIterator { - let filtered_atomic_batch: IndexMap<_, _> = IndexMap::from_iter(self.atomic_batch.lock().clone().into_iter()); + let filtered_atomic_batch: IndexMap<_, _> = IndexMap::from_iter(self.atomic_batch.lock().clone()); filtered_atomic_batch.into_iter().map(|(k, v)| (Cow::Owned(k), v.map(|v| Cow::Owned(v)))) } @@ -538,14 +538,14 @@ mod tests { }; use console::{ account::{Address, FromStr}, - network::Testnet3, + network::MainnetV0, }; use anyhow::anyhow; use serial_test::serial; use tracing_test::traced_test; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; // Below are a few objects that mimic the way our DataMaps are organized, // in order to provide a more accurate test setup for some scenarios. diff --git a/ledger/store/src/helpers/rocksdb/internal/mod.rs b/ledger/store/src/helpers/rocksdb/internal/mod.rs index 80dcfdec06..a6411f6bd3 100644 --- a/ledger/store/src/helpers/rocksdb/internal/mod.rs +++ b/ledger/store/src/helpers/rocksdb/internal/mod.rs @@ -24,6 +24,7 @@ pub use nested_map::*; #[cfg(test)] mod tests; +use aleo_std_storage::StorageMode; use anyhow::{bail, Result}; use once_cell::sync::OnceCell; use parking_lot::Mutex; @@ -42,26 +43,32 @@ pub const PREFIX_LEN: usize = 4; // N::ID (u16) + DataID (u16) pub trait Database { /// Opens the database. - fn open(network_id: u16, dev: Option) -> Result + fn open>(network_id: u16, storage: S) -> Result where Self: Sized; - /// Opens the map with the given `network_id`, `(optional) development ID`, and `map_id` from storage. - fn open_map>( + /// Opens the map with the given `network_id`, `storage mode`, and `map_id` from storage. + fn open_map< + S: Clone + Into, + K: Serialize + DeserializeOwned, + V: Serialize + DeserializeOwned, + T: Into, + >( network_id: u16, - dev: Option, + storage: S, map_id: T, ) -> Result>; - /// Opens the nested map with the given `network_id`, `(optional) development ID`, and `map_id` from storage. + /// Opens the nested map with the given `network_id`, `storage mode`, and `map_id` from storage. fn open_nested_map< + S: Clone + Into, M: Serialize + DeserializeOwned, K: Serialize + DeserializeOwned, V: Serialize + DeserializeOwned, T: Into, >( network_id: u16, - dev: Option, + storage: S, map_id: T, ) -> Result>; } @@ -73,8 +80,8 @@ pub struct RocksDB { rocksdb: Arc, /// The network ID. network_id: u16, - /// The optional development ID. - dev: Option, + /// The storage mode. + storage_mode: StorageMode, /// The low-level database transaction that gets executed atomically at the end /// of a real-run `atomic_finalize` or the outermost `atomic_batch_scope`. pub(super) atomic_batch: Arc>, @@ -96,7 +103,7 @@ impl Database for RocksDB { /// /// In production mode, the database opens directory `~/.aleo/storage/ledger-{network}`. /// In development mode, the database opens directory `/path/to/repo/.ledger-{network}-{id}`. - fn open(network_id: u16, dev: Option) -> Result { + fn open>(network_id: u16, storage: S) -> Result { static DB: OnceCell = OnceCell::new(); // Retrieve the database. @@ -110,7 +117,7 @@ impl Database for RocksDB { let prefix_extractor = rocksdb::SliceTransform::create_fixed_prefix(PREFIX_LEN); options.set_prefix_extractor(prefix_extractor); - let primary = aleo_std::aleo_ledger_dir(network_id, dev); + let primary = aleo_std_storage::aleo_ledger_dir(network_id, storage.clone().into()); let rocksdb = { options.increase_parallelism(2); options.set_max_background_jobs(4); @@ -122,28 +129,33 @@ impl Database for RocksDB { Ok::<_, anyhow::Error>(RocksDB { rocksdb, network_id, - dev, + storage_mode: storage.clone().into(), atomic_batch: Default::default(), atomic_depth: Default::default(), }) })? .clone(); - // Ensure the database network ID and development ID match. - match database.network_id == network_id && database.dev == dev { + // Ensure the database network ID and storage mode match. + match database.network_id == network_id && database.storage_mode == storage.into() { true => Ok(database), - false => bail!("Mismatching network ID or development ID in the database"), + false => bail!("Mismatching network ID or storage mode in the database"), } } - /// Opens the map with the given `network_id`, `(optional) development ID`, and `map_id` from storage. - fn open_map>( + /// Opens the map with the given `network_id`, `storage mode`, and `map_id` from storage. + fn open_map< + S: Clone + Into, + K: Serialize + DeserializeOwned, + V: Serialize + DeserializeOwned, + T: Into, + >( network_id: u16, - dev: Option, + storage: S, map_id: T, ) -> Result> { // Open the RocksDB database. - let database = Self::open(network_id, dev)?; + let database = Self::open(network_id, storage)?; // Combine contexts to create a new scope. let mut context = database.network_id.to_le_bytes().to_vec(); @@ -159,19 +171,20 @@ impl Database for RocksDB { }))) } - /// Opens the nested map with the given `network_id`, `(optional) development ID`, and `map_id` from storage. + /// Opens the nested map with the given `network_id`, `storage mode`, and `map_id` from storage. fn open_nested_map< + S: Clone + Into, M: Serialize + DeserializeOwned, K: Serialize + DeserializeOwned, V: Serialize + DeserializeOwned, T: Into, >( network_id: u16, - dev: Option, + storage: S, map_id: T, ) -> Result> { // Open the RocksDB database. - let database = Self::open(network_id, dev)?; + let database = Self::open(network_id, storage)?; // Combine contexts to create a new scope. let mut context = database.network_id.to_le_bytes().to_vec(); @@ -194,6 +207,18 @@ impl RocksDB { pub fn open_testing(temp_dir: std::path::PathBuf, dev: Option) -> Result { use console::prelude::{Rng, TestRng}; + // Ensure the `temp_dir` is unique. + let temp_dir = temp_dir.join(Rng::gen::(&mut TestRng::default()).to_string()); + + // Construct the directory for the test database. + let primary = match dev { + Some(dev) => temp_dir.join(dev.to_string()), + None => temp_dir, + }; + + // Prepare the storage mode. + let storage_mode = StorageMode::from(primary.clone()); + let database = { // Customize database options. let mut options = rocksdb::Options::default(); @@ -203,15 +228,6 @@ impl RocksDB { let prefix_extractor = rocksdb::SliceTransform::create_fixed_prefix(PREFIX_LEN); options.set_prefix_extractor(prefix_extractor); - // Ensure the `temp_dir` is unique. - let temp_dir = temp_dir.join(Rng::gen::(&mut TestRng::default()).to_string()); - - // Construct the directory for the test database. - let primary = match dev { - Some(dev) => temp_dir.join(dev.to_string()), - None => temp_dir, - }; - let rocksdb = { options.increase_parallelism(2); options.set_max_background_jobs(4); @@ -235,16 +251,16 @@ impl RocksDB { Ok::<_, anyhow::Error>(RocksDB { rocksdb, network_id: u16::MAX, - dev, + storage_mode: storage_mode.clone(), atomic_batch: Default::default(), atomic_depth: Default::default(), }) }?; - // Ensure the database development ID match. - match database.dev == dev { + // Ensure the database storage mode match. + match database.storage_mode == storage_mode { true => Ok(database), - false => bail!("Mismatching development ID in the test database"), + false => bail!("Mismatching storage mode in the test database"), } } diff --git a/ledger/store/src/helpers/rocksdb/internal/nested_map.rs b/ledger/store/src/helpers/rocksdb/internal/nested_map.rs index 0634e95a7b..057a6acab7 100644 --- a/ledger/store/src/helpers/rocksdb/internal/nested_map.rs +++ b/ledger/store/src/helpers/rocksdb/internal/nested_map.rs @@ -16,12 +16,15 @@ use super::*; use crate::helpers::{NestedMap, NestedMapRead}; -use console::prelude::{anyhow, FromBytes}; +use console::prelude::{anyhow, cfg_into_iter, FromBytes}; use core::{fmt, fmt::Debug, hash::Hash, mem}; use std::{borrow::Cow, sync::atomic::Ordering}; use tracing::error; +#[cfg(not(feature = "serial"))] +use rayon::iter::{IntoParallelIterator, ParallelIterator}; + #[derive(Clone)] pub struct NestedDataMap< M: Serialize + DeserializeOwned, @@ -441,12 +444,8 @@ impl< // If the 'entry_map' matches 'serialized_map', deserialize the key and value. if entry_map == serialized_map { - // Deserialize the key. - let key = bincode::deserialize(entry_key)?; - // Deserialize the value. - let value = bincode::deserialize(&value)?; // Push the key-value pair to the vector. - entries.push((key, value)); + entries.push((entry_key.to_owned(), value)); } else { // If the 'entry_map' no longer matches the 'serialized_map', // we've moved past the relevant keys and can break the loop. @@ -454,7 +453,15 @@ impl< } } - Ok(entries) + // Possibly deserialize the entries in parallel. + Ok(cfg_into_iter!(entries) + .map(|(k, v)| { + let k = bincode::deserialize::(&k); + let v = bincode::deserialize::(&v); + + k.and_then(|k| v.map(|v| (k, v))) + }) + .collect::>()?) } /// @@ -468,14 +475,14 @@ impl< let operations = self.atomic_batch.lock().clone(); if !operations.is_empty() { - // Perform all the queued operations. + // Traverse the queued operations. for (m, k, v) in operations { // If the map does not match the given map, then continue. if &m != map { continue; } - // Perform the operation. + // Update the confirmed pairs based on the pending operations. match (k, v) { // Insert or update the key-value pair for the key. (Some(k), Some(v)) => { @@ -756,14 +763,14 @@ mod tests { }; use console::{ account::{Address, FromStr}, - network::Testnet3, + network::MainnetV0, }; use anyhow::anyhow; use serial_test::serial; use tracing_test::traced_test; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; // Below are a few objects that mimic the way our NestedDataMaps are organized, // in order to provide a more accurate test setup for some scenarios. diff --git a/ledger/store/src/helpers/rocksdb/internal/tests.rs b/ledger/store/src/helpers/rocksdb/internal/tests.rs index d45466a256..2b59a232fc 100644 --- a/ledger/store/src/helpers/rocksdb/internal/tests.rs +++ b/ledger/store/src/helpers/rocksdb/internal/tests.rs @@ -18,7 +18,7 @@ use crate::helpers::{ MapRead, }; use console::{ - network::{Network, Testnet3}, + network::{MainnetV0, Network}, prelude::{TestRng, Uniform}, types::Scalar, }; @@ -154,7 +154,7 @@ fn test_insert_and_values() { #[test] #[serial] fn test_scalar_mul() { - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; let rng = &mut TestRng::default(); diff --git a/ledger/store/src/helpers/rocksdb/program.rs b/ledger/store/src/helpers/rocksdb/program.rs index f020d2b35b..88b6481c18 100644 --- a/ledger/store/src/helpers/rocksdb/program.rs +++ b/ledger/store/src/helpers/rocksdb/program.rs @@ -26,6 +26,7 @@ use console::{ }; use ledger_committee::Committee; +use aleo_std_storage::StorageMode; use indexmap::IndexSet; /// A RocksDB finalize storage. @@ -37,8 +38,8 @@ pub struct FinalizeDB { program_id_map: DataMap, IndexSet>>, /// The key-value map. key_value_map: NestedDataMap<(ProgramID, Identifier), Plaintext, Value>, - /// The optional development ID. - dev: Option, + /// The storage mode. + storage_mode: StorageMode, } #[rustfmt::skip] @@ -48,15 +49,15 @@ impl FinalizeStorage for FinalizeDB { type KeyValueMap = NestedDataMap<(ProgramID, Identifier), Plaintext, Value>; /// Initializes the finalize storage. - fn open(dev: Option) -> Result { + fn open>(storage: S) -> Result { // Initialize the committee store. - let committee_store = CommitteeStore::>::open(dev)?; + let committee_store = CommitteeStore::>::open(storage.clone())?; // Return the finalize storage. Ok(Self { committee_store, - program_id_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::Program(ProgramMap::ProgramID))?, - key_value_map: rocksdb::RocksDB::open_nested_map(N::ID, dev, MapID::Program(ProgramMap::KeyValueID))?, - dev, + program_id_map: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::Program(ProgramMap::ProgramID))?, + key_value_map: rocksdb::RocksDB::open_nested_map(N::ID, storage.clone(), MapID::Program(ProgramMap::KeyValueID))?, + storage_mode: storage.into(), }) } @@ -69,8 +70,8 @@ impl FinalizeStorage for FinalizeDB { Ok(Self { committee_store, program_id_map: rocksdb::RocksDB::open_map_testing(temp_dir.clone(), dev, MapID::Program(ProgramMap::ProgramID))?, - key_value_map: rocksdb::RocksDB::open_nested_map_testing(temp_dir.clone(), dev, MapID::Program(ProgramMap::KeyValueID))?, - dev, + key_value_map: rocksdb::RocksDB::open_nested_map_testing(temp_dir, dev, MapID::Program(ProgramMap::KeyValueID))?, + storage_mode: dev.into(), }) } @@ -89,9 +90,9 @@ impl FinalizeStorage for FinalizeDB { &self.key_value_map } - /// Returns the optional development ID. - fn dev(&self) -> Option { - self.dev + /// Returns the storage mode. + fn storage_mode(&self) -> &StorageMode { + &self.storage_mode } } @@ -104,8 +105,8 @@ pub struct CommitteeDB { round_to_height_map: DataMap, /// The committee map. committee_map: DataMap>, - /// The optional development ID. - dev: Option, + /// The storage mode. + storage_mode: StorageMode, } #[rustfmt::skip] @@ -115,12 +116,12 @@ impl CommitteeStorage for CommitteeDB { type CommitteeMap = DataMap>; /// Initializes the committee storage. - fn open(dev: Option) -> Result { + fn open>(storage: S) -> Result { Ok(Self { - current_round_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::Committee(CommitteeMap::CurrentRound))?, - round_to_height_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::Committee(CommitteeMap::RoundToHeight))?, - committee_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::Committee(CommitteeMap::Committee))?, - dev, + current_round_map: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::Committee(CommitteeMap::CurrentRound))?, + round_to_height_map: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::Committee(CommitteeMap::RoundToHeight))?, + committee_map: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::Committee(CommitteeMap::Committee))?, + storage_mode: storage.into(), }) } @@ -131,7 +132,7 @@ impl CommitteeStorage for CommitteeDB { current_round_map: rocksdb::RocksDB::open_map_testing(temp_dir.clone(), dev, MapID::Committee(CommitteeMap::CurrentRound))?, round_to_height_map: rocksdb::RocksDB::open_map_testing(temp_dir.clone(), dev, MapID::Committee(CommitteeMap::RoundToHeight))?, committee_map: rocksdb::RocksDB::open_map_testing(temp_dir, dev, MapID::Committee(CommitteeMap::Committee))?, - dev, + storage_mode: dev.into(), }) } @@ -150,8 +151,8 @@ impl CommitteeStorage for CommitteeDB { &self.committee_map } - /// Returns the optional development ID. - fn dev(&self) -> Option { - self.dev + /// Returns the storage mode. + fn storage_mode(&self) -> &StorageMode { + &self.storage_mode } } diff --git a/ledger/store/src/helpers/rocksdb/transaction.rs b/ledger/store/src/helpers/rocksdb/transaction.rs index bef3c1fe73..2cac1c9c2c 100644 --- a/ledger/store/src/helpers/rocksdb/transaction.rs +++ b/ledger/store/src/helpers/rocksdb/transaction.rs @@ -71,7 +71,7 @@ impl TransactionStorage for TransactionDB { // Initialize the execution store. let execution_store = ExecutionStore::>::open(fee_store.clone())?; // Return the transaction storage. - Ok(Self { id_map: rocksdb::RocksDB::open_map(N::ID, execution_store.dev(), MapID::Transaction(TransactionMap::ID))?, deployment_store, execution_store, fee_store }) + Ok(Self { id_map: rocksdb::RocksDB::open_map(N::ID, execution_store.storage_mode().clone(), MapID::Transaction(TransactionMap::ID))?, deployment_store, execution_store, fee_store }) } /// Returns the ID map. @@ -130,16 +130,16 @@ impl DeploymentStorage for DeploymentDB { /// Initializes the deployment storage. fn open(fee_store: FeeStore) -> Result { - // Retrieve the optional development ID. - let dev = fee_store.dev(); + // Retrieve the storage mode. + let storage_mode = fee_store.storage_mode(); Ok(Self { - id_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::Deployment(DeploymentMap::ID))?, - edition_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::Deployment(DeploymentMap::Edition))?, - reverse_id_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::Deployment(DeploymentMap::ReverseID))?, - owner_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::Deployment(DeploymentMap::Owner))?, - program_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::Deployment(DeploymentMap::Program))?, - verifying_key_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::Deployment(DeploymentMap::VerifyingKey))?, - certificate_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::Deployment(DeploymentMap::Certificate))?, + id_map: rocksdb::RocksDB::open_map(N::ID, storage_mode.clone(), MapID::Deployment(DeploymentMap::ID))?, + edition_map: rocksdb::RocksDB::open_map(N::ID, storage_mode.clone(), MapID::Deployment(DeploymentMap::Edition))?, + reverse_id_map: rocksdb::RocksDB::open_map(N::ID, storage_mode.clone(), MapID::Deployment(DeploymentMap::ReverseID))?, + owner_map: rocksdb::RocksDB::open_map(N::ID, storage_mode.clone(), MapID::Deployment(DeploymentMap::Owner))?, + program_map: rocksdb::RocksDB::open_map(N::ID, storage_mode.clone(), MapID::Deployment(DeploymentMap::Program))?, + verifying_key_map: rocksdb::RocksDB::open_map(N::ID, storage_mode.clone(), MapID::Deployment(DeploymentMap::VerifyingKey))?, + certificate_map: rocksdb::RocksDB::open_map(N::ID, storage_mode.clone(), MapID::Deployment(DeploymentMap::Certificate))?, fee_store, }) } @@ -208,12 +208,12 @@ impl ExecutionStorage for ExecutionDB { /// Initializes the execution storage. fn open(fee_store: FeeStore) -> Result { - // Retrieve the optional development ID. - let dev = fee_store.dev(); + // Retrieve the storage mode. + let storage_mode = fee_store.storage_mode(); Ok(Self { - id_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::Execution(ExecutionMap::ID))?, - reverse_id_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::Execution(ExecutionMap::ReverseID))?, - inclusion_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::Execution(ExecutionMap::Inclusion))?, + id_map: rocksdb::RocksDB::open_map(N::ID, storage_mode.clone(), MapID::Execution(ExecutionMap::ID))?, + reverse_id_map: rocksdb::RocksDB::open_map(N::ID, storage_mode.clone(), MapID::Execution(ExecutionMap::ReverseID))?, + inclusion_map: rocksdb::RocksDB::open_map(N::ID, storage_mode.clone(), MapID::Execution(ExecutionMap::Inclusion))?, fee_store, }) } @@ -259,11 +259,11 @@ impl FeeStorage for FeeDB { /// Initializes the fee storage. fn open(transition_store: TransitionStore) -> Result { - // Retrieve the optional development ID. - let dev = transition_store.dev(); + // Retrieve the storage mode. + let storage_mode = transition_store.storage_mode(); Ok(Self { - fee_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::Fee(FeeMap::Fee))?, - reverse_fee_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::Fee(FeeMap::ReverseFee))?, + fee_map: rocksdb::RocksDB::open_map(N::ID, storage_mode.clone(), MapID::Fee(FeeMap::Fee))?, + reverse_fee_map: rocksdb::RocksDB::open_map(N::ID, storage_mode.clone(), MapID::Fee(FeeMap::ReverseFee))?, transition_store, }) } diff --git a/ledger/store/src/helpers/rocksdb/transition.rs b/ledger/store/src/helpers/rocksdb/transition.rs index b6af3398d5..44ee06c33e 100644 --- a/ledger/store/src/helpers/rocksdb/transition.rs +++ b/ledger/store/src/helpers/rocksdb/transition.rs @@ -26,6 +26,8 @@ use console::{ types::{Field, Group}, }; +use aleo_std_storage::StorageMode; + /// A database transition storage. #[derive(Clone)] pub struct TransitionDB { @@ -43,6 +45,8 @@ pub struct TransitionDB { tcm_map: DataMap>, /// The reverse `tcm` map. reverse_tcm_map: DataMap, N::TransitionID>, + /// The signer commitments. + scm_map: DataMap>, } #[rustfmt::skip] @@ -54,17 +58,19 @@ impl TransitionStorage for TransitionDB { type ReverseTPKMap = DataMap, N::TransitionID>; type TCMMap = DataMap>; type ReverseTCMMap = DataMap, N::TransitionID>; + type SCMMap = DataMap>; /// Initializes the transition storage. - fn open(dev: Option) -> Result { + fn open>(storage: S) -> Result { Ok(Self { - locator_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::Transition(TransitionMap::Locator))?, - input_store: InputStore::open(dev)?, - output_store: OutputStore::open(dev)?, - tpk_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::Transition(TransitionMap::TPK))?, - reverse_tpk_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::Transition(TransitionMap::ReverseTPK))?, - tcm_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::Transition(TransitionMap::TCM))?, - reverse_tcm_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::Transition(TransitionMap::ReverseTCM))?, + locator_map: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::Transition(TransitionMap::Locator))?, + input_store: InputStore::open(storage.clone())?, + output_store: OutputStore::open(storage.clone())?, + tpk_map: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::Transition(TransitionMap::TPK))?, + reverse_tpk_map: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::Transition(TransitionMap::ReverseTPK))?, + tcm_map: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::Transition(TransitionMap::TCM))?, + reverse_tcm_map: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::Transition(TransitionMap::ReverseTCM))?, + scm_map: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::Transition(TransitionMap::SCM))?, }) } @@ -102,6 +108,11 @@ impl TransitionStorage for TransitionDB { fn reverse_tcm_map(&self) -> &Self::ReverseTCMMap { &self.reverse_tcm_map } + + /// Returns the signer commitments. + fn scm_map(&self) -> &Self::SCMMap { + &self.scm_map + } } /// An database transition input storage. @@ -123,8 +134,8 @@ pub struct InputDB { record_tag: DataMap, Field>, /// The mapping of `external commitment` to `()`. Note: This is **not** the record commitment. external_record: DataMap, ()>, - /// The optional development ID. - dev: Option, + /// The storage mode. + storage_mode: StorageMode, } #[rustfmt::skip] @@ -139,17 +150,17 @@ impl InputStorage for InputDB { type ExternalRecordMap = DataMap, ()>; /// Initializes the transition input storage. - fn open(dev: Option) -> Result { + fn open>(storage: S) -> Result { Ok(Self { - id_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::TransitionInput(TransitionInputMap::ID))?, - reverse_id_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::TransitionInput(TransitionInputMap::ReverseID))?, - constant: rocksdb::RocksDB::open_map(N::ID, dev, MapID::TransitionInput(TransitionInputMap::Constant))?, - public: rocksdb::RocksDB::open_map(N::ID, dev, MapID::TransitionInput(TransitionInputMap::Public))?, - private: rocksdb::RocksDB::open_map(N::ID, dev, MapID::TransitionInput(TransitionInputMap::Private))?, - record: rocksdb::RocksDB::open_map(N::ID, dev, MapID::TransitionInput(TransitionInputMap::Record))?, - record_tag: rocksdb::RocksDB::open_map(N::ID, dev, MapID::TransitionInput(TransitionInputMap::RecordTag))?, - external_record: rocksdb::RocksDB::open_map(N::ID, dev, MapID::TransitionInput(TransitionInputMap::ExternalRecord))?, - dev, + id_map: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::TransitionInput(TransitionInputMap::ID))?, + reverse_id_map: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::TransitionInput(TransitionInputMap::ReverseID))?, + constant: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::TransitionInput(TransitionInputMap::Constant))?, + public: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::TransitionInput(TransitionInputMap::Public))?, + private: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::TransitionInput(TransitionInputMap::Private))?, + record: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::TransitionInput(TransitionInputMap::Record))?, + record_tag: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::TransitionInput(TransitionInputMap::RecordTag))?, + external_record: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::TransitionInput(TransitionInputMap::ExternalRecord))?, + storage_mode: storage.into(), }) } @@ -193,9 +204,9 @@ impl InputStorage for InputDB { &self.external_record } - /// Returns the optional development ID. - fn dev(&self) -> Option { - self.dev + /// Returns the storage mode. + fn storage_mode(&self) -> &StorageMode { + &self.storage_mode } } @@ -221,8 +232,8 @@ pub struct OutputDB { external_record: DataMap, ()>, /// The mapping of `future hash` to `(optional) future`. future: DataMap, Option>>, - /// The optional development ID. - dev: Option, + /// The storage mode. + storage_mode: StorageMode, } #[rustfmt::skip] @@ -238,18 +249,18 @@ impl OutputStorage for OutputDB { type FutureMap = DataMap, Option>>; /// Initializes the transition output storage. - fn open(dev: Option) -> Result { + fn open>(storage: S) -> Result { Ok(Self { - id_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::TransitionOutput(TransitionOutputMap::ID))?, - reverse_id_map: rocksdb::RocksDB::open_map(N::ID, dev, MapID::TransitionOutput(TransitionOutputMap::ReverseID))?, - constant: rocksdb::RocksDB::open_map(N::ID, dev, MapID::TransitionOutput(TransitionOutputMap::Constant))?, - public: rocksdb::RocksDB::open_map(N::ID, dev, MapID::TransitionOutput(TransitionOutputMap::Public))?, - private: rocksdb::RocksDB::open_map(N::ID, dev, MapID::TransitionOutput(TransitionOutputMap::Private))?, - record: rocksdb::RocksDB::open_map(N::ID, dev, MapID::TransitionOutput(TransitionOutputMap::Record))?, - record_nonce: rocksdb::RocksDB::open_map(N::ID, dev, MapID::TransitionOutput(TransitionOutputMap::RecordNonce))?, - external_record: rocksdb::RocksDB::open_map(N::ID, dev, MapID::TransitionOutput(TransitionOutputMap::ExternalRecord))?, - future: rocksdb::RocksDB::open_map(N::ID, dev, MapID::TransitionOutput(TransitionOutputMap::Future))?, - dev, + id_map: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::TransitionOutput(TransitionOutputMap::ID))?, + reverse_id_map: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::TransitionOutput(TransitionOutputMap::ReverseID))?, + constant: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::TransitionOutput(TransitionOutputMap::Constant))?, + public: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::TransitionOutput(TransitionOutputMap::Public))?, + private: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::TransitionOutput(TransitionOutputMap::Private))?, + record: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::TransitionOutput(TransitionOutputMap::Record))?, + record_nonce: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::TransitionOutput(TransitionOutputMap::RecordNonce))?, + external_record: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::TransitionOutput(TransitionOutputMap::ExternalRecord))?, + future: rocksdb::RocksDB::open_map(N::ID, storage.clone(), MapID::TransitionOutput(TransitionOutputMap::Future))?, + storage_mode: storage.into(), }) } @@ -298,8 +309,8 @@ impl OutputStorage for OutputDB { &self.future } - /// Returns the optional development ID. - fn dev(&self) -> Option { - self.dev + /// Returns the storage mode. + fn storage_mode(&self) -> &StorageMode { + &self.storage_mode } } diff --git a/ledger/store/src/program/committee.rs b/ledger/store/src/program/committee.rs index 62cd6e0bbb..3e7d70dc78 100644 --- a/ledger/store/src/program/committee.rs +++ b/ledger/store/src/program/committee.rs @@ -21,6 +21,7 @@ use crate::{ use console::network::prelude::*; use ledger_committee::Committee; +use aleo_std_storage::StorageMode; use anyhow::Result; use core::marker::PhantomData; @@ -36,7 +37,7 @@ pub trait CommitteeStorage: 'static + Clone + Send + Sync { type CommitteeMap: for<'a> Map<'a, u32, Committee>; /// Initializes the committee storage. - fn open(dev: Option) -> Result; + fn open>(storage: S) -> Result; /// Initializes the test-variant of the storage. #[cfg(any(test, feature = "test"))] @@ -49,8 +50,8 @@ pub trait CommitteeStorage: 'static + Clone + Send + Sync { /// Returns the committee map. fn committee_map(&self) -> &Self::CommitteeMap; - /// Returns the optional development ID. - fn dev(&self) -> Option; + /// Returns the storage mode. + fn storage_mode(&self) -> &StorageMode; /// Starts an atomic batch write operation. fn start_atomic(&self) { @@ -299,9 +300,9 @@ pub struct CommitteeStore> { impl> CommitteeStore { /// Initializes the committee store. - pub fn open(dev: Option) -> Result { + pub fn open>(storage: S) -> Result { // Initialize the committee storage. - let storage = C::open(dev)?; + let storage = C::open(storage.clone())?; // Return the committee store. Ok(Self { storage, _phantom: PhantomData }) } @@ -355,9 +356,9 @@ impl> CommitteeStore { self.storage.finish_atomic() } - /// Returns the optional development ID. - pub fn dev(&self) -> Option { - self.storage.dev() + /// Returns the storage mode. + pub fn storage_mode(&self) -> &StorageMode { + self.storage.storage_mode() } } @@ -412,7 +413,7 @@ mod tests { use super::*; use crate::helpers::memory::CommitteeMemory; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; #[test] fn test_insert_get_remove() { diff --git a/ledger/store/src/program/finalize.rs b/ledger/store/src/program/finalize.rs index 7e4d45bb99..a9608ea420 100644 --- a/ledger/store/src/program/finalize.rs +++ b/ledger/store/src/program/finalize.rs @@ -26,6 +26,7 @@ use console::{ }; use synthesizer_program::{FinalizeOperation, FinalizeStoreTrait}; +use aleo_std_storage::StorageMode; use anyhow::Result; use core::marker::PhantomData; use indexmap::IndexSet; @@ -78,7 +79,7 @@ pub trait FinalizeStorage: 'static + Clone + Send + Sync { type KeyValueMap: for<'a> NestedMap<'a, (ProgramID, Identifier), Plaintext, Value>; /// Initializes the program state storage. - fn open(dev: Option) -> Result; + fn open>(storage: S) -> Result; /// Initializes the test-variant of the storage. #[cfg(any(test, feature = "test"))] @@ -91,8 +92,8 @@ pub trait FinalizeStorage: 'static + Clone + Send + Sync { /// Returns the key-value map. fn key_value_map(&self) -> &Self::KeyValueMap; - /// Returns the optional development ID. - fn dev(&self) -> Option; + /// Returns the storage mode. + fn storage_mode(&self) -> &StorageMode; /// Starts an atomic batch write operation. fn start_atomic(&self) { @@ -313,7 +314,7 @@ pub trait FinalizeStorage: 'static + Clone + Send + Sync { None => bail!("Illegal operation: program ID '{program_id}' is not initialized - cannot remove mapping."), }; // Remove the mapping name. - if !mapping_names.remove(&mapping_name) { + if !mapping_names.shift_remove(&mapping_name) { bail!("Illegal operation: mapping '{mapping_name}' does not exist in storage - cannot remove mapping."); } @@ -530,8 +531,8 @@ pub struct FinalizeStore> { impl> FinalizeStore { /// Initializes the finalize store. - pub fn open(dev: Option) -> Result { - Self::from(P::open(dev)?) + pub fn open>(storage: S) -> Result { + Self::from(P::open(storage)?) } /// Initializes the test-variant of the storage. @@ -581,9 +582,9 @@ impl> FinalizeStore { self.storage.finish_atomic() } - /// Returns the optional development ID. - pub fn dev(&self) -> Option { - self.storage.dev() + /// Returns the storage mode. + pub fn storage_mode(&self) -> &StorageMode { + self.storage.storage_mode() } } @@ -768,9 +769,9 @@ impl> FinalizeStore { mod tests { use super::*; use crate::helpers::memory::FinalizeMemory; - use console::{network::Testnet3, program::Literal, types::U64}; + use console::{network::MainnetV0, program::Literal, types::U64}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Checks `initialize_mapping`, `insert_key_value`, `remove_key_value`, and `remove_mapping`. fn check_initialize_insert_remove( @@ -1313,7 +1314,7 @@ mod tests { // Insert the key and value. let timer = std::time::Instant::now(); - finalize_store.insert_key_value(program_id, mapping_name, key.clone(), value.clone()).unwrap(); + finalize_store.insert_key_value(program_id, mapping_name, key.clone(), value).unwrap(); println!("FinalizeStore::insert_key_value - {} μs", timer.elapsed().as_micros()); // Insert the list of keys and values. diff --git a/ledger/store/src/transaction/deployment.rs b/ledger/store/src/transaction/deployment.rs index 476e85f293..bdc7d95b46 100644 --- a/ledger/store/src/transaction/deployment.rs +++ b/ledger/store/src/transaction/deployment.rs @@ -28,6 +28,7 @@ use ledger_block::{Deployment, Fee, Transaction}; use synthesizer_program::Program; use synthesizer_snark::{Certificate, VerifyingKey}; +use aleo_std_storage::StorageMode; use anyhow::Result; use core::marker::PhantomData; use std::borrow::Cow; @@ -71,9 +72,9 @@ pub trait DeploymentStorage: Clone + Send + Sync { /// Returns the fee storage. fn fee_store(&self) -> &FeeStore; - /// Returns the optional development ID. - fn dev(&self) -> Option { - self.fee_store().dev() + /// Returns the storage mode. + fn storage_mode(&self) -> &StorageMode { + self.fee_store().storage_mode() } /// Starts an atomic batch write operation. @@ -547,9 +548,9 @@ impl> DeploymentStore { self.storage.finish_atomic() } - /// Returns the optional development ID. - pub fn dev(&self) -> Option { - self.storage.dev() + /// Returns the storage mode. + pub fn storage_mode(&self) -> &StorageMode { + self.storage.storage_mode() } } diff --git a/ledger/store/src/transaction/execution.rs b/ledger/store/src/transaction/execution.rs index cb3811813a..1ebfaa9d95 100644 --- a/ledger/store/src/transaction/execution.rs +++ b/ledger/store/src/transaction/execution.rs @@ -25,6 +25,7 @@ use console::network::prelude::*; use ledger_block::{Execution, Transaction, Transition}; use synthesizer_snark::Proof; +use aleo_std_storage::StorageMode; use anyhow::Result; use core::marker::PhantomData; use std::borrow::Cow; @@ -56,9 +57,9 @@ pub trait ExecutionStorage: Clone + Send + Sync { self.fee_store().transition_store() } - /// Returns the optional development ID. - fn dev(&self) -> Option { - self.transition_store().dev() + /// Returns the storage mode. + fn storage_mode(&self) -> &StorageMode { + self.transition_store().storage_mode() } /// Starts an atomic batch write operation. @@ -353,9 +354,9 @@ impl> ExecutionStore { self.storage.finish_atomic() } - /// Returns the optional development ID. - pub fn dev(&self) -> Option { - self.storage.dev() + /// Returns the storage mode. + pub fn storage_mode(&self) -> &StorageMode { + self.storage.storage_mode() } } @@ -393,7 +394,7 @@ mod tests { use super::*; use crate::{helpers::memory::ExecutionMemory, TransitionStore}; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; fn insert_get_remove(transaction: Transaction) -> Result<()> { let transaction_id = transaction.id(); diff --git a/ledger/store/src/transaction/fee.rs b/ledger/store/src/transaction/fee.rs index 5f7dbadd7b..f821afaea8 100644 --- a/ledger/store/src/transaction/fee.rs +++ b/ledger/store/src/transaction/fee.rs @@ -24,6 +24,7 @@ use console::network::prelude::*; use ledger_block::Fee; use synthesizer_snark::Proof; +use aleo_std_storage::StorageMode; use anyhow::Result; use core::marker::PhantomData; @@ -47,9 +48,9 @@ pub trait FeeStorage: Clone + Send + Sync { /// Returns the transition storage. fn transition_store(&self) -> &TransitionStore; - /// Returns the optional development ID. - fn dev(&self) -> Option { - self.transition_store().dev() + /// Returns the storage mode. + fn storage_mode(&self) -> &StorageMode { + self.transition_store().storage_mode() } /// Starts an atomic batch write operation. @@ -235,9 +236,9 @@ impl> FeeStore { self.storage.finish_atomic() } - /// Returns the optional development ID. - pub fn dev(&self) -> Option { - self.storage.dev() + /// Returns the storage mode. + pub fn storage_mode(&self) -> &StorageMode { + self.storage.storage_mode() } } diff --git a/ledger/store/src/transaction/mod.rs b/ledger/store/src/transaction/mod.rs index b3f56bec8d..7d62c529b1 100644 --- a/ledger/store/src/transaction/mod.rs +++ b/ledger/store/src/transaction/mod.rs @@ -36,6 +36,7 @@ use ledger_block::{Deployment, Execution, Transaction}; use synthesizer_program::Program; use synthesizer_snark::{Certificate, VerifyingKey}; +use aleo_std_storage::StorageMode; use anyhow::Result; use serde::{Deserialize, Serialize}; use std::borrow::Cow; @@ -76,14 +77,14 @@ pub trait TransactionStorage: Clone + Send + Sync { fn fee_store(&self) -> &FeeStore; /// Returns the transition store. fn transition_store(&self) -> &TransitionStore { - debug_assert!(self.deployment_store().dev() == self.execution_store().dev()); - debug_assert!(self.execution_store().dev() == self.fee_store().dev()); + debug_assert!(self.deployment_store().storage_mode() == self.execution_store().storage_mode()); + debug_assert!(self.execution_store().storage_mode() == self.fee_store().storage_mode()); self.fee_store().transition_store() } - /// Returns the optional development ID. - fn dev(&self) -> Option { - self.transition_store().dev() + /// Returns the storage mode. + fn storage_mode(&self) -> &StorageMode { + self.transition_store().storage_mode() } /// Starts an atomic batch write operation. @@ -306,9 +307,9 @@ impl> TransactionStore { self.storage.finish_atomic() } - /// Returns the optional development ID. - pub fn dev(&self) -> Option { - self.storage.dev() + /// Returns the storage mode. + pub fn storage_mode(&self) -> &StorageMode { + self.storage.storage_mode() } } diff --git a/ledger/store/src/transition/input.rs b/ledger/store/src/transition/input.rs index 53c12f5147..33ba49dc71 100644 --- a/ledger/store/src/transition/input.rs +++ b/ledger/store/src/transition/input.rs @@ -23,6 +23,7 @@ use console::{ }; use ledger_block::Input; +use aleo_std_storage::StorageMode; use anyhow::Result; use std::borrow::Cow; @@ -46,7 +47,7 @@ pub trait InputStorage: Clone + Send + Sync { type ExternalRecordMap: for<'a> Map<'a, Field, ()>; /// Initializes the transition input storage. - fn open(dev: Option) -> Result; + fn open>(storage: S) -> Result; /// Returns the ID map. fn id_map(&self) -> &Self::IDMap; @@ -65,8 +66,8 @@ pub trait InputStorage: Clone + Send + Sync { /// Returns the external record map. fn external_record_map(&self) -> &Self::ExternalRecordMap; - /// Returns the optional development ID. - fn dev(&self) -> Option; + /// Returns the storage mode. + fn storage_mode(&self) -> &StorageMode; /// Starts an atomic batch write operation. fn start_atomic(&self) { @@ -305,9 +306,9 @@ pub struct InputStore> { impl> InputStore { /// Initializes the transition input store. - pub fn open(dev: Option) -> Result { + pub fn open>(storage: S) -> Result { // Initialize a new transition input storage. - let storage = I::open(dev)?; + let storage = I::open(storage)?; // Return the transition input store. Ok(Self { constant: storage.constant_map().clone(), @@ -378,9 +379,9 @@ impl> InputStore { self.storage.finish_atomic() } - /// Returns the optional development ID. - pub fn dev(&self) -> Option { - self.storage.dev() + /// Returns the storage mode. + pub fn storage_mode(&self) -> &StorageMode { + self.storage.storage_mode() } } diff --git a/ledger/store/src/transition/mod.rs b/ledger/store/src/transition/mod.rs index 734cf186e4..e813caa01b 100644 --- a/ledger/store/src/transition/mod.rs +++ b/ledger/store/src/transition/mod.rs @@ -31,6 +31,7 @@ use console::{ }; use ledger_block::{Input, Output, Transition}; +use aleo_std_storage::StorageMode; use anyhow::Result; use std::borrow::Cow; @@ -50,9 +51,11 @@ pub trait TransitionStorage: Clone + Send + Sync { type TCMMap: for<'a> Map<'a, N::TransitionID, Field>; /// The mapping of `transition commitment` to `transition ID`. type ReverseTCMMap: for<'a> Map<'a, Field, N::TransitionID>; + /// The signer commitments. + type SCMMap: for<'a> Map<'a, N::TransitionID, Field>; /// Initializes the transition storage. - fn open(dev: Option) -> Result; + fn open>(storage: S) -> Result; /// Returns the transition program IDs and function names. fn locator_map(&self) -> &Self::LocatorMap; @@ -68,11 +71,13 @@ pub trait TransitionStorage: Clone + Send + Sync { fn tcm_map(&self) -> &Self::TCMMap; /// Returns the reverse `tcm` map. fn reverse_tcm_map(&self) -> &Self::ReverseTCMMap; + /// Returns the signer commitments map. + fn scm_map(&self) -> &Self::SCMMap; - /// Returns the optional development ID. - fn dev(&self) -> Option { - debug_assert!(self.input_store().dev() == self.output_store().dev()); - self.input_store().dev() + /// Returns the storage mode. + fn storage_mode(&self) -> &StorageMode { + debug_assert!(self.input_store().storage_mode() == self.output_store().storage_mode()); + self.input_store().storage_mode() } /// Starts an atomic batch write operation. @@ -84,6 +89,7 @@ pub trait TransitionStorage: Clone + Send + Sync { self.reverse_tpk_map().start_atomic(); self.tcm_map().start_atomic(); self.reverse_tcm_map().start_atomic(); + self.scm_map().start_atomic(); } /// Checks if an atomic batch is in progress. @@ -95,6 +101,7 @@ pub trait TransitionStorage: Clone + Send + Sync { || self.reverse_tpk_map().is_atomic_in_progress() || self.tcm_map().is_atomic_in_progress() || self.reverse_tcm_map().is_atomic_in_progress() + || self.scm_map().is_atomic_in_progress() } /// Checkpoints the atomic batch. @@ -106,6 +113,7 @@ pub trait TransitionStorage: Clone + Send + Sync { self.reverse_tpk_map().atomic_checkpoint(); self.tcm_map().atomic_checkpoint(); self.reverse_tcm_map().atomic_checkpoint(); + self.scm_map().atomic_checkpoint(); } /// Clears the latest atomic batch checkpoint. @@ -117,6 +125,7 @@ pub trait TransitionStorage: Clone + Send + Sync { self.reverse_tpk_map().clear_latest_checkpoint(); self.tcm_map().clear_latest_checkpoint(); self.reverse_tcm_map().clear_latest_checkpoint(); + self.scm_map().clear_latest_checkpoint(); } /// Rewinds the atomic batch to the previous checkpoint. @@ -128,6 +137,7 @@ pub trait TransitionStorage: Clone + Send + Sync { self.reverse_tpk_map().atomic_rewind(); self.tcm_map().atomic_rewind(); self.reverse_tcm_map().atomic_rewind(); + self.scm_map().atomic_rewind(); } /// Aborts an atomic batch write operation. @@ -139,6 +149,7 @@ pub trait TransitionStorage: Clone + Send + Sync { self.reverse_tpk_map().abort_atomic(); self.tcm_map().abort_atomic(); self.reverse_tcm_map().abort_atomic(); + self.scm_map().abort_atomic(); } /// Finishes an atomic batch write operation. @@ -149,7 +160,8 @@ pub trait TransitionStorage: Clone + Send + Sync { self.tpk_map().finish_atomic()?; self.reverse_tpk_map().finish_atomic()?; self.tcm_map().finish_atomic()?; - self.reverse_tcm_map().finish_atomic() + self.reverse_tcm_map().finish_atomic()?; + self.scm_map().finish_atomic() } /// Stores the given `transition` into storage. @@ -171,6 +183,8 @@ pub trait TransitionStorage: Clone + Send + Sync { self.tcm_map().insert(transition_id, *transition.tcm())?; // Store the reverse `tcm` entry. self.reverse_tcm_map().insert(*transition.tcm(), transition_id)?; + // Store `scm`. + self.scm_map().insert(transition_id, *transition.scm())?; Ok(()) }) @@ -204,6 +218,8 @@ pub trait TransitionStorage: Clone + Send + Sync { self.tcm_map().remove(transition_id)?; // Remove the reverse `tcm` entry. self.reverse_tcm_map().remove(&tcm)?; + // Remove `scm`. + self.scm_map().remove(transition_id)?; Ok(()) }) @@ -224,9 +240,11 @@ pub trait TransitionStorage: Clone + Send + Sync { let tpk = self.tpk_map().get_confirmed(transition_id)?; // Retrieve `tcm`. let tcm = self.tcm_map().get_confirmed(transition_id)?; + // Retrieve `scm`. + let scm = self.scm_map().get_confirmed(transition_id)?; - match (tpk, tcm) { - (Some(tpk), Some(tcm)) => { + match (tpk, tcm, scm) { + (Some(tpk), Some(tcm), Some(scm)) => { // Construct the transition. let transition = Transition::new( program_id, @@ -235,6 +253,7 @@ pub trait TransitionStorage: Clone + Send + Sync { outputs, cow_to_cloned!(tpk), cow_to_cloned!(tcm), + cow_to_cloned!(scm), )?; // Ensure the transition ID matches. match transition.id() == transition_id { @@ -264,15 +283,17 @@ pub struct TransitionStore> { tcm: T::TCMMap, /// The reverse `tcm` map. reverse_tcm: T::ReverseTCMMap, + /// The map of signer commitments. + scm: T::SCMMap, /// The transition storage. storage: T, } impl> TransitionStore { /// Initializes the transition store. - pub fn open(dev: Option) -> Result { + pub fn open>(storage: S) -> Result { // Initialize the transition storage. - let storage = T::open(dev)?; + let storage = T::open(storage)?; // Return the transition store. Ok(Self { locator: storage.locator_map().clone(), @@ -282,6 +303,7 @@ impl> TransitionStore { reverse_tpk: storage.reverse_tpk_map().clone(), tcm: storage.tcm_map().clone(), reverse_tcm: storage.reverse_tcm_map().clone(), + scm: storage.scm_map().clone(), storage, }) } @@ -296,6 +318,7 @@ impl> TransitionStore { reverse_tpk: storage.reverse_tpk_map().clone(), tcm: storage.tcm_map().clone(), reverse_tcm: storage.reverse_tcm_map().clone(), + scm: storage.scm_map().clone(), storage, } } @@ -345,9 +368,9 @@ impl> TransitionStore { self.storage.finish_atomic() } - /// Returns the optional development ID. - pub fn dev(&self) -> Option { - self.storage.dev() + /// Returns the storage mode. + pub fn storage_mode(&self) -> &StorageMode { + self.storage.storage_mode() } } @@ -614,6 +637,11 @@ impl> TransitionStore { pub fn tcms(&self) -> impl '_ + Iterator>> { self.tcm.values_confirmed() } + + /// Returns an iterator over the signer commitments, for all transitions. + pub fn scms(&self) -> impl '_ + Iterator>> { + self.scm.values_confirmed() + } } #[cfg(test)] diff --git a/ledger/store/src/transition/output.rs b/ledger/store/src/transition/output.rs index 2c9a82c0ef..01acfa41cb 100644 --- a/ledger/store/src/transition/output.rs +++ b/ledger/store/src/transition/output.rs @@ -23,6 +23,7 @@ use console::{ }; use ledger_block::Output; +use aleo_std_storage::StorageMode; use anyhow::Result; use std::borrow::Cow; @@ -48,7 +49,7 @@ pub trait OutputStorage: Clone + Send + Sync { type FutureMap: for<'a> Map<'a, Field, Option>>; /// Initializes the transition output storage. - fn open(dev: Option) -> Result; + fn open>(storage: S) -> Result; /// Returns the ID map. fn id_map(&self) -> &Self::IDMap; @@ -69,8 +70,8 @@ pub trait OutputStorage: Clone + Send + Sync { /// Returns the future map. fn future_map(&self) -> &Self::FutureMap; - /// Returns the optional development ID. - fn dev(&self) -> Option; + /// Returns the storage mode. + fn storage_mode(&self) -> &StorageMode; /// Starts an atomic batch write operation. fn start_atomic(&self) { @@ -326,9 +327,9 @@ pub struct OutputStore> { impl> OutputStore { /// Initializes the transition output store. - pub fn open(dev: Option) -> Result { + pub fn open>(storage: S) -> Result { // Initialize a new transition output storage. - let storage = O::open(dev)?; + let storage = O::open(storage)?; // Return the transition output store. Ok(Self { constant: storage.constant_map().clone(), @@ -401,9 +402,9 @@ impl> OutputStore { self.storage.finish_atomic() } - /// Returns the optional development ID. - pub fn dev(&self) -> Option { - self.storage.dev() + /// Returns the storage mode. + pub fn storage_mode(&self) -> &StorageMode { + self.storage.storage_mode() } } diff --git a/ledger/test-helpers/Cargo.toml b/ledger/test-helpers/Cargo.toml index a9889f8940..eba63ce2ee 100644 --- a/ledger/test-helpers/Cargo.toml +++ b/ledger/test-helpers/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-ledger-test-helpers" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Test helpers for a decentralized virtual machine" homepage = "https://aleo.org" @@ -19,39 +19,39 @@ edition = "2021" [dependencies.console] package = "snarkvm-console" path = "../../console" -version = "=0.16.15" +version = "=0.16.19" [dependencies.circuit] package = "snarkvm-circuit" path = "../../circuit" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-block] package = "snarkvm-ledger-block" path = "../block" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-query] package = "snarkvm-ledger-query" path = "../query" -version = "=0.16.15" +version = "=0.16.19" default-features = false features = [ "query" ] [dependencies.ledger-store] package = "snarkvm-ledger-store" path = "../store" -version = "=0.16.15" +version = "=0.16.19" [dependencies.synthesizer-program] package = "snarkvm-synthesizer-program" path = "../../synthesizer/program" -version = "=0.16.15" +version = "=0.16.19" [dependencies.synthesizer-process] package = "snarkvm-synthesizer-process" path = "../../synthesizer/process" -version = "=0.16.15" +version = "=0.16.19" [dependencies.once_cell] version = "1.18" diff --git a/ledger/test-helpers/src/lib.rs b/ledger/test-helpers/src/lib.rs index 813fb8cb0b..7bcf84440a 100644 --- a/ledger/test-helpers/src/lib.rs +++ b/ledger/test-helpers/src/lib.rs @@ -39,7 +39,7 @@ use synthesizer_program::Program; use once_cell::sync::OnceCell; -type CurrentNetwork = console::network::Testnet3; +type CurrentNetwork = console::network::MainnetV0; type CurrentAleo = circuit::network::AleoV0; /****************************************** Transition ********************************************/ @@ -413,7 +413,7 @@ fn sample_genesis_block_and_components_raw( // Prepare the confirmed transaction. let confirmed = ConfirmedTransaction::accepted_execute(0, transaction.clone(), vec![]).unwrap(); // Prepare the transactions. - let transactions = Transactions::from_iter([confirmed].into_iter()); + let transactions = Transactions::from_iter([confirmed]); // Construct the ratifications. let ratifications = Ratifications::try_from(vec![]).unwrap(); @@ -424,8 +424,18 @@ fn sample_genesis_block_and_components_raw( let previous_hash = ::BlockHash::default(); // Construct the block. - let block = - Block::new_beacon(&private_key, previous_hash, header, ratifications, None, transactions, vec![], rng).unwrap(); + let block = Block::new_beacon( + &private_key, + previous_hash, + header, + ratifications, + None.into(), + vec![], + transactions, + vec![], + rng, + ) + .unwrap(); assert!(block.header().is_genesis(), "Failed to initialize a genesis block"); // Return the block, transaction, and private key. (block, transaction, private_key) diff --git a/metrics/Cargo.toml b/metrics/Cargo.toml index 04dc3a620d..457d43f039 100644 --- a/metrics/Cargo.toml +++ b/metrics/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-metrics" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Metrics for a decentralized virtual machine" homepage = "https://aleo.org" @@ -24,7 +24,7 @@ license = "Apache-2.0" edition = "2021" [dependencies.metrics] -version = "0.21" +version = "0.22" [dependencies.metrics-exporter-prometheus] -version = "0.12" +version = "0.13" diff --git a/metrics/src/lib.rs b/metrics/src/lib.rs index 4108fb9a86..81cfa46bbd 100644 --- a/metrics/src/lib.rs +++ b/metrics/src/lib.rs @@ -31,7 +31,7 @@ pub fn register_metrics() { /// Registers a counter with the given name. pub fn register_counter(name: &'static str) { - ::metrics::register_counter!(name); + let _counter = ::metrics::counter!(name); } /// Updates a counter with the given name to the given value. @@ -39,7 +39,8 @@ pub fn register_counter(name: &'static str) { /// Counters represent a single monotonic value, which means the value can only be incremented, /// not decremented, and always starts out with an initial value of zero. pub fn counter>(name: &'static str, value: V) { - ::metrics::counter!(name, value.into()); + let counter = ::metrics::counter!(name); + counter.absolute(value.into()); } /// Increments a counter with the given name by one. @@ -47,14 +48,15 @@ pub fn counter>(name: &'static str, value: V) { /// Counters represent a single monotonic value, which means the value can only be incremented, /// not decremented, and always starts out with an initial value of zero. pub fn increment_counter(name: &'static str) { - ::metrics::increment_counter!(name); + let counter = ::metrics::counter!(name); + counter.increment(1); } /******** Gauge ********/ /// Registers a gauge with the given name. pub fn register_gauge(name: &'static str) { - ::metrics::register_gauge!(name); + let _gauge = ::metrics::gauge!(name); } /// Updates a gauge with the given name to the given value. @@ -62,7 +64,8 @@ pub fn register_gauge(name: &'static str) { /// Gauges represent a single value that can go up or down over time, /// and always starts out with an initial value of zero. pub fn gauge>(name: &'static str, value: V) { - ::metrics::gauge!(name, value.into()); + let gauge = ::metrics::gauge!(name); + gauge.set(value.into()); } /// Increments a gauge with the given name by the given value. @@ -70,7 +73,8 @@ pub fn gauge>(name: &'static str, value: V) { /// Gauges represent a single value that can go up or down over time, /// and always starts out with an initial value of zero. pub fn increment_gauge>(name: &'static str, value: V) { - ::metrics::increment_gauge!(name, value.into()); + let gauge = ::metrics::gauge!(name); + gauge.increment(value.into()); } /// Decrements a gauge with the given name by the given value. @@ -78,17 +82,19 @@ pub fn increment_gauge>(name: &'static str, value: V) { /// Gauges represent a single value that can go up or down over time, /// and always starts out with an initial value of zero. pub fn decrement_gauge>(name: &'static str, value: V) { - ::metrics::decrement_gauge!(name, value.into()); + let gauge = ::metrics::gauge!(name); + gauge.decrement(value.into()); } /******** Histogram ********/ /// Registers a histogram with the given name. pub fn register_histogram(name: &'static str) { - ::metrics::register_histogram!(name); + let _histogram = ::metrics::histogram!(name); } /// Updates a histogram with the given name to the given value. pub fn histogram>(name: &'static str, value: V) { - ::metrics::histogram!(name, value.into()); + let histogram = ::metrics::histogram!(name); + histogram.record(value.into()); } diff --git a/parameters/Cargo.toml b/parameters/Cargo.toml index 932f9ba0e2..d735149b19 100644 --- a/parameters/Cargo.toml +++ b/parameters/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-parameters" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Parameters for a decentralized virtual machine" homepage = "https://aleo.org" @@ -31,15 +31,15 @@ wasm = [ "encoding", "js-sys", "web-sys" ] [dependencies.snarkvm-curves] path = "../curves" -version = "=0.16.15" +version = "=0.16.19" default-features = false [dependencies.snarkvm-utilities] path = "../utilities" -version = "=0.16.15" +version = "=0.16.19" [dependencies.aleo-std] -version = "0.1.18" +version = "0.1.24" default-features = false features = [ "storage" ] diff --git a/parameters/examples/inclusion.rs b/parameters/examples/inclusion.rs index e7d0812197..40845d8739 100644 --- a/parameters/examples/inclusion.rs +++ b/parameters/examples/inclusion.rs @@ -16,7 +16,7 @@ use snarkvm_algorithms::crypto_hash::sha256::sha256; use snarkvm_circuit::{Aleo, Assignment}; use snarkvm_console::{ account::PrivateKey, - network::{Network, Testnet3}, + network::{MainnetV0, Network}, prelude::{One, ToBytes, Zero}, program::{Plaintext, Record, StatePath}, types::Field, @@ -170,8 +170,8 @@ pub fn main() -> Result<()> { } match args[1].as_str() { - "testnet3" => { - inclusion::()?; + "mainnet" => { + inclusion::()?; } _ => panic!("Invalid network"), }; diff --git a/parameters/examples/setup.rs b/parameters/examples/setup.rs index b7c5765652..86849715fb 100644 --- a/parameters/examples/setup.rs +++ b/parameters/examples/setup.rs @@ -14,7 +14,7 @@ use snarkvm_algorithms::crypto_hash::sha256::sha256; use snarkvm_circuit::Aleo; -use snarkvm_console::network::{prelude::ToBytes, Network, Testnet3}; +use snarkvm_console::network::{prelude::ToBytes, MainnetV0, Network}; use snarkvm_synthesizer::{Process, Program}; use anyhow::Result; @@ -60,7 +60,7 @@ fn write_metadata(filename: &str, metadata: &Value) -> Result<()> { /// (Do not use) Writes the metadata files. (cargo run --release --example setup usrs) pub fn usrs() -> Result<()> { - let paths = fs::read_dir("../src/testnet3/resources/").unwrap(); + let paths = fs::read_dir("../src/mainnet/resources/").unwrap(); for path in paths { let path = path?.path(); if let Some("usrs") = path.extension().and_then(|s| s.to_str()) { @@ -149,7 +149,7 @@ pub fn main() -> Result<()> { match args[1].as_str() { "usrs" => usrs()?, - "credits" => credits_program::()?, + "credits" => credits_program::()?, _ => panic!("Invalid parameter"), }; diff --git a/parameters/scripts/README.md b/parameters/scripts/README.md index 12185721de..02dd421eb7 100644 --- a/parameters/scripts/README.md +++ b/parameters/scripts/README.md @@ -1,6 +1,6 @@ # Parameter Scripts These scripts will run the parameter setup programs in the `examples` folder and move the resulting `.params` -and `.checksum` files to `testnet*` folder under the `src` directory. +and `.checksum` files to `mainnet*` folder under the `src` directory. If the parameter size has changed, you will need to manually update these in each corresponding struct. diff --git a/parameters/scripts/testnet3/credits.sh b/parameters/scripts/mainnet/credits.sh similarity index 62% rename from parameters/scripts/testnet3/credits.sh rename to parameters/scripts/mainnet/credits.sh index df8a1a68d0..9a9526350b 100755 --- a/parameters/scripts/testnet3/credits.sh +++ b/parameters/scripts/mainnet/credits.sh @@ -4,6 +4,6 @@ cargo run --release --example setup credits -- --nocapture || exit -mv *.metadata ../../src/testnet3/resources || exit +mv *.metadata ../../src/mainnet/resources || exit mv *.prover.* ~/.aleo/resources || exit -mv *.verifier ../../src/testnet3/resources || exit +mv *.verifier ../../src/mainnet/resources || exit diff --git a/parameters/scripts/mainnet/inclusion.sh b/parameters/scripts/mainnet/inclusion.sh new file mode 100755 index 0000000000..f9f6d7797e --- /dev/null +++ b/parameters/scripts/mainnet/inclusion.sh @@ -0,0 +1,9 @@ +# Generates the inclusion proving and verifying key. + +# Inputs: network + +cargo run --release --example inclusion mainnet -- --nocapture || exit + +mv inclusion.metadata ../../src/mainnet/resources || exit +mv inclusion.prover.* ~/.aleo/resources || exit +mv inclusion.verifier ../../src/mainnet/resources || exit diff --git a/parameters/scripts/testnet3/inclusion.sh b/parameters/scripts/testnet3/inclusion.sh deleted file mode 100755 index 3472647ec5..0000000000 --- a/parameters/scripts/testnet3/inclusion.sh +++ /dev/null @@ -1,9 +0,0 @@ -# Generates the inclusion proving and verifying key. - -# Inputs: network - -cargo run --release --example inclusion testnet3 -- --nocapture || exit - -mv inclusion.metadata ../../src/testnet3/resources || exit -mv inclusion.prover.* ~/.aleo/resources || exit -mv inclusion.verifier ../../src/testnet3/resources || exit diff --git a/parameters/src/lib.rs b/parameters/src/lib.rs index 7dcf27c5f0..7959ca1b5a 100644 --- a/parameters/src/lib.rs +++ b/parameters/src/lib.rs @@ -30,7 +30,7 @@ pub mod macros; pub mod errors; pub use errors::*; -pub mod testnet3; +pub mod mainnet; pub mod prelude { pub use crate::errors::*; diff --git a/parameters/src/testnet3/genesis.rs b/parameters/src/mainnet/genesis.rs similarity index 93% rename from parameters/src/testnet3/genesis.rs rename to parameters/src/mainnet/genesis.rs index 344db0d17e..45196d18d3 100644 --- a/parameters/src/testnet3/genesis.rs +++ b/parameters/src/mainnet/genesis.rs @@ -27,6 +27,6 @@ mod tests { #[test] fn test_genesis_block() { let bytes = GenesisBytes::load_bytes(); - assert_eq!(13728, bytes.len() as u64, "Update me if serialization has changed"); + assert_eq!(13989, bytes.len() as u64, "Update me if serialization has changed"); } } diff --git a/parameters/src/testnet3/mod.rs b/parameters/src/mainnet/mod.rs similarity index 89% rename from parameters/src/testnet3/mod.rs rename to parameters/src/mainnet/mod.rs index 5233242d83..23fdd63c72 100644 --- a/parameters/src/testnet3/mod.rs +++ b/parameters/src/mainnet/mod.rs @@ -18,7 +18,7 @@ pub use genesis::*; pub mod powers; pub use powers::*; -const REMOTE_URL: &str = "https://s3-us-west-1.amazonaws.com/testnet3.parameters"; +const REMOTE_URL: &str = "https://s3-us-west-1.amazonaws.com/mainnet.parameters"; // Degrees #[cfg(not(feature = "wasm"))] @@ -115,19 +115,19 @@ macro_rules! insert_credit_keys { ($map:ident, $type:ident<$network:ident>, $variant:ident) => {{ paste::paste! { let string = stringify!([<$variant:lower>]); - $crate::insert_key!($map, string, $type<$network>, ("bond_public", $crate::testnet3::[]::load_bytes())); - $crate::insert_key!($map, string, $type<$network>, ("unbond_public", $crate::testnet3::[]::load_bytes())); - $crate::insert_key!($map, string, $type<$network>, ("unbond_delegator_as_validator", $crate::testnet3::[]::load_bytes())); - $crate::insert_key!($map, string, $type<$network>, ("claim_unbond_public", $crate::testnet3::[]::load_bytes())); - $crate::insert_key!($map, string, $type<$network>, ("set_validator_state", $crate::testnet3::[]::load_bytes())); - $crate::insert_key!($map, string, $type<$network>, ("transfer_private", $crate::testnet3::[]::load_bytes())); - $crate::insert_key!($map, string, $type<$network>, ("transfer_public", $crate::testnet3::[]::load_bytes())); - $crate::insert_key!($map, string, $type<$network>, ("transfer_private_to_public", $crate::testnet3::[]::load_bytes())); - $crate::insert_key!($map, string, $type<$network>, ("transfer_public_to_private", $crate::testnet3::[]::load_bytes())); - $crate::insert_key!($map, string, $type<$network>, ("join", $crate::testnet3::[]::load_bytes())); - $crate::insert_key!($map, string, $type<$network>, ("split", $crate::testnet3::[]::load_bytes())); - $crate::insert_key!($map, string, $type<$network>, ("fee_private", $crate::testnet3::[]::load_bytes())); - $crate::insert_key!($map, string, $type<$network>, ("fee_public", $crate::testnet3::[]::load_bytes())); + $crate::insert_key!($map, string, $type<$network>, ("bond_public", $crate::mainnet::[]::load_bytes())); + $crate::insert_key!($map, string, $type<$network>, ("unbond_public", $crate::mainnet::[]::load_bytes())); + $crate::insert_key!($map, string, $type<$network>, ("unbond_delegator_as_validator", $crate::mainnet::[]::load_bytes())); + $crate::insert_key!($map, string, $type<$network>, ("claim_unbond_public", $crate::mainnet::[]::load_bytes())); + $crate::insert_key!($map, string, $type<$network>, ("set_validator_state", $crate::mainnet::[]::load_bytes())); + $crate::insert_key!($map, string, $type<$network>, ("transfer_private", $crate::mainnet::[]::load_bytes())); + $crate::insert_key!($map, string, $type<$network>, ("transfer_public", $crate::mainnet::[]::load_bytes())); + $crate::insert_key!($map, string, $type<$network>, ("transfer_private_to_public", $crate::mainnet::[]::load_bytes())); + $crate::insert_key!($map, string, $type<$network>, ("transfer_public_to_private", $crate::mainnet::[]::load_bytes())); + $crate::insert_key!($map, string, $type<$network>, ("join", $crate::mainnet::[]::load_bytes())); + $crate::insert_key!($map, string, $type<$network>, ("split", $crate::mainnet::[]::load_bytes())); + $crate::insert_key!($map, string, $type<$network>, ("fee_private", $crate::mainnet::[]::load_bytes())); + $crate::insert_key!($map, string, $type<$network>, ("fee_public", $crate::mainnet::[]::load_bytes())); } }}; } @@ -149,7 +149,7 @@ impl_remote!(InclusionProver, REMOTE_URL, "resources/", "inclusion", "prover"); impl_local!(InclusionVerifier, "resources/", "inclusion", "verifier"); /// The function name for the inclusion circuit. -pub const TESTNET3_INCLUSION_FUNCTION_NAME: &str = "inclusion"; +pub const NETWORK_INCLUSION_FUNCTION_NAME: &str = "inclusion"; lazy_static! { pub static ref INCLUSION_PROVING_KEY: Vec = diff --git a/parameters/src/testnet3/powers.rs b/parameters/src/mainnet/powers.rs similarity index 100% rename from parameters/src/testnet3/powers.rs rename to parameters/src/mainnet/powers.rs diff --git a/parameters/src/testnet3/resources/beta-h.metadata b/parameters/src/mainnet/resources/beta-h.metadata similarity index 100% rename from parameters/src/testnet3/resources/beta-h.metadata rename to parameters/src/mainnet/resources/beta-h.metadata diff --git a/parameters/src/testnet3/resources/beta-h.usrs b/parameters/src/mainnet/resources/beta-h.usrs similarity index 100% rename from parameters/src/testnet3/resources/beta-h.usrs rename to parameters/src/mainnet/resources/beta-h.usrs diff --git a/parameters/src/mainnet/resources/block.genesis b/parameters/src/mainnet/resources/block.genesis new file mode 100644 index 0000000000..a18eb8c052 Binary files /dev/null and b/parameters/src/mainnet/resources/block.genesis differ diff --git a/parameters/src/mainnet/resources/bond_public.metadata b/parameters/src/mainnet/resources/bond_public.metadata new file mode 100644 index 0000000000..d6e3d20801 --- /dev/null +++ b/parameters/src/mainnet/resources/bond_public.metadata @@ -0,0 +1,6 @@ +{ + "prover_checksum": "81d3f2b91a7c9c1e788edefedef4ac136be4f1d65bb05c9675e59e6d6da843c2", + "prover_size": 28928250, + "verifier_checksum": "26790f191f07b5814f5f324e417603e79cae78cd986a8bb98c248ac5816b48cc", + "verifier_size": 665 +} \ No newline at end of file diff --git a/parameters/src/mainnet/resources/bond_public.verifier b/parameters/src/mainnet/resources/bond_public.verifier new file mode 100644 index 0000000000..0adbec27db Binary files /dev/null and b/parameters/src/mainnet/resources/bond_public.verifier differ diff --git a/parameters/src/mainnet/resources/claim_unbond_public.metadata b/parameters/src/mainnet/resources/claim_unbond_public.metadata new file mode 100644 index 0000000000..7e651302bc --- /dev/null +++ b/parameters/src/mainnet/resources/claim_unbond_public.metadata @@ -0,0 +1,6 @@ +{ + "prover_checksum": "5b99b8dc31f44ee56a0b1d07370191174e72414969df2fd35f1cc7c061791815", + "prover_size": 16861332, + "verifier_checksum": "e53699624b4677f8b1826dcc54f6980aa6400170032244a9082e5bee6c89d39d", + "verifier_size": 665 +} \ No newline at end of file diff --git a/parameters/src/mainnet/resources/claim_unbond_public.verifier b/parameters/src/mainnet/resources/claim_unbond_public.verifier new file mode 100644 index 0000000000..2cbb331c38 Binary files /dev/null and b/parameters/src/mainnet/resources/claim_unbond_public.verifier differ diff --git a/parameters/src/mainnet/resources/fee_private.metadata b/parameters/src/mainnet/resources/fee_private.metadata new file mode 100644 index 0000000000..ae797e9eae --- /dev/null +++ b/parameters/src/mainnet/resources/fee_private.metadata @@ -0,0 +1,6 @@ +{ + "prover_checksum": "27b72ed5e8086127f8cfcfc94b8c63543e5901a368a3f782aedcb51f9ace738e", + "prover_size": 66297972, + "verifier_checksum": "099648c5dcbb0eb8c7f1031195273f5e1375831cda977711f487fbed7e33bb20", + "verifier_size": 665 +} \ No newline at end of file diff --git a/parameters/src/mainnet/resources/fee_private.verifier b/parameters/src/mainnet/resources/fee_private.verifier new file mode 100644 index 0000000000..7756de8de8 Binary files /dev/null and b/parameters/src/mainnet/resources/fee_private.verifier differ diff --git a/parameters/src/mainnet/resources/fee_public.metadata b/parameters/src/mainnet/resources/fee_public.metadata new file mode 100644 index 0000000000..b94bca4f26 --- /dev/null +++ b/parameters/src/mainnet/resources/fee_public.metadata @@ -0,0 +1,6 @@ +{ + "prover_checksum": "88f6575a2f0e08d9768fa038081d3ccdb9d27f85cc52209007d35ea3ef51c1c4", + "prover_size": 29174402, + "verifier_checksum": "50ddf9c83807fc854d56afcda7171321d8fdef46271b3a3ea7b3c1485c3b193f", + "verifier_size": 665 +} \ No newline at end of file diff --git a/parameters/src/mainnet/resources/fee_public.verifier b/parameters/src/mainnet/resources/fee_public.verifier new file mode 100644 index 0000000000..d5a9df4ffa Binary files /dev/null and b/parameters/src/mainnet/resources/fee_public.verifier differ diff --git a/parameters/src/testnet3/resources/genesis.metadata b/parameters/src/mainnet/resources/genesis.metadata similarity index 100% rename from parameters/src/testnet3/resources/genesis.metadata rename to parameters/src/mainnet/resources/genesis.metadata diff --git a/parameters/src/mainnet/resources/inclusion.metadata b/parameters/src/mainnet/resources/inclusion.metadata new file mode 100644 index 0000000000..76f795f99c --- /dev/null +++ b/parameters/src/mainnet/resources/inclusion.metadata @@ -0,0 +1,6 @@ +{ + "prover_checksum": "8faa4d3aaaa5e786d20b61f825e50901f9dcf470455d1d2994e091eefcc66a4e", + "prover_size": 233812212, + "verifier_checksum": "2b6fdf5a869db365620a44fc3991e3f807a4e670bb976277ad327f3179866553", + "verifier_size": 665 +} \ No newline at end of file diff --git a/parameters/src/mainnet/resources/inclusion.verifier b/parameters/src/mainnet/resources/inclusion.verifier new file mode 100644 index 0000000000..f317f07efa Binary files /dev/null and b/parameters/src/mainnet/resources/inclusion.verifier differ diff --git a/parameters/src/mainnet/resources/join.metadata b/parameters/src/mainnet/resources/join.metadata new file mode 100644 index 0000000000..b6ff59da8e --- /dev/null +++ b/parameters/src/mainnet/resources/join.metadata @@ -0,0 +1,6 @@ +{ + "prover_checksum": "b609cd8cd51eb0870e87b31db05b45768a77daed7a2b0b3c8f5a570e12044112", + "prover_size": 74722164, + "verifier_checksum": "70691d33b4028fd2813edcb9468fa702239b93adab56fc8d3e9ea0636668a844", + "verifier_size": 665 +} \ No newline at end of file diff --git a/parameters/src/mainnet/resources/join.verifier b/parameters/src/mainnet/resources/join.verifier new file mode 100644 index 0000000000..035670470f Binary files /dev/null and b/parameters/src/mainnet/resources/join.verifier differ diff --git a/parameters/src/testnet3/resources/mint.metadata b/parameters/src/mainnet/resources/mint.metadata similarity index 100% rename from parameters/src/testnet3/resources/mint.metadata rename to parameters/src/mainnet/resources/mint.metadata diff --git a/parameters/src/testnet3/resources/neg-powers-of-beta.metadata b/parameters/src/mainnet/resources/neg-powers-of-beta.metadata similarity index 100% rename from parameters/src/testnet3/resources/neg-powers-of-beta.metadata rename to parameters/src/mainnet/resources/neg-powers-of-beta.metadata diff --git a/parameters/src/testnet3/resources/neg-powers-of-beta.usrs b/parameters/src/mainnet/resources/neg-powers-of-beta.usrs similarity index 100% rename from parameters/src/testnet3/resources/neg-powers-of-beta.usrs rename to parameters/src/mainnet/resources/neg-powers-of-beta.usrs diff --git a/parameters/src/testnet3/resources/powers-of-beta-15.metadata b/parameters/src/mainnet/resources/powers-of-beta-15.metadata similarity index 100% rename from parameters/src/testnet3/resources/powers-of-beta-15.metadata rename to parameters/src/mainnet/resources/powers-of-beta-15.metadata diff --git a/parameters/src/testnet3/resources/powers-of-beta-15.usrs b/parameters/src/mainnet/resources/powers-of-beta-15.usrs similarity index 100% rename from parameters/src/testnet3/resources/powers-of-beta-15.usrs rename to parameters/src/mainnet/resources/powers-of-beta-15.usrs diff --git a/parameters/src/testnet3/resources/powers-of-beta-16.metadata b/parameters/src/mainnet/resources/powers-of-beta-16.metadata similarity index 100% rename from parameters/src/testnet3/resources/powers-of-beta-16.metadata rename to parameters/src/mainnet/resources/powers-of-beta-16.metadata diff --git a/parameters/src/testnet3/resources/powers-of-beta-16.usrs b/parameters/src/mainnet/resources/powers-of-beta-16.usrs similarity index 100% rename from parameters/src/testnet3/resources/powers-of-beta-16.usrs rename to parameters/src/mainnet/resources/powers-of-beta-16.usrs diff --git a/parameters/src/testnet3/resources/powers-of-beta-17.metadata b/parameters/src/mainnet/resources/powers-of-beta-17.metadata similarity index 100% rename from parameters/src/testnet3/resources/powers-of-beta-17.metadata rename to parameters/src/mainnet/resources/powers-of-beta-17.metadata diff --git a/parameters/src/testnet3/resources/powers-of-beta-18.metadata b/parameters/src/mainnet/resources/powers-of-beta-18.metadata similarity index 100% rename from parameters/src/testnet3/resources/powers-of-beta-18.metadata rename to parameters/src/mainnet/resources/powers-of-beta-18.metadata diff --git a/parameters/src/testnet3/resources/powers-of-beta-19.metadata b/parameters/src/mainnet/resources/powers-of-beta-19.metadata similarity index 100% rename from parameters/src/testnet3/resources/powers-of-beta-19.metadata rename to parameters/src/mainnet/resources/powers-of-beta-19.metadata diff --git a/parameters/src/testnet3/resources/powers-of-beta-20.metadata b/parameters/src/mainnet/resources/powers-of-beta-20.metadata similarity index 100% rename from parameters/src/testnet3/resources/powers-of-beta-20.metadata rename to parameters/src/mainnet/resources/powers-of-beta-20.metadata diff --git a/parameters/src/testnet3/resources/powers-of-beta-21.metadata b/parameters/src/mainnet/resources/powers-of-beta-21.metadata similarity index 100% rename from parameters/src/testnet3/resources/powers-of-beta-21.metadata rename to parameters/src/mainnet/resources/powers-of-beta-21.metadata diff --git a/parameters/src/testnet3/resources/powers-of-beta-22.metadata b/parameters/src/mainnet/resources/powers-of-beta-22.metadata similarity index 100% rename from parameters/src/testnet3/resources/powers-of-beta-22.metadata rename to parameters/src/mainnet/resources/powers-of-beta-22.metadata diff --git a/parameters/src/testnet3/resources/powers-of-beta-23.metadata b/parameters/src/mainnet/resources/powers-of-beta-23.metadata similarity index 100% rename from parameters/src/testnet3/resources/powers-of-beta-23.metadata rename to parameters/src/mainnet/resources/powers-of-beta-23.metadata diff --git a/parameters/src/testnet3/resources/powers-of-beta-24.metadata b/parameters/src/mainnet/resources/powers-of-beta-24.metadata similarity index 100% rename from parameters/src/testnet3/resources/powers-of-beta-24.metadata rename to parameters/src/mainnet/resources/powers-of-beta-24.metadata diff --git a/parameters/src/testnet3/resources/powers-of-beta-25.metadata b/parameters/src/mainnet/resources/powers-of-beta-25.metadata similarity index 100% rename from parameters/src/testnet3/resources/powers-of-beta-25.metadata rename to parameters/src/mainnet/resources/powers-of-beta-25.metadata diff --git a/parameters/src/testnet3/resources/powers-of-beta-26.metadata b/parameters/src/mainnet/resources/powers-of-beta-26.metadata similarity index 100% rename from parameters/src/testnet3/resources/powers-of-beta-26.metadata rename to parameters/src/mainnet/resources/powers-of-beta-26.metadata diff --git a/parameters/src/testnet3/resources/powers-of-beta-27.metadata b/parameters/src/mainnet/resources/powers-of-beta-27.metadata similarity index 100% rename from parameters/src/testnet3/resources/powers-of-beta-27.metadata rename to parameters/src/mainnet/resources/powers-of-beta-27.metadata diff --git a/parameters/src/testnet3/resources/powers-of-beta-28.metadata b/parameters/src/mainnet/resources/powers-of-beta-28.metadata similarity index 100% rename from parameters/src/testnet3/resources/powers-of-beta-28.metadata rename to parameters/src/mainnet/resources/powers-of-beta-28.metadata diff --git a/parameters/src/testnet3/resources/powers-of-beta-gamma.metadata b/parameters/src/mainnet/resources/powers-of-beta-gamma.metadata similarity index 100% rename from parameters/src/testnet3/resources/powers-of-beta-gamma.metadata rename to parameters/src/mainnet/resources/powers-of-beta-gamma.metadata diff --git a/parameters/src/testnet3/resources/powers-of-beta-gamma.usrs b/parameters/src/mainnet/resources/powers-of-beta-gamma.usrs similarity index 100% rename from parameters/src/testnet3/resources/powers-of-beta-gamma.usrs rename to parameters/src/mainnet/resources/powers-of-beta-gamma.usrs diff --git a/parameters/src/mainnet/resources/set_validator_state.metadata b/parameters/src/mainnet/resources/set_validator_state.metadata new file mode 100644 index 0000000000..13434d577f --- /dev/null +++ b/parameters/src/mainnet/resources/set_validator_state.metadata @@ -0,0 +1,6 @@ +{ + "prover_checksum": "f782f04cf9f46464f307b4ae6418f2b8bec375e341e5a02a51c9d6b8b38e4f7f", + "prover_size": 17390188, + "verifier_checksum": "a224e3690b8c789b026fa5c93d2aada9148f4d45c756c492fb59accb128be724", + "verifier_size": 665 +} \ No newline at end of file diff --git a/parameters/src/mainnet/resources/set_validator_state.verifier b/parameters/src/mainnet/resources/set_validator_state.verifier new file mode 100644 index 0000000000..73ac6b6bc3 Binary files /dev/null and b/parameters/src/mainnet/resources/set_validator_state.verifier differ diff --git a/parameters/src/testnet3/resources/shifted-powers-of-beta-15.metadata b/parameters/src/mainnet/resources/shifted-powers-of-beta-15.metadata similarity index 100% rename from parameters/src/testnet3/resources/shifted-powers-of-beta-15.metadata rename to parameters/src/mainnet/resources/shifted-powers-of-beta-15.metadata diff --git a/parameters/src/testnet3/resources/shifted-powers-of-beta-15.usrs b/parameters/src/mainnet/resources/shifted-powers-of-beta-15.usrs similarity index 100% rename from parameters/src/testnet3/resources/shifted-powers-of-beta-15.usrs rename to parameters/src/mainnet/resources/shifted-powers-of-beta-15.usrs diff --git a/parameters/src/testnet3/resources/shifted-powers-of-beta-16.metadata b/parameters/src/mainnet/resources/shifted-powers-of-beta-16.metadata similarity index 100% rename from parameters/src/testnet3/resources/shifted-powers-of-beta-16.metadata rename to parameters/src/mainnet/resources/shifted-powers-of-beta-16.metadata diff --git a/parameters/src/testnet3/resources/shifted-powers-of-beta-16.usrs b/parameters/src/mainnet/resources/shifted-powers-of-beta-16.usrs similarity index 100% rename from parameters/src/testnet3/resources/shifted-powers-of-beta-16.usrs rename to parameters/src/mainnet/resources/shifted-powers-of-beta-16.usrs diff --git a/parameters/src/testnet3/resources/shifted-powers-of-beta-17.metadata b/parameters/src/mainnet/resources/shifted-powers-of-beta-17.metadata similarity index 100% rename from parameters/src/testnet3/resources/shifted-powers-of-beta-17.metadata rename to parameters/src/mainnet/resources/shifted-powers-of-beta-17.metadata diff --git a/parameters/src/testnet3/resources/shifted-powers-of-beta-18.metadata b/parameters/src/mainnet/resources/shifted-powers-of-beta-18.metadata similarity index 100% rename from parameters/src/testnet3/resources/shifted-powers-of-beta-18.metadata rename to parameters/src/mainnet/resources/shifted-powers-of-beta-18.metadata diff --git a/parameters/src/testnet3/resources/shifted-powers-of-beta-19.metadata b/parameters/src/mainnet/resources/shifted-powers-of-beta-19.metadata similarity index 100% rename from parameters/src/testnet3/resources/shifted-powers-of-beta-19.metadata rename to parameters/src/mainnet/resources/shifted-powers-of-beta-19.metadata diff --git a/parameters/src/testnet3/resources/shifted-powers-of-beta-20.metadata b/parameters/src/mainnet/resources/shifted-powers-of-beta-20.metadata similarity index 100% rename from parameters/src/testnet3/resources/shifted-powers-of-beta-20.metadata rename to parameters/src/mainnet/resources/shifted-powers-of-beta-20.metadata diff --git a/parameters/src/testnet3/resources/shifted-powers-of-beta-21.metadata b/parameters/src/mainnet/resources/shifted-powers-of-beta-21.metadata similarity index 100% rename from parameters/src/testnet3/resources/shifted-powers-of-beta-21.metadata rename to parameters/src/mainnet/resources/shifted-powers-of-beta-21.metadata diff --git a/parameters/src/testnet3/resources/shifted-powers-of-beta-22.metadata b/parameters/src/mainnet/resources/shifted-powers-of-beta-22.metadata similarity index 100% rename from parameters/src/testnet3/resources/shifted-powers-of-beta-22.metadata rename to parameters/src/mainnet/resources/shifted-powers-of-beta-22.metadata diff --git a/parameters/src/testnet3/resources/shifted-powers-of-beta-23.metadata b/parameters/src/mainnet/resources/shifted-powers-of-beta-23.metadata similarity index 100% rename from parameters/src/testnet3/resources/shifted-powers-of-beta-23.metadata rename to parameters/src/mainnet/resources/shifted-powers-of-beta-23.metadata diff --git a/parameters/src/testnet3/resources/shifted-powers-of-beta-24.metadata b/parameters/src/mainnet/resources/shifted-powers-of-beta-24.metadata similarity index 100% rename from parameters/src/testnet3/resources/shifted-powers-of-beta-24.metadata rename to parameters/src/mainnet/resources/shifted-powers-of-beta-24.metadata diff --git a/parameters/src/testnet3/resources/shifted-powers-of-beta-25.metadata b/parameters/src/mainnet/resources/shifted-powers-of-beta-25.metadata similarity index 100% rename from parameters/src/testnet3/resources/shifted-powers-of-beta-25.metadata rename to parameters/src/mainnet/resources/shifted-powers-of-beta-25.metadata diff --git a/parameters/src/testnet3/resources/shifted-powers-of-beta-26.metadata b/parameters/src/mainnet/resources/shifted-powers-of-beta-26.metadata similarity index 100% rename from parameters/src/testnet3/resources/shifted-powers-of-beta-26.metadata rename to parameters/src/mainnet/resources/shifted-powers-of-beta-26.metadata diff --git a/parameters/src/testnet3/resources/shifted-powers-of-beta-27.metadata b/parameters/src/mainnet/resources/shifted-powers-of-beta-27.metadata similarity index 100% rename from parameters/src/testnet3/resources/shifted-powers-of-beta-27.metadata rename to parameters/src/mainnet/resources/shifted-powers-of-beta-27.metadata diff --git a/parameters/src/testnet3/resources/shifted-powers-of-beta-28.metadata b/parameters/src/mainnet/resources/shifted-powers-of-beta-28.metadata similarity index 100% rename from parameters/src/testnet3/resources/shifted-powers-of-beta-28.metadata rename to parameters/src/mainnet/resources/shifted-powers-of-beta-28.metadata diff --git a/parameters/src/mainnet/resources/split.metadata b/parameters/src/mainnet/resources/split.metadata new file mode 100644 index 0000000000..c5712cd3ae --- /dev/null +++ b/parameters/src/mainnet/resources/split.metadata @@ -0,0 +1,6 @@ +{ + "prover_checksum": "9a6198f6bf0f9b0516feab70779eaaf91082b8b081ca79d7ddadbca44b58e85a", + "prover_size": 75161428, + "verifier_checksum": "1e576c6838e48ae946724a64e0831bc6bb0c6adc125b469e52da098008c69f06", + "verifier_size": 665 +} \ No newline at end of file diff --git a/parameters/src/mainnet/resources/split.verifier b/parameters/src/mainnet/resources/split.verifier new file mode 100644 index 0000000000..992b7d62f6 Binary files /dev/null and b/parameters/src/mainnet/resources/split.verifier differ diff --git a/parameters/src/mainnet/resources/transfer_private.metadata b/parameters/src/mainnet/resources/transfer_private.metadata new file mode 100644 index 0000000000..16f11c11cb --- /dev/null +++ b/parameters/src/mainnet/resources/transfer_private.metadata @@ -0,0 +1,6 @@ +{ + "prover_checksum": "d6c6d61a87f38905468c7e479e30a9899535635450cadf3de69eae4b490621db", + "prover_size": 75949172, + "verifier_checksum": "118d42c3a97e01506e233aaadec6956b8de1a187b46ee59e6a266c1e85f14d6f", + "verifier_size": 665 +} \ No newline at end of file diff --git a/parameters/src/mainnet/resources/transfer_private.verifier b/parameters/src/mainnet/resources/transfer_private.verifier new file mode 100644 index 0000000000..360b2774aa Binary files /dev/null and b/parameters/src/mainnet/resources/transfer_private.verifier differ diff --git a/parameters/src/mainnet/resources/transfer_private_to_public.metadata b/parameters/src/mainnet/resources/transfer_private_to_public.metadata new file mode 100644 index 0000000000..ed72b09d1b --- /dev/null +++ b/parameters/src/mainnet/resources/transfer_private_to_public.metadata @@ -0,0 +1,6 @@ +{ + "prover_checksum": "4c0561cf4342c601ccd49eee4c039711c2e2cf92a01b0b3a58b7f1242e902ceb", + "prover_size": 66299476, + "verifier_checksum": "be9a2abeeb2c9c5dcea11582f1869e0b1447b45ebfad5582604903ce338da405", + "verifier_size": 665 +} \ No newline at end of file diff --git a/parameters/src/mainnet/resources/transfer_private_to_public.verifier b/parameters/src/mainnet/resources/transfer_private_to_public.verifier new file mode 100644 index 0000000000..77b4ab602b Binary files /dev/null and b/parameters/src/mainnet/resources/transfer_private_to_public.verifier differ diff --git a/parameters/src/mainnet/resources/transfer_public.metadata b/parameters/src/mainnet/resources/transfer_public.metadata new file mode 100644 index 0000000000..876e221125 --- /dev/null +++ b/parameters/src/mainnet/resources/transfer_public.metadata @@ -0,0 +1,6 @@ +{ + "prover_checksum": "f8e5f6437b945174b62313ece8a1c9dcbeac5dfff5b0fef2e968c9b92f86da06", + "prover_size": 28913482, + "verifier_checksum": "5facdc35d2205f3a90a7a2eb89fa1418beabc6f6393e18d6498c60f02a3185e3", + "verifier_size": 665 +} \ No newline at end of file diff --git a/parameters/src/mainnet/resources/transfer_public.verifier b/parameters/src/mainnet/resources/transfer_public.verifier new file mode 100644 index 0000000000..1089392f46 Binary files /dev/null and b/parameters/src/mainnet/resources/transfer_public.verifier differ diff --git a/parameters/src/mainnet/resources/transfer_public_to_private.metadata b/parameters/src/mainnet/resources/transfer_public_to_private.metadata new file mode 100644 index 0000000000..9c9f075355 --- /dev/null +++ b/parameters/src/mainnet/resources/transfer_public_to_private.metadata @@ -0,0 +1,6 @@ +{ + "prover_checksum": "cf0916dc5debc8b894a856540e1525254214367af3d58b53d1472d5d95af5a95", + "prover_size": 38413316, + "verifier_checksum": "472004f0fd523239675d32b5e1ebea61cd6855b5f41126e70e05b83ec6a2a1a4", + "verifier_size": 665 +} \ No newline at end of file diff --git a/parameters/src/mainnet/resources/transfer_public_to_private.verifier b/parameters/src/mainnet/resources/transfer_public_to_private.verifier new file mode 100644 index 0000000000..65e2d54f53 Binary files /dev/null and b/parameters/src/mainnet/resources/transfer_public_to_private.verifier differ diff --git a/parameters/src/mainnet/resources/unbond_delegator_as_validator.metadata b/parameters/src/mainnet/resources/unbond_delegator_as_validator.metadata new file mode 100644 index 0000000000..d1e5ca6e66 --- /dev/null +++ b/parameters/src/mainnet/resources/unbond_delegator_as_validator.metadata @@ -0,0 +1,6 @@ +{ + "prover_checksum": "785f2318f0c12b883b99ff1649cf401d2f1d024fe2dd30916a276cd8c199f757", + "prover_size": 27062250, + "verifier_checksum": "34f8fb353c7c1a4e590b52000d78bf28100328f6250eb6c9ef11c9dc0a2bb066", + "verifier_size": 665 +} \ No newline at end of file diff --git a/parameters/src/mainnet/resources/unbond_delegator_as_validator.verifier b/parameters/src/mainnet/resources/unbond_delegator_as_validator.verifier new file mode 100644 index 0000000000..2f245c62d3 Binary files /dev/null and b/parameters/src/mainnet/resources/unbond_delegator_as_validator.verifier differ diff --git a/parameters/src/mainnet/resources/unbond_public.metadata b/parameters/src/mainnet/resources/unbond_public.metadata new file mode 100644 index 0000000000..3dffb3f508 --- /dev/null +++ b/parameters/src/mainnet/resources/unbond_public.metadata @@ -0,0 +1,6 @@ +{ + "prover_checksum": "fc15a9ae0f3eca24e6a622e8a8ce24682e73ec39d64f22b0876db28794763ea4", + "prover_size": 17414380, + "verifier_checksum": "a6106dcfefffd65e46488c7dc6228f9c379c35497c62779f2e186f2d9908eff9", + "verifier_size": 665 +} \ No newline at end of file diff --git a/parameters/src/mainnet/resources/unbond_public.verifier b/parameters/src/mainnet/resources/unbond_public.verifier new file mode 100644 index 0000000000..19485b625f Binary files /dev/null and b/parameters/src/mainnet/resources/unbond_public.verifier differ diff --git a/parameters/src/testnet3/resources/block.genesis b/parameters/src/testnet3/resources/block.genesis deleted file mode 100644 index c33b0398b6..0000000000 Binary files a/parameters/src/testnet3/resources/block.genesis and /dev/null differ diff --git a/parameters/src/testnet3/resources/bond_public.metadata b/parameters/src/testnet3/resources/bond_public.metadata deleted file mode 100644 index 09c21d773d..0000000000 --- a/parameters/src/testnet3/resources/bond_public.metadata +++ /dev/null @@ -1,6 +0,0 @@ -{ - "prover_checksum": "9c3547df0e580953f75e42f30e97c5f1eea7ca40d244aeb8054ff6b25a65bd53", - "prover_size": 28802978, - "verifier_checksum": "10315aeb75b3e933292d6493629634eda93bfc85e8d16caf86127015c56734fd", - "verifier_size": 665 -} \ No newline at end of file diff --git a/parameters/src/testnet3/resources/bond_public.verifier b/parameters/src/testnet3/resources/bond_public.verifier deleted file mode 100644 index ec9e26dd70..0000000000 Binary files a/parameters/src/testnet3/resources/bond_public.verifier and /dev/null differ diff --git a/parameters/src/testnet3/resources/claim_unbond_public.metadata b/parameters/src/testnet3/resources/claim_unbond_public.metadata deleted file mode 100644 index 22c1a5cf42..0000000000 --- a/parameters/src/testnet3/resources/claim_unbond_public.metadata +++ /dev/null @@ -1,6 +0,0 @@ -{ - "prover_checksum": "f8b64aa87fe94f44c566a3e1ab7fb0b6be4b3da0ac1b1038ba26bff6363ada5e", - "prover_size": 16734260, - "verifier_checksum": "8fd74456a2c8714d70b575ccdbcc180d3a882eb14bd2cbea944265f53c9a7ab4", - "verifier_size": 665 -} \ No newline at end of file diff --git a/parameters/src/testnet3/resources/claim_unbond_public.verifier b/parameters/src/testnet3/resources/claim_unbond_public.verifier deleted file mode 100644 index c50f7dd3a4..0000000000 Binary files a/parameters/src/testnet3/resources/claim_unbond_public.verifier and /dev/null differ diff --git a/parameters/src/testnet3/resources/fee_private.metadata b/parameters/src/testnet3/resources/fee_private.metadata deleted file mode 100644 index 0a39342dd6..0000000000 --- a/parameters/src/testnet3/resources/fee_private.metadata +++ /dev/null @@ -1,6 +0,0 @@ -{ - "prover_checksum": "43fab9849bfab3aca5c890622bd75ade9b2921cd7a8e74e71cadeba1e247af7f", - "prover_size": 66172740, - "verifier_checksum": "f3dfefcb9e6a691eb0168d547551fc4637c8703ee737c1795d335906b441548d", - "verifier_size": 665 -} \ No newline at end of file diff --git a/parameters/src/testnet3/resources/fee_private.verifier b/parameters/src/testnet3/resources/fee_private.verifier deleted file mode 100644 index df7b543fb0..0000000000 Binary files a/parameters/src/testnet3/resources/fee_private.verifier and /dev/null differ diff --git a/parameters/src/testnet3/resources/fee_public.metadata b/parameters/src/testnet3/resources/fee_public.metadata deleted file mode 100644 index 8606958f1a..0000000000 --- a/parameters/src/testnet3/resources/fee_public.metadata +++ /dev/null @@ -1,6 +0,0 @@ -{ - "prover_checksum": "634f153fe46f16dc1fe69a8fb01fe0d635ae5b1bda2ccc738187b6d71c97079d", - "prover_size": 29049130, - "verifier_checksum": "09eeb4f23ee22f3cc4d2878ba698e38e8f3b1b8755a55f00e4f237a69825de9d", - "verifier_size": 665 -} \ No newline at end of file diff --git a/parameters/src/testnet3/resources/fee_public.verifier b/parameters/src/testnet3/resources/fee_public.verifier deleted file mode 100644 index 3432de13a7..0000000000 Binary files a/parameters/src/testnet3/resources/fee_public.verifier and /dev/null differ diff --git a/parameters/src/testnet3/resources/inclusion.metadata b/parameters/src/testnet3/resources/inclusion.metadata deleted file mode 100644 index 3532ae5ea8..0000000000 --- a/parameters/src/testnet3/resources/inclusion.metadata +++ /dev/null @@ -1,6 +0,0 @@ -{ - "prover_checksum": "cd85cc53639becf39b9fc927643abda23f9d385ff2cb890f5df809e7a338bff8", - "prover_size": 232051458, - "verifier_checksum": "e6f3add8fb9f911e02e1aa08b761f24cc8ae5fb70df4da47a36a5bbb83b189ec", - "verifier_size": 665 -} \ No newline at end of file diff --git a/parameters/src/testnet3/resources/inclusion.verifier b/parameters/src/testnet3/resources/inclusion.verifier deleted file mode 100644 index 845a9beed7..0000000000 Binary files a/parameters/src/testnet3/resources/inclusion.verifier and /dev/null differ diff --git a/parameters/src/testnet3/resources/join.metadata b/parameters/src/testnet3/resources/join.metadata deleted file mode 100644 index f8a1f72945..0000000000 --- a/parameters/src/testnet3/resources/join.metadata +++ /dev/null @@ -1,6 +0,0 @@ -{ - "prover_checksum": "1a76fe88fe132b46af0e3053cf4509cc02346705ecf592483a3775cd465eee40", - "prover_size": 74596892, - "verifier_checksum": "4f1701b27513a630ba70d9a83bf4b611cfe3c566e7c339ea7151923a6728f240", - "verifier_size": 665 -} \ No newline at end of file diff --git a/parameters/src/testnet3/resources/join.verifier b/parameters/src/testnet3/resources/join.verifier deleted file mode 100644 index 4a483fca1b..0000000000 Binary files a/parameters/src/testnet3/resources/join.verifier and /dev/null differ diff --git a/parameters/src/testnet3/resources/set_validator_state.metadata b/parameters/src/testnet3/resources/set_validator_state.metadata deleted file mode 100644 index f48bd71a94..0000000000 --- a/parameters/src/testnet3/resources/set_validator_state.metadata +++ /dev/null @@ -1,6 +0,0 @@ -{ - "prover_checksum": "5ce19becc2e48750214de6538606e9f5ad9188c811b753045eb32ab4cace626a", - "prover_size": 16990236, - "verifier_checksum": "730d95b5c75918f018e16be47288e372736865b953b29883af552ccf7d63752d", - "verifier_size": 665 -} \ No newline at end of file diff --git a/parameters/src/testnet3/resources/set_validator_state.verifier b/parameters/src/testnet3/resources/set_validator_state.verifier deleted file mode 100644 index a4c4868902..0000000000 Binary files a/parameters/src/testnet3/resources/set_validator_state.verifier and /dev/null differ diff --git a/parameters/src/testnet3/resources/split.metadata b/parameters/src/testnet3/resources/split.metadata deleted file mode 100644 index d57ce0a226..0000000000 --- a/parameters/src/testnet3/resources/split.metadata +++ /dev/null @@ -1,6 +0,0 @@ -{ - "prover_checksum": "e6d12b9f6578fcae9a805296a6e1f7d282b352457ccf34baceba29e618c79ca2", - "prover_size": 75036196, - "verifier_checksum": "2f9733dbd5a671499a8c8e97a0e043a74b97ed1fecf7834f49d0cd39c9ed171c", - "verifier_size": 665 -} \ No newline at end of file diff --git a/parameters/src/testnet3/resources/split.verifier b/parameters/src/testnet3/resources/split.verifier deleted file mode 100644 index c1bf758ed5..0000000000 Binary files a/parameters/src/testnet3/resources/split.verifier and /dev/null differ diff --git a/parameters/src/testnet3/resources/transfer_private.metadata b/parameters/src/testnet3/resources/transfer_private.metadata deleted file mode 100644 index 594bef3696..0000000000 --- a/parameters/src/testnet3/resources/transfer_private.metadata +++ /dev/null @@ -1,6 +0,0 @@ -{ - "prover_checksum": "2b487c0b05c5997a7405bbdcd9583cba17da8adf192d6b314dfa95fd70db18ea", - "prover_size": 75823940, - "verifier_checksum": "3a3cbba0e1e038eb15acba228157885b63a779e5c5cb061466948f408fab8439", - "verifier_size": 665 -} \ No newline at end of file diff --git a/parameters/src/testnet3/resources/transfer_private.verifier b/parameters/src/testnet3/resources/transfer_private.verifier deleted file mode 100644 index d351e3219c..0000000000 Binary files a/parameters/src/testnet3/resources/transfer_private.verifier and /dev/null differ diff --git a/parameters/src/testnet3/resources/transfer_private_to_public.metadata b/parameters/src/testnet3/resources/transfer_private_to_public.metadata deleted file mode 100644 index de95819682..0000000000 --- a/parameters/src/testnet3/resources/transfer_private_to_public.metadata +++ /dev/null @@ -1,6 +0,0 @@ -{ - "prover_checksum": "1ff64cb9cefbbed3416bfb67a0477327446ab5eccc9f725b27df195b948e956f", - "prover_size": 66174244, - "verifier_checksum": "d5b60dec01f95a92b305d914578657d35e1d390ae63e86f0665324b05f0f742d", - "verifier_size": 665 -} \ No newline at end of file diff --git a/parameters/src/testnet3/resources/transfer_private_to_public.verifier b/parameters/src/testnet3/resources/transfer_private_to_public.verifier deleted file mode 100644 index 23a4ad33eb..0000000000 Binary files a/parameters/src/testnet3/resources/transfer_private_to_public.verifier and /dev/null differ diff --git a/parameters/src/testnet3/resources/transfer_public.metadata b/parameters/src/testnet3/resources/transfer_public.metadata deleted file mode 100644 index d1cc764212..0000000000 --- a/parameters/src/testnet3/resources/transfer_public.metadata +++ /dev/null @@ -1,6 +0,0 @@ -{ - "prover_checksum": "a74565e4fd408a90b2d04b0e6c0dea6bf0ab6a27926ef28049da62d18727f6c6", - "prover_size": 28788210, - "verifier_checksum": "a4c2906a95b2f8bdcc6f192a0c71fb0a1c1aa3830feb54454627cf552674932a", - "verifier_size": 665 -} \ No newline at end of file diff --git a/parameters/src/testnet3/resources/transfer_public.verifier b/parameters/src/testnet3/resources/transfer_public.verifier deleted file mode 100644 index d2cd596b91..0000000000 Binary files a/parameters/src/testnet3/resources/transfer_public.verifier and /dev/null differ diff --git a/parameters/src/testnet3/resources/transfer_public_to_private.metadata b/parameters/src/testnet3/resources/transfer_public_to_private.metadata deleted file mode 100644 index 999ada83f5..0000000000 --- a/parameters/src/testnet3/resources/transfer_public_to_private.metadata +++ /dev/null @@ -1,6 +0,0 @@ -{ - "prover_checksum": "1bcddf96204302f7a5eb371c3b482f3a8cc102ff222d8bb85328121d927322e1", - "prover_size": 38288044, - "verifier_checksum": "b094554656f1716b5212a98e9c55e544f87f69575fdcc4a8783b5cb4ed6de54b", - "verifier_size": 665 -} \ No newline at end of file diff --git a/parameters/src/testnet3/resources/transfer_public_to_private.verifier b/parameters/src/testnet3/resources/transfer_public_to_private.verifier deleted file mode 100644 index 9937585a09..0000000000 Binary files a/parameters/src/testnet3/resources/transfer_public_to_private.verifier and /dev/null differ diff --git a/parameters/src/testnet3/resources/unbond_delegator_as_validator.metadata b/parameters/src/testnet3/resources/unbond_delegator_as_validator.metadata deleted file mode 100644 index 26d1165177..0000000000 --- a/parameters/src/testnet3/resources/unbond_delegator_as_validator.metadata +++ /dev/null @@ -1,6 +0,0 @@ -{ - "prover_checksum": "115a86bcc00299fed1f64277fb9688160c425981ce0f62a79cf52515931d9098", - "prover_size": 17159372, - "verifier_checksum": "9585609c87768bf6ebd87cf6b43a4ddfa921a24773feae45e5688685abe36df5", - "verifier_size": 665 -} \ No newline at end of file diff --git a/parameters/src/testnet3/resources/unbond_delegator_as_validator.verifier b/parameters/src/testnet3/resources/unbond_delegator_as_validator.verifier deleted file mode 100644 index 8506f2216b..0000000000 Binary files a/parameters/src/testnet3/resources/unbond_delegator_as_validator.verifier and /dev/null differ diff --git a/parameters/src/testnet3/resources/unbond_public.metadata b/parameters/src/testnet3/resources/unbond_public.metadata deleted file mode 100644 index 458b639921..0000000000 --- a/parameters/src/testnet3/resources/unbond_public.metadata +++ /dev/null @@ -1,6 +0,0 @@ -{ - "prover_checksum": "9547c05b4fad4bb957c1b50b5fa15407cc7996b358fc6154240078a5547d4497", - "prover_size": 17014428, - "verifier_checksum": "09873cdd4edccecc576ed77501a6af9276e4952a3c02e20cded951b27105266a", - "verifier_size": 665 -} \ No newline at end of file diff --git a/parameters/src/testnet3/resources/unbond_public.verifier b/parameters/src/testnet3/resources/unbond_public.verifier deleted file mode 100644 index aaf88c581c..0000000000 Binary files a/parameters/src/testnet3/resources/unbond_public.verifier and /dev/null differ diff --git a/rust-toolchain b/rust-toolchain index 883bde3070..22d6771a47 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.71.1 \ No newline at end of file +1.72.1 diff --git a/synthesizer/Cargo.toml b/synthesizer/Cargo.toml index 9afbf50875..d038cc648a 100644 --- a/synthesizer/Cargo.toml +++ b/synthesizer/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-synthesizer" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Synthesizer for a decentralized virtual machine" homepage = "https://aleo.org" @@ -34,7 +34,6 @@ cuda = [ "algorithms/cuda" ] serial = [ "console/serial", "ledger-block/serial", - "ledger-coinbase/serial", "ledger-committee/serial", "ledger-query/serial", "ledger-store/serial", @@ -52,7 +51,6 @@ wasm = [ "snark", "console/wasm", "ledger-block/wasm", - "ledger-coinbase/wasm", "ledger-committee/wasm", "ledger-query/wasm", "ledger-store/wasm", @@ -69,65 +67,60 @@ harness = false [dependencies.algorithms] package = "snarkvm-algorithms" path = "../algorithms" -version = "=0.16.15" +version = "=0.16.19" [dependencies.circuit] package = "snarkvm-circuit" path = "../circuit" -version = "=0.16.15" +version = "=0.16.19" [dependencies.console] package = "snarkvm-console" path = "../console" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-block] package = "snarkvm-ledger-block" path = "../ledger/block" -version = "=0.16.15" - -[dependencies.ledger-coinbase] -package = "snarkvm-ledger-coinbase" -path = "../ledger/coinbase" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-committee] package = "snarkvm-ledger-committee" path = "../ledger/committee" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-query] package = "snarkvm-ledger-query" path = "../ledger/query" -version = "=0.16.15" +version = "=0.16.19" default-features = false features = [ "query" ] [dependencies.ledger-store] package = "snarkvm-ledger-store" path = "../ledger/store" -version = "=0.16.15" +version = "=0.16.19" [dependencies.synthesizer-process] package = "snarkvm-synthesizer-process" path = "./process" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.synthesizer-program] package = "snarkvm-synthesizer-program" path = "./program" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.synthesizer-snark] package = "snarkvm-synthesizer-snark" path = "./snark" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.aleo-std] -version = "0.1.18" +version = "0.1.24" default-features = false [dependencies.anyhow] diff --git a/synthesizer/benches/kary_merkle_tree.rs b/synthesizer/benches/kary_merkle_tree.rs index 17e7f8eebc..3b41f8a460 100644 --- a/synthesizer/benches/kary_merkle_tree.rs +++ b/synthesizer/benches/kary_merkle_tree.rs @@ -21,7 +21,7 @@ use console::{ collections::kary_merkle_tree::KaryMerkleTree, network::{ prelude::{TestRng, ToBits, Uniform}, - Testnet3, + MainnetV0, }, types::Field, }; @@ -29,7 +29,7 @@ use synthesizer_snark::{ProvingKey, UniversalSRS}; use criterion::Criterion; -type CurrentNetwork = Testnet3; +type CurrentNetwork = MainnetV0; type CurrentAleo = AleoV0; type NativePathHasher = Sha3_256; @@ -42,7 +42,7 @@ const ARITY: u8 = 8; /// Generates the specified number of random Merkle tree leaves. macro_rules! generate_leaves { - ($num_leaves:expr, $rng:expr) => {{ (0..$num_leaves).map(|_| Field::::rand($rng).to_bits_le()).collect::>() }}; + ($num_leaves:expr, $rng:expr) => {{ (0..$num_leaves).map(|_| Field::::rand($rng).to_bits_le()).collect::>() }}; } fn batch_prove(c: &mut Criterion) { @@ -74,14 +74,12 @@ fn batch_prove(c: &mut Criterion) { CurrentAleo::reset(); // Initialize the Merkle path circuit. - let path = KaryMerklePath::, DEPTH, ARITY>::new( - Mode::Private, - merkle_path.clone(), - ); + let path = + KaryMerklePath::, DEPTH, ARITY>::new(Mode::Private, merkle_path); // Initialize the Merkle root. let root = >::Hash::new(Mode::Private, *merkle_tree.root()); // Initialize the Merkle leaf. - let leaf: Vec<_> = Inject::new(Mode::Private, merkle_leaf.clone()); + let leaf: Vec<_> = Inject::new(Mode::Private, merkle_leaf); // Verify the merkle path. let candidate = path.verify(&circuit_leaf_hasher, &circuit_path_hasher, &root, &leaf); diff --git a/synthesizer/process/Cargo.toml b/synthesizer/process/Cargo.toml index 8b3ec8171d..86336cae5d 100644 --- a/synthesizer/process/Cargo.toml +++ b/synthesizer/process/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-synthesizer-process" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "A process for a decentralized virtual machine" homepage = "https://aleo.org" @@ -48,48 +48,48 @@ timer = [ "aleo-std/timer" ] [dependencies.console] package = "snarkvm-console" path = "../../console" -version = "=0.16.15" +version = "=0.16.19" default-features = false features = [ "network", "program", "types" ] [dependencies.circuit] package = "snarkvm-circuit" path = "../../circuit" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-block] package = "snarkvm-ledger-block" path = "../../ledger/block" -version = "=0.16.15" +version = "=0.16.19" [dependencies.ledger-query] package = "snarkvm-ledger-query" path = "../../ledger/query" -version = "=0.16.15" +version = "=0.16.19" default-features = false [dependencies.ledger-store] package = "snarkvm-ledger-store" path = "../../ledger/store" -version = "=0.16.15" +version = "=0.16.19" [dependencies.synthesizer-program] package = "snarkvm-synthesizer-program" path = "../../synthesizer/program" -version = "=0.16.15" +version = "=0.16.19" [dependencies.synthesizer-snark] package = "snarkvm-synthesizer-snark" path = "../../synthesizer/snark" -version = "=0.16.15" +version = "=0.16.19" [dependencies.utilities] package = "snarkvm-utilities" path = "../../utilities" -version = "=0.16.15" +version = "=0.16.19" [dependencies.aleo-std] -version = "0.1.18" +version = "0.1.24" default-features = false [dependencies.colored] diff --git a/synthesizer/process/src/execute.rs b/synthesizer/process/src/execute.rs index 7311f018be..5340eb402c 100644 --- a/synthesizer/process/src/execute.rs +++ b/synthesizer/process/src/execute.rs @@ -32,6 +32,10 @@ impl Process { #[cfg(feature = "aleo-cli")] println!("{}", format!(" • Executing '{locator}'...",).dimmed()); + // This is the root request and does not have a caller. + let caller = None; + // This is the root request and we do not have a root_tvk to pass on. + let root_tvk = None; // Initialize the trace. let trace = Arc::new(RwLock::new(Trace::new())); // Initialize the call stack. @@ -41,7 +45,7 @@ impl Process { // Retrieve the stack. let stack = self.get_stack(request.program_id())?; // Execute the circuit. - let response = stack.execute_function::(call_stack, None, rng)?; + let response = stack.execute_function::(call_stack, caller, root_tvk, rng)?; lap!(timer, "Execute the function"); // Extract the trace. @@ -59,7 +63,7 @@ mod tests { use super::*; use console::types::Address; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; type CurrentAleo = circuit::AleoV0; #[test] diff --git a/synthesizer/process/src/finalize.rs b/synthesizer/process/src/finalize.rs index 974ed1e158..ee1c28906f 100644 --- a/synthesizer/process/src/finalize.rs +++ b/synthesizer/process/src/finalize.rs @@ -448,7 +448,7 @@ mod tests { BlockStore, }; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; type CurrentAleo = circuit::network::AleoV0; #[test] diff --git a/synthesizer/process/src/lib.rs b/synthesizer/process/src/lib.rs index 392574ee2b..53953ecad6 100644 --- a/synthesizer/process/src/lib.rs +++ b/synthesizer/process/src/lib.rs @@ -42,7 +42,7 @@ mod tests; use console::{ account::PrivateKey, network::prelude::*, - program::{Identifier, Literal, Locator, Plaintext, ProgramID, Record, Response, Value}, + program::{compute_function_id, Identifier, Literal, Locator, Plaintext, ProgramID, Record, Response, Value}, types::{Field, U16, U64}, }; use ledger_block::{Deployment, Execution, Fee, Input, Transition}; @@ -283,7 +283,7 @@ impl Process { #[cfg(any(test, feature = "test"))] pub mod test_helpers { use super::*; - use console::{account::PrivateKey, network::Testnet3, program::Identifier}; + use console::{account::PrivateKey, network::MainnetV0, program::Identifier}; use ledger_block::Transition; use ledger_query::Query; use ledger_store::{helpers::memory::BlockMemory, BlockStore}; @@ -291,7 +291,7 @@ pub mod test_helpers { use once_cell::sync::OnceCell; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; type CurrentAleo = circuit::network::AleoV0; pub fn sample_key() -> (Identifier, ProvingKey, VerifyingKey) { diff --git a/synthesizer/process/src/stack/authorization/mod.rs b/synthesizer/process/src/stack/authorization/mod.rs index ec1df28e24..89637fb8d8 100644 --- a/synthesizer/process/src/stack/authorization/mod.rs +++ b/synthesizer/process/src/stack/authorization/mod.rs @@ -238,6 +238,13 @@ fn ensure_request_and_transition_matches( request.tcm(), transition.tcm(), ); + // Ensure the request and transition have the same 'scm'. + ensure!( + request.scm() == transition.scm(), + "The request ({}) and transition ({}) at index {index} must have the same 'scm' in the authorization.", + request.scm(), + transition.scm(), + ); Ok(()) } @@ -247,7 +254,7 @@ pub(crate) mod test_helpers { use crate::Process; use console::account::PrivateKey; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; type CurrentAleo = circuit::AleoV0; /// Returns a sample authorization. diff --git a/synthesizer/process/src/stack/authorize.rs b/synthesizer/process/src/stack/authorize.rs index 5cc289c185..6e740bd50f 100644 --- a/synthesizer/process/src/stack/authorize.rs +++ b/synthesizer/process/src/stack/authorize.rs @@ -33,16 +33,23 @@ impl Stack { // Retrieve the input types. let input_types = self.get_function(&function_name)?.input_types(); lap!(timer, "Retrieve the input types"); + // Set is_root to true. + let is_root = true; + // This is the root request and does not have a caller. + let caller = None; + // This is the root request and we do not have a root_tvk to pass on. + let root_tvk = None; // Compute the request. - let request = Request::sign(private_key, program_id, function_name, inputs, &input_types, rng)?; + let request = + Request::sign(private_key, program_id, function_name, inputs, &input_types, root_tvk, is_root, rng)?; lap!(timer, "Compute the request"); // Initialize the authorization. let authorization = Authorization::new(request.clone()); // Construct the call stack. let call_stack = CallStack::Authorize(vec![request], *private_key, authorization.clone()); // Construct the authorization from the function. - let _response = self.execute_function::(call_stack, None, rng)?; + let _response = self.execute_function::(call_stack, caller, root_tvk, rng)?; finish!(timer, "Construct the authorization from the function"); // Return the authorization. diff --git a/synthesizer/process/src/stack/call/mod.rs b/synthesizer/process/src/stack/call/mod.rs index 5d6578ab73..0dff0bbc18 100644 --- a/synthesizer/process/src/stack/call/mod.rs +++ b/synthesizer/process/src/stack/call/mod.rs @@ -12,12 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::{CallStack, Registers, RegistersCall, StackEvaluate, StackExecute}; +use crate::{stack::Address, CallStack, Registers, RegistersCall, StackEvaluate, StackExecute}; use aleo_std::prelude::{finish, lap, timer}; -use console::{network::prelude::*, program::Request}; +use console::{ + account::Field, + network::prelude::*, + program::{Register, Request, Value, ValueType}, +}; use synthesizer_program::{ Call, CallOperator, + Operand, RegistersLoad, RegistersLoadCircuit, RegistersSigner, @@ -42,6 +47,7 @@ pub trait CallTrait { stack: &(impl StackEvaluate + StackExecute + StackMatches + StackProgram), registers: &mut ( impl RegistersCall + + RegistersSigner + RegistersSignerCircuit + RegistersLoadCircuit + RegistersStoreCircuit @@ -61,8 +67,7 @@ impl CallTrait for Call { let timer = timer!("Call::evaluate"); // Load the operands values. - let inputs: Vec<_> = - self.operands().iter().map(|operand| registers.load(stack.deref(), operand)).try_collect()?; + let inputs: Vec<_> = self.operands().iter().map(|operand| registers.load(stack, operand)).try_collect()?; // Retrieve the substack and resource. let (substack, resource) = match self.operator() { @@ -135,6 +140,7 @@ impl CallTrait for Call { stack: &(impl StackEvaluate + StackExecute + StackMatches + StackProgram), registers: &mut ( impl RegistersCall + + RegistersSigner + RegistersSignerCircuit + RegistersLoadCircuit + RegistersStoreCircuit @@ -177,6 +183,9 @@ impl CallTrait for Call { }; lap!(timer, "Retrieve the substack and resource"); + // If we are not handling the root request, retrieve the root request's tvk + let root_tvk = registers.root_tvk().ok(); + // If the operator is a closure, retrieve the closure and compute the output. let outputs = if let Ok(closure) = substack.program().get_closure(resource) { lap!(timer, "Execute the closure"); @@ -203,6 +212,9 @@ impl CallTrait for Call { // Retrieve the number of public variables in the circuit. let num_public = A::num_public(); + // Indicate that external calls are never a root request. + let is_root = false; + use circuit::Eject; // Eject the existing circuit. let r1cs = A::eject_r1cs_and_reset(); @@ -224,6 +236,8 @@ impl CallTrait for Call { *function.name(), inputs.iter(), &function.input_types(), + root_tvk, + is_root, rng, )?; @@ -236,12 +250,12 @@ impl CallTrait for Call { authorization.push(request.clone()); // Execute the request. - let response = substack.execute_function::(call_stack, console_caller, rng)?; + let response = substack.execute_function::(call_stack, console_caller, root_tvk, rng)?; // Return the request and response. (request, response) } - CallStack::CheckDeployment(_, private_key, ..) | CallStack::PackageRun(_, private_key, ..) => { + CallStack::PackageRun(_, private_key, ..) => { // Compute the request. let request = Request::sign( &private_key, @@ -249,6 +263,8 @@ impl CallTrait for Call { *function.name(), inputs.iter(), &function.input_types(), + root_tvk, + is_root, rng, )?; @@ -257,8 +273,75 @@ impl CallTrait for Call { // Push the request onto the call stack. call_stack.push(request.clone())?; - // Execute the request. - let response = substack.execute_function::(call_stack, console_caller, rng)?; + // Evaluate the request. + let response = substack.execute_function::(call_stack, console_caller, root_tvk, rng)?; + + // Return the request and response. + (request, response) + } + CallStack::CheckDeployment(_, private_key, ..) => { + // Compute the request. + let request = Request::sign( + &private_key, + *substack.program_id(), + *function.name(), + inputs.iter(), + &function.input_types(), + root_tvk, + is_root, + rng, + )?; + + // Compute the address. + let address = Address::try_from(&private_key)?; + // Sample dummy outputs + let outputs = function + .outputs() + .iter() + .map(|output| match output.value_type() { + ValueType::Record(record_name) => { + // Get the register index containing the record. + let index = match output.operand() { + Operand::Register(Register::Locator(index)) => Field::from_u64(*index), + _ => bail!("Expected a `Register::Locator` operand for a record output."), + }; + // Compute the encryption randomizer as `HashToScalar(tvk || index)`. + let randomizer = N::hash_to_scalar_psd2(&[*request.tvk(), index])?; + // Construct the record nonce. + let record_nonce = N::g_scalar_multiply(&randomizer); + Ok(Value::Record(substack.sample_record( + &address, + record_name, + record_nonce, + rng, + )?)) + } + _ => substack.sample_value(&address, output.value_type(), rng), + }) + .collect::>>()?; + // Map the output operands to registers. + let output_registers = function + .outputs() + .iter() + .map(|output| match output.operand() { + Operand::Register(register) => Some(register.clone()), + _ => None, + }) + .collect::>(); + + // Compute the response. + let response = crate::Response::new( + request.network_id(), + substack.program().id(), + function.name(), + request.inputs().len(), + request.tvk(), + request.tcm(), + outputs, + &function.output_types(), + &output_registers, + )?; + // Return the request and response. (request, response) } @@ -281,7 +364,7 @@ impl CallTrait for Call { substack.evaluate_function::(registers.call_stack().replicate(), console_caller)?; // Execute the request. let response = - substack.execute_function::(registers.call_stack(), console_caller, rng)?; + substack.execute_function::(registers.call_stack(), console_caller, root_tvk, rng)?; // Ensure the values are equal. if console_response.outputs() != response.outputs() { #[cfg(debug_assertions)] diff --git a/synthesizer/process/src/stack/deploy.rs b/synthesizer/process/src/stack/deploy.rs index 39b46f2f6f..be662d134f 100644 --- a/synthesizer/process/src/stack/deploy.rs +++ b/synthesizer/process/src/stack/deploy.rs @@ -73,11 +73,28 @@ impl Stack { let program_id = self.program.id(); + // Check that the number of combined constraints does not exceed the deployment limit. + ensure!(deployment.num_combined_constraints()? <= N::MAX_DEPLOYMENT_LIMIT); + // Construct the call stacks and assignments used to verify the certificates. let mut call_stacks = Vec::with_capacity(deployment.verifying_keys().len()); + // The `root_tvk` is `None` when verifying the deployment of an individual circuit. + let root_tvk = None; + + // The `caller` is `None` when verifying the deployment of an individual circuit. + let caller = None; + + // Check that the number of functions matches the number of verifying keys. + ensure!( + deployment.program().functions().len() == deployment.verifying_keys().len(), + "The number of functions in the program does not match the number of verifying keys" + ); + // Iterate through the program functions and construct the callstacks and corresponding assignments. - for function in deployment.program().functions().values() { + for (function, (_, (verifying_key, _))) in + deployment.program().functions().values().zip_eq(deployment.verifying_keys()) + { // Initialize a burner private key. let burner_private_key = PrivateKey::new(rng)?; // Compute the burner address. @@ -98,6 +115,8 @@ impl Stack { }) .collect::>>()?; lap!(timer, "Sample the inputs"); + // Sample 'is_root'. + let is_root = true; // Compute the request, with a burner private key. let request = Request::sign( @@ -106,23 +125,35 @@ impl Stack { *function.name(), inputs.into_iter(), &input_types, + root_tvk, + is_root, rng, )?; lap!(timer, "Compute the request for {}", function.name()); // Initialize the assignments. let assignments = Assignments::::default(); + // Initialize the constraint limit. Account for the constraint added after synthesis that makes the Varuna zerocheck hiding. + let Some(constraint_limit) = verifying_key.circuit_info.num_constraints.checked_sub(1) else { + // Since a deployment must always pay non-zero fee, it must always have at least one constraint. + bail!("The constraint limit of 0 for function '{}' is invalid", function.name()); + }; // Initialize the call stack. - let call_stack = CallStack::CheckDeployment(vec![request], burner_private_key, assignments.clone()); + let call_stack = CallStack::CheckDeployment( + vec![request], + burner_private_key, + assignments.clone(), + Some(constraint_limit as u64), + ); // Append the function name, callstack, and assignments. call_stacks.push((function.name(), call_stack, assignments)); } // Verify the certificates. let rngs = (0..call_stacks.len()).map(|_| StdRng::from_seed(rng.gen())).collect::>(); - cfg_iter!(call_stacks).zip_eq(deployment.verifying_keys()).zip_eq(rngs).try_for_each( + cfg_into_iter!(call_stacks).zip_eq(deployment.verifying_keys()).zip_eq(rngs).try_for_each( |(((function_name, call_stack, assignments), (_, (verifying_key, certificate))), mut rng)| { // Synthesize the circuit. - if let Err(err) = self.execute_function::(call_stack.clone(), None, &mut rng) { + if let Err(err) = self.execute_function::(call_stack, caller, root_tvk, &mut rng) { bail!("Failed to synthesize the circuit for '{function_name}': {err}") } // Check the certificate. diff --git a/synthesizer/process/src/stack/evaluate.rs b/synthesizer/process/src/stack/evaluate.rs index 9dda9b6db2..d00aaa8a11 100644 --- a/synthesizer/process/src/stack/evaluate.rs +++ b/synthesizer/process/src/stack/evaluate.rs @@ -132,11 +132,11 @@ impl StackEvaluate for Stack { let function = self.get_function(request.function_name())?; let inputs = request.inputs(); let signer = *request.signer(); - let caller = match caller { + let (is_root, caller) = match caller { // If a caller is provided, then this is an evaluation of a child function. - Some(caller) => caller.to_address()?, + Some(caller) => (false, caller.to_address()?), // If no caller is provided, then this is an evaluation of a top-level function. - None => signer, + None => (true, signer), }; let tvk = *request.tvk(); @@ -163,7 +163,7 @@ impl StackEvaluate for Stack { lap!(timer, "Initialize the registers"); // Ensure the request is well-formed. - ensure!(request.verify(&function.input_types()), "Request is invalid"); + ensure!(request.verify(&function.input_types(), is_root), "Request is invalid"); lap!(timer, "Verify the request"); // Store the inputs. diff --git a/synthesizer/process/src/stack/execute.rs b/synthesizer/process/src/stack/execute.rs index 20758e5e84..4a2936d910 100644 --- a/synthesizer/process/src/stack/execute.rs +++ b/synthesizer/process/src/stack/execute.rs @@ -135,6 +135,7 @@ impl StackExecute for Stack { &self, mut call_stack: CallStack, console_caller: Option>, + root_tvk: Option>, rng: &mut R, ) -> Result> { let timer = timer!("Stack::execute_function"); @@ -142,6 +143,12 @@ impl StackExecute for Stack { // Ensure the circuit environment is clean. A::reset(); + // If in 'CheckDeployment' mode, set the constraint limit. + // We do not have to reset it after function calls because `CheckDeployment` mode does not execute those. + if let CallStack::CheckDeployment(_, _, _, constraint_limit) = &call_stack { + A::set_constraint_limit(*constraint_limit); + } + // Retrieve the next request. let console_request = call_stack.pop()?; @@ -153,6 +160,8 @@ impl StackExecute for Stack { console_request.network_id() ); + // We can only have a root_tvk if this request was called by another request + ensure!(console_caller.is_some() == root_tvk.is_some()); // Determine if this is the top-level caller. let console_is_root = console_caller.is_none(); @@ -188,12 +197,24 @@ impl StackExecute for Stack { lap!(timer, "Verify the input types"); // Ensure the request is well-formed. - ensure!(console_request.verify(&input_types), "Request is invalid"); + ensure!(console_request.verify(&input_types, console_is_root), "Request is invalid"); lap!(timer, "Verify the console request"); // Initialize the registers. let mut registers = Registers::new(call_stack, self.get_register_types(function.name())?.clone()); + // Set the root tvk, from a parent request or the current request. + // inject the `root_tvk` as `Mode::Private`. + if let Some(root_tvk) = root_tvk { + registers.set_root_tvk(root_tvk); + registers.set_root_tvk_circuit(circuit::Field::::new(circuit::Mode::Private, root_tvk)); + } else { + registers.set_root_tvk(*console_request.tvk()); + registers.set_root_tvk_circuit(circuit::Field::::new(circuit::Mode::Private, *console_request.tvk())); + } + + let root_tvk = Some(registers.root_tvk_circuit()?); + use circuit::{Eject, Inject}; // Inject the transition public key `tpk` as `Mode::Public`. @@ -209,7 +230,7 @@ impl StackExecute for Stack { let caller = Ternary::ternary(&is_root, request.signer(), &parent); // Ensure the request has a valid signature, inputs, and transition view key. - A::assert(request.verify(&input_types, &tpk)); + A::assert(request.verify(&input_types, &tpk, root_tvk, is_root)); lap!(timer, "Verify the circuit request"); // Set the transition signer. @@ -416,7 +437,7 @@ impl StackExecute for Stack { lap!(timer, "Save the transition"); } // If the circuit is in `CheckDeployment` mode, then save the assignment. - else if let CallStack::CheckDeployment(_, _, ref assignments) = registers.call_stack() { + else if let CallStack::CheckDeployment(_, _, ref assignments, _) = registers.call_stack() { // Construct the call metrics. let metrics = CallMetrics { program_id: *self.program_id(), diff --git a/synthesizer/process/src/stack/finalize_types/initialize.rs b/synthesizer/process/src/stack/finalize_types/initialize.rs index e36fe3d552..25bb0c7ca9 100644 --- a/synthesizer/process/src/stack/finalize_types/initialize.rs +++ b/synthesizer/process/src/stack/finalize_types/initialize.rs @@ -660,7 +660,27 @@ impl FinalizeTypes { } } } - "cast.lossy" => bail!("Instruction '{instruction}' is not supported yet."), + "cast.lossy" => { + // Retrieve the cast operation. + let operation = match instruction { + Instruction::CastLossy(operation) => operation, + _ => bail!("Instruction '{instruction}' is not a cast.lossy operation."), + }; + + // Ensure the instruction has one destination register. + ensure!( + instruction.destinations().len() == 1, + "Instruction '{instruction}' has multiple destinations." + ); + + // Ensure the casted register type is valid and defined. + match operation.cast_type() { + CastType::Plaintext(PlaintextType::Literal(_)) => { + ensure!(instruction.operands().len() == 1, "Expected 1 operand."); + } + _ => bail!("`cast.lossy` is only supported for casting to a literal type."), + } + } _ => bail!("Instruction '{instruction}' is not for opcode '{opcode}'."), }, Opcode::Command(opcode) => { diff --git a/synthesizer/process/src/stack/helpers/matches.rs b/synthesizer/process/src/stack/helpers/matches.rs index 975045943f..4ed9a81de7 100644 --- a/synthesizer/process/src/stack/helpers/matches.rs +++ b/synthesizer/process/src/stack/helpers/matches.rs @@ -13,7 +13,6 @@ // limitations under the License. use super::*; -use console::program::{Argument, FinalizeType}; impl StackMatches for Stack { /// Checks that the given value matches the layout of the value type. diff --git a/synthesizer/process/src/stack/helpers/sample.rs b/synthesizer/process/src/stack/helpers/sample.rs index 0ad9f94171..ed9eaaf9d0 100644 --- a/synthesizer/process/src/stack/helpers/sample.rs +++ b/synthesizer/process/src/stack/helpers/sample.rs @@ -15,42 +15,6 @@ use super::*; impl Stack { - /// Returns a value for the given value type. - pub fn sample_value( - &self, - burner_address: &Address, - value_type: &ValueType, - rng: &mut R, - ) -> Result> { - match value_type { - ValueType::Constant(plaintext_type) - | ValueType::Public(plaintext_type) - | ValueType::Private(plaintext_type) => Ok(Value::Plaintext(self.sample_plaintext(plaintext_type, rng)?)), - ValueType::Record(record_name) => { - Ok(Value::Record(self.sample_record(burner_address, record_name, rng)?)) - } - ValueType::ExternalRecord(locator) => { - bail!("Illegal operation: Cannot sample external records (for '{locator}.record').") - } - ValueType::Future(locator) => bail!("Illegal operation: Cannot sample futures (for '{locator}.future')."), - } - } - - /// Returns a record for the given record name, with the given burner address. - pub fn sample_record( - &self, - burner_address: &Address, - record_name: &Identifier, - rng: &mut R, - ) -> Result>> { - // Sample a record. - let record = self.sample_record_internal(burner_address, record_name, 0, rng)?; - // Ensure the record matches the value type. - self.matches_record(&record, record_name)?; - // Return the record. - Ok(record) - } - /// Samples a plaintext value according to the given plaintext type. pub fn sample_plaintext( &self, @@ -64,14 +28,23 @@ impl Stack { // Return the plaintext value. Ok(plaintext) } -} -impl Stack { + /// Samples a future value according to the given future type. + pub fn sample_future(&self, locator: &Locator, rng: &mut R) -> Result> { + // Sample a future value. + let future = self.sample_future_internal(locator, 0, rng)?; + // Ensure the future value matches the future type. + self.matches_future(&future, locator)?; + // Return the future value. + Ok(future) + } + /// Returns a record for the given record name. - fn sample_record_internal( + pub(crate) fn sample_record_internal( &self, burner_address: &Address, record_name: &Identifier, + nonce: Group, depth: usize, rng: &mut R, ) -> Result>> { @@ -99,9 +72,6 @@ impl Stack { }) .collect::>>()?; - // Initialize the nonce. - let nonce = Group::rand(rng); - // Return the record. Record::>::from_plaintext(owner, data, nonce) } @@ -182,4 +152,46 @@ impl Stack { // Return the plaintext. Ok(plaintext) } + + /// Samples a future value according to the given locator. + fn sample_future_internal( + &self, + locator: &Locator, + depth: usize, + rng: &mut R, + ) -> Result> { + // Retrieve the associated function. + let function = match locator.program_id() == self.program_id() { + true => self.get_function_ref(locator.resource())?, + false => self.get_external_program(locator.program_id())?.get_function_ref(locator.resource())?, + }; + + // Retrieve the finalize inputs. + let inputs = match function.finalize_logic() { + Some(finalize_logic) => finalize_logic.inputs(), + None => bail!("Function '{locator}' does not have a finalize block"), + }; + + let arguments = inputs + .into_iter() + .map(|input| { + match input.finalize_type() { + FinalizeType::Plaintext(plaintext_type) => { + // Sample the plaintext value. + let plaintext = self.sample_plaintext_internal(plaintext_type, depth + 1, rng)?; + // Return the argument. + Ok(Argument::Plaintext(plaintext)) + } + FinalizeType::Future(locator) => { + // Sample the future value. + let future = self.sample_future_internal(locator, depth + 1, rng)?; + // Return the argument. + Ok(Argument::Future(future)) + } + } + }) + .collect::>>()?; + + Ok(Future::new(*locator.program_id(), *locator.resource(), arguments)) + } } diff --git a/synthesizer/process/src/stack/helpers/synthesize.rs b/synthesizer/process/src/stack/helpers/synthesize.rs index c3530d0071..72d7d7bc24 100644 --- a/synthesizer/process/src/stack/helpers/synthesize.rs +++ b/synthesizer/process/src/stack/helpers/synthesize.rs @@ -49,16 +49,32 @@ impl Stack { _ => self.sample_value(&burner_address, input_type, rng), }) .collect::>>()?; + // Sample 'is_root'. + let is_root = true; + + // The `root_tvk` is `None` when deploying an individual circuit. + let root_tvk = None; + + // The caller is `None` when deploying an individual circuit. + let caller = None; // Compute the request, with a burner private key. - let request = - Request::sign(&burner_private_key, *program_id, *function_name, inputs.into_iter(), &input_types, rng)?; + let request = Request::sign( + &burner_private_key, + *program_id, + *function_name, + inputs.into_iter(), + &input_types, + root_tvk, + is_root, + rng, + )?; // Initialize the authorization. let authorization = Authorization::new(request.clone()); // Initialize the call stack. let call_stack = CallStack::Synthesize(vec![request], burner_private_key, authorization); // Synthesize the circuit. - let _response = self.execute_function::(call_stack, None, rng)?; + let _response = self.execute_function::(call_stack, caller, root_tvk, rng)?; // Ensure the proving key exists. ensure!(self.contains_proving_key(function_name), "Function '{function_name}' is missing a proving key."); diff --git a/synthesizer/process/src/stack/mod.rs b/synthesizer/process/src/stack/mod.rs index 2b95b46fb7..8f23e126d8 100644 --- a/synthesizer/process/src/stack/mod.rs +++ b/synthesizer/process/src/stack/mod.rs @@ -41,8 +41,10 @@ use console::{ account::{Address, PrivateKey}, network::prelude::*, program::{ + Argument, Entry, EntryType, + FinalizeType, Future, Identifier, Literal, @@ -79,7 +81,7 @@ pub type Assignments = Arc pub enum CallStack { Authorize(Vec>, PrivateKey, Authorization), Synthesize(Vec>, PrivateKey, Authorization), - CheckDeployment(Vec>, PrivateKey, Assignments), + CheckDeployment(Vec>, PrivateKey, Assignments, Option), Evaluate(Authorization), Execute(Authorization, Arc>>), PackageRun(Vec>, PrivateKey, Assignments), @@ -107,11 +109,14 @@ impl CallStack { CallStack::Synthesize(requests, private_key, authorization) => { CallStack::Synthesize(requests.clone(), *private_key, authorization.replicate()) } - CallStack::CheckDeployment(requests, private_key, assignments) => CallStack::CheckDeployment( - requests.clone(), - *private_key, - Arc::new(RwLock::new(assignments.read().clone())), - ), + CallStack::CheckDeployment(requests, private_key, assignments, constraint_limit) => { + CallStack::CheckDeployment( + requests.clone(), + *private_key, + Arc::new(RwLock::new(assignments.read().clone())), + *constraint_limit, + ) + } CallStack::Evaluate(authorization) => CallStack::Evaluate(authorization.replicate()), CallStack::Execute(authorization, trace) => { CallStack::Execute(authorization.replicate(), Arc::new(RwLock::new(trace.read().clone()))) @@ -292,6 +297,46 @@ impl StackProgram for Stack { } Ok(num_calls) } + + /// Returns a value for the given value type. + fn sample_value( + &self, + burner_address: &Address, + value_type: &ValueType, + rng: &mut R, + ) -> Result> { + match value_type { + ValueType::Constant(plaintext_type) + | ValueType::Public(plaintext_type) + | ValueType::Private(plaintext_type) => Ok(Value::Plaintext(self.sample_plaintext(plaintext_type, rng)?)), + ValueType::Record(record_name) => { + Ok(Value::Record(self.sample_record(burner_address, record_name, Group::rand(rng), rng)?)) + } + ValueType::ExternalRecord(locator) => { + // Retrieve the external stack. + let stack = self.get_external_stack(locator.program_id())?; + // Sample the output. + Ok(Value::Record(stack.sample_record(burner_address, locator.resource(), Group::rand(rng), rng)?)) + } + ValueType::Future(locator) => Ok(Value::Future(self.sample_future(locator, rng)?)), + } + } + + /// Returns a record for the given record name, with the given burner address and nonce. + fn sample_record( + &self, + burner_address: &Address, + record_name: &Identifier, + nonce: Group, + rng: &mut R, + ) -> Result>> { + // Sample a record. + let record = self.sample_record_internal(burner_address, record_name, nonce, 0, rng)?; + // Ensure the record matches the value type. + self.matches_record(&record, record_name)?; + // Return the record. + Ok(record) + } } impl StackProgramTypes for Stack { @@ -376,13 +421,13 @@ impl Stack { /// Removes the proving key for the given function name. #[inline] pub fn remove_proving_key(&self, function_name: &Identifier) { - self.proving_keys.write().remove(function_name); + self.proving_keys.write().shift_remove(function_name); } /// Removes the verifying key for the given function name. #[inline] pub fn remove_verifying_key(&self, function_name: &Identifier) { - self.verifying_keys.write().remove(function_name); + self.verifying_keys.write().shift_remove(function_name); } } diff --git a/synthesizer/process/src/stack/register_types/initialize.rs b/synthesizer/process/src/stack/register_types/initialize.rs index 7b3265a1f5..abfec5a480 100644 --- a/synthesizer/process/src/stack/register_types/initialize.rs +++ b/synthesizer/process/src/stack/register_types/initialize.rs @@ -554,7 +554,27 @@ impl RegisterTypes { } } } - "cast.lossy" => bail!("Instruction '{instruction}' is not supported yet."), + "cast.lossy" => { + // Retrieve the cast operation. + let operation = match instruction { + Instruction::CastLossy(operation) => operation, + _ => bail!("Instruction '{instruction}' is not a cast.lossy operation."), + }; + + // Ensure the instruction has one destination register. + ensure!( + instruction.destinations().len() == 1, + "Instruction '{instruction}' has multiple destinations." + ); + + // Ensure the casted register type is valid and defined. + match operation.cast_type() { + CastType::Plaintext(PlaintextType::Literal(_)) => { + ensure!(instruction.operands().len() == 1, "Expected 1 operand."); + } + _ => bail!("`cast.lossy` is only supported for casting to a literal type."), + } + } _ => bail!("Instruction '{instruction}' is not for opcode '{opcode}'."), }, Opcode::Command(opcode) => { diff --git a/synthesizer/process/src/stack/registers/caller.rs b/synthesizer/process/src/stack/registers/caller.rs index ddea05cdec..3839138afe 100644 --- a/synthesizer/process/src/stack/registers/caller.rs +++ b/synthesizer/process/src/stack/registers/caller.rs @@ -27,6 +27,18 @@ impl> RegistersSigner for Registers self.signer = Some(signer); } + /// Returns the root transition view key. + #[inline] + fn root_tvk(&self) -> Result> { + self.root_tvk.ok_or_else(|| anyhow!("Root tvk (console) is not set in the registers.")) + } + + /// Sets the root transition view key. + #[inline] + fn set_root_tvk(&mut self, root_tvk: Field) { + self.root_tvk = Some(root_tvk); + } + /// Returns the transition caller. #[inline] fn caller(&self) -> Result> { @@ -65,6 +77,18 @@ impl> RegistersSignerCircuit for self.signer_circuit = Some(signer_circuit); } + /// Returns the root transition view key, as a circuit. + #[inline] + fn root_tvk_circuit(&self) -> Result> { + self.root_tvk_circuit.clone().ok_or_else(|| anyhow!("Root tvk (circuit) is not set in the registers.")) + } + + /// Sets the root transition view key, as a circuit. + #[inline] + fn set_root_tvk_circuit(&mut self, root_tvk_circuit: circuit::Field) { + self.root_tvk_circuit = Some(root_tvk_circuit); + } + /// Returns the transition caller, as a circuit. #[inline] fn caller_circuit(&self) -> Result> { diff --git a/synthesizer/process/src/stack/registers/mod.rs b/synthesizer/process/src/stack/registers/mod.rs index 3e6af26bbc..225a194d31 100644 --- a/synthesizer/process/src/stack/registers/mod.rs +++ b/synthesizer/process/src/stack/registers/mod.rs @@ -51,6 +51,10 @@ pub struct Registers> { signer: Option>, /// The transition signer, as a circuit. signer_circuit: Option>, + /// The root transition view key. + root_tvk: Option>, + /// The root transition view key, as a circuit. + root_tvk_circuit: Option>, /// The transition caller. caller: Option>, /// The transition caller, as a circuit. @@ -72,6 +76,8 @@ impl> Registers { circuit_registers: IndexMap::new(), signer: None, signer_circuit: None, + root_tvk: None, + root_tvk_circuit: None, caller: None, caller_circuit: None, tvk: None, diff --git a/synthesizer/process/src/tests/test_credits.rs b/synthesizer/process/src/tests/test_credits.rs index aefae59a3c..201a9a7313 100644 --- a/synthesizer/process/src/tests/test_credits.rs +++ b/synthesizer/process/src/tests/test_credits.rs @@ -16,7 +16,7 @@ use crate::Process; use circuit::network::AleoV0; use console::{ account::{Address, PrivateKey}, - network::{prelude::*, Testnet3}, + network::{prelude::*, MainnetV0}, program::{Identifier, Literal, Plaintext, ProgramID, Value}, types::U64, }; @@ -34,7 +34,7 @@ use synthesizer_program::{FinalizeGlobalState, FinalizeStoreTrait, Program}; use indexmap::IndexMap; -type CurrentNetwork = Testnet3; +type CurrentNetwork = MainnetV0; type CurrentAleo = AleoV0; const NUM_BLOCKS_TO_UNLOCK: u32 = 360; @@ -1520,14 +1520,20 @@ mod sanity_checks { let program_id = *program.id(); // Retrieve the input types. let input_types = program.get_function(&function_name).unwrap().input_types(); + // Sample 'root_tvk'. + let root_tvk = None; + // Sample 'is_root'. + let is_root = true; // Compute the request. - let request = Request::sign(private_key, program_id, function_name, inputs.iter(), &input_types, rng).unwrap(); + let request = + Request::sign(private_key, program_id, function_name, inputs.iter(), &input_types, root_tvk, is_root, rng) + .unwrap(); // Initialize the assignments. let assignments = Assignments::::default(); // Initialize the call stack. - let call_stack = CallStack::CheckDeployment(vec![request], *private_key, assignments.clone()); + let call_stack = CallStack::CheckDeployment(vec![request], *private_key, assignments.clone(), None); // Synthesize the circuit. - let _response = stack.execute_function::(call_stack, None, rng).unwrap(); + let _response = stack.execute_function::(call_stack, None, None, rng).unwrap(); // Retrieve the assignment. let assignment = assignments.read().last().unwrap().0.clone(); assignment @@ -1560,10 +1566,10 @@ mod sanity_checks { // Compute the assignment. let assignment = get_assignment::<_, CurrentAleo>(stack, &private_key, function_name, &[r0, r1, r2], rng); - assert_eq!(15, assignment.num_public()); - assert_eq!(50681, assignment.num_private()); - assert_eq!(50729, assignment.num_constraints()); - assert_eq!((98547, 109769, 77341), assignment.num_nonzeros()); + assert_eq!(16, assignment.num_public()); + assert_eq!(50956, assignment.num_private()); + assert_eq!(51002, assignment.num_constraints()); + assert_eq!((99540, 111472, 77613), assignment.num_nonzeros()); } #[test] @@ -1588,10 +1594,10 @@ mod sanity_checks { // Compute the assignment. let assignment = get_assignment::<_, CurrentAleo>(stack, &private_key, function_name, &[r0, r1], rng); - assert_eq!(10, assignment.num_public()); - assert_eq!(12043, assignment.num_private()); - assert_eq!(12052, assignment.num_constraints()); - assert_eq!((27250, 36303, 16407), assignment.num_nonzeros()); + assert_eq!(11, assignment.num_public()); + assert_eq!(12318, assignment.num_private()); + assert_eq!(12325, assignment.num_constraints()); + assert_eq!((28243, 38006, 16679), assignment.num_nonzeros()); } #[test] @@ -1622,10 +1628,10 @@ mod sanity_checks { // Compute the assignment. let assignment = get_assignment::<_, CurrentAleo>(stack, &private_key, function_name, &[r0, r1, r2, r3], rng); - assert_eq!(14, assignment.num_public()); - assert_eq!(37840, assignment.num_private()); - assert_eq!(37878, assignment.num_constraints()); - assert_eq!((72163, 80588, 56623), assignment.num_nonzeros()); + assert_eq!(15, assignment.num_public()); + assert_eq!(38115, assignment.num_private()); + assert_eq!(38151, assignment.num_constraints()); + assert_eq!((73156, 82291, 56895), assignment.num_nonzeros()); } #[test] @@ -1650,9 +1656,9 @@ mod sanity_checks { // Compute the assignment. let assignment = get_assignment::<_, CurrentAleo>(stack, &private_key, function_name, &[r0, r1, r2], rng); - assert_eq!(11, assignment.num_public()); - assert_eq!(12645, assignment.num_private()); - assert_eq!(12657, assignment.num_constraints()); - assert_eq!((29594, 39585, 16941), assignment.num_nonzeros()); + assert_eq!(12, assignment.num_public()); + assert_eq!(12920, assignment.num_private()); + assert_eq!(12930, assignment.num_constraints()); + assert_eq!((30587, 41288, 17213), assignment.num_nonzeros()); } } diff --git a/synthesizer/process/src/tests/test_execute.rs b/synthesizer/process/src/tests/test_execute.rs index 1837b54967..61b80a33ff 100644 --- a/synthesizer/process/src/tests/test_execute.rs +++ b/synthesizer/process/src/tests/test_execute.rs @@ -21,7 +21,7 @@ use crate::{ use circuit::{network::AleoV0, Aleo}; use console::{ account::{Address, PrivateKey, ViewKey}, - network::{prelude::*, Testnet3}, + network::{prelude::*, MainnetV0}, program::{Identifier, Literal, Plaintext, ProgramID, Record, Value}, types::{Field, U64}, }; @@ -41,7 +41,7 @@ use indexmap::IndexMap; use parking_lot::RwLock; use std::sync::Arc; -type CurrentNetwork = Testnet3; +type CurrentNetwork = MainnetV0; type CurrentAleo = AleoV0; /// Samples a new finalize state. @@ -395,7 +395,7 @@ output r4 as field.private;", // Re-run to ensure state continues to work. let trace = Arc::new(RwLock::new(Trace::new())); let call_stack = CallStack::execute(authorization, trace).unwrap(); - let response = stack.execute_function::(call_stack, None, rng).unwrap(); + let response = stack.execute_function::(call_stack, None, None, rng).unwrap(); let candidate = response.outputs(); assert_eq!(3, candidate.len()); assert_eq!(r2, candidate[0]); @@ -1926,7 +1926,7 @@ function a: // Construct the expected transition order. let expected_order = [ - (program0.id(), Identifier::::from_str("c").unwrap()), + (program0.id(), Identifier::::from_str("c").unwrap()), (program1.id(), Identifier::from_str("b").unwrap()), (program2.id(), Identifier::from_str("a").unwrap()), ]; @@ -2108,16 +2108,16 @@ fn test_complex_execution_order() { // Construct the expected execution order. let expected_order = [ - (program0.id(), Identifier::::from_str("c").unwrap()), - (program1.id(), Identifier::::from_str("d").unwrap()), - (program2.id(), Identifier::::from_str("b").unwrap()), - (program0.id(), Identifier::::from_str("c").unwrap()), - (program1.id(), Identifier::::from_str("d").unwrap()), - (program2.id(), Identifier::::from_str("b").unwrap()), - (program1.id(), Identifier::::from_str("d").unwrap()), - (program0.id(), Identifier::::from_str("c").unwrap()), - (program3.id(), Identifier::::from_str("e").unwrap()), - (program4.id(), Identifier::::from_str("a").unwrap()), + (program0.id(), Identifier::::from_str("c").unwrap()), + (program1.id(), Identifier::::from_str("d").unwrap()), + (program2.id(), Identifier::::from_str("b").unwrap()), + (program0.id(), Identifier::::from_str("c").unwrap()), + (program1.id(), Identifier::::from_str("d").unwrap()), + (program2.id(), Identifier::::from_str("b").unwrap()), + (program1.id(), Identifier::::from_str("d").unwrap()), + (program0.id(), Identifier::::from_str("c").unwrap()), + (program3.id(), Identifier::::from_str("e").unwrap()), + (program4.id(), Identifier::::from_str("a").unwrap()), ]; for (transition, (expected_program_id, expected_function_name)) in trace.transitions().iter().zip_eq(expected_order.iter()) diff --git a/synthesizer/process/src/trace/mod.rs b/synthesizer/process/src/trace/mod.rs index 988be7ad29..69789b89f2 100644 --- a/synthesizer/process/src/trace/mod.rs +++ b/synthesizer/process/src/trace/mod.rs @@ -314,9 +314,6 @@ impl Trace { verifier_inputs.push((verifying_key, batch_inclusion_inputs)); } // Verify the proof. - match VerifyingKey::verify_batch(locator, verifier_inputs, proof) { - true => Ok(()), - false => bail!("Failed to verify proof"), - } + VerifyingKey::verify_batch(locator, verifier_inputs, proof).map_err(|e| anyhow!("Failed to verify proof - {e}")) } } diff --git a/synthesizer/process/src/traits/mod.rs b/synthesizer/process/src/traits/mod.rs index c82b4ffd59..d0b6856a8f 100644 --- a/synthesizer/process/src/traits/mod.rs +++ b/synthesizer/process/src/traits/mod.rs @@ -72,6 +72,7 @@ pub trait StackExecute { &self, call_stack: CallStack, console_caller: Option>, + root_tvk: Option>, rng: &mut R, ) -> Result>; } diff --git a/synthesizer/process/src/verify_execution.rs b/synthesizer/process/src/verify_execution.rs index f4c57cf744..7684a5099f 100644 --- a/synthesizer/process/src/verify_execution.rs +++ b/synthesizer/process/src/verify_execution.rs @@ -73,16 +73,10 @@ impl Process { // Ensure the number of outputs is within the allowed range. ensure!(transition.outputs().len() <= N::MAX_OUTPUTS, "Transition exceeded maximum number of outputs"); - // Compute the function ID as `Hash(network_id, program_id, function_name)`. - let function_id = N::hash_bhp1024( - &( - U16::::new(N::ID), - transition.program_id().name(), - transition.program_id().network(), - transition.function_name(), - ) - .to_bits_le(), - )?; + // Retrieve the network ID. + let network_id = U16::new(N::ID); + // Compute the function ID. + let function_id = compute_function_id(&network_id, transition.program_id(), transition.function_name())?; // Ensure each input is valid. if transition @@ -137,6 +131,16 @@ impl Process { let num_instances = verifier_inputs.values().map(|(_, inputs)| inputs.len()).sum::(); // Ensure the number of instances matches the number of transitions. ensure!(num_instances == execution.transitions().len(), "The number of verifier instances is incorrect"); + // Ensure the same signer is used for all transitions. + execution.transitions().try_fold(None, |signer, transition| { + Ok(match signer { + None => Some(transition.scm()), + Some(signer) => { + ensure!(signer == transition.scm(), "The transitions did not use the same signer"); + Some(signer) + } + }) + })?; // Construct the list of verifier inputs. let verifier_inputs: Vec<_> = verifier_inputs.values().cloned().collect(); @@ -173,7 +177,7 @@ impl Process { let (parent_x, parent_y) = parent.to_address()?.to_xy_coordinates(); // [Inputs] Construct the verifier inputs to verify the proof. - let mut inputs = vec![N::Field::one(), *tpk_x, *tpk_y, **transition.tcm()]; + let mut inputs = vec![N::Field::one(), *tpk_x, *tpk_y, **transition.tcm(), **transition.scm()]; // [Inputs] Extend the verifier inputs with the input IDs. inputs.extend(transition.inputs().iter().flat_map(|input| input.verifier_inputs())); // [Inputs] Extend the verifier inputs with the public inputs for 'self.caller'. diff --git a/synthesizer/process/src/verify_fee.rs b/synthesizer/process/src/verify_fee.rs index 5d7a9455c4..71b92dafc5 100644 --- a/synthesizer/process/src/verify_fee.rs +++ b/synthesizer/process/src/verify_fee.rs @@ -76,11 +76,10 @@ impl Process { fn verify_fee_private(&self, fee: &&Fee) -> Result<()> { let timer = timer!("Process::verify_fee_private"); - // Compute the function ID as `Hash(network_id, program_id, function_name)`. - let function_id = N::hash_bhp1024( - &(U16::::new(N::ID), fee.program_id().name(), fee.program_id().network(), fee.function_name()) - .to_bits_le(), - )?; + // Retrieve the network ID. + let network_id = U16::new(N::ID); + // Compute the function ID. + let function_id = compute_function_id(&network_id, fee.program_id(), fee.function_name())?; // Ensure the fee contains 1 input record. ensure!( @@ -120,7 +119,7 @@ impl Process { let (parent_x, parent_y) = fee.program_id().to_address()?.to_xy_coordinates(); // Construct the public inputs to verify the proof. - let mut inputs = vec![N::Field::one(), *tpk_x, *tpk_y, **fee.tcm()]; + let mut inputs = vec![N::Field::one(), *tpk_x, *tpk_y, **fee.tcm(), **fee.scm()]; // Extend the inputs with the input IDs. inputs.extend(fee.inputs().iter().flat_map(|input| input.verifier_inputs())); // Extend the verifier inputs with the public inputs for 'self.caller'. @@ -146,11 +145,10 @@ impl Process { fn verify_fee_public(&self, fee: &&Fee) -> Result<()> { let timer = timer!("Process::verify_fee_public"); - // Compute the function ID as `Hash(network_id, program_id, function_name)`. - let function_id = N::hash_bhp1024( - &(U16::::new(N::ID), fee.program_id().name(), fee.program_id().network(), fee.function_name()) - .to_bits_le(), - )?; + // Retrieve the network ID. + let network_id = U16::new(N::ID); + // Compute the function ID. + let function_id = compute_function_id(&network_id, fee.program_id(), fee.function_name())?; // Ensure the fee contains all public inputs. ensure!( @@ -190,7 +188,7 @@ impl Process { let (parent_x, parent_y) = fee.program_id().to_address()?.to_xy_coordinates(); // Construct the public inputs to verify the proof. - let mut inputs = vec![N::Field::one(), *tpk_x, *tpk_y, **fee.tcm()]; + let mut inputs = vec![N::Field::one(), *tpk_x, *tpk_y, **fee.tcm(), **fee.scm()]; // Extend the inputs with the input IDs. inputs.extend(fee.inputs().iter().flat_map(|input| input.verifier_inputs())); // Extend the verifier inputs with the public inputs for 'self.caller' @@ -241,17 +239,17 @@ mod tests { // Compute the deployment ID. let deployment_id = deployment.to_deployment_id().unwrap(); // Verify the fee. - assert!(process.verify_fee(&fee, deployment_id).is_ok()); + process.verify_fee(&fee, deployment_id).unwrap(); } Transaction::Execute(_, execution, fee) => { // Compute the execution ID. let execution_id = execution.to_execution_id().unwrap(); // Verify the fee. - assert!(process.verify_fee(&fee.unwrap(), execution_id).is_ok()); + process.verify_fee(&fee.unwrap(), execution_id).unwrap(); } Transaction::Fee(_, fee) => match fee.is_fee_private() { - true => assert!(process.verify_fee_private(&&fee).is_ok()), - false => assert!(process.verify_fee_public(&&fee).is_ok()), + true => process.verify_fee_private(&&fee).unwrap(), + false => process.verify_fee_public(&&fee).unwrap(), }, } } diff --git a/synthesizer/program/Cargo.toml b/synthesizer/program/Cargo.toml index ae2ad7a9ba..9c1515671c 100644 --- a/synthesizer/program/Cargo.toml +++ b/synthesizer/program/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-synthesizer-program" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Program for a decentralized virtual machine" homepage = "https://aleo.org" @@ -31,12 +31,12 @@ wasm = [ "console/wasm" ] [dependencies.circuit] package = "snarkvm-circuit" path = "../../circuit" -version = "=0.16.15" +version = "=0.16.19" [dependencies.console] package = "snarkvm-console" path = "../../console" -version = "=0.16.15" +version = "=0.16.19" default-features = false features = [ "account", "network", "program", "types" ] diff --git a/synthesizer/program/benches/instruction.rs b/synthesizer/program/benches/instruction.rs index 7940c49261..fcf76c4e44 100644 --- a/synthesizer/program/benches/instruction.rs +++ b/synthesizer/program/benches/instruction.rs @@ -18,7 +18,7 @@ // extern crate criterion; // // use console::{ -// network::{Testnet3, Network}, +// network::{MainnetV0, Network}, // prelude::{TestRng, Uniform, Zero}, // program::{ // Identifier, @@ -62,10 +62,10 @@ // // /// A helper function to construct a set of `FinalizeRegisters` with the given arguments. // fn setup_finalize_registers( -// stack: &Stack, +// stack: &Stack, // finalize_body: impl Display, -// args: &[Value], -// ) -> FinalizeRegisters { +// args: &[Value], +// ) -> FinalizeRegisters { // // Initialize a `Finalize` block with the benchmark arguments as inputs. // let mut finalize_string = "finalize foo:".to_string(); // for (i, arg) in args.iter().enumerate() { @@ -75,11 +75,11 @@ // })); // } // finalize_string.push_str(&finalize_body.to_string()); -// let finalize = Finalize::::from_str(&finalize_string).unwrap(); +// let finalize = Finalize::::from_str(&finalize_string).unwrap(); // // Construct the finalize state. -// let state = FinalizeGlobalState::new::(0, 0, 0, 0, ::BlockHash::default()).unwrap(); +// let state = FinalizeGlobalState::new::(0, 0, 0, 0, ::BlockHash::default()).unwrap(); // // Initialize a fresh set of finalize registers. -// let mut registers = FinalizeRegisters::new(state, ::TransitionID::default(), Identifier::from_str("test").unwrap(), FinalizeTypes::from_finalize(stack, &finalize).unwrap()); +// let mut registers = FinalizeRegisters::new(state, ::TransitionID::default(), Identifier::from_str("test").unwrap(), FinalizeTypes::from_finalize(stack, &finalize).unwrap()); // // Add the arguments into the registers. // for (i, arg) in args.iter().enumerate() { // registers.store(stack, &Register::Locator(i as u64), arg.clone()).unwrap(); @@ -92,7 +92,7 @@ // // Initialize an RNG. // let rng = &mut TestRng::default(); // // Initialize a process. -// let process = Process::::load().unwrap(); +// let process = Process::::load().unwrap(); // // Get the stack for the credits program. // // Note that this is not used for anything other than to satisfy the function signature for `finalize`. // // This is because `Stack`s are only used in finalize contexts to check that structs are well-formed. @@ -104,7 +104,7 @@ // { // use snarkvm_synthesizer_program::$instruction; // let name = concat!(stringify!($instruction), "/", stringify!($input)); -// let instruction = Instruction::::$instruction($instruction::from_str(&format!("{} r0 into r1", $instruction::::opcode().to_string())).unwrap()); +// let instruction = Instruction::::$instruction($instruction::from_str(&format!("{} r0 into r1", $instruction::::opcode().to_string())).unwrap()); // c.bench_function(&format!("{name}/instruction"), |b| { // b.iter_batched( // || { @@ -122,7 +122,7 @@ // { // use snarkvm_synthesizer_program::$instruction; // let name = concat!(stringify!($instruction), "/", stringify!($input)); -// let instruction = Instruction::::$instruction($instruction::from_str(&format!("{} r0 into r1 as {}", $instruction::::opcode().to_string(), $as_type)).unwrap()); +// let instruction = Instruction::::$instruction($instruction::from_str(&format!("{} r0 into r1 as {}", $instruction::::opcode().to_string(), $as_type)).unwrap()); // c.bench_function(&format!("{name}/instruction"), |b| { // b.iter_batched( // || { @@ -140,7 +140,7 @@ // { // use snarkvm_synthesizer_program::$instruction; // let name = concat!(stringify!($instruction), "/", stringify!($input_a), "_", stringify!($input_b)); -// let instruction = Instruction::::$instruction($instruction::from_str(&format!("{} r0 r1 into r2", $instruction::::opcode().to_string())).unwrap()); +// let instruction = Instruction::::$instruction($instruction::from_str(&format!("{} r0 r1 into r2", $instruction::::opcode().to_string())).unwrap()); // c.bench_function(&format!("{name}/instruction"), |b| { // b.iter_batched( // || { @@ -158,7 +158,7 @@ // { // use snarkvm_synthesizer_program::$instruction; // let name = concat!(stringify!($instruction), "/", stringify!($input_a), "_", stringify!($input_b), "_", stringify!($input_c)); -// let instruction = Instruction::::$instruction($instruction::from_str(&format!("{} r0 r1 r2 into r3", $instruction::::opcode().to_string())).unwrap()); +// let instruction = Instruction::::$instruction($instruction::from_str(&format!("{} r0 r1 r2 into r3", $instruction::::opcode().to_string())).unwrap()); // c.bench_function(&format!("{name}/instruction"), |b| { // b.iter_batched( // || { @@ -179,7 +179,7 @@ // $({ // // Define the default sampling method. // let mut samples = iter::repeat_with(|| { -// let mut arg: $input:: = Uniform::rand(rng); +// let mut arg: $input:: = Uniform::rand(rng); // while (std::panic::catch_unwind(|| arg.$operation())).is_err() { // arg = Uniform::rand(rng); // } @@ -203,7 +203,7 @@ // $({ // // Define the default sampling method. // let mut samples = iter::repeat_with(|| { -// let mut arg: $input:: = Uniform::rand(rng); +// let mut arg: $input:: = Uniform::rand(rng); // while (std::panic::catch_unwind(|| arg.$operation().unwrap())).is_err() { // arg = Uniform::rand(rng); // } @@ -227,8 +227,8 @@ // $({ // // Define the default sampling method. // let mut samples = iter::repeat_with(|| { -// let mut first: $input_a:: = Uniform::rand(rng); -// let mut second: $input_b:: = Uniform::rand(rng); +// let mut first: $input_a:: = Uniform::rand(rng); +// let mut second: $input_b:: = Uniform::rand(rng); // while (std::panic::catch_unwind(|| first.$operation(&second))).is_err() { // first = Uniform::rand(rng); // second = Uniform::rand(rng); @@ -252,9 +252,9 @@ // ($operation:tt, $instruction:ident { $( ($input_a:ident, $input_b:ident, $input_c:ident), )+ }) => { // $({ // let mut samples = iter::repeat_with(|| { -// let mut first: $input_a:: = Uniform::rand(rng); -// let mut second: $input_b:: = Uniform::rand(rng); -// let mut third: $input_c:: = Uniform::rand(rng); +// let mut first: $input_a:: = Uniform::rand(rng); +// let mut second: $input_b:: = Uniform::rand(rng); +// let mut third: $input_c:: = Uniform::rand(rng); // while (std::panic::catch_unwind(|| $input_b::ternary(&first, &second, &third))).is_err() { // first = Uniform::rand(rng); // second = Uniform::rand(rng); @@ -314,13 +314,13 @@ // macro_rules! bench_assert { // ($typ:tt) => { // let mut samples = iter::repeat_with(|| { -// let result = $typ::::rand(rng); +// let result = $typ::::rand(rng); // (result.clone(), result) // }); // { // use snarkvm_synthesizer_program::AssertEq; // let name = concat!("AssertEq/", stringify!($typ), "_", stringify!($typ)); -// let instruction = Instruction::::AssertEq(AssertEq::from_str(&format!("{} r0 r1", AssertEq::::opcode().to_string())).unwrap()); +// let instruction = Instruction::::AssertEq(AssertEq::from_str(&format!("{} r0 r1", AssertEq::::opcode().to_string())).unwrap()); // c.bench_function(&format!("{name}/instruction"), |b| { // b.iter_batched( // || { @@ -333,17 +333,17 @@ // }); // }; // let mut samples = iter::repeat_with(|| { -// let first = $typ::::rand(rng); -// let mut second = $typ::::rand(rng); +// let first = $typ::::rand(rng); +// let mut second = $typ::::rand(rng); // while first == second { -// second = $typ::::rand(rng); +// second = $typ::::rand(rng); // } // (first, second) // }); // { // use snarkvm_synthesizer_program::AssertNeq; // let name = concat!("AssertNeq/", stringify!($typ), "_", stringify!($typ)); -// let instruction = Instruction::::AssertNeq(AssertNeq::from_str(&format!("{} r0 r1", AssertNeq::::opcode().to_string())).unwrap()); +// let instruction = Instruction::::AssertNeq(AssertNeq::from_str(&format!("{} r0 r1", AssertNeq::::opcode().to_string())).unwrap()); // c.bench_function(&format!("{name}/instruction"), |b| { // b.iter_batched( // || { @@ -390,19 +390,19 @@ // // macro_rules! bench_ped64_commit_instruction { // ($instruction:tt) => { -// let mut samples = iter::repeat_with(|| { (Boolean::::rand(rng), Scalar::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (Boolean::::rand(rng), Scalar::::rand(rng)) }); // bench_instruction!(samples, $instruction { (Boolean, Scalar), }); -// let mut samples = iter::repeat_with(|| { (I8::::rand(rng), Scalar::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (I8::::rand(rng), Scalar::::rand(rng)) }); // bench_instruction!(samples, $instruction { (I8, Scalar), }); -// let mut samples = iter::repeat_with(|| { (I16::::rand(rng), Scalar::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (I16::::rand(rng), Scalar::::rand(rng)) }); // bench_instruction!(samples, $instruction { (I16, Scalar), }); -// let mut samples = iter::repeat_with(|| { (I32::::rand(rng), Scalar::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (I32::::rand(rng), Scalar::::rand(rng)) }); // bench_instruction!(samples, $instruction { (I32, Scalar), }); -// let mut samples = iter::repeat_with(|| { (U8::::rand(rng), Scalar::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (U8::::rand(rng), Scalar::::rand(rng)) }); // bench_instruction!(samples, $instruction { (U8, Scalar), }); -// let mut samples = iter::repeat_with(|| { (U16::::rand(rng), Scalar::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (U16::::rand(rng), Scalar::::rand(rng)) }); // bench_instruction!(samples, $instruction { (U16, Scalar), }); -// let mut samples = iter::repeat_with(|| { (U32::::rand(rng), Scalar::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (U32::::rand(rng), Scalar::::rand(rng)) }); // bench_instruction!(samples, $instruction { (U32, Scalar), }); // } // } @@ -410,19 +410,19 @@ // macro_rules! bench_commit_instruction { // ($instruction:tt) => { // bench_ped64_commit_instruction!($instruction); -// let mut samples = iter::repeat_with(|| { (Field::::rand(rng), Scalar::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (Field::::rand(rng), Scalar::::rand(rng)) }); // bench_instruction!(samples, $instruction { (Field, Scalar), }); -// let mut samples = iter::repeat_with(|| { (Group::::rand(rng), Scalar::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (Group::::rand(rng), Scalar::::rand(rng)) }); // bench_instruction!(samples, $instruction { (Group, Scalar), }); -// let mut samples = iter::repeat_with(|| { (I64::::rand(rng), Scalar::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (I64::::rand(rng), Scalar::::rand(rng)) }); // bench_instruction!(samples, $instruction { (I64, Scalar), }); -// let mut samples = iter::repeat_with(|| { (I128::::rand(rng), Scalar::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (I128::::rand(rng), Scalar::::rand(rng)) }); // bench_instruction!(samples, $instruction { (I128, Scalar), }); -// let mut samples = iter::repeat_with(|| { (U64::::rand(rng), Scalar::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (U64::::rand(rng), Scalar::::rand(rng)) }); // bench_instruction!(samples, $instruction { (U64, Scalar), }); -// let mut samples = iter::repeat_with(|| { (U128::::rand(rng), Scalar::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (U128::::rand(rng), Scalar::::rand(rng)) }); // bench_instruction!(samples, $instruction { (U128, Scalar), }); -// let mut samples = iter::repeat_with(|| { (Scalar::::rand(rng), Scalar::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (Scalar::::rand(rng), Scalar::::rand(rng)) }); // bench_instruction!(samples, $instruction { (Scalar, Scalar), }); // } // } @@ -435,9 +435,9 @@ // bench_ped64_commit_instruction!(CommitPED64); // // bench_ped64_commit_instruction!(CommitPED128); -// let mut samples = iter::repeat_with(|| { (I64::::rand(rng), Scalar::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (I64::::rand(rng), Scalar::::rand(rng)) }); // bench_instruction!(samples, CommitPED128 { (I64, Scalar), }); -// let mut samples = iter::repeat_with(|| { (U64::::rand(rng), Scalar::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (U64::::rand(rng), Scalar::::rand(rng)) }); // bench_instruction!(samples, CommitPED128 { (U64, Scalar), }); // // use console::prelude::Div; @@ -505,19 +505,19 @@ // // macro_rules! bench_ped64_hash_instruction { // ($instruction:tt) => { -// let mut samples = iter::repeat_with(|| { Boolean::::rand(rng) }); +// let mut samples = iter::repeat_with(|| { Boolean::::rand(rng) }); // bench_instruction!(samples, $instruction { Boolean, }, "group"); -// let mut samples = iter::repeat_with(|| { I8::::rand(rng) }); +// let mut samples = iter::repeat_with(|| { I8::::rand(rng) }); // bench_instruction!(samples, $instruction { I8, }, "group"); -// let mut samples = iter::repeat_with(|| { I16::::rand(rng) }); +// let mut samples = iter::repeat_with(|| { I16::::rand(rng) }); // bench_instruction!(samples, $instruction { I16, }, "group"); -// let mut samples = iter::repeat_with(|| { I32::::rand(rng) }); +// let mut samples = iter::repeat_with(|| { I32::::rand(rng) }); // bench_instruction!(samples, $instruction { I32, }, "group"); -// let mut samples = iter::repeat_with(|| { U8::::rand(rng) }); +// let mut samples = iter::repeat_with(|| { U8::::rand(rng) }); // bench_instruction!(samples, $instruction { U8, }, "group"); -// let mut samples = iter::repeat_with(|| { U16::::rand(rng) }); +// let mut samples = iter::repeat_with(|| { U16::::rand(rng) }); // bench_instruction!(samples, $instruction { U16, }, "group"); -// let mut samples = iter::repeat_with(|| { U32::::rand(rng) }); +// let mut samples = iter::repeat_with(|| { U32::::rand(rng) }); // bench_instruction!(samples, $instruction { U32, }, "group"); // } // } @@ -525,19 +525,19 @@ // macro_rules! bench_hash_instruction { // ($instruction:tt) => { // bench_ped64_hash_instruction!($instruction); -// let mut samples = iter::repeat_with(|| { Field::::rand(rng) }); +// let mut samples = iter::repeat_with(|| { Field::::rand(rng) }); // bench_instruction!(samples, $instruction { Field, }, "group"); -// let mut samples = iter::repeat_with(|| { Group::::rand(rng) }); +// let mut samples = iter::repeat_with(|| { Group::::rand(rng) }); // bench_instruction!(samples, $instruction { Group, }, "group"); -// let mut samples = iter::repeat_with(|| { I64::::rand(rng) }); +// let mut samples = iter::repeat_with(|| { I64::::rand(rng) }); // bench_instruction!(samples, $instruction { I64, }, "group"); -// let mut samples = iter::repeat_with(|| { I128::::rand(rng) }); +// let mut samples = iter::repeat_with(|| { I128::::rand(rng) }); // bench_instruction!(samples, $instruction { I128, }, "group"); -// let mut samples = iter::repeat_with(|| { U64::::rand(rng) }); +// let mut samples = iter::repeat_with(|| { U64::::rand(rng) }); // bench_instruction!(samples, $instruction { U64, }, "group"); -// let mut samples = iter::repeat_with(|| { U128::::rand(rng) }); +// let mut samples = iter::repeat_with(|| { U128::::rand(rng) }); // bench_instruction!(samples, $instruction { U128, }, "group"); -// let mut samples = iter::repeat_with(|| { Scalar::::rand(rng) }); +// let mut samples = iter::repeat_with(|| { Scalar::::rand(rng) }); // bench_instruction!(samples, $instruction { Scalar, }, "group"); // } // } @@ -550,9 +550,9 @@ // bench_ped64_hash_instruction!(HashPED64); // // bench_ped64_hash_instruction!(HashPED128); -// let mut samples = iter::repeat_with(|| { I64::::rand(rng) }); +// let mut samples = iter::repeat_with(|| { I64::::rand(rng) }); // bench_instruction!(samples, HashPED128 { I64, }, "group"); -// let mut samples = iter::repeat_with(|| { U64::::rand(rng) }); +// let mut samples = iter::repeat_with(|| { U64::::rand(rng) }); // bench_instruction!(samples, HashPED128 { U64, }, "group"); // // bench_hash_instruction!(HashPSD2); @@ -562,46 +562,46 @@ // use console::prelude::Inverse; // bench_instruction_with_default!(inverse?, Inv { Field, }); // -// let mut samples = iter::repeat_with(|| { (Boolean::::rand(rng), Boolean::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (Boolean::::rand(rng), Boolean::::rand(rng)) }); // bench_instruction!(samples, IsEq { (Boolean, Boolean), }); // bench_instruction!(samples, IsNeq { (Boolean, Boolean), }); -// let mut samples = iter::repeat_with(|| { (Field::::rand(rng), Field::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (Field::::rand(rng), Field::::rand(rng)) }); // bench_instruction!(samples, IsEq { (Field, Field), }); // bench_instruction!(samples, IsNeq { (Field, Field), }); -// let mut samples = iter::repeat_with(|| { (Group::::rand(rng), Group::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (Group::::rand(rng), Group::::rand(rng)) }); // bench_instruction!(samples, IsEq { (Group, Group), }); // bench_instruction!(samples, IsNeq { (Group, Group), }); -// let mut samples = iter::repeat_with(|| { (I8::::rand(rng), I8::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (I8::::rand(rng), I8::::rand(rng)) }); // bench_instruction!(samples, IsEq { (I8, I8), }); // bench_instruction!(samples, IsNeq { (I8, I8), }); -// let mut samples = iter::repeat_with(|| { (I16::::rand(rng), I16::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (I16::::rand(rng), I16::::rand(rng)) }); // bench_instruction!(samples, IsEq { (I16, I16), }); // bench_instruction!(samples, IsNeq { (I16, I16), }); -// let mut samples = iter::repeat_with(|| { (I32::::rand(rng), I32::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (I32::::rand(rng), I32::::rand(rng)) }); // bench_instruction!(samples, IsEq { (I32, I32), }); // bench_instruction!(samples, IsNeq { (I32, I32), }); -// let mut samples = iter::repeat_with(|| { (I64::::rand(rng), I64::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (I64::::rand(rng), I64::::rand(rng)) }); // bench_instruction!(samples, IsEq { (I64, I64), }); // bench_instruction!(samples, IsNeq { (I64, I64), }); -// let mut samples = iter::repeat_with(|| { (I128::::rand(rng), I128::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (I128::::rand(rng), I128::::rand(rng)) }); // bench_instruction!(samples, IsEq { (I128, I128), }); // bench_instruction!(samples, IsNeq { (I128, I128), }); -// let mut samples = iter::repeat_with(|| { (Scalar::::rand(rng), Scalar::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (Scalar::::rand(rng), Scalar::::rand(rng)) }); // bench_instruction!(samples, IsEq { (Scalar, Scalar), }); // bench_instruction!(samples, IsNeq { (Scalar, Scalar), }); -// let mut samples = iter::repeat_with(|| { (U8::::rand(rng), U8::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (U8::::rand(rng), U8::::rand(rng)) }); // bench_instruction!(samples, IsEq { (U8, U8), }); // bench_instruction!(samples, IsNeq { (U8, U8), }); -// let mut samples = iter::repeat_with(|| { (U16::::rand(rng), U16::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (U16::::rand(rng), U16::::rand(rng)) }); // bench_instruction!(samples, IsEq { (U16, U16), }); // bench_instruction!(samples, IsNeq { (U16, U16), }); -// let mut samples = iter::repeat_with(|| { (U32::::rand(rng), U32::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (U32::::rand(rng), U32::::rand(rng)) }); // bench_instruction!(samples, IsEq { (U32, U32), }); // bench_instruction!(samples, IsNeq { (U32, U32), }); -// let mut samples = iter::repeat_with(|| { (U64::::rand(rng), U64::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (U64::::rand(rng), U64::::rand(rng)) }); // bench_instruction!(samples, IsEq { (U64, U64), }); // bench_instruction!(samples, IsNeq { (U64, U64), }); -// let mut samples = iter::repeat_with(|| { (U128::::rand(rng), U128::::rand(rng)) }); +// let mut samples = iter::repeat_with(|| { (U128::::rand(rng), U128::::rand(rng)) }); // bench_instruction!(samples, IsEq { (U128, U128), }); // bench_instruction!(samples, IsNeq { (U128, U128), }); // @@ -651,25 +651,25 @@ // (Scalar, Group), // }); // // Use a custom sampling method for integer multiplication, since there is a high chance of overflow. -// let mut samples = iter::repeat((I8::::zero(), I8::::zero())); +// let mut samples = iter::repeat((I8::::zero(), I8::::zero())); // bench_instruction!(samples, Mul { (I8, I8), }); -// let mut samples = iter::repeat((I16::::zero(), I16::::zero())); +// let mut samples = iter::repeat((I16::::zero(), I16::::zero())); // bench_instruction!(samples, Mul { (I16, I16), }); -// let mut samples = iter::repeat((I32::::zero(), I32::::zero())); +// let mut samples = iter::repeat((I32::::zero(), I32::::zero())); // bench_instruction!(samples, Mul { (I32, I32), }); -// let mut samples = iter::repeat((I64::::zero(), I64::::zero())); +// let mut samples = iter::repeat((I64::::zero(), I64::::zero())); // bench_instruction!(samples, Mul { (I64, I64), }); -// let mut samples = iter::repeat((I128::::zero(), I128::::zero())); +// let mut samples = iter::repeat((I128::::zero(), I128::::zero())); // bench_instruction!(samples, Mul { (I128, I128), }); -// let mut samples = iter::repeat((U8::::zero(), U8::::zero())); +// let mut samples = iter::repeat((U8::::zero(), U8::::zero())); // bench_instruction!(samples, Mul { (U8, U8), }); -// let mut samples = iter::repeat((U16::::zero(), U16::::zero())); +// let mut samples = iter::repeat((U16::::zero(), U16::::zero())); // bench_instruction!(samples, Mul { (U16, U16), }); -// let mut samples = iter::repeat((U32::::zero(), U32::::zero())); +// let mut samples = iter::repeat((U32::::zero(), U32::::zero())); // bench_instruction!(samples, Mul { (U32, U32), }); -// let mut samples = iter::repeat((U64::::zero(), U64::::zero())); +// let mut samples = iter::repeat((U64::::zero(), U64::::zero())); // bench_instruction!(samples, Mul { (U64, U64), }); -// let mut samples = iter::repeat((U128::::zero(), U128::::zero())); +// let mut samples = iter::repeat((U128::::zero(), U128::::zero())); // bench_instruction!(samples, Mul { (U128, U128), }); // // use console::prelude::MulWrapped; @@ -721,65 +721,65 @@ // (Field, Field), // }); // // Use a custom sampling method for integer exponentiation, since there is a high chance of overflow. -// let mut samples = iter::repeat((I8::::zero(), U8::::zero())); +// let mut samples = iter::repeat((I8::::zero(), U8::::zero())); // bench_instruction!(samples, Pow { (I8, U8), }); -// let mut samples = iter::repeat((I8::::zero(), U16::::zero())); +// let mut samples = iter::repeat((I8::::zero(), U16::::zero())); // bench_instruction!(samples, Pow { (I8, U16), }); -// let mut samples = iter::repeat((I8::::zero(), U32::::zero())); +// let mut samples = iter::repeat((I8::::zero(), U32::::zero())); // bench_instruction!(samples, Pow { (I8, U32), }); -// let mut samples = iter::repeat((I16::::zero(), U8::::zero())); +// let mut samples = iter::repeat((I16::::zero(), U8::::zero())); // bench_instruction!(samples, Pow { (I16, U8), }); -// let mut samples = iter::repeat((I16::::zero(), U16::::zero())); +// let mut samples = iter::repeat((I16::::zero(), U16::::zero())); // bench_instruction!(samples, Pow { (I16, U16), }); -// let mut samples = iter::repeat((I16::::zero(), U32::::zero())); +// let mut samples = iter::repeat((I16::::zero(), U32::::zero())); // bench_instruction!(samples, Pow { (I16, U32), }); -// let mut samples = iter::repeat((I32::::zero(), U8::::zero())); +// let mut samples = iter::repeat((I32::::zero(), U8::::zero())); // bench_instruction!(samples, Pow { (I32, U8), }); -// let mut samples = iter::repeat((I32::::zero(), U16::::zero())); +// let mut samples = iter::repeat((I32::::zero(), U16::::zero())); // bench_instruction!(samples, Pow { (I32, U16), }); -// let mut samples = iter::repeat((I32::::zero(), U32::::zero())); +// let mut samples = iter::repeat((I32::::zero(), U32::::zero())); // bench_instruction!(samples, Pow { (I32, U32), }); -// let mut samples = iter::repeat((I64::::zero(), U8::::zero())); +// let mut samples = iter::repeat((I64::::zero(), U8::::zero())); // bench_instruction!(samples, Pow { (I64, U8), }); -// let mut samples = iter::repeat((I64::::zero(), U16::::zero())); +// let mut samples = iter::repeat((I64::::zero(), U16::::zero())); // bench_instruction!(samples, Pow { (I64, U16), }); -// let mut samples = iter::repeat((I64::::zero(), U32::::zero())); +// let mut samples = iter::repeat((I64::::zero(), U32::::zero())); // bench_instruction!(samples, Pow { (I64, U32), }); -// let mut samples = iter::repeat((I128::::zero(), U8::::zero())); +// let mut samples = iter::repeat((I128::::zero(), U8::::zero())); // bench_instruction!(samples, Pow { (I128, U8), }); -// let mut samples = iter::repeat((I128::::zero(), U16::::zero())); +// let mut samples = iter::repeat((I128::::zero(), U16::::zero())); // bench_instruction!(samples, Pow { (I128, U16), }); -// let mut samples = iter::repeat((I128::::zero(), U32::::zero())); +// let mut samples = iter::repeat((I128::::zero(), U32::::zero())); // bench_instruction!(samples, Pow { (I128, U32), }); -// let mut samples = iter::repeat((U8::::zero(), U8::::zero())); +// let mut samples = iter::repeat((U8::::zero(), U8::::zero())); // bench_instruction!(samples, Pow { (U8, U8), }); -// let mut samples = iter::repeat((U8::::zero(), U16::::zero())); +// let mut samples = iter::repeat((U8::::zero(), U16::::zero())); // bench_instruction!(samples, Pow { (U8, U16), }); -// let mut samples = iter::repeat((U8::::zero(), U32::::zero())); +// let mut samples = iter::repeat((U8::::zero(), U32::::zero())); // bench_instruction!(samples, Pow { (U8, U32), }); -// let mut samples = iter::repeat((U16::::zero(), U8::::zero())); +// let mut samples = iter::repeat((U16::::zero(), U8::::zero())); // bench_instruction!(samples, Pow { (U16, U8), }); -// let mut samples = iter::repeat((U16::::zero(), U16::::zero())); +// let mut samples = iter::repeat((U16::::zero(), U16::::zero())); // bench_instruction!(samples, Pow { (U16, U16), }); -// let mut samples = iter::repeat((U16::::zero(), U32::::zero())); +// let mut samples = iter::repeat((U16::::zero(), U32::::zero())); // bench_instruction!(samples, Pow { (U16, U32), }); -// let mut samples = iter::repeat((U32::::zero(), U8::::zero())); +// let mut samples = iter::repeat((U32::::zero(), U8::::zero())); // bench_instruction!(samples, Pow { (U32, U8), }); -// let mut samples = iter::repeat((U32::::zero(), U16::::zero())); +// let mut samples = iter::repeat((U32::::zero(), U16::::zero())); // bench_instruction!(samples, Pow { (U32, U16), }); -// let mut samples = iter::repeat((U32::::zero(), U32::::zero())); +// let mut samples = iter::repeat((U32::::zero(), U32::::zero())); // bench_instruction!(samples, Pow { (U32, U32), }); -// let mut samples = iter::repeat((U64::::zero(), U8::::zero())); +// let mut samples = iter::repeat((U64::::zero(), U8::::zero())); // bench_instruction!(samples, Pow { (U64, U8), }); -// let mut samples = iter::repeat((U64::::zero(), U16::::zero())); +// let mut samples = iter::repeat((U64::::zero(), U16::::zero())); // bench_instruction!(samples, Pow { (U64, U16), }); -// let mut samples = iter::repeat((U64::::zero(), U32::::zero())); +// let mut samples = iter::repeat((U64::::zero(), U32::::zero())); // bench_instruction!(samples, Pow { (U64, U32), }); -// let mut samples = iter::repeat((U128::::zero(), U8::::zero())); +// let mut samples = iter::repeat((U128::::zero(), U8::::zero())); // bench_instruction!(samples, Pow { (U128, U8), }); -// let mut samples = iter::repeat((U128::::zero(), U16::::zero())); +// let mut samples = iter::repeat((U128::::zero(), U16::::zero())); // bench_instruction!(samples, Pow { (U128, U16), }); -// let mut samples = iter::repeat((U128::::zero(), U32::::zero())); +// let mut samples = iter::repeat((U128::::zero(), U32::::zero())); // bench_instruction!(samples, Pow { (U128, U32), }); // // use console::prelude::PowWrapped; @@ -845,65 +845,65 @@ // }); // // // Use a custom sampling method for left-shift, since there is a high chance of overflow. -// let mut samples = iter::repeat((I8::::zero(), U8::::zero())); +// let mut samples = iter::repeat((I8::::zero(), U8::::zero())); // bench_instruction!(samples, Shl { (I8, U8), }); -// let mut samples = iter::repeat((I8::::zero(), U16::::zero())); +// let mut samples = iter::repeat((I8::::zero(), U16::::zero())); // bench_instruction!(samples, Shl { (I8, U16), }); -// let mut samples = iter::repeat((I8::::zero(), U32::::zero())); +// let mut samples = iter::repeat((I8::::zero(), U32::::zero())); // bench_instruction!(samples, Shl { (I8, U32), }); -// let mut samples = iter::repeat((I16::::zero(), U8::::zero())); +// let mut samples = iter::repeat((I16::::zero(), U8::::zero())); // bench_instruction!(samples, Shl { (I16, U8), }); -// let mut samples = iter::repeat((I16::::zero(), U16::::zero())); +// let mut samples = iter::repeat((I16::::zero(), U16::::zero())); // bench_instruction!(samples, Shl { (I16, U16), }); -// let mut samples = iter::repeat((I16::::zero(), U32::::zero())); +// let mut samples = iter::repeat((I16::::zero(), U32::::zero())); // bench_instruction!(samples, Shl { (I16, U32), }); -// let mut samples = iter::repeat((I32::::zero(), U8::::zero())); +// let mut samples = iter::repeat((I32::::zero(), U8::::zero())); // bench_instruction!(samples, Shl { (I32, U8), }); -// let mut samples = iter::repeat((I32::::zero(), U16::::zero())); +// let mut samples = iter::repeat((I32::::zero(), U16::::zero())); // bench_instruction!(samples, Shl { (I32, U16), }); -// let mut samples = iter::repeat((I32::::zero(), U32::::zero())); +// let mut samples = iter::repeat((I32::::zero(), U32::::zero())); // bench_instruction!(samples, Shl { (I32, U32), }); -// let mut samples = iter::repeat((I64::::zero(), U8::::zero())); +// let mut samples = iter::repeat((I64::::zero(), U8::::zero())); // bench_instruction!(samples, Shl { (I64, U8), }); -// let mut samples = iter::repeat((I64::::zero(), U16::::zero())); +// let mut samples = iter::repeat((I64::::zero(), U16::::zero())); // bench_instruction!(samples, Shl { (I64, U16), }); -// let mut samples = iter::repeat((I64::::zero(), U32::::zero())); +// let mut samples = iter::repeat((I64::::zero(), U32::::zero())); // bench_instruction!(samples, Shl { (I64, U32), }); -// let mut samples = iter::repeat((I128::::zero(), U8::::zero())); +// let mut samples = iter::repeat((I128::::zero(), U8::::zero())); // bench_instruction!(samples, Shl { (I128, U8), }); -// let mut samples = iter::repeat((I128::::zero(), U16::::zero())); +// let mut samples = iter::repeat((I128::::zero(), U16::::zero())); // bench_instruction!(samples, Shl { (I128, U16), }); -// let mut samples = iter::repeat((I128::::zero(), U32::::zero())); +// let mut samples = iter::repeat((I128::::zero(), U32::::zero())); // bench_instruction!(samples, Shl { (I128, U32), }); -// let mut samples = iter::repeat((U8::::zero(), U8::::zero())); +// let mut samples = iter::repeat((U8::::zero(), U8::::zero())); // bench_instruction!(samples, Shl { (U8, U8), }); -// let mut samples = iter::repeat((U8::::zero(), U16::::zero())); +// let mut samples = iter::repeat((U8::::zero(), U16::::zero())); // bench_instruction!(samples, Shl { (U8, U16), }); -// let mut samples = iter::repeat((U8::::zero(), U32::::zero())); +// let mut samples = iter::repeat((U8::::zero(), U32::::zero())); // bench_instruction!(samples, Shl { (U8, U32), }); -// let mut samples = iter::repeat((U16::::zero(), U8::::zero())); +// let mut samples = iter::repeat((U16::::zero(), U8::::zero())); // bench_instruction!(samples, Shl { (U16, U8), }); -// let mut samples = iter::repeat((U16::::zero(), U16::::zero())); +// let mut samples = iter::repeat((U16::::zero(), U16::::zero())); // bench_instruction!(samples, Shl { (U16, U16), }); -// let mut samples = iter::repeat((U16::::zero(), U32::::zero())); +// let mut samples = iter::repeat((U16::::zero(), U32::::zero())); // bench_instruction!(samples, Shl { (U16, U32), }); -// let mut samples = iter::repeat((U32::::zero(), U8::::zero())); +// let mut samples = iter::repeat((U32::::zero(), U8::::zero())); // bench_instruction!(samples, Shl { (U32, U8), }); -// let mut samples = iter::repeat((U32::::zero(), U16::::zero())); +// let mut samples = iter::repeat((U32::::zero(), U16::::zero())); // bench_instruction!(samples, Shl { (U32, U16), }); -// let mut samples = iter::repeat((U32::::zero(), U32::::zero())); +// let mut samples = iter::repeat((U32::::zero(), U32::::zero())); // bench_instruction!(samples, Shl { (U32, U32), }); -// let mut samples = iter::repeat((U64::::zero(), U8::::zero())); +// let mut samples = iter::repeat((U64::::zero(), U8::::zero())); // bench_instruction!(samples, Shl { (U64, U8), }); -// let mut samples = iter::repeat((U64::::zero(), U16::::zero())); +// let mut samples = iter::repeat((U64::::zero(), U16::::zero())); // bench_instruction!(samples, Shl { (U64, U16), }); -// let mut samples = iter::repeat((U64::::zero(), U32::::zero())); +// let mut samples = iter::repeat((U64::::zero(), U32::::zero())); // bench_instruction!(samples, Shl { (U64, U32), }); -// let mut samples = iter::repeat((U128::::zero(), U8::::zero())); +// let mut samples = iter::repeat((U128::::zero(), U8::::zero())); // bench_instruction!(samples, Shl { (U128, U8), }); -// let mut samples = iter::repeat((U128::::zero(), U16::::zero())); +// let mut samples = iter::repeat((U128::::zero(), U16::::zero())); // bench_instruction!(samples, Shl { (U128, U16), }); -// let mut samples = iter::repeat((U128::::zero(), U32::::zero())); +// let mut samples = iter::repeat((U128::::zero(), U32::::zero())); // bench_instruction!(samples, Shl { (U128, U32), }); // // use console::prelude::ShlWrapped; @@ -941,65 +941,65 @@ // }); // // // Use a custom sampling method for left-shift, since there is a high chance of overflow. -// let mut samples = iter::repeat((I8::::zero(), U8::::zero())); +// let mut samples = iter::repeat((I8::::zero(), U8::::zero())); // bench_instruction!(samples, Shr { (I8, U8), }); -// let mut samples = iter::repeat((I8::::zero(), U16::::zero())); +// let mut samples = iter::repeat((I8::::zero(), U16::::zero())); // bench_instruction!(samples, Shr { (I8, U16), }); -// let mut samples = iter::repeat((I8::::zero(), U32::::zero())); +// let mut samples = iter::repeat((I8::::zero(), U32::::zero())); // bench_instruction!(samples, Shr { (I8, U32), }); -// let mut samples = iter::repeat((I16::::zero(), U8::::zero())); +// let mut samples = iter::repeat((I16::::zero(), U8::::zero())); // bench_instruction!(samples, Shr { (I16, U8), }); -// let mut samples = iter::repeat((I16::::zero(), U16::::zero())); +// let mut samples = iter::repeat((I16::::zero(), U16::::zero())); // bench_instruction!(samples, Shr { (I16, U16), }); -// let mut samples = iter::repeat((I16::::zero(), U32::::zero())); +// let mut samples = iter::repeat((I16::::zero(), U32::::zero())); // bench_instruction!(samples, Shr { (I16, U32), }); -// let mut samples = iter::repeat((I32::::zero(), U8::::zero())); +// let mut samples = iter::repeat((I32::::zero(), U8::::zero())); // bench_instruction!(samples, Shr { (I32, U8), }); -// let mut samples = iter::repeat((I32::::zero(), U16::::zero())); +// let mut samples = iter::repeat((I32::::zero(), U16::::zero())); // bench_instruction!(samples, Shr { (I32, U16), }); -// let mut samples = iter::repeat((I32::::zero(), U32::::zero())); +// let mut samples = iter::repeat((I32::::zero(), U32::::zero())); // bench_instruction!(samples, Shr { (I32, U32), }); -// let mut samples = iter::repeat((I64::::zero(), U8::::zero())); +// let mut samples = iter::repeat((I64::::zero(), U8::::zero())); // bench_instruction!(samples, Shr { (I64, U8), }); -// let mut samples = iter::repeat((I64::::zero(), U16::::zero())); +// let mut samples = iter::repeat((I64::::zero(), U16::::zero())); // bench_instruction!(samples, Shr { (I64, U16), }); -// let mut samples = iter::repeat((I64::::zero(), U32::::zero())); +// let mut samples = iter::repeat((I64::::zero(), U32::::zero())); // bench_instruction!(samples, Shr { (I64, U32), }); -// let mut samples = iter::repeat((I128::::zero(), U8::::zero())); +// let mut samples = iter::repeat((I128::::zero(), U8::::zero())); // bench_instruction!(samples, Shr { (I128, U8), }); -// let mut samples = iter::repeat((I128::::zero(), U16::::zero())); +// let mut samples = iter::repeat((I128::::zero(), U16::::zero())); // bench_instruction!(samples, Shr { (I128, U16), }); -// let mut samples = iter::repeat((I128::::zero(), U32::::zero())); +// let mut samples = iter::repeat((I128::::zero(), U32::::zero())); // bench_instruction!(samples, Shr { (I128, U32), }); -// let mut samples = iter::repeat((U8::::zero(), U8::::zero())); +// let mut samples = iter::repeat((U8::::zero(), U8::::zero())); // bench_instruction!(samples, Shr { (U8, U8), }); -// let mut samples = iter::repeat((U8::::zero(), U16::::zero())); +// let mut samples = iter::repeat((U8::::zero(), U16::::zero())); // bench_instruction!(samples, Shr { (U8, U16), }); -// let mut samples = iter::repeat((U8::::zero(), U32::::zero())); +// let mut samples = iter::repeat((U8::::zero(), U32::::zero())); // bench_instruction!(samples, Shr { (U8, U32), }); -// let mut samples = iter::repeat((U16::::zero(), U8::::zero())); +// let mut samples = iter::repeat((U16::::zero(), U8::::zero())); // bench_instruction!(samples, Shr { (U16, U8), }); -// let mut samples = iter::repeat((U16::::zero(), U16::::zero())); +// let mut samples = iter::repeat((U16::::zero(), U16::::zero())); // bench_instruction!(samples, Shr { (U16, U16), }); -// let mut samples = iter::repeat((U16::::zero(), U32::::zero())); +// let mut samples = iter::repeat((U16::::zero(), U32::::zero())); // bench_instruction!(samples, Shr { (U16, U32), }); -// let mut samples = iter::repeat((U32::::zero(), U8::::zero())); +// let mut samples = iter::repeat((U32::::zero(), U8::::zero())); // bench_instruction!(samples, Shr { (U32, U8), }); -// let mut samples = iter::repeat((U32::::zero(), U16::::zero())); +// let mut samples = iter::repeat((U32::::zero(), U16::::zero())); // bench_instruction!(samples, Shr { (U32, U16), }); -// let mut samples = iter::repeat((U32::::zero(), U32::::zero())); +// let mut samples = iter::repeat((U32::::zero(), U32::::zero())); // bench_instruction!(samples, Shr { (U32, U32), }); -// let mut samples = iter::repeat((U64::::zero(), U8::::zero())); +// let mut samples = iter::repeat((U64::::zero(), U8::::zero())); // bench_instruction!(samples, Shr { (U64, U8), }); -// let mut samples = iter::repeat((U64::::zero(), U16::::zero())); +// let mut samples = iter::repeat((U64::::zero(), U16::::zero())); // bench_instruction!(samples, Shr { (U64, U16), }); -// let mut samples = iter::repeat((U64::::zero(), U32::::zero())); +// let mut samples = iter::repeat((U64::::zero(), U32::::zero())); // bench_instruction!(samples, Shr { (U64, U32), }); -// let mut samples = iter::repeat((U128::::zero(), U8::::zero())); +// let mut samples = iter::repeat((U128::::zero(), U8::::zero())); // bench_instruction!(samples, Shr { (U128, U8), }); -// let mut samples = iter::repeat((U128::::zero(), U16::::zero())); +// let mut samples = iter::repeat((U128::::zero(), U16::::zero())); // bench_instruction!(samples, Shr { (U128, U16), }); -// let mut samples = iter::repeat((U128::::zero(), U32::::zero())); +// let mut samples = iter::repeat((U128::::zero(), U32::::zero())); // bench_instruction!(samples, Shr { (U128, U32), }); // // use console::prelude::ShrWrapped; diff --git a/synthesizer/program/src/bytes.rs b/synthesizer/program/src/bytes.rs index a8f9b0e544..555df50c64 100644 --- a/synthesizer/program/src/bytes.rs +++ b/synthesizer/program/src/bytes.rs @@ -142,9 +142,9 @@ impl, Command: CommandTrait> ToB mod tests { use super::*; use crate::Program; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_bytes() -> Result<()> { diff --git a/synthesizer/program/src/closure/bytes.rs b/synthesizer/program/src/closure/bytes.rs index 60d717bf30..da3b8d7264 100644 --- a/synthesizer/program/src/closure/bytes.rs +++ b/synthesizer/program/src/closure/bytes.rs @@ -118,9 +118,9 @@ impl> ToBytes for ClosureCore Result<()> { diff --git a/synthesizer/program/src/closure/input/mod.rs b/synthesizer/program/src/closure/input/mod.rs index bbf9d4d0e4..927a089ed2 100644 --- a/synthesizer/program/src/closure/input/mod.rs +++ b/synthesizer/program/src/closure/input/mod.rs @@ -69,9 +69,9 @@ impl PartialOrd for Input { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_input_type_name() -> Result<()> { diff --git a/synthesizer/program/src/closure/input/parse.rs b/synthesizer/program/src/closure/input/parse.rs index 5a0f7c2481..c233d74d8c 100644 --- a/synthesizer/program/src/closure/input/parse.rs +++ b/synthesizer/program/src/closure/input/parse.rs @@ -94,9 +94,9 @@ impl Display for Input { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_input_parse() -> Result<()> { diff --git a/synthesizer/program/src/closure/mod.rs b/synthesizer/program/src/closure/mod.rs index aad825d1ea..be54fddb4a 100644 --- a/synthesizer/program/src/closure/mod.rs +++ b/synthesizer/program/src/closure/mod.rs @@ -154,7 +154,7 @@ mod tests { use crate::{Closure, Instruction}; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; #[test] fn test_add_input() { @@ -188,7 +188,7 @@ mod tests { // Ensure that an instruction can be added. let instruction = Instruction::::from_str("add r0 r1 into r2;").unwrap(); - assert!(closure.add_instruction(instruction.clone()).is_ok()); + assert!(closure.add_instruction(instruction).is_ok()); // Ensure that adding more than the maximum number of instructions will fail. for i in 3..CurrentNetwork::MAX_INSTRUCTIONS * 2 { @@ -209,7 +209,7 @@ mod tests { // Ensure that an output can be added. let output = Output::::from_str("output r0 as field;").unwrap(); - assert!(closure.add_output(output.clone()).is_ok()); + assert!(closure.add_output(output).is_ok()); // Ensure that adding more than the maximum number of outputs will fail. for i in 1..CurrentNetwork::MAX_OUTPUTS * 2 { diff --git a/synthesizer/program/src/closure/output/mod.rs b/synthesizer/program/src/closure/output/mod.rs index c886fab747..2a07177a1b 100644 --- a/synthesizer/program/src/closure/output/mod.rs +++ b/synthesizer/program/src/closure/output/mod.rs @@ -54,9 +54,9 @@ impl TypeName for Output { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_output_type_name() { diff --git a/synthesizer/program/src/closure/output/parse.rs b/synthesizer/program/src/closure/output/parse.rs index b9e7fd444a..bf2f4290cd 100644 --- a/synthesizer/program/src/closure/output/parse.rs +++ b/synthesizer/program/src/closure/output/parse.rs @@ -86,11 +86,11 @@ impl Display for Output { mod tests { use super::*; use console::{ - network::Testnet3, + network::MainnetV0, program::{Literal, Register, U8}, }; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_output_parse() -> Result<()> { diff --git a/synthesizer/program/src/closure/parse.rs b/synthesizer/program/src/closure/parse.rs index 4d9894b0d7..9560dfc924 100644 --- a/synthesizer/program/src/closure/parse.rs +++ b/synthesizer/program/src/closure/parse.rs @@ -88,9 +88,9 @@ impl> Display for ClosureCore> ToBytes for FinalizeCore mod tests { use super::*; use crate::Finalize; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_finalize_bytes() -> Result<()> { diff --git a/synthesizer/program/src/finalize/input/mod.rs b/synthesizer/program/src/finalize/input/mod.rs index 88848caedc..1081768a45 100644 --- a/synthesizer/program/src/finalize/input/mod.rs +++ b/synthesizer/program/src/finalize/input/mod.rs @@ -69,9 +69,9 @@ impl PartialOrd for Input { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_input_type_name() -> Result<()> { diff --git a/synthesizer/program/src/finalize/input/parse.rs b/synthesizer/program/src/finalize/input/parse.rs index e2601c9a26..7cbe05e80d 100644 --- a/synthesizer/program/src/finalize/input/parse.rs +++ b/synthesizer/program/src/finalize/input/parse.rs @@ -88,9 +88,9 @@ impl Display for Input { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_input_parse() -> Result<()> { diff --git a/synthesizer/program/src/finalize/mod.rs b/synthesizer/program/src/finalize/mod.rs index 2a6f575109..d376e4554a 100644 --- a/synthesizer/program/src/finalize/mod.rs +++ b/synthesizer/program/src/finalize/mod.rs @@ -113,7 +113,7 @@ impl> FinalizeCore { // Ensure the maximum number of commands has not been exceeded. ensure!(self.commands.len() < N::MAX_COMMANDS, "Cannot add more than {} commands", N::MAX_COMMANDS); // Ensure the number of write commands has not been exceeded. - ensure!(self.num_writes < N::MAX_WRITES, "Cannot add more than {} 'set' commands", N::MAX_WRITES); + ensure!(self.num_writes < N::MAX_WRITES, "Cannot add more than {} 'set' & 'remove' commands", N::MAX_WRITES); // Ensure the command is not a call instruction. ensure!(!command.is_call(), "Forbidden operation: Finalize cannot invoke a 'call'"); @@ -168,7 +168,7 @@ mod tests { use crate::{Command, Finalize}; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; #[test] fn test_add_input() { @@ -202,7 +202,7 @@ mod tests { // Ensure that a command can be added. let command = Command::::from_str("add r0 r1 into r2;").unwrap(); - assert!(finalize.add_command(command.clone()).is_ok()); + assert!(finalize.add_command(command).is_ok()); // Ensure that adding more than the maximum number of commands will fail. for i in 3..CurrentNetwork::MAX_COMMANDS * 2 { diff --git a/synthesizer/program/src/finalize/parse.rs b/synthesizer/program/src/finalize/parse.rs index ba60af4d33..79ca7ac9c5 100644 --- a/synthesizer/program/src/finalize/parse.rs +++ b/synthesizer/program/src/finalize/parse.rs @@ -90,9 +90,9 @@ impl> Display for FinalizeCore mod tests { use super::*; use crate::Finalize; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_finalize_parse() { diff --git a/synthesizer/program/src/function/bytes.rs b/synthesizer/program/src/function/bytes.rs index 64ddf4938c..50dbe7fb18 100644 --- a/synthesizer/program/src/function/bytes.rs +++ b/synthesizer/program/src/function/bytes.rs @@ -135,9 +135,9 @@ impl, Command: CommandTrait> ToB mod tests { use super::*; use crate::Function; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_function_bytes() -> Result<()> { diff --git a/synthesizer/program/src/function/input/mod.rs b/synthesizer/program/src/function/input/mod.rs index 193ae71141..8e6887826e 100644 --- a/synthesizer/program/src/function/input/mod.rs +++ b/synthesizer/program/src/function/input/mod.rs @@ -69,9 +69,9 @@ impl PartialOrd for Input { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_input_type_name() -> Result<()> { diff --git a/synthesizer/program/src/function/input/parse.rs b/synthesizer/program/src/function/input/parse.rs index 991e6efbc8..31a8cb50e4 100644 --- a/synthesizer/program/src/function/input/parse.rs +++ b/synthesizer/program/src/function/input/parse.rs @@ -94,9 +94,9 @@ impl Display for Input { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_input_parse() -> Result<()> { diff --git a/synthesizer/program/src/function/mod.rs b/synthesizer/program/src/function/mod.rs index 9f03a3c4a9..24674e9777 100644 --- a/synthesizer/program/src/function/mod.rs +++ b/synthesizer/program/src/function/mod.rs @@ -208,7 +208,7 @@ mod tests { use crate::{Function, Instruction}; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; #[test] fn test_add_input() { @@ -242,7 +242,7 @@ mod tests { // Ensure that an instruction can be added. let instruction = Instruction::::from_str("add r0 r1 into r2;").unwrap(); - assert!(function.add_instruction(instruction.clone()).is_ok()); + assert!(function.add_instruction(instruction).is_ok()); // Ensure that adding more than the maximum number of instructions will fail. for i in 3..CurrentNetwork::MAX_INSTRUCTIONS * 2 { @@ -263,7 +263,7 @@ mod tests { // Ensure that an output can be added. let output = Output::::from_str("output r0 as field.private;").unwrap(); - assert!(function.add_output(output.clone()).is_ok()); + assert!(function.add_output(output).is_ok()); // Ensure that adding more than the maximum number of outputs will fail. for i in 1..CurrentNetwork::MAX_OUTPUTS * 2 { diff --git a/synthesizer/program/src/function/output/mod.rs b/synthesizer/program/src/function/output/mod.rs index 864affe4cf..1b5fb50581 100644 --- a/synthesizer/program/src/function/output/mod.rs +++ b/synthesizer/program/src/function/output/mod.rs @@ -54,9 +54,9 @@ impl TypeName for Output { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_output_type_name() { diff --git a/synthesizer/program/src/function/output/parse.rs b/synthesizer/program/src/function/output/parse.rs index 9f9328581f..b157beb175 100644 --- a/synthesizer/program/src/function/output/parse.rs +++ b/synthesizer/program/src/function/output/parse.rs @@ -86,11 +86,11 @@ impl Display for Output { mod tests { use super::*; use console::{ - network::Testnet3, + network::MainnetV0, program::{Literal, Register, U8}, }; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_output_parse() -> Result<()> { diff --git a/synthesizer/program/src/function/parse.rs b/synthesizer/program/src/function/parse.rs index 7f65dc6fb2..48258a3e0b 100644 --- a/synthesizer/program/src/function/parse.rs +++ b/synthesizer/program/src/function/parse.rs @@ -123,9 +123,9 @@ impl, Command: CommandTrait> Dis mod tests { use super::*; use crate::Function; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_function_parse() { diff --git a/synthesizer/program/src/import/mod.rs b/synthesizer/program/src/import/mod.rs index f7baec62d5..46082a0e4d 100644 --- a/synthesizer/program/src/import/mod.rs +++ b/synthesizer/program/src/import/mod.rs @@ -73,9 +73,9 @@ impl PartialOrd for Import { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_import_type_name() -> Result<()> { diff --git a/synthesizer/program/src/import/parse.rs b/synthesizer/program/src/import/parse.rs index 0f4e749e98..ad53f31e7c 100644 --- a/synthesizer/program/src/import/parse.rs +++ b/synthesizer/program/src/import/parse.rs @@ -71,9 +71,9 @@ impl Display for Import { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_import_parse() -> Result<()> { diff --git a/synthesizer/program/src/lib.rs b/synthesizer/program/src/lib.rs index 26f9b7c2b8..39daab2ceb 100644 --- a/synthesizer/program/src/lib.rs +++ b/synthesizer/program/src/lib.rs @@ -271,7 +271,7 @@ impl, Command: CommandTrait> Pro /// Returns a reference to the function with the given name. pub fn get_function_ref(&self, name: &Identifier) -> Result<&FunctionCore> { // Attempt to retrieve the function. - let function = self.functions.get(name).ok_or_else(|| anyhow!("Function '{name}' is not defined."))?; + let function = self.functions.get(name).ok_or(anyhow!("Function '{}/{name}' is not defined.", self.id))?; // Ensure the function name matches. ensure!(function.name() == name, "Expected function '{name}', but found function '{}'", function.name()); // Ensure the number of inputs is within the allowed range. @@ -575,6 +575,7 @@ impl, Command: CommandTrait> Pro "u64", "u128", "scalar", + "signature", "string", // Boolean "true", @@ -660,11 +661,11 @@ impl, Command: CommandTrait> Typ mod tests { use super::*; use console::{ - network::Testnet3, + network::MainnetV0, program::{Locator, ValueType}, }; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_program_mapping() -> Result<()> { diff --git a/synthesizer/program/src/logic/command/await_.rs b/synthesizer/program/src/logic/command/await_.rs index f7c43803ef..5fc745c11e 100644 --- a/synthesizer/program/src/logic/command/await_.rs +++ b/synthesizer/program/src/logic/command/await_.rs @@ -114,9 +114,9 @@ impl ToBytes for Await { #[cfg(test)] mod tests { use super::*; - use console::{network::Testnet3, program::Register}; + use console::{network::MainnetV0, program::Register}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() { diff --git a/synthesizer/program/src/logic/command/branch.rs b/synthesizer/program/src/logic/command/branch.rs index a6ac651627..7efc86c665 100644 --- a/synthesizer/program/src/logic/command/branch.rs +++ b/synthesizer/program/src/logic/command/branch.rs @@ -167,11 +167,11 @@ impl ToBytes for Branch { mod tests { use super::*; use console::{ - network::Testnet3, + network::MainnetV0, program::{Identifier, Register}, }; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() { diff --git a/synthesizer/program/src/logic/command/contains.rs b/synthesizer/program/src/logic/command/contains.rs index 14e1618d89..a3b0479c2e 100644 --- a/synthesizer/program/src/logic/command/contains.rs +++ b/synthesizer/program/src/logic/command/contains.rs @@ -202,9 +202,9 @@ impl ToBytes for Contains { #[cfg(test)] mod tests { use super::*; - use console::{network::Testnet3, program::Register}; + use console::{network::MainnetV0, program::Register}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() { diff --git a/synthesizer/program/src/logic/command/get.rs b/synthesizer/program/src/logic/command/get.rs index ac56eb92c0..84b355e945 100644 --- a/synthesizer/program/src/logic/command/get.rs +++ b/synthesizer/program/src/logic/command/get.rs @@ -352,9 +352,9 @@ impl ToBytes for Get { #[cfg(test)] mod tests { use super::*; - use console::{network::Testnet3, program::Register}; + use console::{network::MainnetV0, program::Register}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; struct OldGet { mapping: Identifier, diff --git a/synthesizer/program/src/logic/command/get_or_use.rs b/synthesizer/program/src/logic/command/get_or_use.rs index 7c2ef6d7d7..a4ef7cc080 100644 --- a/synthesizer/program/src/logic/command/get_or_use.rs +++ b/synthesizer/program/src/logic/command/get_or_use.rs @@ -275,9 +275,9 @@ impl ToBytes for GetOrUse { #[cfg(test)] mod tests { use super::*; - use console::{network::Testnet3, program::Register}; + use console::{network::MainnetV0, program::Register}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; pub struct OldGetOrUse { pub mapping: Identifier, diff --git a/synthesizer/program/src/logic/command/mod.rs b/synthesizer/program/src/logic/command/mod.rs index 5e5aa7c750..187683c640 100644 --- a/synthesizer/program/src/logic/command/mod.rs +++ b/synthesizer/program/src/logic/command/mod.rs @@ -357,9 +357,9 @@ impl Display for Command { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_command_bytes() { diff --git a/synthesizer/program/src/logic/command/position.rs b/synthesizer/program/src/logic/command/position.rs index d0fb251a43..a8b738954c 100644 --- a/synthesizer/program/src/logic/command/position.rs +++ b/synthesizer/program/src/logic/command/position.rs @@ -125,9 +125,9 @@ impl ToBytes for Position { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() { diff --git a/synthesizer/program/src/logic/command/rand_chacha.rs b/synthesizer/program/src/logic/command/rand_chacha.rs index 829bab7373..caf7ce6eab 100644 --- a/synthesizer/program/src/logic/command/rand_chacha.rs +++ b/synthesizer/program/src/logic/command/rand_chacha.rs @@ -288,9 +288,9 @@ impl ToBytes for RandChaCha { #[cfg(test)] mod tests { use super::*; - use console::{network::Testnet3, program::Register}; + use console::{network::MainnetV0, program::Register}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; fn valid_destination_types() -> &'static [LiteralType] { &[ diff --git a/synthesizer/program/src/logic/command/remove.rs b/synthesizer/program/src/logic/command/remove.rs index 52ce26629f..134a278c81 100644 --- a/synthesizer/program/src/logic/command/remove.rs +++ b/synthesizer/program/src/logic/command/remove.rs @@ -167,9 +167,9 @@ impl ToBytes for Remove { #[cfg(test)] mod tests { use super::*; - use console::{network::Testnet3, program::Register}; + use console::{network::MainnetV0, program::Register}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() { diff --git a/synthesizer/program/src/logic/command/set.rs b/synthesizer/program/src/logic/command/set.rs index 83d187dde7..9b687f5e90 100644 --- a/synthesizer/program/src/logic/command/set.rs +++ b/synthesizer/program/src/logic/command/set.rs @@ -199,9 +199,9 @@ impl ToBytes for Set { #[cfg(test)] mod tests { use super::*; - use console::{network::Testnet3, program::Register}; + use console::{network::MainnetV0, program::Register}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() { diff --git a/synthesizer/program/src/logic/finalize_operation/mod.rs b/synthesizer/program/src/logic/finalize_operation/mod.rs index 15de98767d..03f25cb2e5 100644 --- a/synthesizer/program/src/logic/finalize_operation/mod.rs +++ b/synthesizer/program/src/logic/finalize_operation/mod.rs @@ -42,9 +42,9 @@ pub enum FinalizeOperation { #[cfg(test)] pub(crate) mod test_helpers { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Samples a random `InitializeMapping`. pub(crate) fn sample_initialize_mapping(rng: &mut TestRng) -> FinalizeOperation { diff --git a/synthesizer/program/src/logic/instruction/bytes.rs b/synthesizer/program/src/logic/instruction/bytes.rs index 0c0c35954a..61fede6a78 100644 --- a/synthesizer/program/src/logic/instruction/bytes.rs +++ b/synthesizer/program/src/logic/instruction/bytes.rs @@ -79,9 +79,9 @@ impl ToBytes for Instruction { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_bytes() -> Result<()> { diff --git a/synthesizer/program/src/logic/instruction/mod.rs b/synthesizer/program/src/logic/instruction/mod.rs index 930920ca5e..91c09fae9e 100644 --- a/synthesizer/program/src/logic/instruction/mod.rs +++ b/synthesizer/program/src/logic/instruction/mod.rs @@ -461,9 +461,9 @@ impl Display for Instruction { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_opcodes() { diff --git a/synthesizer/program/src/logic/instruction/operand/mod.rs b/synthesizer/program/src/logic/instruction/operand/mod.rs index c7f180d4c9..e0b503e4fc 100644 --- a/synthesizer/program/src/logic/instruction/operand/mod.rs +++ b/synthesizer/program/src/logic/instruction/operand/mod.rs @@ -77,9 +77,9 @@ impl From<&Register> for Operand { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_operand_from_literal() -> Result<()> { diff --git a/synthesizer/program/src/logic/instruction/operand/parse.rs b/synthesizer/program/src/logic/instruction/operand/parse.rs index ccc699ee60..7c54e2cd6b 100644 --- a/synthesizer/program/src/logic/instruction/operand/parse.rs +++ b/synthesizer/program/src/logic/instruction/operand/parse.rs @@ -83,9 +83,9 @@ impl Display for Operand { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_operand_parse() -> Result<()> { diff --git a/synthesizer/program/src/logic/instruction/operation/assert.rs b/synthesizer/program/src/logic/instruction/operation/assert.rs index ee9a36b7ba..769eaa789e 100644 --- a/synthesizer/program/src/logic/instruction/operation/assert.rs +++ b/synthesizer/program/src/logic/instruction/operation/assert.rs @@ -263,9 +263,9 @@ impl ToBytes for AssertInstruction { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() { diff --git a/synthesizer/program/src/logic/instruction/operation/async_.rs b/synthesizer/program/src/logic/instruction/operation/async_.rs index 194fa8a5f9..35fa6b07ec 100644 --- a/synthesizer/program/src/logic/instruction/operation/async_.rs +++ b/synthesizer/program/src/logic/instruction/operation/async_.rs @@ -348,9 +348,9 @@ impl ToBytes for Async { mod tests { use super::*; // use circuit::AleoV0; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; // type CurrentAleo = AleoV0; // // /// Samples the stack. Note: Do not replicate this for real program use, it is insecure. diff --git a/synthesizer/program/src/logic/instruction/operation/call.rs b/synthesizer/program/src/logic/instruction/operation/call.rs index 12cc42168d..627e0b32ac 100644 --- a/synthesizer/program/src/logic/instruction/operation/call.rs +++ b/synthesizer/program/src/logic/instruction/operation/call.rs @@ -444,11 +444,11 @@ impl ToBytes for Call { mod tests { use super::*; use console::{ - network::Testnet3, + network::MainnetV0, program::{Access, Address, Identifier, Literal, U64}, }; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; const TEST_CASES: &[&str] = &[ "call foo", diff --git a/synthesizer/program/src/logic/instruction/operation/cast.rs b/synthesizer/program/src/logic/instruction/operation/cast.rs index a516daf425..87c45a3a80 100644 --- a/synthesizer/program/src/logic/instruction/operation/cast.rs +++ b/synthesizer/program/src/logic/instruction/operation/cast.rs @@ -206,9 +206,12 @@ impl CastOperation { stack: &(impl StackMatches + StackProgram), registers: &mut (impl RegistersSigner + RegistersLoad + RegistersStore), ) -> Result<()> { - // TODO (howardwu & d0cd): Re-enable after stabilizing. + // If the variant is `cast.lossy`, then check that the `cast_type` is a `PlaintextType::Literal`. if VARIANT == CastVariant::CastLossy as u8 { - bail!("cast.lossy is not supported (yet)") + ensure!( + matches!(self.cast_type, CastType::Plaintext(PlaintextType::Literal(..))), + "`cast.lossy` is only supported for casting to a literal type" + ) } // Load the operands values. @@ -333,9 +336,12 @@ impl CastOperation { stack: &(impl StackMatches + StackProgram), registers: &mut (impl RegistersSignerCircuit + RegistersLoadCircuit + RegistersStoreCircuit), ) -> Result<()> { - // TODO (howardwu & d0cd): Re-enable after stabilizing. + // If the variant is `cast.lossy`, then check that the `cast_type` is a `PlaintextType::Literal`. if VARIANT == CastVariant::CastLossy as u8 { - bail!("cast.lossy is not supported (yet)") + ensure!( + matches!(self.cast_type, CastType::Plaintext(PlaintextType::Literal(..))), + "`cast.lossy` is only supported for casting to a literal type" + ) } use circuit::{Eject, Inject}; @@ -582,9 +588,12 @@ impl CastOperation { stack: &(impl StackMatches + StackProgram), registers: &mut (impl RegistersLoad + RegistersStore), ) -> Result<()> { - // TODO (howardwu & d0cd): Re-enable after stabilizing. + // If the variant is `cast.lossy`, then check that the `cast_type` is a `PlaintextType::Literal`. if VARIANT == CastVariant::CastLossy as u8 { - bail!("cast.lossy is not supported (yet)") + ensure!( + matches!(self.cast_type, CastType::Plaintext(PlaintextType::Literal(..))), + "`cast.lossy` is only supported for casting to a literal type" + ) } // Load the operands values. @@ -641,6 +650,14 @@ impl CastOperation { stack: &impl StackProgram, input_types: &[RegisterType], ) -> Result>> { + // If the variant is `cast.lossy`, then check that the `cast_type` is a `PlaintextType::Literal`. + if VARIANT == CastVariant::CastLossy as u8 { + ensure!( + matches!(self.cast_type, CastType::Plaintext(PlaintextType::Literal(..))), + "`cast.lossy` is only supported for casting to a literal type" + ) + } + // Ensure the number of operands is correct. ensure!( input_types.len() == self.operands.len(), @@ -1108,11 +1125,11 @@ impl ToBytes for CastOperation { mod tests { use super::*; use console::{ - network::Testnet3, + network::MainnetV0, program::{Access, Identifier}, }; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() { diff --git a/synthesizer/program/src/logic/instruction/operation/commit.rs b/synthesizer/program/src/logic/instruction/operation/commit.rs index ffc3320cd0..35904c2a94 100644 --- a/synthesizer/program/src/logic/instruction/operation/commit.rs +++ b/synthesizer/program/src/logic/instruction/operation/commit.rs @@ -349,9 +349,9 @@ impl ToBytes for CommitInstruction { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// **Attention**: When changing this, also update in `tests/instruction/commit.rs`. fn valid_destination_types() -> &'static [LiteralType] { diff --git a/synthesizer/program/src/logic/instruction/operation/hash.rs b/synthesizer/program/src/logic/instruction/operation/hash.rs index cd7954e887..21acdd04ab 100644 --- a/synthesizer/program/src/logic/instruction/operation/hash.rs +++ b/synthesizer/program/src/logic/instruction/operation/hash.rs @@ -497,9 +497,9 @@ impl ToBytes for HashInstruction { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// **Attention**: When changing this, also update in `tests/instruction/hash.rs`. fn valid_destination_types() -> &'static [PlaintextType] { diff --git a/synthesizer/program/src/logic/instruction/operation/is.rs b/synthesizer/program/src/logic/instruction/operation/is.rs index aa56e93757..21ee23905a 100644 --- a/synthesizer/program/src/logic/instruction/operation/is.rs +++ b/synthesizer/program/src/logic/instruction/operation/is.rs @@ -275,9 +275,9 @@ impl ToBytes for IsInstruction { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() { diff --git a/synthesizer/program/src/logic/instruction/operation/macros.rs b/synthesizer/program/src/logic/instruction/operation/macros.rs index e283e0945b..46ced3ebbe 100644 --- a/synthesizer/program/src/logic/instruction/operation/macros.rs +++ b/synthesizer/program/src/logic/instruction/operation/macros.rs @@ -95,7 +95,7 @@ macro_rules! operation { use console::types::*; // Prepare the environment. - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; type CurrentAleo = circuit::network::AleoV0; // Prepare the operator. @@ -150,7 +150,7 @@ macro_rules! operation { use console::types::*; // Prepare the environment. - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; type CurrentAleo = circuit::network::AleoV0; // Prepare the operator. diff --git a/synthesizer/program/src/logic/instruction/operation/sign_verify.rs b/synthesizer/program/src/logic/instruction/operation/sign_verify.rs index 22a9fb480a..34b1e3feec 100644 --- a/synthesizer/program/src/logic/instruction/operation/sign_verify.rs +++ b/synthesizer/program/src/logic/instruction/operation/sign_verify.rs @@ -274,9 +274,9 @@ impl ToBytes for SignVerify { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() { diff --git a/synthesizer/program/src/logic/instruction/parse.rs b/synthesizer/program/src/logic/instruction/parse.rs index 7eba572702..0212d13166 100644 --- a/synthesizer/program/src/logic/instruction/parse.rs +++ b/synthesizer/program/src/logic/instruction/parse.rs @@ -85,9 +85,9 @@ impl FromStr for Instruction { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() -> Result<()> { diff --git a/synthesizer/program/src/mapping/bytes.rs b/synthesizer/program/src/mapping/bytes.rs index 323fdbc64f..9f38c621b4 100644 --- a/synthesizer/program/src/mapping/bytes.rs +++ b/synthesizer/program/src/mapping/bytes.rs @@ -45,9 +45,9 @@ impl ToBytes for Mapping { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_mapping_bytes() -> Result<()> { diff --git a/synthesizer/program/src/mapping/key/mod.rs b/synthesizer/program/src/mapping/key/mod.rs index 3132c8a251..ed1f4005fd 100644 --- a/synthesizer/program/src/mapping/key/mod.rs +++ b/synthesizer/program/src/mapping/key/mod.rs @@ -43,9 +43,9 @@ impl TypeName for MapKey { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_key_type_name() -> Result<()> { diff --git a/synthesizer/program/src/mapping/key/parse.rs b/synthesizer/program/src/mapping/key/parse.rs index 607a8f6c70..5438873b93 100644 --- a/synthesizer/program/src/mapping/key/parse.rs +++ b/synthesizer/program/src/mapping/key/parse.rs @@ -79,9 +79,9 @@ impl Display for MapKey { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_key_parse() -> Result<()> { diff --git a/synthesizer/program/src/mapping/parse.rs b/synthesizer/program/src/mapping/parse.rs index e2dd389f8f..4f25ed546c 100644 --- a/synthesizer/program/src/mapping/parse.rs +++ b/synthesizer/program/src/mapping/parse.rs @@ -78,9 +78,9 @@ impl Display for Mapping { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_mapping_parse() { diff --git a/synthesizer/program/src/mapping/value/mod.rs b/synthesizer/program/src/mapping/value/mod.rs index c32207fdf6..b62104c6b8 100644 --- a/synthesizer/program/src/mapping/value/mod.rs +++ b/synthesizer/program/src/mapping/value/mod.rs @@ -43,9 +43,9 @@ impl TypeName for MapValue { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_value_type_name() { diff --git a/synthesizer/program/src/mapping/value/parse.rs b/synthesizer/program/src/mapping/value/parse.rs index 280bf71788..787aed922b 100644 --- a/synthesizer/program/src/mapping/value/parse.rs +++ b/synthesizer/program/src/mapping/value/parse.rs @@ -79,9 +79,9 @@ impl Display for MapValue { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_value_parse() -> Result<()> { diff --git a/synthesizer/program/src/parse.rs b/synthesizer/program/src/parse.rs index 22d6cfa5bb..aeb6822dd1 100644 --- a/synthesizer/program/src/parse.rs +++ b/synthesizer/program/src/parse.rs @@ -184,9 +184,9 @@ impl, Command: CommandTrait> Dis mod tests { use super::*; use crate::Program; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_program_parse() -> Result<()> { diff --git a/synthesizer/program/src/resources/credits.aleo b/synthesizer/program/src/resources/credits.aleo index 534bb4ce86..980f9208ca 100644 --- a/synthesizer/program/src/resources/credits.aleo +++ b/synthesizer/program/src/resources/credits.aleo @@ -34,6 +34,19 @@ struct committee_state: /**********************************************************************************************************************/ +/// The `metadata` mapping stores: +/// - The number of members in the committee. +/// - The number of delegators. +mapping metadata: + // The key represents the index at which the count is stored. + // - This address (aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc) stores the number of **members** in the committee. + // - This address (aleo1qgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqanmpl0) stores the number of **delegators**. + key as address.public; + // The value represents the count. + value as u32.public; + +/**********************************************************************************************************************/ + // The `bonded` mapping represents the amount of microcredits that are currently bonded. mapping bonded: // The key represents the address of the staker, which includes the validators and their delegators. @@ -124,54 +137,73 @@ finalize bond_public: /* Committee */ + // Check if the validator is already in the committee. + contains committee[r0] into r4; + // If the validator is already in the committee, jump to the `continue_bond_validator` logic. + branch.eq r4 true to continue_bond_validator; + + // Get the committee size. + get.or_use metadata[aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc] 0u32 into r5; + // Increment the committee size by one. + add r5 1u32 into r6; + // Determine if the committee size is less than or equal to 200. + lte r6 200u32 into r7; + // Enforce that the committee size is less than or equal to 200. + assert.eq r7 true; + // Set the new committee size. + set r6 into metadata[aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc]; + + // Continues the rest of the `bond_validator` logic. + position continue_bond_validator; + // Construct the initial committee state. // Note: We set the initial 'is_open' state to 'true'. - cast 0u64 true into r4 as committee_state; + cast 0u64 true into r8 as committee_state; // Retrieve the committee state of the specified validator. - get.or_use committee[r0] r4 into r5; + get.or_use committee[r0] r8 into r9; // Ensure that the validator is open to stakers. - assert.eq r5.is_open true; + assert.eq r9.is_open true; // Increment the stake for the specified validator. - add r5.microcredits r2 into r6; + add r9.microcredits r2 into r10; // Construct the updated committee state. - cast r6 r5.is_open into r7 as committee_state; + cast r10 r9.is_open into r11 as committee_state; /* Bonded */ // Construct the initial bond state. - cast r1 0u64 into r8 as bond_state; + cast r0 0u64 into r12 as bond_state; // Get the bond state for the caller, or default to the initial bond state. - get.or_use bonded[r0] r8 into r9; + get.or_use bonded[r0] r12 into r13; // Enforce the validator matches in the bond state. - assert.eq r9.validator r1; + assert.eq r13.validator r0; // Increment the microcredits in the bond state. - add r9.microcredits r2 into r10; + add r9.microcredits r2 into r14; // Determine if the amount is at least one million credits. - gte r10 1_000_000_000_000u64 into r11; + gte r14 1_000_000_000_000u64 into r15; // Enforce the amount is at least one million credits. - assert.eq r11 true; + assert.eq r15 true; // Construct the updated bond state. - cast r1 r10 into r12 as bond_state; + cast r0 r14 into r16 as bond_state; /* Account */ // Get the balance of the caller. // If the account does not exist, this finalize scope will fail. - get account[r0] into r13; + get account[r0] into r17; // Decrement the balance of the caller. - sub r13 r2 into r14; + sub r17 r2 into r18; /* Writes */ // Update the committee state of the specified validator. - set r7 into committee[r0]; + set r11 into committee[r0]; // Update the bond state for the caller. - set r12 into bonded[r0]; + set r16 into bonded[r0]; // Update the balance of the caller. - set r14 into account[r0]; + set r18 into account[r0]; // Ends the `bond_validator` logic. branch.eq true true to end; @@ -184,56 +216,74 @@ finalize bond_public: /* Committee */ // Check if the caller is a validator. - contains committee[r0] into r15; + contains committee[r0] into r19; // Enforce the caller is *not* a validator. - assert.eq r15 false; + assert.eq r19 false; // Get the stake for the specified validator. // If the validator does not exist, this finalize scope will fail. - get committee[r1] into r16; + get committee[r1] into r20; // Ensure that the validator is open to stakers. - assert.eq r16.is_open true; + assert.eq r20.is_open true; // Increment the stake for the specified validator. - add r16.microcredits r2 into r17; + add r20.microcredits r2 into r21; // Construct the updated committee state. - cast r17 r16.is_open into r18 as committee_state; + cast r21 r20.is_open into r22 as committee_state; + + // Check if the delegator is already bonded to the validator. + contains bonded[r0] into r23; + // If the delegator is already bonded to the validator, jump to the `continue_bond_delegator` logic. + branch.eq r23 true to continue_bond_delegator; + // Get the number of delegators. + get.or_use metadata[aleo1qgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqanmpl0] 0u32 into r24; + // Increment the number of bonded delegators by one. + add r24 1u32 into r25; + // Determine if the number of delegators is less than or equal to 100_000. + lte r25 100_000u32 into r26; + // Enforce that the number of delegators is less than or equal to 100_000. + assert.eq r26 true; + // Set the new number of delegators. + set r25 into metadata[aleo1qgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqanmpl0]; + + // Continues the rest of the `bond_delegator` logic. + position continue_bond_delegator; /* Bonded */ // Construct the initial bond state. - cast r1 0u64 into r19 as bond_state; + cast r1 0u64 into r27 as bond_state; // Get the bond state for the caller, or default to the initial bond state. - get.or_use bonded[r0] r19 into r20; + get.or_use bonded[r0] r27 into r28; // Enforce the validator matches in the bond state. - assert.eq r20.validator r1; + assert.eq r28.validator r1; // Increment the microcredits in the bond state. - add r20.microcredits r2 into r21; + add r28.microcredits r2 into r29; // Determine if the amount is at least 10 credits. - gte r21 10_000_000u64 into r22; + gte r29 10_000_000u64 into r30; // Enforce the amount is at least 10 credits. - assert.eq r22 true; + assert.eq r30 true; // Construct the updated bond state. - cast r1 r21 into r23 as bond_state; + cast r1 r29 into r31 as bond_state; /* Account */ // Get the balance of the caller. // If the account does not exist, this finalize scope will fail. - get account[r0] into r24; + get account[r0] into r32; // Decrement the balance of the caller. - sub r24 r2 into r25; + sub r32 r2 into r33; /* Writes */ // Update the committee state for the specified validator. - set r18 into committee[r1]; + set r22 into committee[r1]; // Update the bond state for the caller. - set r23 into bonded[r0]; + set r31 into bonded[r0]; // Update the balance of the caller. - set r25 into account[r0]; + set r33 into account[r0]; // The terminus. position end; @@ -348,6 +398,13 @@ finalize unbond_public: // Remove the validator from the committee. remove committee[r0]; + // Get the committee size. + get metadata[aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc] into r15; + // Decrement the committee size by one. + sub r15 1u32 into r16; + // Set the new committee size. + set r16 into metadata[aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc]; + /* Bonded */ // Remove the bond state for the validator. @@ -356,12 +413,12 @@ finalize unbond_public: /* Unbonding */ // Increment the microcredits in the unbond state. - add r3.microcredits r8.microcredits into r15; + add r3.microcredits r8.microcredits into r17; // Construct the updated unbond state. - cast r15 r4 into r16 as unbond_state; + cast r17 r4 into r18 as unbond_state; // Update the unbond state for the caller. - set r16 into unbonding[r0]; + set r18 into unbonding[r0]; // Ends the `remove_validator` logic. branch.eq true true to end; @@ -372,17 +429,17 @@ finalize unbond_public: position unbond_delegator; // Get the bond state for the caller, or fail if it does not exist. - get bonded[r0] into r17; + get bonded[r0] into r19; // Decrement the microcredits in the bond state. - sub r17.microcredits r1 into r18; + sub r19.microcredits r1 into r20; // Determine if the remaining bond is at least 10 credits. - gte r18 10_000_000u64 into r19; + gte r20 10_000_000u64 into r21; // If the remaining balance is at least 10 credits, jump to the `decrement_delegator` logic. - branch.eq r19 true to decrement_delegator; + branch.eq r21 true to decrement_delegator; // If the remaining balance is less than 10 credits, jump to the `remove_delegator` logic. - branch.eq r19 false to remove_delegator; + branch.eq r21 false to remove_delegator; /*** Decrement Delegator ***/ @@ -393,30 +450,30 @@ finalize unbond_public: // Get the stake for the specified validator. // If the validator does not exist, this finalize scope will fail. - get committee[r17.validator] into r20; + get committee[r19.validator] into r22; // Decrement the stake for the specified validator. - sub r20.microcredits r1 into r21; + sub r22.microcredits r1 into r23; // Construct the updated committee state. - cast r21 r20.is_open into r22 as committee_state; + cast r23 r22.is_open into r24 as committee_state; // Update the stake for the specified validator. - set r22 into committee[r17.validator]; + set r24 into committee[r19.validator]; /* Bonded */ // Construct the updated bond state. - cast r17.validator r18 into r23 as bond_state; + cast r19.validator r20 into r25 as bond_state; // Update the bond state for the caller. - set r23 into bonded[r0]; + set r25 into bonded[r0]; /* Unbonding */ // Increment the microcredits in the unbond state. - add r3.microcredits r1 into r24; + add r3.microcredits r1 into r26; // Construct the updated unbond state. - cast r24 r4 into r25 as unbond_state; + cast r26 r4 into r27 as unbond_state; // Update the unbond state for the caller. - set r25 into unbonding[r0]; + set r27 into unbonding[r0]; // Ends the `decrement_delegator` logic. branch.eq true true to end; @@ -430,13 +487,20 @@ finalize unbond_public: // Get the stake for the specified validator. // If the validator does not exist, this finalize scope will fail. - get committee[r17.validator] into r26; + get committee[r19.validator] into r28; // Decrement the stake for the specified validator. - sub r26.microcredits r17.microcredits into r27; + sub r28.microcredits r19.microcredits into r29; // Construct the updated committee state. - cast r27 r26.is_open into r28 as committee_state; + cast r29 r28.is_open into r30 as committee_state; // Update the stake for the specified validator. - set r28 into committee[r17.validator]; + set r30 into committee[r19.validator]; + + // Get the number of delegators. + get metadata[aleo1qgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqanmpl0] into r31; + // Decrement the number of bonded delegators by one. + sub r31 1u32 into r32; + // Set the new number of delegators. + set r32 into metadata[aleo1qgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqanmpl0]; /* Bonded */ @@ -446,12 +510,12 @@ finalize unbond_public: /* Unbonding */ // Increment the microcredits in the unbond state. - add r3.microcredits r17.microcredits into r29; + add r3.microcredits r19.microcredits into r33; // Construct the updated unbond state. - cast r29 r4 into r30 as unbond_state; + cast r33 r4 into r34 as unbond_state; // Update the unbond state for the caller. - set r30 into unbonding[r0]; + set r34 into unbonding[r0]; // The terminus. position end; @@ -505,23 +569,28 @@ finalize unbond_delegator_as_validator: // Construct the updated committee state. cast r5 r2.is_open into r6 as committee_state; + // Get the number of delegators. + get metadata[aleo1qgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqanmpl0] into r7; + // Decrement the number of delegators by one. + sub r7 1u32 into r8; + /* End Committee */ /* Start Unbond */ // Construct the initial unbond state. - cast 0u64 0u32 into r7 as unbond_state; + cast 0u64 0u32 into r9 as unbond_state; // Get the unbond state for the delegator, or default to the initial unbond state. - get.or_use unbonding[r1] r7 into r8; + get.or_use unbonding[r1] r9 into r10; // Increment the microcredits in the unbond state. - add r8.microcredits r4.microcredits into r9; + add r10.microcredits r4.microcredits into r11; // Compute the height at which the unbonding will be complete, starting from the current block. // Note: Calling unbond across multiple blocks before the unbonding is complete will reset the height each time. - add block.height 360u32 into r10; + add block.height 360u32 into r12; // Construct the updated unbond state. - cast r9 r10 into r11 as unbond_state; + cast r11 r12 into r13 as unbond_state; /* End Unbond */ @@ -532,7 +601,9 @@ finalize unbond_delegator_as_validator: // Remove the bond state for the delegator. remove bonded[r1]; // Update the unbond state for the delegator. - set r11 into unbonding[r1]; + set r13 into unbonding[r1]; + // Update the number of delegators. + set r8 into metadata[aleo1qgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqanmpl0]; /* End Writes */ diff --git a/synthesizer/program/src/serialize.rs b/synthesizer/program/src/serialize.rs index 4e23a291a4..764c74965c 100644 --- a/synthesizer/program/src/serialize.rs +++ b/synthesizer/program/src/serialize.rs @@ -42,9 +42,9 @@ impl<'de, N: Network, Instruction: InstructionTrait, Command: CommandTrait mod tests { use super::*; use crate::Program; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_serde_json() -> Result<()> { diff --git a/synthesizer/program/src/traits/stack_and_registers.rs b/synthesizer/program/src/traits/stack_and_registers.rs index 50418e894f..5a5f55f72c 100644 --- a/synthesizer/program/src/traits/stack_and_registers.rs +++ b/synthesizer/program/src/traits/stack_and_registers.rs @@ -16,6 +16,7 @@ use std::sync::Arc; use crate::{FinalizeGlobalState, Function, Operand, Program}; use console::{ + account::Group, network::Network, prelude::{bail, Result}, program::{ @@ -35,6 +36,7 @@ use console::{ }, types::{Address, Field}, }; +use rand::{CryptoRng, Rng}; pub trait StackMatches { /// Checks that the given value matches the layout of the value type. @@ -83,6 +85,23 @@ pub trait StackProgram { /// Returns the expected number of calls for the given function name. fn get_number_of_calls(&self, function_name: &Identifier) -> Result; + + /// Samples a value for the given value_type. + fn sample_value( + &self, + burner_address: &Address, + value_type: &ValueType, + rng: &mut R, + ) -> Result>; + + /// Returns a record for the given record name, with the given burner address and nonce. + fn sample_record( + &self, + burner_address: &Address, + record_name: &Identifier, + record_nonce: Group, + rng: &mut R, + ) -> Result>>; } pub trait FinalizeRegistersState { @@ -103,6 +122,12 @@ pub trait RegistersSigner { /// Sets the transition signer. fn set_signer(&mut self, signer: Address); + /// Returns the root transition view key. + fn root_tvk(&self) -> Result>; + + /// Sets the root transition view key. + fn set_root_tvk(&mut self, root_tvk: Field); + /// Returns the transition caller. fn caller(&self) -> Result>; @@ -123,6 +148,12 @@ pub trait RegistersSignerCircuit> { /// Sets the transition signer, as a circuit. fn set_signer_circuit(&mut self, signer_circuit: circuit::Address); + /// Returns the root transition view key, as a circuit. + fn root_tvk_circuit(&self) -> Result>; + + /// Sets the root transition view key, as a circuit. + fn set_root_tvk_circuit(&mut self, root_tvk_circuit: circuit::Field); + /// Returns the transition caller, as a circuit. fn caller_circuit(&self) -> Result>; diff --git a/synthesizer/program/tests/helpers/sample.rs b/synthesizer/program/tests/helpers/sample.rs index c7587d03ea..066e6c8b60 100644 --- a/synthesizer/program/tests/helpers/sample.rs +++ b/synthesizer/program/tests/helpers/sample.rs @@ -14,7 +14,7 @@ use circuit::AleoV0; use console::{ - network::Testnet3, + network::MainnetV0, prelude::*, program::{Identifier, Literal, Plaintext, Register, Value}, }; @@ -24,7 +24,7 @@ use snarkvm_synthesizer_program::{ }; use synthesizer_process::{Authorization, CallStack, FinalizeRegisters, Registers, Stack, StackProgramTypes}; -type CurrentNetwork = Testnet3; +type CurrentNetwork = MainnetV0; type CurrentAleo = AleoV0; /// Samples the registers. Note: Do not replicate this for real program use, it is insecure. diff --git a/synthesizer/program/tests/instruction/assert.rs b/synthesizer/program/tests/instruction/assert.rs index bd3216a7c7..61811eaef4 100644 --- a/synthesizer/program/tests/instruction/assert.rs +++ b/synthesizer/program/tests/instruction/assert.rs @@ -18,14 +18,14 @@ use crate::helpers::sample::{sample_finalize_registers, sample_registers}; use circuit::AleoV0; use console::{ - network::Testnet3, + network::MainnetV0, prelude::*, program::{Identifier, Literal, LiteralType, Register}, }; use snarkvm_synthesizer_program::{AssertEq, AssertInstruction, AssertNeq, Opcode, Operand, Program}; use synthesizer_process::{Process, Stack}; -type CurrentNetwork = Testnet3; +type CurrentNetwork = MainnetV0; type CurrentAleo = AleoV0; const ITERATIONS: usize = 100; diff --git a/synthesizer/program/tests/instruction/commit.rs b/synthesizer/program/tests/instruction/commit.rs index 22bd82fdae..abdc6f6cb3 100644 --- a/synthesizer/program/tests/instruction/commit.rs +++ b/synthesizer/program/tests/instruction/commit.rs @@ -18,7 +18,7 @@ use crate::helpers::sample::{sample_finalize_registers, sample_registers}; use circuit::{AleoV0, Eject}; use console::{ - network::Testnet3, + network::MainnetV0, prelude::*, program::{Identifier, Literal, LiteralType, Plaintext, Register, Value}, }; @@ -38,7 +38,7 @@ use snarkvm_synthesizer_program::{ }; use synthesizer_process::{Process, Stack}; -type CurrentNetwork = Testnet3; +type CurrentNetwork = MainnetV0; type CurrentAleo = AleoV0; const ITERATIONS: usize = 50; diff --git a/synthesizer/program/tests/instruction/hash.rs b/synthesizer/program/tests/instruction/hash.rs index bef9a9d312..46f0caf732 100644 --- a/synthesizer/program/tests/instruction/hash.rs +++ b/synthesizer/program/tests/instruction/hash.rs @@ -18,7 +18,7 @@ use crate::helpers::sample::{sample_finalize_registers, sample_registers}; use circuit::{AleoV0, Eject}; use console::{ - network::Testnet3, + network::MainnetV0, prelude::*, program::{Identifier, Literal, LiteralType, Plaintext, PlaintextType, Register, Value}, }; @@ -47,7 +47,7 @@ use snarkvm_synthesizer_program::{ }; use synthesizer_process::{Process, Stack}; -type CurrentNetwork = Testnet3; +type CurrentNetwork = MainnetV0; type CurrentAleo = AleoV0; const ITERATIONS: usize = 50; diff --git a/synthesizer/program/tests/instruction/is.rs b/synthesizer/program/tests/instruction/is.rs index ba22a6e01c..a60121da9b 100644 --- a/synthesizer/program/tests/instruction/is.rs +++ b/synthesizer/program/tests/instruction/is.rs @@ -18,7 +18,7 @@ use crate::helpers::sample::{sample_finalize_registers, sample_registers}; use circuit::AleoV0; use console::{ - network::Testnet3, + network::MainnetV0, prelude::*, program::{Identifier, Literal, LiteralType, Register}, }; @@ -34,7 +34,7 @@ use snarkvm_synthesizer_program::{ }; use synthesizer_process::{Process, Stack}; -type CurrentNetwork = Testnet3; +type CurrentNetwork = MainnetV0; type CurrentAleo = AleoV0; const ITERATIONS: usize = 100; diff --git a/synthesizer/snark/Cargo.toml b/synthesizer/snark/Cargo.toml index 100ce851b9..1d63ac19fb 100644 --- a/synthesizer/snark/Cargo.toml +++ b/synthesizer/snark/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-synthesizer-snark" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "SNARK wrappers for a decentralized virtual machine" homepage = "https://aleo.org" @@ -33,18 +33,18 @@ wasm = [ "console/wasm", "snarkvm-algorithms/wasm" ] [dependencies.circuit] package = "snarkvm-circuit" path = "../../circuit" -version = "=0.16.15" +version = "=0.16.19" [dependencies.console] package = "snarkvm-console" path = "../../console" -version = "=0.16.15" +version = "=0.16.19" default-features = false features = [ "network" ] [dependencies.snarkvm-algorithms] path = "../../algorithms" -version = "=0.16.15" +version = "=0.16.19" [dependencies.bincode] version = "1" diff --git a/synthesizer/snark/src/certificate/parse.rs b/synthesizer/snark/src/certificate/parse.rs index 40aa1414d2..cc22051156 100644 --- a/synthesizer/snark/src/certificate/parse.rs +++ b/synthesizer/snark/src/certificate/parse.rs @@ -74,9 +74,9 @@ impl Display for Certificate { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() -> Result<()> { diff --git a/synthesizer/snark/src/lib.rs b/synthesizer/snark/src/lib.rs index f0a0c292c5..458d684ce7 100644 --- a/synthesizer/snark/src/lib.rs +++ b/synthesizer/snark/src/lib.rs @@ -50,11 +50,11 @@ pub(crate) mod test_helpers { environment::{Assignment, Circuit, Eject, Environment, Inject, Mode, One}, types::Field, }; - use console::{network::Testnet3, prelude::One as _}; + use console::{network::MainnetV0, prelude::One as _}; use once_cell::sync::OnceCell; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; /// Compute 2^EXPONENT - 1, in a purposefully constraint-inefficient manner for testing. fn create_example_circuit() -> Field { @@ -138,9 +138,9 @@ pub(crate) mod test_helpers { mod test { use super::*; use circuit::environment::{Circuit, Environment}; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_varuna() { diff --git a/synthesizer/snark/src/proof/mod.rs b/synthesizer/snark/src/proof/mod.rs index 9bdebe464c..745e087c07 100644 --- a/synthesizer/snark/src/proof/mod.rs +++ b/synthesizer/snark/src/proof/mod.rs @@ -26,7 +26,7 @@ pub struct Proof { impl Proof { /// Initializes a new proof. - pub(super) const fn new(proof: varuna::Proof) -> Self { + pub const fn new(proof: varuna::Proof) -> Self { Self { proof } } } diff --git a/synthesizer/snark/src/proof/parse.rs b/synthesizer/snark/src/proof/parse.rs index 9ce603dfc0..9fc9fdd3a0 100644 --- a/synthesizer/snark/src/proof/parse.rs +++ b/synthesizer/snark/src/proof/parse.rs @@ -72,9 +72,9 @@ impl Display for Proof { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; + use console::network::MainnetV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_parse() -> Result<()> { diff --git a/synthesizer/snark/src/proving_key/mod.rs b/synthesizer/snark/src/proving_key/mod.rs index 07b3cd9d8e..5f13807c33 100644 --- a/synthesizer/snark/src/proving_key/mod.rs +++ b/synthesizer/snark/src/proving_key/mod.rs @@ -65,10 +65,12 @@ impl ProvingKey { let timer = std::time::Instant::now(); // Prepare the instances. + let num_expected_instances = assignments.len(); let instances: BTreeMap<_, _> = assignments .iter() .map(|(proving_key, assignments)| (proving_key.deref(), assignments.as_slice())) .collect(); + ensure!(instances.len() == num_expected_instances, "Incorrect number of proving keys for batch proof"); // Retrieve the proving parameters. let universal_prover = N::varuna_universal_prover(); diff --git a/synthesizer/snark/src/verifying_key/mod.rs b/synthesizer/snark/src/verifying_key/mod.rs index 700d791080..a9494acf79 100644 --- a/synthesizer/snark/src/verifying_key/mod.rs +++ b/synthesizer/snark/src/verifying_key/mod.rs @@ -61,13 +61,19 @@ impl VerifyingKey { /// Returns `true` if the batch proof is valid for the given public inputs. #[allow(clippy::type_complexity)] - pub fn verify_batch(locator: &str, inputs: Vec<(VerifyingKey, Vec>)>, proof: &Proof) -> bool { + pub fn verify_batch( + locator: &str, + inputs: Vec<(VerifyingKey, Vec>)>, + proof: &Proof, + ) -> Result<()> { #[cfg(feature = "aleo-cli")] let timer = std::time::Instant::now(); // Convert the instances. + let num_expected_keys = inputs.len(); let keys_to_inputs: BTreeMap<_, _> = inputs.iter().map(|(verifying_key, inputs)| (verifying_key.deref(), inputs.as_slice())).collect(); + ensure!(keys_to_inputs.len() == num_expected_keys, "Incorrect number of verifying keys for batch proof"); // Retrieve the verification parameters. let universal_verifier = N::varuna_universal_verifier(); @@ -77,13 +83,16 @@ impl VerifyingKey { match Varuna::::verify_batch(universal_verifier, fiat_shamir, &keys_to_inputs, proof) { Ok(is_valid) => { #[cfg(feature = "aleo-cli")] - println!("{}", format!(" • Verified '{locator}' (in {} ms)", timer.elapsed().as_millis()).dimmed()); - is_valid + println!( + "{}", + format!(" • Verified '{locator}': {is_valid} (in {} ms)", timer.elapsed().as_millis()).dimmed() + ); + if is_valid { Ok(()) } else { bail!("'verify_batch' failed") } } Err(error) => { #[cfg(feature = "aleo-cli")] println!("{}", format!(" • Verifier failed: {error}").dimmed()); - false + bail!(error) } } } diff --git a/synthesizer/src/vm/deploy.rs b/synthesizer/src/vm/deploy.rs index e080ba54d9..f9e260793c 100644 --- a/synthesizer/src/vm/deploy.rs +++ b/synthesizer/src/vm/deploy.rs @@ -40,7 +40,7 @@ impl> VM { let owner = ProgramOwner::new(private_key, deployment_id, rng)?; // Compute the minimum deployment cost. - let (minimum_deployment_cost, (_, _)) = deployment_cost(&deployment)?; + let (minimum_deployment_cost, _) = deployment_cost(&deployment)?; // Authorize the fee. let fee_authorization = match fee_record { Some(record) => self.authorize_fee_private( diff --git a/synthesizer/src/vm/execute.rs b/synthesizer/src/vm/execute.rs index 31a2111188..b27626504d 100644 --- a/synthesizer/src/vm/execute.rs +++ b/synthesizer/src/vm/execute.rs @@ -208,7 +208,7 @@ mod tests { use super::*; use console::{ account::{Address, ViewKey}, - network::Testnet3, + network::MainnetV0, program::{Ciphertext, Value}, types::Field, }; @@ -217,7 +217,7 @@ mod tests { use indexmap::IndexMap; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; fn prepare_vm( rng: &mut TestRng, @@ -271,13 +271,13 @@ mod tests { // Assert the size of the transaction. let transaction_size_in_bytes = transaction.to_bytes_le().unwrap().len(); - assert_eq!(3629, transaction_size_in_bytes, "Update me if serialization has changed"); + assert_eq!(3693, transaction_size_in_bytes, "Update me if serialization has changed"); // Assert the size of the execution. assert!(matches!(transaction, Transaction::Execute(_, _, _))); if let Transaction::Execute(_, execution, _) = &transaction { let execution_size_in_bytes = execution.to_bytes_le().unwrap().len(); - assert_eq!(2210, execution_size_in_bytes, "Update me if serialization has changed"); + assert_eq!(2242, execution_size_in_bytes, "Update me if serialization has changed"); } } @@ -305,13 +305,13 @@ mod tests { // Assert the size of the transaction. let transaction_size_in_bytes = transaction.to_bytes_le().unwrap().len(); - assert_eq!(2807, transaction_size_in_bytes, "Update me if serialization has changed"); + assert_eq!(2871, transaction_size_in_bytes, "Update me if serialization has changed"); // Assert the size of the execution. assert!(matches!(transaction, Transaction::Execute(_, _, _))); if let Transaction::Execute(_, execution, _) = &transaction { let execution_size_in_bytes = execution.to_bytes_le().unwrap().len(); - assert_eq!(1388, execution_size_in_bytes, "Update me if serialization has changed"); + assert_eq!(1420, execution_size_in_bytes, "Update me if serialization has changed"); } } @@ -340,13 +340,13 @@ mod tests { // Assert the size of the transaction. let transaction_size_in_bytes = transaction.to_bytes_le().unwrap().len(); - assert_eq!(3474, transaction_size_in_bytes, "Update me if serialization has changed"); + assert_eq!(3538, transaction_size_in_bytes, "Update me if serialization has changed"); // Assert the size of the execution. assert!(matches!(transaction, Transaction::Execute(_, _, _))); if let Transaction::Execute(_, execution, _) = &transaction { let execution_size_in_bytes = execution.to_bytes_le().unwrap().len(); - assert_eq!(2055, execution_size_in_bytes, "Update me if serialization has changed"); + assert_eq!(2087, execution_size_in_bytes, "Update me if serialization has changed"); } } @@ -374,13 +374,13 @@ mod tests { // Assert the size of the transaction. let transaction_size_in_bytes = transaction.to_bytes_le().unwrap().len(); - assert_eq!(2134, transaction_size_in_bytes, "Update me if serialization has changed"); + assert_eq!(2166, transaction_size_in_bytes, "Update me if serialization has changed"); // Assert the size of the execution. assert!(matches!(transaction, Transaction::Execute(_, _, _))); if let Transaction::Execute(_, execution, _) = &transaction { let execution_size_in_bytes = execution.to_bytes_le().unwrap().len(); - assert_eq!(2099, execution_size_in_bytes, "Update me if serialization has changed"); + assert_eq!(2131, execution_size_in_bytes, "Update me if serialization has changed"); } } @@ -397,7 +397,7 @@ mod tests { }; // Assert the size of the transition. let fee_size_in_bytes = fee.to_bytes_le().unwrap().len(); - assert_eq!(2011, fee_size_in_bytes, "Update me if serialization has changed"); + assert_eq!(2043, fee_size_in_bytes, "Update me if serialization has changed"); } #[test] @@ -413,6 +413,6 @@ mod tests { }; // Assert the size of the transition. let fee_size_in_bytes = fee.to_bytes_le().unwrap().len(); - assert_eq!(1384, fee_size_in_bytes, "Update me if serialization has changed"); + assert_eq!(1416, fee_size_in_bytes, "Update me if serialization has changed"); } } diff --git a/synthesizer/src/vm/finalize.rs b/synthesizer/src/vm/finalize.rs index 8c9422d153..8d759526dd 100644 --- a/synthesizer/src/vm/finalize.rs +++ b/synthesizer/src/vm/finalize.rs @@ -31,7 +31,7 @@ impl> VM { state: FinalizeGlobalState, coinbase_reward: Option, candidate_ratifications: Vec>, - candidate_solutions: Option<&CoinbaseSolution>, + candidate_solutions: &Solutions, candidate_transactions: impl ExactSizeIterator>, ) -> Result<(Ratifications, Transactions, Vec, Vec>)> { let timer = timer!("VM::speculate"); @@ -72,7 +72,7 @@ impl> VM { &self, state: FinalizeGlobalState, ratifications: &Ratifications, - solutions: Option<&CoinbaseSolution>, + solutions: &Solutions, transactions: &Transactions, ) -> Result>> { let timer = timer!("VM::check_speculate"); @@ -114,7 +114,7 @@ impl> VM { &self, state: FinalizeGlobalState, ratifications: &Ratifications, - solutions: Option<&CoinbaseSolution>, + solutions: &Solutions, transactions: &Transactions, ) -> Result>> { let timer = timer!("VM::finalize"); @@ -151,7 +151,7 @@ impl> VM { state: FinalizeGlobalState, coinbase_reward: Option, ratifications: Vec>, - solutions: Option<&CoinbaseSolution>, + solutions: &Solutions, transactions: impl ExactSizeIterator>, ) -> Result<( Ratifications, @@ -166,17 +166,28 @@ impl> VM { let timer = timer!("VM::atomic_speculate"); + // Retrieve the number of solutions. + let num_solutions = solutions.len(); // Retrieve the number of transactions. let num_transactions = transactions.len(); // Perform the finalize operation on the preset finalize mode. atomic_finalize!(self.finalize_store(), FinalizeMode::DryRun, { + // Ensure the number of solutions does not exceed the maximum. + if num_solutions > Solutions::::MAX_ABORTED_SOLUTIONS { + // Note: This will abort the entire atomic batch. + return Err(format!( + "Too many solutions in the block - {num_solutions} (max: {})", + Solutions::::MAX_ABORTED_SOLUTIONS + )); + } + // Ensure the number of transactions does not exceed the maximum. - if num_transactions > 2 * Transactions::::MAX_TRANSACTIONS { + if num_transactions > Transactions::::MAX_ABORTED_TRANSACTIONS { // Note: This will abort the entire atomic batch. return Err(format!( "Too many transactions in the block - {num_transactions} (max: {})", - 2 * Transactions::::MAX_TRANSACTIONS + Transactions::::MAX_ABORTED_TRANSACTIONS )); } @@ -221,8 +232,14 @@ impl> VM { let mut deployments = IndexSet::new(); // Initialize a counter for the confirmed transaction index. let mut counter = 0u32; + // Initialize a list of created transition IDs. + let mut transition_ids: IndexSet = IndexSet::new(); // Initialize a list of spent input IDs. let mut input_ids: IndexSet> = IndexSet::new(); + // Initialize a list of created output IDs. + let mut output_ids: IndexSet> = IndexSet::new(); + // Initialize the list of created transition public keys. + let mut tpks: IndexSet> = IndexSet::new(); // Finalize the transactions. 'outer: for transaction in transactions { @@ -235,6 +252,19 @@ impl> VM { continue 'outer; } + // Ensure that the transaction is not producing a duplicate transition. + for transition_id in transaction.transition_ids() { + // If the transition ID is already produced in this block or previous blocks, abort the transaction. + if transition_ids.contains(transition_id) + || self.transition_store().contains_transition_id(transition_id).unwrap_or(true) + { + // Store the aborted transaction. + aborted.push((transaction.clone(), format!("Duplicate transition {transition_id}"))); + // Continue to the next transaction. + continue 'outer; + } + } + // Ensure that the transaction is not double-spending an input. for input_id in transaction.input_ids() { // If the input ID is already spent in this block or previous blocks, abort the transaction. @@ -248,6 +278,31 @@ impl> VM { } } + // Ensure that the transaction is not producing a duplicate output. + for output_id in transaction.output_ids() { + // If the output ID is already produced in this block or previous blocks, abort the transaction. + if output_ids.contains(output_id) + || self.transition_store().contains_output_id(output_id).unwrap_or(true) + { + // Store the aborted transaction. + aborted.push((transaction.clone(), format!("Duplicate output {output_id}"))); + // Continue to the next transaction. + continue 'outer; + } + } + + // // Ensure that the transaction is not producing a duplicate transition public key. + // // Note that the tpk and tcm are corresponding, so a uniqueness check for just the tpk is sufficient. + for tpk in transaction.transition_public_keys() { + // If the transition public key is already produced in this block or previous blocks, abort the transaction. + if tpks.contains(tpk) || self.transition_store().contains_tpk(tpk).unwrap_or(true) { + // Store the aborted transaction. + aborted.push((transaction.clone(), format!("Duplicate transition public key {tpk}"))); + // Continue to the next transaction. + continue 'outer; + } + } + // Process the transaction in an isolated atomic batch. // - If the transaction succeeds, the finalize operations are stored. // - If the transaction fails, the atomic batch is aborted and no finalize operations are stored. @@ -361,8 +416,14 @@ impl> VM { match outcome { // If the transaction succeeded, store it and continue to the next transaction. Ok(confirmed_transaction) => { + // Add the transition IDs to the set of produced transition IDs. + transition_ids.extend(confirmed_transaction.transaction().transition_ids()); // Add the input IDs to the set of spent input IDs. input_ids.extend(confirmed_transaction.transaction().input_ids()); + // Add the output IDs to the set of produced output IDs. + output_ids.extend(confirmed_transaction.transaction().output_ids()); + // Add the transition public keys to the set of produced transition public keys. + tpks.extend(confirmed_transaction.transaction().transition_public_keys()); // Store the confirmed transaction. confirmed.push(confirmed_transaction); // Increment the transaction index counter. @@ -450,7 +511,7 @@ impl> VM { &self, state: FinalizeGlobalState, ratifications: &Ratifications, - solutions: Option<&CoinbaseSolution>, + solutions: &Solutions, transactions: &Transactions, ) -> Result>> { // Acquire the atomic lock, which is needed to ensure this function is not called concurrently @@ -697,6 +758,8 @@ impl> VM { let bonded_mapping = Identifier::from_str("bonded")?; // Construct the account mapping name. let account_mapping = Identifier::from_str("account")?; + // Construct the metadata mapping name. + let metadata_mapping = Identifier::from_str("metadata")?; // Initialize a list of finalize operations. let mut finalize_operations = Vec::new(); @@ -715,6 +778,11 @@ impl> VM { committee.starting_round() == 0, "Ratify::Genesis(..) expected a genesis committee round of 0" ); + // Ensure that the number of members in the committee does not exceed the maximum. + ensure!( + committee.members().len() <= Committee::::MAX_COMMITTEE_SIZE as usize, + "Ratify::Genesis(..) exceeds the maximum number of committee members" + ); // Ensure genesis has not been ratified yet. ensure!(!is_genesis_ratified, "Ratify::Genesis(..) has already been ratified"); @@ -752,6 +820,17 @@ impl> VM { store.replace_mapping(program_id, bonded_mapping, next_bonded_map)?, ]); + // Update the number of validators. + finalize_operations.extend(&[ + // Update the number of validators in the metadata mapping. + store.update_key_value( + program_id, + metadata_mapping, + Plaintext::from_str("aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc")?, + Value::from_str(&format!("{}u32", committee.num_members()))?, + )?, + ]); + // Iterate over the public balances. for (address, amount) in public_balances { // Construct the key. @@ -788,7 +867,7 @@ impl> VM { store: &FinalizeStore, state: FinalizeGlobalState, post_ratifications: impl Iterator>, - solutions: Option<&CoinbaseSolution>, + solutions: &Solutions, ) -> Result>> { // Construct the program ID. let program_id = ProgramID::from_str("credits.aleo")?; @@ -831,6 +910,7 @@ impl> VM { let next_stakers = staking_rewards(¤t_stakers, ¤t_committee, *block_reward); // Compute the updated committee, using the stakers. let next_committee = to_next_committee(¤t_committee, state.block_round(), &next_stakers)?; + // Construct the next committee map and next bonded map. let (next_committee_map, next_bonded_map) = to_next_commitee_map_and_bonded_map(&next_committee, &next_stakers); @@ -857,7 +937,7 @@ impl> VM { continue; } // Retrieve the solutions. - let Some(solutions) = solutions else { + let Some(solutions) = solutions.deref() else { continue; }; // Compute the proof targets, with the corresponding addresses. @@ -905,6 +985,7 @@ mod tests { types::Field, }; use ledger_block::{Block, Header, Metadata, Transaction, Transition}; + use ledger_committee::MIN_VALIDATOR_STAKE; use ledger_store::helpers::memory::ConsensusMemory; use synthesizer_program::Program; @@ -990,8 +1071,13 @@ finalize transfer_public: rng: &mut R, ) -> Result> { // Speculate on the candidate ratifications, solutions, and transactions. - let (ratifications, transactions, aborted_transaction_ids, ratified_finalize_operations) = - vm.speculate(sample_finalize_state(1), None, vec![], None, transactions.iter())?; + let (ratifications, transactions, aborted_transaction_ids, ratified_finalize_operations) = vm.speculate( + sample_finalize_state(previous_block.height() + 1), + Some(0), + vec![], + &None.into(), + transactions.iter(), + )?; // Construct the metadata associated with the block. let metadata = Metadata::new( @@ -1023,7 +1109,8 @@ finalize transfer_public: previous_block.hash(), header, ratifications, - None, + None.into(), + vec![], transactions, aborted_transaction_ids, rng, @@ -1175,7 +1262,7 @@ finalize transfer_public: // Prepare the confirmed transactions. let (ratifications, confirmed_transactions, aborted_transaction_ids, _) = vm - .speculate(sample_finalize_state(1), None, vec![], None, [deployment_transaction.clone()].iter()) + .speculate(sample_finalize_state(1), None, vec![], &None.into(), [deployment_transaction.clone()].iter()) .unwrap(); assert_eq!(confirmed_transactions.len(), 1); assert!(aborted_transaction_ids.is_empty()); @@ -1184,25 +1271,26 @@ finalize transfer_public: assert!(!vm.contains_program(&program_id)); // Finalize the transaction. - assert!(vm.finalize(sample_finalize_state(1), &ratifications, None, &confirmed_transactions).is_ok()); + assert!(vm.finalize(sample_finalize_state(1), &ratifications, &None.into(), &confirmed_transactions).is_ok()); // Ensure the VM contains this program. assert!(vm.contains_program(&program_id)); // Ensure the VM can't redeploy the same transaction. - assert!(vm.finalize(sample_finalize_state(1), &ratifications, None, &confirmed_transactions).is_err()); + assert!(vm.finalize(sample_finalize_state(1), &ratifications, &None.into(), &confirmed_transactions).is_err()); // Ensure the VM contains this program. assert!(vm.contains_program(&program_id)); // Ensure the dry run of the redeployment will cause a reject transaction to be created. - let (_, candidate_transactions, aborted_transaction_ids, _) = - vm.atomic_speculate(sample_finalize_state(1), None, vec![], None, [deployment_transaction].iter()).unwrap(); + let (_, candidate_transactions, aborted_transaction_ids, _) = vm + .atomic_speculate(sample_finalize_state(1), None, vec![], &None.into(), [deployment_transaction].iter()) + .unwrap(); assert_eq!(candidate_transactions.len(), 1); assert!(matches!(candidate_transactions[0], ConfirmedTransaction::RejectedDeploy(..))); assert!(aborted_transaction_ids.is_empty()); - // Check that the unconfirmed transaction id of the rejected deployment is correct. + // Check that the unconfirmed transaction ID of the rejected deployment is correct. assert_eq!(candidate_transactions[0].to_unconfirmed_transaction_id().unwrap(), deployment_transaction_id); } @@ -1299,7 +1387,7 @@ finalize transfer_public: { let transactions = [mint_10.clone(), transfer_10.clone(), transfer_20.clone()]; let (_, confirmed_transactions, aborted_transaction_ids, _) = - vm.atomic_speculate(sample_finalize_state(1), None, vec![], None, transactions.iter()).unwrap(); + vm.atomic_speculate(sample_finalize_state(1), None, vec![], &None.into(), transactions.iter()).unwrap(); // Assert that all the transactions are accepted. assert_eq!(confirmed_transactions.len(), 3); @@ -1319,7 +1407,7 @@ finalize transfer_public: { let transactions = [transfer_20.clone(), mint_10.clone(), mint_20.clone(), transfer_30.clone()]; let (_, confirmed_transactions, aborted_transaction_ids, _) = - vm.atomic_speculate(sample_finalize_state(1), None, vec![], None, transactions.iter()).unwrap(); + vm.atomic_speculate(sample_finalize_state(1), None, vec![], &None.into(), transactions.iter()).unwrap(); // Assert that all the transactions are accepted. assert_eq!(confirmed_transactions.len(), 4); @@ -1339,7 +1427,7 @@ finalize transfer_public: { let transactions = [transfer_20.clone(), transfer_10.clone()]; let (_, confirmed_transactions, aborted_transaction_ids, _) = - vm.atomic_speculate(sample_finalize_state(1), None, vec![], None, transactions.iter()).unwrap(); + vm.atomic_speculate(sample_finalize_state(1), None, vec![], &None.into(), transactions.iter()).unwrap(); // Assert that the accepted and rejected transactions are correct. assert_eq!(confirmed_transactions.len(), 2); @@ -1363,7 +1451,7 @@ finalize transfer_public: { let transactions = [mint_20.clone(), transfer_30.clone(), transfer_20.clone(), transfer_10.clone()]; let (_, confirmed_transactions, aborted_transaction_ids, _) = - vm.atomic_speculate(sample_finalize_state(1), None, vec![], None, transactions.iter()).unwrap(); + vm.atomic_speculate(sample_finalize_state(1), None, vec![], &None.into(), transactions.iter()).unwrap(); // Assert that the accepted and rejected transactions are correct. assert_eq!(confirmed_transactions.len(), 4); @@ -1461,8 +1549,9 @@ function ped_hash: create_execution(&vm, caller_private_key, program_id, "ped_hash", inputs, &mut unspent_records, rng); // Speculatively execute the transaction. Ensure that this call does not panic and returns a rejected transaction. - let (_, confirmed_transactions, aborted_transaction_ids, _) = - vm.speculate(sample_finalize_state(1), None, vec![], None, [transaction.clone()].iter()).unwrap(); + let (_, confirmed_transactions, aborted_transaction_ids, _) = vm + .speculate(sample_finalize_state(1), None, vec![], &None.into(), [transaction.clone()].iter()) + .unwrap(); assert!(aborted_transaction_ids.is_empty()); // Ensure that the transaction is rejected. @@ -1686,4 +1775,215 @@ finalize compute: VM::>::MAXIMUM_CONFIRMED_TRANSACTIONS ); } + + #[test] + fn test_genesis_ratify_greater_than_max_committee_size() { + // Initialize an RNG. + let rng = &mut TestRng::default(); + + // Initialize the VM. + let vm = + VM::from(ConsensusStore::>::open(None).unwrap()).unwrap(); + + // Construct the validators, greater than the maximum committee size. + let validators = (0..(Committee::::MAX_COMMITTEE_SIZE + 1)) + .map(|_| { + let private_key = PrivateKey::::new(rng).unwrap(); + let amount = MIN_VALIDATOR_STAKE; + let is_open = true; + (private_key, (amount, is_open)) + }) + .collect::>(); + + // Construct the committee. + let mut committee_map = IndexMap::new(); + for (private_key, (amount, _)) in &validators { + let address = Address::try_from(private_key).unwrap(); + committee_map.insert(address, (*amount, true)); + } + + // Attempt to construct a `Committee` with more than the maximum committee size. + let result = Committee::new_genesis(committee_map); + assert!(result.is_err()); + + // Reset the validators. + let validators = (0..Committee::::MAX_COMMITTEE_SIZE) + .map(|_| { + let private_key = PrivateKey::new(rng).unwrap(); + let amount = MIN_VALIDATOR_STAKE; + let is_open = true; + (private_key, (amount, is_open)) + }) + .collect::>(); + + // Track the allocated amount. + let mut allocated_amount = 0; + + // Construct the committee. + let mut committee_map = IndexMap::new(); + for (private_key, (amount, _)) in &validators { + let address = Address::try_from(private_key).unwrap(); + committee_map.insert(address, (*amount, true)); + allocated_amount += *amount; + } + + // Construct the public balances, allocating the remaining supply. + let mut public_balances = IndexMap::new(); + let remaining_supply = ::STARTING_SUPPLY - allocated_amount; + for (private_key, _) in &validators { + let address = Address::try_from(private_key).unwrap(); + let amount = remaining_supply / validators.len() as u64; + allocated_amount += amount; + public_balances.insert(address, amount); + } + let remaining_supply = ::STARTING_SUPPLY - allocated_amount; + if remaining_supply > 0 { + let address = Address::try_from(&PrivateKey::::new(rng).unwrap()).unwrap(); + public_balances.insert(address, remaining_supply); + } + + // Construct the genesis block, which should pass. + let block = vm + .genesis_quorum( + validators.keys().next().unwrap(), + Committee::new_genesis(committee_map).unwrap(), + public_balances, + rng, + ) + .unwrap(); + + // Add the block. + vm.add_next_block(&block).unwrap(); + } + + #[test] + fn test_max_committee_limit_with_bonds() { + // Initialize an RNG. + let rng = &mut TestRng::default(); + + // Initialize the VM. + let vm = + VM::from(ConsensusStore::>::open(None).unwrap()).unwrap(); + + // Construct the validators, one less than the maximum committee size. + let validators = (0..Committee::::MAX_COMMITTEE_SIZE - 1) + .map(|_| { + let private_key = PrivateKey::::new(rng).unwrap(); + let amount = MIN_VALIDATOR_STAKE; + let is_open = true; + (private_key, (amount, is_open)) + }) + .collect::>(); + + // Track the allocated amount. + let mut allocated_amount = 0; + + // Construct the committee. + let mut committee_map = IndexMap::new(); + for (private_key, (amount, _)) in &validators { + let address = Address::try_from(private_key).unwrap(); + committee_map.insert(address, (*amount, true)); + allocated_amount += *amount; + } + + // Initialize two new validators. + let first_private_key = PrivateKey::::new(rng).unwrap(); + let first_address = Address::try_from(&first_private_key).unwrap(); + let second_private_key = PrivateKey::::new(rng).unwrap(); + let second_address = Address::try_from(&second_private_key).unwrap(); + + // Construct the public balances, allocating the remaining supply to the first validator and two new validators. + let mut public_balances = IndexMap::new(); + let remaining_supply = ::STARTING_SUPPLY - allocated_amount; + let amount = remaining_supply / 3; + public_balances.insert(Address::try_from(validators.keys().next().unwrap()).unwrap(), amount); + public_balances.insert(first_address, amount); + public_balances.insert(second_address, remaining_supply - 2 * amount); + + // Construct the genesis block, which should pass. + let genesis_block = vm + .genesis_quorum( + validators.keys().next().unwrap(), + Committee::new_genesis(committee_map).unwrap(), + public_balances, + rng, + ) + .unwrap(); + + // Add the block. + vm.add_next_block(&genesis_block).unwrap(); + + // Bond the first validator. + let bond_first_transaction = vm + .execute( + &first_private_key, + ("credits.aleo", "bond_public"), + vec![ + Value::::from_str(&first_address.to_string()).unwrap(), + Value::::from_str(&format!("{MIN_VALIDATOR_STAKE}u64")).unwrap(), + ] + .iter(), + None, + 0, + None, + rng, + ) + .unwrap(); + + // Construct the next block. + let next_block = sample_next_block( + &vm, + validators.keys().next().unwrap(), + &[bond_first_transaction], + &genesis_block, + &mut vec![], + rng, + ) + .unwrap(); + + // Check that the transaction was accepted. + assert!(next_block.aborted_transaction_ids().is_empty()); + + // Add the next block to the VM. + vm.add_next_block(&next_block).unwrap(); + + // Check that the first validator was added to the committee. + let committee = vm.finalize_store().committee_store().current_committee().unwrap(); + assert!(committee.is_committee_member(first_address)); + + // Attempt to bond the second validator. + let bond_second_transaction = vm + .execute( + &second_private_key, + ("credits.aleo", "bond_public"), + vec![ + Value::::from_str(&second_address.to_string()).unwrap(), + Value::::from_str(&format!("{MIN_VALIDATOR_STAKE}u64")).unwrap(), + ] + .iter(), + None, + 0, + None, + rng, + ) + .unwrap(); + + // Construct the next block. + let next_block = sample_next_block( + &vm, + validators.keys().next().unwrap(), + &[bond_second_transaction], + &next_block, + &mut vec![], + rng, + ) + .unwrap(); + + // Check that the transaction was rejected. + assert!(next_block.transactions().iter().next().unwrap().is_rejected()); + + // Check that the second validator was not added to the committee. + let committee = vm.finalize_store().committee_store().current_committee().unwrap(); + assert!(!committee.is_committee_member(second_address)); + } } diff --git a/synthesizer/src/vm/helpers/cost.rs b/synthesizer/src/vm/helpers/cost.rs index 6f349baa84..bcee10e70d 100644 --- a/synthesizer/src/vm/helpers/cost.rs +++ b/synthesizer/src/vm/helpers/cost.rs @@ -12,31 +12,37 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::VM; +use crate::{ + prelude::{Stack, StackProgramTypes}, + VM, +}; use console::{ prelude::*, - program::{LiteralType, PlaintextType}, + program::{FinalizeType, Identifier, LiteralType, PlaintextType}, }; use ledger_block::{Deployment, Execution}; use ledger_store::ConsensusStorage; -use synthesizer_program::{Command, Finalize, Instruction}; - -use std::collections::HashMap; +use synthesizer_program::{CastType, Command, Finalize, Instruction, Operand, StackProgram}; -/// Returns the *minimum* cost in microcredits to publish the given deployment (total cost, (storage cost, namespace cost)). -pub fn deployment_cost(deployment: &Deployment) -> Result<(u64, (u64, u64))> { +/// Returns the *minimum* cost in microcredits to publish the given deployment (total cost, (storage cost, synthesis cost, namespace cost)). +pub fn deployment_cost(deployment: &Deployment) -> Result<(u64, (u64, u64, u64))> { // Determine the number of bytes in the deployment. let size_in_bytes = deployment.size_in_bytes()?; // Retrieve the program ID. let program_id = deployment.program_id(); // Determine the number of characters in the program ID. let num_characters = u32::try_from(program_id.name().to_string().len())?; + // Compute the number of combined constraints in the program. + let num_combined_constraints = deployment.num_combined_constraints()?; // Compute the storage cost in microcredits. let storage_cost = size_in_bytes .checked_mul(N::DEPLOYMENT_FEE_MULTIPLIER) .ok_or(anyhow!("The storage cost computation overflowed for a deployment"))?; + // Compute the synthesis cost in microcredits. + let synthesis_cost = num_combined_constraints * N::SYNTHESIS_FEE_MULTIPLIER; + // Compute the namespace cost in credits: 10^(10 - num_characters). let namespace_cost = 10u64 .checked_pow(10u32.saturating_sub(num_characters)) @@ -45,13 +51,14 @@ pub fn deployment_cost(deployment: &Deployment) -> Result<(u64, ( // Compute the total cost in microcredits. let total_cost = storage_cost - .checked_add(namespace_cost) + .checked_add(synthesis_cost) + .and_then(|x| x.checked_add(namespace_cost)) .ok_or(anyhow!("The total cost computation overflowed for a deployment"))?; - Ok((total_cost, (storage_cost, namespace_cost))) + Ok((total_cost, (storage_cost, synthesis_cost, namespace_cost))) } -/// Returns the *minimum* cost in microcredits to publish the given execution (total cost, (storage cost, namespace cost)). +/// Returns the *minimum* cost in microcredits to publish the given execution (total cost, (storage cost, finalize cost)). pub fn execution_cost>( vm: &VM, execution: &Execution, @@ -59,34 +66,20 @@ pub fn execution_cost>( // Compute the storage cost in microcredits. let storage_cost = execution.size_in_bytes()?; - // Prepare the program lookup. - let lookup = execution - .transitions() - .map(|transition| { - let program_id = transition.program_id(); - Ok((*program_id, vm.process().read().get_program(program_id)?.clone())) - }) - .collect::>>()?; - // Compute the finalize cost in microcredits. let mut finalize_cost = 0u64; // Iterate over the transitions to accumulate the finalize cost. for transition in execution.transitions() { - // Retrieve the program ID. - let program_id = transition.program_id(); - // Retrieve the function name. - let function_name = transition.function_name(); - // Retrieve the program. - let program = lookup.get(program_id).ok_or(anyhow!("Program '{program_id}' is missing"))?; + // Retrieve the program ID and function name. + let (program_id, function_name) = (transition.program_id(), transition.function_name()); // Retrieve the finalize cost. - let cost = match program.get_function(function_name)?.finalize_logic() { - Some(finalize) => cost_in_microcredits(finalize)?, - None => continue, - }; + let cost = cost_in_microcredits(vm.process().read().get_stack(program_id)?, function_name)?; // Accumulate the finalize cost. - finalize_cost = finalize_cost - .checked_add(cost) - .ok_or(anyhow!("The finalize cost computation overflowed for an execution"))?; + if cost > 0 { + finalize_cost = finalize_cost + .checked_add(cost) + .ok_or(anyhow!("The finalize cost computation overflowed on '{program_id}/{function_name}'"))?; + } } // Compute the total cost in microcredits. @@ -98,107 +91,292 @@ pub fn execution_cost>( } /// Returns the minimum number of microcredits required to run the finalize. -pub fn cost_in_microcredits(finalize: &Finalize) -> Result { - // Defines the cost of each command. +pub fn cost_in_microcredits(stack: &Stack, function_name: &Identifier) -> Result { + /// A helper function to determine the plaintext type in bytes. + fn plaintext_size_in_bytes(stack: &Stack, plaintext_type: &PlaintextType) -> Result { + match plaintext_type { + PlaintextType::Literal(literal_type) => Ok(literal_type.size_in_bytes::() as u64), + PlaintextType::Struct(struct_name) => { + // Retrieve the struct from the stack. + let struct_ = stack.program().get_struct(struct_name)?; + // Retrieve the size of the struct name. + let size_of_name = struct_.name().to_bytes_le()?.len() as u64; + // Retrieve the size of all the members of the struct. + let size_of_members = struct_.members().iter().try_fold(0u64, |acc, (_, member_type)| { + acc.checked_add(plaintext_size_in_bytes(stack, member_type)?).ok_or(anyhow!( + "Overflowed while computing the size of the struct '{}/{struct_name}' - {member_type}", + stack.program_id() + )) + })?; + // Return the size of the struct. + Ok(size_of_name.saturating_add(size_of_members)) + } + PlaintextType::Array(array_type) => { + // Retrieve the number of elements in the array. + let num_elements = **array_type.length() as u64; + // Compute the size of an array element. + let size_of_element = plaintext_size_in_bytes(stack, array_type.next_element_type())?; + // Return the size of the array. + Ok(num_elements.saturating_mul(size_of_element)) + } + } + } + + /// A helper function to compute the following: base_cost + (byte_multiplier * size_of_operands). + fn cost_in_size<'a, N: Network>( + stack: &Stack, + finalize: &Finalize, + operands: impl IntoIterator>, + byte_multiplier: u64, + base_cost: u64, + ) -> Result { + // Retrieve the finalize types. + let finalize_types = stack.get_finalize_types(finalize.name())?; + // Compute the size of the operands. + let size_of_operands = operands.into_iter().try_fold(0u64, |acc, operand| { + // Determine the size of the operand. + let operand_size = match finalize_types.get_type_from_operand(stack, operand)? { + FinalizeType::Plaintext(plaintext_type) => plaintext_size_in_bytes(stack, &plaintext_type)?, + FinalizeType::Future(future) => { + bail!("Future '{future}' is not a valid operand in the finalize scope"); + } + }; + // Safely add the size to the accumulator. + acc.checked_add(operand_size).ok_or(anyhow!( + "Overflowed while computing the size of the operand '{operand}' in '{}/{}' (finalize)", + stack.program_id(), + finalize.name() + )) + })?; + // Return the cost. + Ok(base_cost.saturating_add(byte_multiplier.saturating_mul(size_of_operands))) + } + + // Finalize costs for compute heavy operations, derived as: + // `BASE_COST + (PER_BYTE_COST * SIZE_IN_BYTES)`. + + const CAST_BASE_COST: u64 = 500; + const CAST_PER_BYTE_COST: u64 = 30; + + const HASH_BASE_COST: u64 = 10_000; + const HASH_PER_BYTE_COST: u64 = 30; + + const HASH_BHP_BASE_COST: u64 = 50_000; + const HASH_BHP_PER_BYTE_COST: u64 = 300; + + const HASH_PSD_BASE_COST: u64 = 40_000; + const HASH_PSD_PER_BYTE_COST: u64 = 75; + + const MAPPING_BASE_COST: u64 = 10_000; + const MAPPING_PER_BYTE_COST: u64 = 10; + + const SET_BASE_COST: u64 = 10_000; + const SET_PER_BYTE_COST: u64 = 100; + + // Retrieve the finalize logic. + let Some(finalize) = stack.get_function_ref(function_name)?.finalize_logic() else { + // Return a finalize cost of 0, if the function does not have a finalize scope. + return Ok(0); + }; + + // Measure the cost of each command. let cost = |command: &Command| match command { - Command::Instruction(Instruction::Abs(_)) => Ok(2_000), - Command::Instruction(Instruction::AbsWrapped(_)) => Ok(2_000), - Command::Instruction(Instruction::Add(_)) => Ok(2_000), - Command::Instruction(Instruction::AddWrapped(_)) => Ok(2_000), - Command::Instruction(Instruction::And(_)) => Ok(2_000), - Command::Instruction(Instruction::AssertEq(_)) => Ok(2_000), - Command::Instruction(Instruction::AssertNeq(_)) => Ok(2_000), - Command::Instruction(Instruction::Async(_)) => bail!("`async` is not supported in finalize."), - Command::Instruction(Instruction::Call(_)) => bail!("`call` is not supported in finalize."), - Command::Instruction(Instruction::Cast(_)) => Ok(2_000), - Command::Instruction(Instruction::CastLossy(_)) => Ok(2_000), - Command::Instruction(Instruction::CommitBHP256(_)) => Ok(200_000), - Command::Instruction(Instruction::CommitBHP512(_)) => Ok(200_000), - Command::Instruction(Instruction::CommitBHP768(_)) => Ok(200_000), - Command::Instruction(Instruction::CommitBHP1024(_)) => Ok(200_000), - Command::Instruction(Instruction::CommitPED64(_)) => Ok(100_000), - Command::Instruction(Instruction::CommitPED128(_)) => Ok(100_000), - Command::Instruction(Instruction::Div(_)) => Ok(10_000), - Command::Instruction(Instruction::DivWrapped(_)) => Ok(2_000), - Command::Instruction(Instruction::Double(_)) => Ok(2_000), - Command::Instruction(Instruction::GreaterThan(_)) => Ok(2_000), - Command::Instruction(Instruction::GreaterThanOrEqual(_)) => Ok(2_000), - Command::Instruction(Instruction::HashBHP256(_)) => Ok(100_000), - Command::Instruction(Instruction::HashBHP512(_)) => Ok(100_000), - Command::Instruction(Instruction::HashBHP768(_)) => Ok(100_000), - Command::Instruction(Instruction::HashBHP1024(_)) => Ok(100_000), - Command::Instruction(Instruction::HashKeccak256(_)) => Ok(100_000), - Command::Instruction(Instruction::HashKeccak384(_)) => Ok(100_000), - Command::Instruction(Instruction::HashKeccak512(_)) => Ok(100_000), - Command::Instruction(Instruction::HashPED64(_)) => Ok(20_000), - Command::Instruction(Instruction::HashPED128(_)) => Ok(30_000), - Command::Instruction(Instruction::HashPSD2(hash)) => match hash.destination_type() { - PlaintextType::Literal(LiteralType::Address) | PlaintextType::Literal(LiteralType::Group) => Ok(600_000), - PlaintextType::Literal(..) => Ok(60_000), - plaintext_type => bail!("`hash.psd2` is not supported for plaintext type '{plaintext_type}'"), - }, - Command::Instruction(Instruction::HashPSD4(hash)) => match hash.destination_type() { - PlaintextType::Literal(LiteralType::Address) | PlaintextType::Literal(LiteralType::Group) => Ok(700_000), - PlaintextType::Literal(..) => Ok(100_000), - plaintext_type => bail!("`hash.psd4` is not supported for plaintext type '{plaintext_type}'"), + Command::Instruction(Instruction::Abs(_)) => Ok(500), + Command::Instruction(Instruction::AbsWrapped(_)) => Ok(500), + Command::Instruction(Instruction::Add(_)) => Ok(500), + Command::Instruction(Instruction::AddWrapped(_)) => Ok(500), + Command::Instruction(Instruction::And(_)) => Ok(500), + Command::Instruction(Instruction::AssertEq(_)) => Ok(500), + Command::Instruction(Instruction::AssertNeq(_)) => Ok(500), + Command::Instruction(Instruction::Async(_)) => bail!("'async' is not supported in finalize"), + Command::Instruction(Instruction::Call(_)) => bail!("'call' is not supported in finalize"), + Command::Instruction(Instruction::Cast(cast)) => match cast.cast_type() { + CastType::Plaintext(PlaintextType::Literal(_)) => Ok(500), + CastType::Plaintext(plaintext_type) => Ok(plaintext_size_in_bytes(stack, plaintext_type)? + .saturating_mul(CAST_PER_BYTE_COST) + .saturating_add(CAST_BASE_COST)), + CastType::GroupXCoordinate + | CastType::GroupYCoordinate + | CastType::Record(_) + | CastType::ExternalRecord(_) => Ok(500), }, - Command::Instruction(Instruction::HashPSD8(hash)) => match hash.destination_type() { - PlaintextType::Literal(LiteralType::Address) | PlaintextType::Literal(LiteralType::Group) => Ok(800_000), - PlaintextType::Literal(..) => Ok(200_000), - plaintext_type => bail!("`hash.psd8` is not supported for plaintext type '{plaintext_type}'"), + Command::Instruction(Instruction::CastLossy(cast_lossy)) => match cast_lossy.cast_type() { + CastType::Plaintext(PlaintextType::Literal(_)) => Ok(500), + CastType::Plaintext(plaintext_type) => Ok(plaintext_size_in_bytes(stack, plaintext_type)? + .saturating_mul(CAST_PER_BYTE_COST) + .saturating_add(CAST_BASE_COST)), + CastType::GroupXCoordinate + | CastType::GroupYCoordinate + | CastType::Record(_) + | CastType::ExternalRecord(_) => Ok(500), }, - Command::Instruction(Instruction::HashSha3_256(_)) => Ok(100_000), - Command::Instruction(Instruction::HashSha3_384(_)) => Ok(100_000), - Command::Instruction(Instruction::HashSha3_512(_)) => Ok(100_000), + Command::Instruction(Instruction::CommitBHP256(commit)) => { + cost_in_size(stack, finalize, commit.operands(), HASH_BHP_PER_BYTE_COST, HASH_BHP_BASE_COST) + } + Command::Instruction(Instruction::CommitBHP512(commit)) => { + cost_in_size(stack, finalize, commit.operands(), HASH_BHP_PER_BYTE_COST, HASH_BHP_BASE_COST) + } + Command::Instruction(Instruction::CommitBHP768(commit)) => { + cost_in_size(stack, finalize, commit.operands(), HASH_BHP_PER_BYTE_COST, HASH_BHP_BASE_COST) + } + Command::Instruction(Instruction::CommitBHP1024(commit)) => { + cost_in_size(stack, finalize, commit.operands(), HASH_BHP_PER_BYTE_COST, HASH_BHP_BASE_COST) + } + Command::Instruction(Instruction::CommitPED64(commit)) => { + cost_in_size(stack, finalize, commit.operands(), HASH_PER_BYTE_COST, HASH_BASE_COST) + } + Command::Instruction(Instruction::CommitPED128(commit)) => { + cost_in_size(stack, finalize, commit.operands(), HASH_PER_BYTE_COST, HASH_BASE_COST) + } + Command::Instruction(Instruction::Div(div)) => { + // Ensure `div` has exactly two operands. + ensure!(div.operands().len() == 2, "'div' must contain exactly 2 operands"); + // Retrieve the finalize types. + let finalize_types = stack.get_finalize_types(finalize.name())?; + // Retrieve the price by the operand type. + match finalize_types.get_type_from_operand(stack, &div.operands()[0])? { + FinalizeType::Plaintext(PlaintextType::Literal(LiteralType::Field)) => Ok(1_500), + FinalizeType::Plaintext(PlaintextType::Literal(_)) => Ok(500), + FinalizeType::Plaintext(PlaintextType::Array(_)) => bail!("'div' does not support arrays"), + FinalizeType::Plaintext(PlaintextType::Struct(_)) => bail!("'div' does not support structs"), + FinalizeType::Future(_) => bail!("'div' does not support futures"), + } + } + Command::Instruction(Instruction::DivWrapped(_)) => Ok(500), + Command::Instruction(Instruction::Double(_)) => Ok(500), + Command::Instruction(Instruction::GreaterThan(_)) => Ok(500), + Command::Instruction(Instruction::GreaterThanOrEqual(_)) => Ok(500), + Command::Instruction(Instruction::HashBHP256(hash)) => { + cost_in_size(stack, finalize, hash.operands(), HASH_BHP_PER_BYTE_COST, HASH_BHP_BASE_COST) + } + Command::Instruction(Instruction::HashBHP512(hash)) => { + cost_in_size(stack, finalize, hash.operands(), HASH_BHP_PER_BYTE_COST, HASH_BHP_BASE_COST) + } + Command::Instruction(Instruction::HashBHP768(hash)) => { + cost_in_size(stack, finalize, hash.operands(), HASH_BHP_PER_BYTE_COST, HASH_BHP_BASE_COST) + } + Command::Instruction(Instruction::HashBHP1024(hash)) => { + cost_in_size(stack, finalize, hash.operands(), HASH_BHP_PER_BYTE_COST, HASH_BHP_BASE_COST) + } + Command::Instruction(Instruction::HashKeccak256(hash)) => { + cost_in_size(stack, finalize, hash.operands(), HASH_PER_BYTE_COST, HASH_BASE_COST) + } + Command::Instruction(Instruction::HashKeccak384(hash)) => { + cost_in_size(stack, finalize, hash.operands(), HASH_PER_BYTE_COST, HASH_BASE_COST) + } + Command::Instruction(Instruction::HashKeccak512(hash)) => { + cost_in_size(stack, finalize, hash.operands(), HASH_PER_BYTE_COST, HASH_BASE_COST) + } + Command::Instruction(Instruction::HashPED64(hash)) => { + cost_in_size(stack, finalize, hash.operands(), HASH_PER_BYTE_COST, HASH_BASE_COST) + } + Command::Instruction(Instruction::HashPED128(hash)) => { + cost_in_size(stack, finalize, hash.operands(), HASH_PER_BYTE_COST, HASH_BASE_COST) + } + Command::Instruction(Instruction::HashPSD2(hash)) => { + cost_in_size(stack, finalize, hash.operands(), HASH_PSD_PER_BYTE_COST, HASH_PSD_BASE_COST) + } + Command::Instruction(Instruction::HashPSD4(hash)) => { + cost_in_size(stack, finalize, hash.operands(), HASH_PSD_PER_BYTE_COST, HASH_PSD_BASE_COST) + } + Command::Instruction(Instruction::HashPSD8(hash)) => { + cost_in_size(stack, finalize, hash.operands(), HASH_PSD_PER_BYTE_COST, HASH_PSD_BASE_COST) + } + Command::Instruction(Instruction::HashSha3_256(hash)) => { + cost_in_size(stack, finalize, hash.operands(), HASH_PER_BYTE_COST, HASH_BASE_COST) + } + Command::Instruction(Instruction::HashSha3_384(hash)) => { + cost_in_size(stack, finalize, hash.operands(), HASH_PER_BYTE_COST, HASH_BASE_COST) + } + Command::Instruction(Instruction::HashSha3_512(hash)) => { + cost_in_size(stack, finalize, hash.operands(), HASH_PER_BYTE_COST, HASH_BASE_COST) + } Command::Instruction(Instruction::HashManyPSD2(_)) => { - bail!("`hash_many.psd2` is not supported in finalize.") + bail!("`hash_many.psd2` is not supported in finalize") } Command::Instruction(Instruction::HashManyPSD4(_)) => { - bail!("`hash_many.psd4` is not supported in finalize.") + bail!("`hash_many.psd4` is not supported in finalize") } Command::Instruction(Instruction::HashManyPSD8(_)) => { - bail!("`hash_many.psd8` is not supported in finalize.") - } - Command::Instruction(Instruction::Inv(_)) => Ok(10_000), - Command::Instruction(Instruction::IsEq(_)) => Ok(2_000), - Command::Instruction(Instruction::IsNeq(_)) => Ok(2_000), - Command::Instruction(Instruction::LessThan(_)) => Ok(2_000), - Command::Instruction(Instruction::LessThanOrEqual(_)) => Ok(2_000), - Command::Instruction(Instruction::Modulo(_)) => Ok(2_000), - Command::Instruction(Instruction::Mul(_)) => Ok(150_000), - Command::Instruction(Instruction::MulWrapped(_)) => Ok(2_000), - Command::Instruction(Instruction::Nand(_)) => Ok(2_000), - Command::Instruction(Instruction::Neg(_)) => Ok(2_000), - Command::Instruction(Instruction::Nor(_)) => Ok(2_000), - Command::Instruction(Instruction::Not(_)) => Ok(2_000), - Command::Instruction(Instruction::Or(_)) => Ok(2_000), - Command::Instruction(Instruction::Pow(_)) => Ok(20_000), - Command::Instruction(Instruction::PowWrapped(_)) => Ok(2_000), - Command::Instruction(Instruction::Rem(_)) => Ok(2_000), - Command::Instruction(Instruction::RemWrapped(_)) => Ok(2_000), - Command::Instruction(Instruction::SignVerify(_)) => Ok(250_000), - Command::Instruction(Instruction::Shl(_)) => Ok(2_000), - Command::Instruction(Instruction::ShlWrapped(_)) => Ok(2_000), - Command::Instruction(Instruction::Shr(_)) => Ok(2_000), - Command::Instruction(Instruction::ShrWrapped(_)) => Ok(2_000), - Command::Instruction(Instruction::Square(_)) => Ok(2_000), - Command::Instruction(Instruction::SquareRoot(_)) => Ok(120_000), - Command::Instruction(Instruction::Sub(_)) => Ok(10_000), - Command::Instruction(Instruction::SubWrapped(_)) => Ok(2_000), - Command::Instruction(Instruction::Ternary(_)) => Ok(2_000), - Command::Instruction(Instruction::Xor(_)) => Ok(2_000), - // TODO: The following 'finalize' commands are currently priced higher than expected. - // Expect these numbers to change as their usage is stabilized. - Command::Await(_) => Ok(2_000), - Command::Contains(_) => Ok(12_500), - Command::Get(_) => Ok(25_000), - Command::GetOrUse(_) => Ok(25_000), + bail!("`hash_many.psd8` is not supported in finalize") + } + Command::Instruction(Instruction::Inv(_)) => Ok(2_500), + Command::Instruction(Instruction::IsEq(_)) => Ok(500), + Command::Instruction(Instruction::IsNeq(_)) => Ok(500), + Command::Instruction(Instruction::LessThan(_)) => Ok(500), + Command::Instruction(Instruction::LessThanOrEqual(_)) => Ok(500), + Command::Instruction(Instruction::Modulo(_)) => Ok(500), + Command::Instruction(Instruction::Mul(mul)) => { + // Ensure `mul` has exactly two operands. + ensure!(mul.operands().len() == 2, "'mul' must contain exactly 2 operands"); + // Retrieve the finalize types. + let finalize_types = stack.get_finalize_types(finalize.name())?; + // Retrieve the price by operand type. + match finalize_types.get_type_from_operand(stack, &mul.operands()[0])? { + FinalizeType::Plaintext(PlaintextType::Literal(LiteralType::Group)) => Ok(10_000), + FinalizeType::Plaintext(PlaintextType::Literal(LiteralType::Scalar)) => Ok(10_000), + FinalizeType::Plaintext(PlaintextType::Literal(_)) => Ok(500), + FinalizeType::Plaintext(PlaintextType::Array(_)) => bail!("'mul' does not support arrays"), + FinalizeType::Plaintext(PlaintextType::Struct(_)) => bail!("'mul' does not support structs"), + FinalizeType::Future(_) => bail!("'mul' does not support futures"), + } + } + Command::Instruction(Instruction::MulWrapped(_)) => Ok(500), + Command::Instruction(Instruction::Nand(_)) => Ok(500), + Command::Instruction(Instruction::Neg(_)) => Ok(500), + Command::Instruction(Instruction::Nor(_)) => Ok(500), + Command::Instruction(Instruction::Not(_)) => Ok(500), + Command::Instruction(Instruction::Or(_)) => Ok(500), + Command::Instruction(Instruction::Pow(pow)) => { + // Ensure `pow` has at least one operand. + ensure!(!pow.operands().is_empty(), "'pow' must contain at least 1 operand"); + // Retrieve the finalize types. + let finalize_types = stack.get_finalize_types(finalize.name())?; + // Retrieve the price by operand type. + match finalize_types.get_type_from_operand(stack, &pow.operands()[0])? { + FinalizeType::Plaintext(PlaintextType::Literal(LiteralType::Field)) => Ok(1_500), + FinalizeType::Plaintext(PlaintextType::Literal(_)) => Ok(500), + FinalizeType::Plaintext(PlaintextType::Array(_)) => bail!("'pow' does not support arrays"), + FinalizeType::Plaintext(PlaintextType::Struct(_)) => bail!("'pow' does not support structs"), + FinalizeType::Future(_) => bail!("'pow' does not support futures"), + } + } + Command::Instruction(Instruction::PowWrapped(_)) => Ok(500), + Command::Instruction(Instruction::Rem(_)) => Ok(500), + Command::Instruction(Instruction::RemWrapped(_)) => Ok(500), + Command::Instruction(Instruction::SignVerify(sign)) => { + cost_in_size(stack, finalize, sign.operands(), HASH_PSD_PER_BYTE_COST, HASH_PSD_BASE_COST) + } + Command::Instruction(Instruction::Shl(_)) => Ok(500), + Command::Instruction(Instruction::ShlWrapped(_)) => Ok(500), + Command::Instruction(Instruction::Shr(_)) => Ok(500), + Command::Instruction(Instruction::ShrWrapped(_)) => Ok(500), + Command::Instruction(Instruction::Square(_)) => Ok(500), + Command::Instruction(Instruction::SquareRoot(_)) => Ok(2_500), + Command::Instruction(Instruction::Sub(_)) => Ok(500), + Command::Instruction(Instruction::SubWrapped(_)) => Ok(500), + Command::Instruction(Instruction::Ternary(_)) => Ok(500), + Command::Instruction(Instruction::Xor(_)) => Ok(500), + Command::Await(_) => Ok(500), + Command::Contains(command) => { + cost_in_size(stack, finalize, [command.key()], MAPPING_PER_BYTE_COST, MAPPING_BASE_COST) + } + Command::Get(command) => { + cost_in_size(stack, finalize, [command.key()], MAPPING_PER_BYTE_COST, MAPPING_BASE_COST) + } + Command::GetOrUse(command) => { + cost_in_size(stack, finalize, [command.key()], MAPPING_PER_BYTE_COST, MAPPING_BASE_COST) + } Command::RandChaCha(_) => Ok(25_000), - Command::Remove(_) => Ok(10_000), - Command::Set(_) => Ok(100_000), - Command::BranchEq(_) | Command::BranchNeq(_) => Ok(5_000), - Command::Position(_) => Ok(1_000), + Command::Remove(_) => Ok(MAPPING_BASE_COST), + Command::Set(command) => { + cost_in_size(stack, finalize, [command.key(), command.value()], SET_PER_BYTE_COST, SET_BASE_COST) + } + Command::BranchEq(_) | Command::BranchNeq(_) => Ok(500), + Command::Position(_) => Ok(100), }; + + // Aggregate the cost of all commands in the program. finalize .commands() .iter() diff --git a/synthesizer/src/vm/helpers/macros.rs b/synthesizer/src/vm/helpers/macros.rs index 16911566e3..e0c67c08c4 100644 --- a/synthesizer/src/vm/helpers/macros.rs +++ b/synthesizer/src/vm/helpers/macros.rs @@ -15,19 +15,19 @@ /// A helper macro to downcast a `$variable` to `$object<$network>`. #[macro_export] macro_rules! cast_ref { - // Example: cast_ref!((foo.bar()) as Bar) + // Example: cast_ref!((foo.bar()) as Bar) (($variable:expr) as $object:ident<$($traits:path),+>) => {{ (&$variable as &dyn std::any::Any) .downcast_ref::<$object<$($traits),+>>() .ok_or_else(|| anyhow!("Failed to downcast {}", stringify!($variable)))? }}; - // Example: cast_ref!(bar as Bar) + // Example: cast_ref!(bar as Bar) ($variable:ident as $object:ident<$($traits:path),+>) => {{ (&$variable as &dyn std::any::Any) .downcast_ref::<$object<$($traits),+>>() .ok_or_else(|| anyhow!("Failed to downcast {}", stringify!($variable)))? }}; - // Example: cast_ref!(&bar as Bar) + // Example: cast_ref!(&bar as Bar) (&$variable:ident as $object:ident<$($traits:path),+>) => {{ ($variable as &dyn std::any::Any) .downcast_ref::<$object<$($traits),+>>() @@ -38,13 +38,13 @@ macro_rules! cast_ref { /// A helper macro to downcast a `$variable` to `&mut $object<$network>`. #[macro_export] macro_rules! cast_mut_ref { - // Example: cast_mut_ref!((foo.bar()) as Bar) + // Example: cast_mut_ref!((foo.bar()) as Bar) (($variable:expr) as $object:ident<$($traits:path),+>) => {{ (&mut $variable as &mut dyn std::any::Any) .downcast_mut::<$object<$($traits),+>>() .ok_or_else(|| anyhow!("Failed to downcast mut {}", stringify!($variable)))? }}; - // Example: cast_mut_ref!(bar as Bar) + // Example: cast_mut_ref!(bar as Bar) ($variable:ident as $object:ident<$($traits:path),+>) => {{ (&mut $variable as &mut dyn std::any::Any) .downcast_mut::<$object<$($traits),+>>() @@ -58,13 +58,13 @@ macro_rules! process { // Example: process!(self, logic) ($self:ident, $logic:ident) => {{ match N::ID { - console::network::Testnet3::ID => { + console::network::MainnetV0::ID => { // Cast the process. let process = (&$self.process as &dyn std::any::Any) - .downcast_ref::>>>() + .downcast_ref::>>>() .ok_or_else(|| anyhow!("Failed to downcast {}", stringify!($self.process)))?; // Process the logic. - $logic!(process.read(), console::network::Testnet3, circuit::AleoV0) + $logic!(process.read(), console::network::MainnetV0, circuit::AleoV0) } _ => bail!("Unsupported VM configuration for network: {}", N::ID), } diff --git a/synthesizer/src/vm/helpers/rewards.rs b/synthesizer/src/vm/helpers/rewards.rs index ae5f9d4fba..8395643012 100644 --- a/synthesizer/src/vm/helpers/rewards.rs +++ b/synthesizer/src/vm/helpers/rewards.rs @@ -131,7 +131,7 @@ mod tests { use indexmap::indexmap; - type CurrentNetwork = console::network::Testnet3; + type CurrentNetwork = console::network::MainnetV0; const ITERATIONS: usize = 1000; diff --git a/synthesizer/src/vm/mod.rs b/synthesizer/src/vm/mod.rs index a9e29d1594..1d7a2280cb 100644 --- a/synthesizer/src/vm/mod.rs +++ b/synthesizer/src/vm/mod.rs @@ -26,7 +26,7 @@ use console::{ account::{Address, PrivateKey}, network::prelude::*, program::{Identifier, Literal, Locator, Plaintext, ProgramID, ProgramOwner, Record, Value}, - types::{Field, U64}, + types::{Field, Group, U64}, }; use ledger_block::{ Block, @@ -38,10 +38,10 @@ use ledger_block::{ Ratifications, Ratify, Rejected, + Solutions, Transaction, Transactions, }; -use ledger_coinbase::CoinbaseSolution; use ledger_committee::Committee; use ledger_query::Query; use ledger_store::{ @@ -101,7 +101,7 @@ impl> VM { transaction_store: &TransactionStore, transaction_id: N::TransactionID, ) -> Result, Deployment)>> { - // Retrieve the deployment from the transaction id. + // Retrieve the deployment from the transaction ID. let deployment = match transaction_store.get_deployment(&transaction_id)? { Some(deployment) => deployment, None => bail!("Deployment transaction '{transaction_id}' is not found in storage."), @@ -123,11 +123,11 @@ impl> VM { for import_program_id in program.imports().keys() { // Add the imports to the process if does not exist yet. if !process.contains_program(import_program_id) { - // Fetch the deployment transaction id. + // Fetch the deployment transaction ID. let Some(transaction_id) = transaction_store.deployment_store().find_transaction_id_from_program_id(import_program_id)? else { - bail!("Transaction id for '{program_id}' is not found in storage."); + bail!("Transaction ID for '{program_id}' is not found in storage."); }; // Add the deployment and its imports found recursively. @@ -277,7 +277,9 @@ impl> VM { // Prepare the ratifications. let ratifications = vec![Ratify::Genesis(committee, public_balances)]; // Prepare the solutions. - let solutions = None; // The genesis block does not require solutions. + let solutions = Solutions::::from(None); // The genesis block does not require solutions. + // Prepare the aborted solution IDs. + let aborted_solution_ids = vec![]; // Prepare the transactions. let transactions = (0..Block::::NUM_GENESIS_TRANSACTIONS) .map(|_| self.execute(private_key, locator, inputs.iter(), None, 0, None, rng)) @@ -287,7 +289,7 @@ impl> VM { let state = FinalizeGlobalState::new_genesis::()?; // Speculate on the ratifications, solutions, and transactions. let (ratifications, transactions, aborted_transaction_ids, ratified_finalize_operations) = - self.speculate(state, None, ratifications, solutions.as_ref(), transactions.iter())?; + self.speculate(state, None, ratifications, &solutions, transactions.iter())?; ensure!( aborted_transaction_ids.is_empty(), "Failed to initialize a genesis block - found aborted transaction IDs" @@ -305,6 +307,7 @@ impl> VM { header, ratifications, solutions, + aborted_solution_ids, transactions, aborted_transaction_ids, rng, @@ -360,7 +363,7 @@ pub(crate) mod test_helpers { use super::*; use console::{ account::{Address, ViewKey}, - network::Testnet3, + network::MainnetV0, program::Value, types::Field, }; @@ -371,8 +374,9 @@ pub(crate) mod test_helpers { use indexmap::IndexMap; use once_cell::sync::OnceCell; use std::borrow::Borrow; + use synthesizer_snark::VerifyingKey; - pub(crate) type CurrentNetwork = Testnet3; + pub(crate) type CurrentNetwork = MainnetV0; /// Samples a new finalize state. pub(crate) fn sample_finalize_state(block_height: u32) -> FinalizeGlobalState { @@ -637,11 +641,11 @@ function compute: } pub fn sample_next_block( - vm: &VM>, - private_key: &PrivateKey, - transactions: &[Transaction], + vm: &VM>, + private_key: &PrivateKey, + transactions: &[Transaction], rng: &mut R, - ) -> Result> { + ) -> Result> { // Get the most recent block. let block_hash = vm.block_store().get_block_hash(*vm.block_store().heights().max().unwrap().borrow()).unwrap().unwrap(); @@ -649,21 +653,21 @@ function compute: // Construct the new block header. let (ratifications, transactions, aborted_transaction_ids, ratified_finalize_operations) = - vm.speculate(sample_finalize_state(1), None, vec![], None, transactions.iter())?; + vm.speculate(sample_finalize_state(1), None, vec![], &None.into(), transactions.iter())?; assert!(aborted_transaction_ids.is_empty()); // Construct the metadata associated with the block. let metadata = Metadata::new( - Testnet3::ID, + MainnetV0::ID, previous_block.round() + 1, previous_block.height() + 1, 0, 0, - Testnet3::GENESIS_COINBASE_TARGET, - Testnet3::GENESIS_PROOF_TARGET, + MainnetV0::GENESIS_COINBASE_TARGET, + MainnetV0::GENESIS_PROOF_TARGET, previous_block.last_coinbase_target(), previous_block.last_coinbase_timestamp(), - Testnet3::GENESIS_TIMESTAMP + 1, + MainnetV0::GENESIS_TIMESTAMP + 1, )?; let header = Header::from( @@ -682,7 +686,8 @@ function compute: previous_block.hash(), header, ratifications, - None, + None.into(), + vec![], transactions, aborted_transaction_ids, rng, @@ -815,7 +820,7 @@ finalize getter: .execute( &caller_private_key, ("test_program_1.aleo", "init"), - Vec::>::new().iter(), + Vec::>::new().iter(), Some(third_record), 1, None, @@ -826,7 +831,7 @@ finalize getter: .execute( &caller_private_key, ("test_program_2.aleo", "init"), - Vec::>::new().iter(), + Vec::>::new().iter(), Some(fourth_record), 1, None, @@ -938,17 +943,18 @@ function a: sample_next_block(&vm, &caller_private_key, &[deployment_3.clone(), deployment_4.clone()], rng).unwrap(); vm.add_next_block(&deployment_block).unwrap(); - // Check that the iterator ordering is not the same as the deployment ordering. - let deployment_transaction_ids = - vm.transaction_store().deployment_transaction_ids().map(|id| *id).collect::>(); - // This `assert_ne` check is here to ensure that we are properly loading imports even though any order will work for `VM::from`. - // Note: `deployment_transaction_ids` is sorted lexicographically by transaction id, so the order may change if we update internal methods. - assert_ne!(deployment_transaction_ids, vec![ - deployment_1.id(), - deployment_2.id(), - deployment_3.id(), - deployment_4.id() - ]); + // Sanity check the ordering of the deployment transaction IDs from storage. + { + let deployment_transaction_ids = + vm.transaction_store().deployment_transaction_ids().map(|id| *id).collect::>(); + // This assert check is here to ensure that we are properly loading imports even though any order will work for `VM::from`. + // Note: `deployment_transaction_ids` is sorted lexicographically by transaction ID, so the order may change if we update internal methods. + assert_eq!( + deployment_transaction_ids, + vec![deployment_1.id(), deployment_2.id(), deployment_3.id(), deployment_4.id()], + "Update me if serialization has changed" + ); + } // Enforce that the VM can load properly with the imports. assert!(VM::from(vm.store.clone()).is_ok()); @@ -1003,9 +1009,9 @@ function multitransfer: // Execute the programs. let inputs = [ - Value::::Record(record_1), - Value::::from_str(&address.to_string()).unwrap(), - Value::::from_str("10u64").unwrap(), + Value::::Record(record_1), + Value::::from_str(&address.to_string()).unwrap(), + Value::::from_str("10u64").unwrap(), ]; let execution = vm .execute( @@ -1077,6 +1083,197 @@ function check: assert!(vm.contains_program(&ProgramID::from_str("parent_program.aleo").unwrap())); } + #[test] + fn test_deployment_with_external_records() { + let rng = &mut TestRng::default(); + + // Initialize a private key. + let private_key = sample_genesis_private_key(rng); + + // Initialize the genesis block. + let genesis = sample_genesis_block(rng); + + // Initialize the VM. + let vm = sample_vm(); + // Update the VM. + vm.add_next_block(&genesis).unwrap(); + + // Deploy the program. + let program = Program::from_str( + r" +import credits.aleo; +program test_program.aleo; + +function transfer: + input r0 as credits.aleo/credits.record; + input r1 as u64.private; + input r2 as u64.private; + input r3 as [address; 10u32].private; + call credits.aleo/transfer_private r0 r3[0u32] r1 into r4 r5; + call credits.aleo/transfer_private r5 r3[0u32] r2 into r6 r7; +", + ) + .unwrap(); + + let deployment = vm.deploy(&private_key, &program, None, 0, None, rng).unwrap(); + assert!(vm.check_transaction(&deployment, None, rng).is_ok()); + vm.add_next_block(&sample_next_block(&vm, &private_key, &[deployment], rng).unwrap()).unwrap(); + + // Check that program is deployed. + assert!(vm.contains_program(&ProgramID::from_str("test_program.aleo").unwrap())); + } + + #[test] + fn test_deployment_synthesis_overload() { + let rng = &mut TestRng::default(); + + // Initialize a private key. + let private_key = sample_genesis_private_key(rng); + + // Initialize the genesis block. + let genesis = sample_genesis_block(rng); + + // Initialize the VM. + let vm = sample_vm(); + // Update the VM. + vm.add_next_block(&genesis).unwrap(); + + // Deploy the base program. + let program = Program::from_str( + r" +program synthesis_overload.aleo; + +function do: + input r0 as [[u128; 32u32]; 2u32].private; + hash.sha3_256 r0 into r1 as field; + output r1 as field.public;", + ) + .unwrap(); + + // Create the deployment transaction. + let deployment = vm.deploy(&private_key, &program, None, 0, None, rng).unwrap(); + + // Verify the deployment transaction. It should fail because there are too many constraints. + assert!(vm.check_transaction(&deployment, None, rng).is_err()); + } + + #[test] + fn test_deployment_synthesis_overreport() { + let rng = &mut TestRng::default(); + + // Initialize a private key. + let private_key = sample_genesis_private_key(rng); + + // Initialize the genesis block. + let genesis = sample_genesis_block(rng); + + // Initialize the VM. + let vm = sample_vm(); + // Update the VM. + vm.add_next_block(&genesis).unwrap(); + + // Deploy the base program. + let program = Program::from_str( + r" +program synthesis_overreport.aleo; + +function do: + input r0 as u32.private; + add r0 r0 into r1; + output r1 as u32.public;", + ) + .unwrap(); + + // Create the deployment transaction. + let transaction = vm.deploy(&private_key, &program, None, 0, None, rng).unwrap(); + + // Destructure the deployment transaction. + let Transaction::Deploy(_, program_owner, deployment, fee) = transaction else { + panic!("Expected a deployment transaction"); + }; + + // Increase the number of constraints in the verifying keys. + let mut vks_with_overreport = Vec::with_capacity(deployment.verifying_keys().len()); + for (id, (vk, cert)) in deployment.verifying_keys() { + let mut vk = vk.deref().clone(); + vk.circuit_info.num_constraints += 1; + let vk = VerifyingKey::new(Arc::new(vk)); + vks_with_overreport.push((*id, (vk, cert.clone()))); + } + + // Each additional constraint costs 25 microcredits, so we need to increase the fee by 25 microcredits. + let required_fee = *fee.base_amount().unwrap() + 25; + // Authorize a new fee. + let fee_authorization = vm + .authorize_fee_public(&private_key, required_fee, 0, deployment.as_ref().to_deployment_id().unwrap(), rng) + .unwrap(); + // Compute the fee. + let fee = vm.execute_fee_authorization(fee_authorization, None, rng).unwrap(); + + // Create a new deployment transaction with the overreported verifying keys. + let adjusted_deployment = + Deployment::new(deployment.edition(), deployment.program().clone(), vks_with_overreport).unwrap(); + let adjusted_transaction = Transaction::from_deployment(program_owner, adjusted_deployment, fee).unwrap(); + + // Verify the deployment transaction. It should error when certificate checking for constraint count mismatch. + let res = vm.check_transaction(&adjusted_transaction, None, rng); + assert!(res.is_err()); + } + + #[test] + #[should_panic] + fn test_deployment_synthesis_underreport() { + let rng = &mut TestRng::default(); + + // Initialize a private key. + let private_key = sample_genesis_private_key(rng); + + // Initialize the genesis block. + let genesis = sample_genesis_block(rng); + + // Initialize the VM. + let vm = sample_vm(); + // Update the VM. + vm.add_next_block(&genesis).unwrap(); + + // Deploy the base program. + let program = Program::from_str( + r" +program synthesis_underreport.aleo; + +function do: + input r0 as u32.private; + add r0 r0 into r1; + output r1 as u32.public;", + ) + .unwrap(); + + // Create the deployment transaction. + let transaction = vm.deploy(&private_key, &program, None, 0, None, rng).unwrap(); + + // Destructure the deployment transaction. + let Transaction::Deploy(txid, program_owner, deployment, fee) = transaction else { + panic!("Expected a deployment transaction"); + }; + + // Decrease the number of constraints in the verifying keys. + let mut vks_with_underreport = Vec::with_capacity(deployment.verifying_keys().len()); + for (id, (vk, cert)) in deployment.verifying_keys() { + let mut vk = vk.deref().clone(); + vk.circuit_info.num_constraints -= 2; + let vk = VerifyingKey::new(Arc::new(vk)); + vks_with_underreport.push((*id, (vk, cert.clone()))); + } + + // Create a new deployment transaction with the underreported verifying keys. + let adjusted_deployment = + Deployment::new(deployment.edition(), deployment.program().clone(), vks_with_underreport).unwrap(); + let adjusted_transaction = Transaction::Deploy(txid, program_owner, Box::new(adjusted_deployment), fee); + + // Verify the deployment transaction. It should panic when enforcing the first constraint over the vk limit. + let _ = vm.check_transaction(&adjusted_transaction, None, rng); + } + #[test] #[ignore] fn test_deployment_memory_overload() { diff --git a/synthesizer/src/vm/verify.rs b/synthesizer/src/vm/verify.rs index fe036b7e3a..6fc47523a5 100644 --- a/synthesizer/src/vm/verify.rs +++ b/synthesizer/src/vm/verify.rs @@ -145,7 +145,7 @@ impl> VM { let Ok(deployment_id) = deployment.to_deployment_id() else { bail!("Failed to compute the Merkle root for deployment transaction '{id}'") }; - // Compute the deployment cost. + // Compute the minimum deployment cost. let (cost, _) = deployment_cost(deployment)?; // Ensure the fee is sufficient to cover the cost. if *fee.base_amount()? < cost { @@ -470,8 +470,9 @@ mod tests { let deployment_transaction = vm.deploy(&caller_private_key, &program, Some(credits), 10, None, rng).unwrap(); // Construct the new block header. - let (ratifications, transactions, aborted_transaction_ids, ratified_finalize_operations) = - vm.speculate(sample_finalize_state(1), Some(0u64), vec![], None, [deployment_transaction].iter()).unwrap(); + let (ratifications, transactions, aborted_transaction_ids, ratified_finalize_operations) = vm + .speculate(sample_finalize_state(1), Some(0u64), vec![], &None.into(), [deployment_transaction].iter()) + .unwrap(); assert!(aborted_transaction_ids.is_empty()); // Construct the metadata associated with the block. @@ -506,7 +507,8 @@ mod tests { genesis.hash(), deployment_header, ratifications, - None, + None.into(), + vec![], transactions, aborted_transaction_ids, rng, diff --git a/synthesizer/tests/expectations/process/execute/lossy_casts.out b/synthesizer/tests/expectations/process/execute/lossy_casts.out new file mode 100644 index 0000000000..0a3a6279bc --- /dev/null +++ b/synthesizer/tests/expectations/process/execute/lossy_casts.out @@ -0,0 +1,62 @@ +errors: [] +outputs: +- - 93754672984613362290390329026198290544u128 + - 93754672984613362290390329026198290544i128 + - 16982649547548967024u64 + - -1464094526160584592i64 + - 446349424u32 + - 446349424i32 + - 49264u16 + - -16272i16 + - 112u8 + - 112i8 + - 'false' + - 4764330560507562969049837239139509827871889319573451509694277586124473432540group +- - 0u128 + - 0i128 + - 0u64 + - 0i64 + - 0u32 + - 0i32 + - 0u16 + - 0i16 + - 0u8 + - 0i8 + - 'false' + - 0group +- - 1u128 + - 1i128 + - 1u64 + - 1i64 + - 1u32 + - 1i32 + - 1u16 + - 1i16 + - 1u8 + - 1i8 + - 'true' + - 1540945439182663264862696551825005342995406165131907382295858612069623286213group +- - 0u128 + - 0i128 + - 0u64 + - 0i64 + - 0u32 + - 0i32 + - 0u16 + - 0i16 + - 0u8 + - 0i8 + - 'false' + - 340282366920938463463374607431768211456group +- - 1u128 + - 1i128 + - 1u64 + - 1i64 + - 1u32 + - 1i32 + - 1u16 + - 1i16 + - 1u8 + - 1i8 + - 'true' + - 2207376757013908562861143127796680436121374163712359508096962653679714303999group diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/arrays_in_finalize.out b/synthesizer/tests/expectations/vm/execute_and_finalize/arrays_in_finalize.out index 2f99747752..8217a54a60 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/arrays_in_finalize.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/arrays_in_finalize.out @@ -4,15 +4,15 @@ outputs: execute: arrays_in_finalize.aleo/test_arrays: outputs: - - '{"type":"public","id":"8423501051492945494142580898503776230777967039101310769883569628562838106961field","value":"[\n [\n true,\n false,\n true,\n false\n ]\n]"}' - - '{"type":"public","id":"6373810658910535946682884531888342268371302467625666065790785860646654788892field","value":"[\n [\n false,\n true,\n false,\n true\n ]\n]"}' - - '{"type":"public","id":"3091501445020687319877822274133758457934608796618645756988915091755405157586field","value":"[\n [\n false,\n false,\n false,\n false\n ]\n]"}' - - '{"type":"private","id":"6526736422839961003683955650152924988761580233649162767954364194151255194053field","value":"ciphertext1qvqr73dv3clq8jtx7trf8k9l3eshmh0tyvvp2ta7a0y3pedjj99eczrpwk6045wektcw7mmjzdrm8f67x7egd4dfch3slf4q6ag3lxn0p6cryuecunyl2d9ffr8ntj57dvmv9rg7fhlrtc995w2ruju7j20qgndw85u"}' - - '{"type":"future","id":"5831343183208330086568343850686282945376722092994016952161543991067519254136field","value":"{\n program_id: arrays_in_finalize.aleo,\n function_name: test_arrays,\n arguments: [\n [\n [\n true,\n false,\n true,\n false\n ]\n],\n [\n [\n false,\n true,\n false,\n true\n ]\n]\n ]\n}"}' + - '{"type":"public","id":"4191132437526469726810078556702976385142790887134762205329564706486407091452field","value":"[\n [\n true,\n false,\n true,\n false\n ]\n]"}' + - '{"type":"public","id":"7732313354599796556273728553000823036918857772412470351533433477903799198179field","value":"[\n [\n false,\n true,\n false,\n true\n ]\n]"}' + - '{"type":"public","id":"5608636510680839107900624676979657593964288488498543523280649635497192868408field","value":"[\n [\n false,\n false,\n false,\n false\n ]\n]"}' + - '{"type":"private","id":"17838117880873163791217811658586530829235665776709065547754152530705294791field","value":"ciphertext1qvqgms88ec4yhlndrj62c2eupwvd4u3efn4u2dtgl6gd29ll52y87z7ncynzwv9ntktucne95h0mvgdstwsqejzhv5klrg9cn2se2g7xqhlr94w0j6h7m0nt2l0deyg2c7hfud0s8r8euldthva35k4k7u0sc44p593"}' + - '{"type":"future","id":"1297781464149960028797060285986265412679573504857528613822702946616595852889field","value":"{\n program_id: arrays_in_finalize.aleo,\n function_name: test_arrays,\n arguments: [\n [\n [\n true,\n false,\n true,\n false\n ]\n],\n [\n [\n false,\n true,\n false,\n true\n ]\n]\n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. additional: - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"611935698929626281656171069026748974326705967123466685855354594539166326131field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1y9t0y4lvhm43qdzlfjmfzh8985vfnx9ms368p07x5lsemet5ey8qt0ssjn,\n 21758u64\n ]\n}"}' + - '{"type":"future","id":"2715104495799396615741890969708845641129834494989002430629962063572161077357field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1y9t0y4lvhm43qdzlfjmfzh8985vfnx9ms368p07x5lsemet5ey8qt0ssjn,\n 7030u64\n ]\n}"}' diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/child_and_parent.out b/synthesizer/tests/expectations/vm/execute_and_finalize/child_and_parent.out index cf83c9d485..5e175be82e 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/child_and_parent.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/child_and_parent.out @@ -4,30 +4,30 @@ outputs: execute: child.aleo/foo: outputs: - - '{"type":"public","id":"3583507900097573902692207210661581535840809808651900827750728854102720512424field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' - - '{"type":"public","id":"476166291720572191849579987891810720100233870490756615272004665719966045283field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + - '{"type":"public","id":"5080102022926418909778330219071921101316828719441748927127931330249058015974field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + - '{"type":"public","id":"5521854961454308608590219862110836142563484399396636760251296039833599837132field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' speculate: the execution was accepted add_next_block: succeeded. - verified: true execute: parent.aleo/foo: outputs: - - '{"type":"public","id":"3761717515751581670491990458123447761370813910339791821189914541241041772398field","value":"aleo16w8t56s7v6ud7vu33fr388ph0dq0c7yhp597cyjt88rr3nultcyqcyk9yy"}' - - '{"type":"public","id":"7311055836597830429601351369404551037507421904626326632284143897137420180918field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' - - '{"type":"public","id":"681818897459164396968079033669192296282137044899275115497211144004195398694field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' - - '{"type":"public","id":"3417320637392048962499244658848814085037481834432707606558978225870881469204field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + - '{"type":"public","id":"2180349836718516623986527660803091459313965700848712055858720506742956053113field","value":"aleo16w8t56s7v6ud7vu33fr388ph0dq0c7yhp597cyjt88rr3nultcyqcyk9yy"}' + - '{"type":"public","id":"2306297960481221498781231131707036686317070776613275725765479488798926222971field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + - '{"type":"public","id":"629884147589344887679757377742438552594075704621211994352632325954728373873field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + - '{"type":"public","id":"7179043812459822888643137487185719660290943898185113409588571501637751887110field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' speculate: the execution was accepted add_next_block: succeeded. additional: - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"5245767978479482276373144091068362056657622227760198296183689243703275814117field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx,\n 1244u64\n ]\n}"}' + - '{"type":"future","id":"3347872470791009142460537022787342626917524637524821339588032366241763021507field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx,\n 1276u64\n ]\n}"}' - child_outputs: child.aleo/foo: outputs: - - '{"type":"public","id":"7812033131660295289207078830719348736788767283997224928167372421466500300696field","value":"aleo16w8t56s7v6ud7vu33fr388ph0dq0c7yhp597cyjt88rr3nultcyqcyk9yy"}' - - '{"type":"public","id":"4227271453559074580761782898043117548320729393319599555165417123780466734088field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + - '{"type":"public","id":"2143480774914597553325855510339405850073067321902916033740995314914236889071field","value":"aleo16w8t56s7v6ud7vu33fr388ph0dq0c7yhp597cyjt88rr3nultcyqcyk9yy"}' + - '{"type":"public","id":"1500133418795634855889959966479039744505030118146228739798986109415104921004field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' credits.aleo/fee_public: outputs: - - '{"type":"future","id":"8216972065644000579816790328783540313220942313753411501386970051803831099199field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx,\n 2123u64\n ]\n}"}' + - '{"type":"future","id":"7038990688216256894209117299702421152482248481717682799780559802515876924307field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx,\n 2187u64\n ]\n}"}' diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization.out b/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization.out index d413523f61..9c615c77fa 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization.out @@ -4,23 +4,23 @@ outputs: execute: four_program.aleo/a: outputs: - - '{"type":"future","id":"665183472055988178271814702289264025474680637838536582821282925188065775088field","value":"{\n program_id: four_program.aleo,\n function_name: a,\n arguments: [\n {\n program_id: two_program.aleo,\n function_name: b,\n arguments: [\n {\n program_id: zero_program.aleo,\n function_name: c,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n {\n program_id: one_program.aleo,\n function_name: d,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n {\n program_id: three_program.aleo,\n function_name: e,\n arguments: [\n {\n program_id: two_program.aleo,\n function_name: b,\n arguments: [\n {\n program_id: zero_program.aleo,\n function_name: c,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n {\n program_id: one_program.aleo,\n function_name: d,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n {\n program_id: one_program.aleo,\n function_name: d,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n {\n program_id: zero_program.aleo,\n function_name: c,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n}"}' + - '{"type":"future","id":"8073961850697502005201723808473879821579356096451187824496987505478189255390field","value":"{\n program_id: four_program.aleo,\n function_name: a,\n arguments: [\n {\n program_id: two_program.aleo,\n function_name: b,\n arguments: [\n {\n program_id: zero_program.aleo,\n function_name: c,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n {\n program_id: one_program.aleo,\n function_name: d,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n {\n program_id: three_program.aleo,\n function_name: e,\n arguments: [\n {\n program_id: two_program.aleo,\n function_name: b,\n arguments: [\n {\n program_id: zero_program.aleo,\n function_name: c,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n {\n program_id: one_program.aleo,\n function_name: d,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n {\n program_id: one_program.aleo,\n function_name: d,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n {\n program_id: zero_program.aleo,\n function_name: c,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. additional: - child_outputs: zero_program.aleo/c: outputs: - - '{"type":"future","id":"1480766593085211098189114488792207994373740214001639330000129810788271883137field","value":"{\n program_id: zero_program.aleo,\n function_name: c,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n}"}' + - '{"type":"future","id":"2137985455651054628126680275240269432054325301779207101612589772241739981165field","value":"{\n program_id: zero_program.aleo,\n function_name: c,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n}"}' one_program.aleo/d: outputs: - - '{"type":"future","id":"6874436412573820073608038525233877999669336342335693667065896409420053741810field","value":"{\n program_id: one_program.aleo,\n function_name: d,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n}"}' + - '{"type":"future","id":"5357241693223765542321433170179413948506257034844568471556820282679708829796field","value":"{\n program_id: one_program.aleo,\n function_name: d,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n}"}' two_program.aleo/b: outputs: - - '{"type":"future","id":"439911297771864655257183196286454333195715414280549536084302592849654672842field","value":"{\n program_id: two_program.aleo,\n function_name: b,\n arguments: [\n {\n program_id: zero_program.aleo,\n function_name: c,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n {\n program_id: one_program.aleo,\n function_name: d,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n}"}' + - '{"type":"future","id":"237175359371682654344610765795273369747408298587655173055205899746835808177field","value":"{\n program_id: two_program.aleo,\n function_name: b,\n arguments: [\n {\n program_id: zero_program.aleo,\n function_name: c,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n {\n program_id: one_program.aleo,\n function_name: d,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n}"}' three_program.aleo/e: outputs: - - '{"type":"future","id":"6324349534667114127832388996854882573236888808429320919855235417654165379333field","value":"{\n program_id: three_program.aleo,\n function_name: e,\n arguments: [\n {\n program_id: two_program.aleo,\n function_name: b,\n arguments: [\n {\n program_id: zero_program.aleo,\n function_name: c,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n {\n program_id: one_program.aleo,\n function_name: d,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n {\n program_id: one_program.aleo,\n function_name: d,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n {\n program_id: zero_program.aleo,\n function_name: c,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n}"}' + - '{"type":"future","id":"3616852843624887241027320225932142757072575594346925293061443696405638714355field","value":"{\n program_id: three_program.aleo,\n function_name: e,\n arguments: [\n {\n program_id: two_program.aleo,\n function_name: b,\n arguments: [\n {\n program_id: zero_program.aleo,\n function_name: c,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n {\n program_id: one_program.aleo,\n function_name: d,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n {\n program_id: one_program.aleo,\n function_name: d,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n {\n program_id: zero_program.aleo,\n function_name: c,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n },\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n}"}' credits.aleo/fee_public: outputs: - - '{"type":"future","id":"2642525527921148655203140665689909230400981948693155278410222306693462629362field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8,\n 1312883u64\n ]\n}"}' + - '{"type":"future","id":"3688989155399268747449856447722119301454464433397170543411114503201565062667field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8,\n 264403u64\n ]\n}"}' diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/count_usages.out b/synthesizer/tests/expectations/vm/execute_and_finalize/count_usages.out index bc0c5af71d..15b34329e9 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/count_usages.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/count_usages.out @@ -4,20 +4,20 @@ outputs: execute: count_usages.aleo/add_and_subtract: outputs: - - '{"type":"private","id":"3123182017432916757124403751790889348245620410758014315114714729237515860473field","value":"ciphertext1qyqwsyyjjx85zuu3rh9ujc7lt33dgqj28xcpxa5vz0uscttkelcm2yglca4ja"}' - - '{"type":"future","id":"3075184327471252279705776826446991266718083739660015565935642091055852740382field","value":"{\n program_id: count_usages.aleo,\n function_name: add_and_subtract,\n arguments: [\n {\n program_id: basic_math.aleo,\n function_name: add_and_count,\n arguments: [\n aleo1mrughg5ssadd9fc2uwve7l6u24xn76kyz24zsjtzta03vgkq4vpqggl6fg\n ]\n },\n {\n program_id: basic_math.aleo,\n function_name: sub_and_count,\n arguments: [\n aleo1mrughg5ssadd9fc2uwve7l6u24xn76kyz24zsjtzta03vgkq4vpqggl6fg\n ]\n }\n \n ]\n}"}' + - '{"type":"private","id":"2417893162182175688334393632212980126051692937961342515862782307223843642037field","value":"ciphertext1qyqrdme34cnf0dd08er9nelae88tnvs8g4f3pgpp43pf6j0t75kjvqslqv9d7"}' + - '{"type":"future","id":"705166902367251294198915856269600161357499171183853434375951230037519647203field","value":"{\n program_id: count_usages.aleo,\n function_name: add_and_subtract,\n arguments: [\n {\n program_id: basic_math.aleo,\n function_name: add_and_count,\n arguments: [\n aleo1mrughg5ssadd9fc2uwve7l6u24xn76kyz24zsjtzta03vgkq4vpqggl6fg\n ]\n },\n {\n program_id: basic_math.aleo,\n function_name: sub_and_count,\n arguments: [\n aleo1mrughg5ssadd9fc2uwve7l6u24xn76kyz24zsjtzta03vgkq4vpqggl6fg\n ]\n }\n \n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. additional: - child_outputs: basic_math.aleo/add_and_count: outputs: - - '{"type":"private","id":"8146495595200999887858412726015174541046002665643175756153664146614367276693field","value":"ciphertext1qyqgrgmhxyfjr3cvy50sy2hg8y56suw5wgvytygzms53mp4ms3v26rg226k3t"}' - - '{"type":"future","id":"4731072368922094762332855593966999173744758108005904730949638980529645559135field","value":"{\n program_id: basic_math.aleo,\n function_name: add_and_count,\n arguments: [\n aleo1mrughg5ssadd9fc2uwve7l6u24xn76kyz24zsjtzta03vgkq4vpqggl6fg\n ]\n}"}' + - '{"type":"private","id":"399020463587132384720173345030999750182171151859286922026595618170323893845field","value":"ciphertext1qyq0ec250xje9hyr36a6256sajhjgypznc0ckq9rckcx9hvqqe6expcfm3th0"}' + - '{"type":"future","id":"7862022176391501831567513125389433398315612742902989311778410598142695342538field","value":"{\n program_id: basic_math.aleo,\n function_name: add_and_count,\n arguments: [\n aleo1mrughg5ssadd9fc2uwve7l6u24xn76kyz24zsjtzta03vgkq4vpqggl6fg\n ]\n}"}' basic_math.aleo/sub_and_count: outputs: - - '{"type":"private","id":"961409263208860904485872221121989324413563522578995015597420037381610399703field","value":"ciphertext1qyqv6unr5dg8tj228pl0vgv32p92mcyxxyf9368salhtfqh0hd4scqc89y5m4"}' - - '{"type":"future","id":"4663027849889985446453275863200868545411574358675486387787337708909316167962field","value":"{\n program_id: basic_math.aleo,\n function_name: sub_and_count,\n arguments: [\n aleo1mrughg5ssadd9fc2uwve7l6u24xn76kyz24zsjtzta03vgkq4vpqggl6fg\n ]\n}"}' + - '{"type":"private","id":"2166485610255156621966882910457223948921992536665120764477666903342640510503field","value":"ciphertext1qyqy23z6n3fnm773zq9y4c5syrppp0c28fs2a0wh7t49wljydkjr5ygdylh70"}' + - '{"type":"future","id":"6356013747296129460342419348497415908695385595173072937771394894236053328119field","value":"{\n program_id: basic_math.aleo,\n function_name: sub_and_count,\n arguments: [\n aleo1mrughg5ssadd9fc2uwve7l6u24xn76kyz24zsjtzta03vgkq4vpqggl6fg\n ]\n}"}' credits.aleo/fee_public: outputs: - - '{"type":"future","id":"3084534457419184182612834880575828543753579447019853593724174249884664876235field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8,\n 263392u64\n ]\n}"}' + - '{"type":"future","id":"1585223826336342113009963588330628410761295667183024829434599712242938930728field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8,\n 54628u64\n ]\n}"}' diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/hello.out b/synthesizer/tests/expectations/vm/execute_and_finalize/hello.out index 4ee4b5c467..6d1c9d0566 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/hello.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/hello.out @@ -4,46 +4,46 @@ outputs: execute: hello.aleo/hello: outputs: - - '{"type":"private","id":"6254379462913920094060616443827416926361791013133233839133894947200598009041field","value":"ciphertext1qyqpmnatnq3sjej6qves695qtxu5r6lqnfnx8ck87ce3pez28x90qzgzeh4qh"}' + - '{"type":"private","id":"3176121404187786053742476608354607969269791944150504812747549421863574954935field","value":"ciphertext1qyqwch85jv880t8dxlr9xs9crgjgp4ksn8kkeln2kz9qph7ahyyngpcda2dye"}' speculate: the execution was accepted add_next_block: succeeded. - verified: true execute: hello.aleo/hello: outputs: - - '{"type":"private","id":"4161183151518570414349285932182760288961689691043823886807644299644687930091field","value":"ciphertext1qyqreg8a27jzsgm7m5umh98nr9nwyxhkv3aus5htm6vepdkr67zh5zqc4uzpd"}' + - '{"type":"private","id":"1150202079184853991998868214382005296145686294524629420497502839491280451550field","value":"ciphertext1qyqqh50g4ajk2j5ql8kgfkmqslyvddqrr3e54q7me8l8s2nm04zh6pcpyyud3"}' speculate: the execution was accepted add_next_block: succeeded. - verified: true execute: hello.aleo/goodbye: outputs: - - '{"type":"public","id":"5242826180235740795678885917758843199455932502638973701040836238216490364326field","value":"1u32"}' - - '{"type":"future","id":"5032744372214352919665806641360511690042524830912111693095233654380228978511field","value":"{\n program_id: hello.aleo,\n function_name: goodbye,\n arguments: [\n 1u32,\n 1u32\n ]\n}"}' + - '{"type":"public","id":"3480118852870382894144865857822175070946589099724278834594029902836667201534field","value":"1u32"}' + - '{"type":"future","id":"5509833946703133090359961819746633556337352648574994721286932795133496169216field","value":"{\n program_id: hello.aleo,\n function_name: goodbye,\n arguments: [\n 1u32,\n 1u32\n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. - verified: true execute: hello.aleo/goodbye: outputs: - - '{"type":"public","id":"5954748469306089505201665920330448486455515953532955699388262149494774760375field","value":"1u32"}' - - '{"type":"future","id":"4063241715105271542572794266017703704121932214929814829482077839560118863776field","value":"{\n program_id: hello.aleo,\n function_name: goodbye,\n arguments: [\n 0u32,\n 1u32\n ]\n}"}' + - '{"type":"public","id":"6056606855582681195495740332496796887918173012819660623567958555764517366236field","value":"1u32"}' + - '{"type":"future","id":"1191890728151228917136236794360467496329820983929439085349301662870546796031field","value":"{\n program_id: hello.aleo,\n function_name: goodbye,\n arguments: [\n 0u32,\n 1u32\n ]\n}"}' speculate: the execution was rejected add_next_block: succeeded. additional: - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"5633762070565015506869877991983247311752566772551740661334199093127666173285field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo10knkelvnd55fsaarm25wch7p9suf2tqlgwy5k4nxwms6d262xyfqm2tccr,\n 1285u64\n ]\n}"}' + - '{"type":"future","id":"4794226115128098661953863457300334535735190584732192888559305107927143173518field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo10knkelvnd55fsaarm25wch7p9suf2tqlgwy5k4nxwms6d262xyfqm2tccr,\n 1317u64\n ]\n}"}' - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"4168535226825329132770722118865464284070271653060849404506023921600553004505field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo10knkelvnd55fsaarm25wch7p9suf2tqlgwy5k4nxwms6d262xyfqm2tccr,\n 1285u64\n ]\n}"}' + - '{"type":"future","id":"1739624830440070888681272394177400670284937130272704360430655837962148942436field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo10knkelvnd55fsaarm25wch7p9suf2tqlgwy5k4nxwms6d262xyfqm2tccr,\n 1317u64\n ]\n}"}' - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"7264507997475302694771209211625280132862970630053323876707987175500028146955field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo10knkelvnd55fsaarm25wch7p9suf2tqlgwy5k4nxwms6d262xyfqm2tccr,\n 5334u64\n ]\n}"}' + - '{"type":"future","id":"5590731974465655998543157332935394974986899946419756918684085895219128822776field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo10knkelvnd55fsaarm25wch7p9suf2tqlgwy5k4nxwms6d262xyfqm2tccr,\n 2366u64\n ]\n}"}' - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"2296589459402270097535149680764663519350069575816165257148428557434644368237field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo10knkelvnd55fsaarm25wch7p9suf2tqlgwy5k4nxwms6d262xyfqm2tccr,\n 5334u64\n ]\n}"}' + - '{"type":"future","id":"432042030880064849076909676849286813284474825415060505835239570887258317130field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo10knkelvnd55fsaarm25wch7p9suf2tqlgwy5k4nxwms6d262xyfqm2tccr,\n 2366u64\n ]\n}"}' diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/many_input_and_output.out b/synthesizer/tests/expectations/vm/execute_and_finalize/many_input_and_output.out new file mode 100644 index 0000000000..21cdc80309 --- /dev/null +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/many_input_and_output.out @@ -0,0 +1,147 @@ +errors: [] +outputs: +- verified: true + execute: + gas_dos.aleo/make_trash_empty: + outputs: [] + speculate: the execution was accepted + add_next_block: succeeded. +- verified: true + execute: + gas_dos.aleo/make_trash: + outputs: + - '{"type":"public","id":"6747157736748603480590286328272166026792595420044415085985565949658486836640field","value":"0u8"}' + - '{"type":"public","id":"649973566147243409550290245203382623458718713926298287005827875227629101586field","value":"1u8"}' + - '{"type":"public","id":"4715184471484114421621316918068835569036773074904095137588387911996155207218field","value":"2u8"}' + - '{"type":"public","id":"6010118718732002261351810375013950678580303457924654867349009010796624699379field","value":"3u8"}' + - '{"type":"public","id":"6333722332192433030784808291116138880151228199115059689497917707786299191732field","value":"4u8"}' + - '{"type":"public","id":"5888245555064288391430977044838182586435070649131417859369280771113057190243field","value":"5u8"}' + - '{"type":"public","id":"2705380664623532047544469249146152090862016550891767685765285532434095990009field","value":"6u8"}' + - '{"type":"public","id":"5519628389319624879328309620830309237982407537738349566389273882401739294201field","value":"7u8"}' + - '{"type":"public","id":"7997534825149575584899781068011514298311850117701142304696407678330173846824field","value":"8u8"}' + - '{"type":"public","id":"8351421848133987949134108689305992851517388701279810208886613680610063838811field","value":"9u8"}' + - '{"type":"public","id":"1040364973741132984216208872045302650189239516982574815007069482884664919083field","value":"10u8"}' + - '{"type":"public","id":"653656632487021611433829850348345841758372491630426780843163907813480449226field","value":"11u8"}' + - '{"type":"public","id":"1593623190274459185231022493182745978048719576581716602188209609143075467430field","value":"12u8"}' + - '{"type":"public","id":"7294419130461631769356218452308251405322881405358069999008200992226082717233field","value":"13u8"}' + - '{"type":"public","id":"1924392335704798525876601513574376180904631637832561294379847655890585101681field","value":"14u8"}' + - '{"type":"public","id":"5010979078364274103068904287124840185727981251110897531184800275512425378069field","value":"15u8"}' + speculate: the execution was accepted + add_next_block: succeeded. +- verified: true + execute: + gas_dos.aleo/make_trash_private: + outputs: + - '{"type":"private","id":"3178675254300275843383623280462721192133283660421872326577156508145365668480field","value":"ciphertext1qyqr72l9jxzmxy9grsl272ud24lq4de7pa36zww2c8n6sdt8ft3n2rsktrhcl"}' + - '{"type":"private","id":"3592370700431980549398591027926102431719057246222545849949554376480536512418field","value":"ciphertext1qyqp9mhjastjmtqppl0us4h0s9hwm2udk6sl7z8kmwxx0rjak0xl6rgrhdfp9"}' + - '{"type":"private","id":"5015190936906056906946595445486950479313140539015689642403600858320056079439field","value":"ciphertext1qyq2g4a6rkuzfs8x70r6zwyudgpn6rng0kv7l008nz52tzjjuyxscysn9k37c"}' + - '{"type":"private","id":"6455178200979974567545886653888837738198208830988894675846651316126562112600field","value":"ciphertext1qyqwk37q9hh34pyu5pqf4dqpkx62ct93u8eg503d3xdumxvgz24kzzs8xh5xf"}' + - '{"type":"private","id":"441578724655724425378862348205143575014108836933091743264908377416536569902field","value":"ciphertext1qyqx373jlfqlp8wk0z8d03w92aj5q6arcw5fa7crsln6je7ckufy2rs440p2r"}' + - '{"type":"private","id":"6727562409363713712272278253770938277290531703671883963721201766296710559416field","value":"ciphertext1qyqdrq9fmpxuvu637fzzevfj8k9p9twwt3skkakks43gjg3wxlmtvrcc2p8tg"}' + - '{"type":"private","id":"5900765846499883782656717755603787007957422075389964372791436651348006857224field","value":"ciphertext1qyqv8d0puv5lruc00xprqgfs3hql2jc7g0ku3usuxsqy4usz0l96ypgy9ur3s"}' + - '{"type":"private","id":"8295226756217200209959596718098054063884309676582306399212247817727537167993field","value":"ciphertext1qyqq2du67uasu2glt9kdhec7j7vct2rtdcnll3t8mpcrx02s0u0sxqsge3tlk"}' + - '{"type":"private","id":"8181394151926143042727606222080968091219514666973681831838802634723910704807field","value":"ciphertext1qyqxra6lnwkx3y8klf2vaud8keuk7jj4vd0k0kqgz8n26f3p97mrwrq0cq04s"}' + - '{"type":"private","id":"6734729083449209300118471016891853097724739272233592697735883274736165821640field","value":"ciphertext1qyqth22n052v2gungdh5nyngegq4sh874nruytkew5zq7kf2nnycjqgz37js7"}' + - '{"type":"private","id":"7500972475236275747881588151814005362695655417811301105586042430933060611422field","value":"ciphertext1qyq9nzmelc5zpuvchxr5m77enr4guj7ruv86xsdk2vx4ku3kwpxx2zsmw4usj"}' + - '{"type":"private","id":"8130977734223629619959263278616285929176363729398376780604587589091569071181field","value":"ciphertext1qyqgh960exm7dn5p3vvtvvnpscyd3g62efr78a3syxzcnu3lzvyv2ygq2e3nn"}' + - '{"type":"private","id":"1342233169177097654860453461670823088901477819542643899134838957080640297291field","value":"ciphertext1qyq2u4kvkuqkw9s0wegyczzul8s59mayjgaz0fzhtaemku6da6y5kpgxfu7sq"}' + - '{"type":"private","id":"7391399596647972354386735773625796963369050508605780615676837486755007451180field","value":"ciphertext1qyqr7uqs6wayrttlxd333lat5xxhhqcphkkylpknkg5dy4gunyx6jygdeqlfm"}' + - '{"type":"private","id":"154135336790998671754023870224163576051523380853463012393717687730220473648field","value":"ciphertext1qyqdehj5yytts6ldaa8ntgj8s695e73zhzg8gnv23kyr8zhzf3ftgqgsdeal0"}' + - '{"type":"private","id":"920095085577843523152461784092653536941316929806000265061076826661821648007field","value":"ciphertext1qyqysgfylsuh23tvrszlzzdswkant3vkjgx3v8ljhnfqqsuyk23pgqguzd940"}' + speculate: the execution was accepted + add_next_block: succeeded. +- verified: true + execute: + gas_dos.aleo/make_trash_u64: + outputs: + - '{"type":"public","id":"730906278716886736214549186867912071216789907293619372995407182276178840902field","value":"0u64"}' + - '{"type":"public","id":"1575109245045429171368494780502083018941818963548716389294319521981302512311field","value":"1u64"}' + - '{"type":"public","id":"6542553720898513549147617785580217609728476848281216612038612053165479658830field","value":"2u64"}' + - '{"type":"public","id":"2050986609566910687002825879266223498079680553920166082503745042337551889897field","value":"3u64"}' + - '{"type":"public","id":"5975522125347992543144304600529534160726915753978735389103069215924086929065field","value":"4u64"}' + - '{"type":"public","id":"865214254461360763975319846771214299246126238769524047937335685873932972656field","value":"5u64"}' + - '{"type":"public","id":"7413677619876125297107923298740333237653602847707462889560217756108381577856field","value":"6u64"}' + - '{"type":"public","id":"3818658792814943441144259826962247349479763887533450194755382563551975295868field","value":"7u64"}' + - '{"type":"public","id":"5817474403061562864597825794761190001190072641318722371536768830410804482446field","value":"8u64"}' + - '{"type":"public","id":"7395071954794891679353516576003699033961561851951923345976907792327399116690field","value":"9u64"}' + - '{"type":"public","id":"3874311404551080002723926693546895057089037571699882905239093422478187649242field","value":"10u64"}' + - '{"type":"public","id":"2652544184779857036613378232899309079255075769671475608097048618116099520983field","value":"11u64"}' + - '{"type":"public","id":"6123105630472453276102467379726848248248111229924666892960235071928063826451field","value":"12u64"}' + - '{"type":"public","id":"7303341187590343154113254059959784526630864495886820459905858622304002827944field","value":"13u64"}' + - '{"type":"public","id":"2387756980249753394206100863037748629623359320692766913121732736054762620163field","value":"14u64"}' + - '{"type":"public","id":"3697673160058841840452855423974362417429421748522565469691462360008980535628field","value":"15u64"}' + speculate: the execution was accepted + add_next_block: succeeded. +- verified: true + execute: + gas_dos.aleo/make_trash_call_inner: + outputs: [] + speculate: the execution was accepted + add_next_block: succeeded. +- verified: true + execute: + gas_dos.aleo/make_trash_call_inner_private: + outputs: [] + speculate: the execution was accepted + add_next_block: succeeded. +additional: +- child_outputs: + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"1233502016375300540052185048988005014879973125955662939200057677097020855469field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo10knkelvnd55fsaarm25wch7p9suf2tqlgwy5k4nxwms6d262xyfqm2tccr,\n 1153u64\n ]\n}"}' +- child_outputs: + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"7949043185167856339065705832481459070786322851203345196375864651473234929294field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo10knkelvnd55fsaarm25wch7p9suf2tqlgwy5k4nxwms6d262xyfqm2tccr,\n 2363u64\n ]\n}"}' +- child_outputs: + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"7618522776601875506220555979247223944774138673406542519145196068858902991539field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo10knkelvnd55fsaarm25wch7p9suf2tqlgwy5k4nxwms6d262xyfqm2tccr,\n 3331u64\n ]\n}"}' +- child_outputs: + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"4128578215055107219586693676580863389042669274675087117576661936356041869384field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo10knkelvnd55fsaarm25wch7p9suf2tqlgwy5k4nxwms6d262xyfqm2tccr,\n 2591u64\n ]\n}"}' +- child_outputs: + child.aleo/inner_trash: + outputs: + - '{"type":"public","id":"5904883560300066031961888185189024338105163106003115127107355735397565233528field","value":"0u8"}' + - '{"type":"public","id":"3346629042065382701229893557344247189765599789097218570622975043609670798803field","value":"1u8"}' + - '{"type":"public","id":"4114234764478642651067432258613060895246418822635359350223568880016900828568field","value":"2u8"}' + - '{"type":"public","id":"791622446349226962179035220266689816431702156005686036773793811267759407217field","value":"3u8"}' + - '{"type":"public","id":"5861572462574962129911421840478714197449959818033666853831901127764956991974field","value":"4u8"}' + - '{"type":"public","id":"8295750733030242931291044435301453040050673845774859044070421871333808089231field","value":"5u8"}' + - '{"type":"public","id":"7955491755960271872467489555522237713927603213194488061987008083541383124742field","value":"6u8"}' + - '{"type":"public","id":"3352141292834455276753576005850851253061340486572425616164757702636471923178field","value":"7u8"}' + - '{"type":"public","id":"1454778745521830463882613773299218996297033423719881562973503668404270532584field","value":"8u8"}' + - '{"type":"public","id":"7214833348890557492438630005734195060401225319633334274543131178468025949410field","value":"9u8"}' + - '{"type":"public","id":"8070255258837127839579827105984137383669983211953015519516297263152741166622field","value":"10u8"}' + - '{"type":"public","id":"6658033481790040965433203990044877190888249483767740626424900263358580479885field","value":"11u8"}' + - '{"type":"public","id":"4634805450592919107424233434549539397856300586736332530027446614793085861610field","value":"12u8"}' + - '{"type":"public","id":"6465237487036414684746876776225050063026228756956149581569485610341137167883field","value":"13u8"}' + - '{"type":"public","id":"539780083557878421637523477938110313145014901324462713310417688577608340204field","value":"14u8"}' + - '{"type":"public","id":"3032526681684647445570962976764436225697368058525256456212480567401674887679field","value":"15u8"}' + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"4334081886835801940971123206469013415987775305601578551344205766751953038292field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo10knkelvnd55fsaarm25wch7p9suf2tqlgwy5k4nxwms6d262xyfqm2tccr,\n 7558u64\n ]\n}"}' +- child_outputs: + child.aleo/inner_trash_private: + outputs: + - '{"type":"private","id":"8032697161240434925553233719907517361847178466961641830077911060008789447796field","value":"ciphertext1qyq8v9hksgs9z5n96m4rruzc5f8m25vshdtkh3ckwvtm6gzzpe827qs08fqhe"}' + - '{"type":"private","id":"4738943134012647945226268068877749848128824814436419950647824307962508386185field","value":"ciphertext1qyqx9zgse0u8pmlawdjw4yhsvc4ncluft34zm4h84wa49qjjdhx9upq9sasx4"}' + - '{"type":"private","id":"2635959015923564697286885588132564920865099194175958790989055258375639564872field","value":"ciphertext1qyq009lapuqdrxltqk24dh7lxqgscqecraejsk5fsdem5c9cpn99jrqachjfa"}' + - '{"type":"private","id":"3529010997203471228727679630176343425830488200535857454220765551756642894632field","value":"ciphertext1qyqxxrkc6ky6qr2gahmh3fdx86sx3zd340kq93ypljef9lcyvj2qcrcj2675k"}' + - '{"type":"private","id":"6665382644452199312390682569471698177901671090003591136674026014712215787440field","value":"ciphertext1qyqppt0twxta22kpkxltpmrjjrcc9awhw3d7hygwmmhplc9ctw067pqyg7995"}' + - '{"type":"private","id":"2748689820460604776985274040581262596018845354312291444007836420267464829488field","value":"ciphertext1qyqdhvdkfjcpmgm8fk4uxdxwquf09a723pqp3pvpm8g6y0ljjkk5uqgq9kc0k"}' + - '{"type":"private","id":"1447383371184268978767488566872720862633397185953221781947866349229014585162field","value":"ciphertext1qyqpw5fvuhvxav9maerk5apz4vy7kwww7fasgx5gaemtuagukqh2yzgv8dg5w"}' + - '{"type":"private","id":"6382890757397621046591645619235381972287595253748882780507077881390244013680field","value":"ciphertext1qyqdu79dm6p7p2g9xysnlsgphtk9tar73c7vpfwd8udque73vpz3krqj97u8z"}' + - '{"type":"private","id":"4316066373532442556231595467086777858030760464465764712503159356773410694734field","value":"ciphertext1qyqpuhrw5jdds2pdfve74272zyzp8dmhts57cydw6gzn75d226r2kpc9fuckz"}' + - '{"type":"private","id":"3681815417015076292682872513235796496265803403295723825838200685480906340815field","value":"ciphertext1qyqwxufrfqkp9utdtrwu0nqrvtgnxqppnwga9fp5nv50hrrsqylpyyg546fam"}' + - '{"type":"private","id":"7239731187052707524355678559194102714131401220844799996252791084924098866449field","value":"ciphertext1qyqdha7v553khg0dlca7zqrav2y32qgxzpwexu3pk4lh00uah8dcuqq9l3svw"}' + - '{"type":"private","id":"6915938306677382285025362060620239528744510612859529413977898404015795221508field","value":"ciphertext1qyqfkm26ec8hs6vdpfcppkktwy76msdlwfg8euat9enwew4rcqtlkqqxnzg6r"}' + - '{"type":"private","id":"4660065728032854412381748795889622379272314801373174547945776152533312518220field","value":"ciphertext1qyqqg7rt8p74zyweshpsa7rwfadvz5wrx50heqxjucxs9nynuv58gpgvpeeka"}' + - '{"type":"private","id":"6730070339834180050058900303293497953058084638877897827327393536891839946788field","value":"ciphertext1qyqzsy5xlnj9av5jdy379lm89za69ecjzgtcn3hcc3z42r3h2rkdjqczey6p4"}' + - '{"type":"private","id":"3905598913166472693352955825211180882338391772928515609728936680972478660573field","value":"ciphertext1qyqfpea03nqftwz4rlr9tym4azz26985stv0z8xuu9gzwclyee7ygqqgjcp3k"}' + - '{"type":"private","id":"7215693369984008673223118085891715586218466956518910943400085339158665270425field","value":"ciphertext1qyqqmqcfmqrals8ajt564w6s3lau2dmxn09lgjdx8s3a2ugdnuqh6rgkw6ywd"}' + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"5813903071441008439034377261900917439453188395995082500140988193573411054956field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo10knkelvnd55fsaarm25wch7p9suf2tqlgwy5k4nxwms6d262xyfqm2tccr,\n 11438u64\n ]\n}"}' diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/mapping_operations.out b/synthesizer/tests/expectations/vm/execute_and_finalize/mapping_operations.out index 6b2773e6cf..0cec3ce62d 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/mapping_operations.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/mapping_operations.out @@ -4,44 +4,44 @@ outputs: execute: mapping_operations.aleo/empty_remove: outputs: - - '{"type":"future","id":"7635640739633293853436744163909014640199975942090334368682977334784204769011field","value":"{\n program_id: mapping_operations.aleo,\n function_name: empty_remove,\n arguments: [\n 10u8\n ]\n}"}' + - '{"type":"future","id":"528917916050546693969666750679371761292623528001587956260557894521828605078field","value":"{\n program_id: mapping_operations.aleo,\n function_name: empty_remove,\n arguments: [\n 10u8\n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. - verified: true execute: mapping_operations.aleo/insert_contains_remove: outputs: - - '{"type":"future","id":"2222820579352641087756930842916349134795974577897148450258189134473958563715field","value":"{\n program_id: mapping_operations.aleo,\n function_name: insert_contains_remove,\n arguments: [\n 0u8,\n 0u8\n ]\n}"}' + - '{"type":"future","id":"1878591124600593274844632247963154904652598107721964702057358386743661676785field","value":"{\n program_id: mapping_operations.aleo,\n function_name: insert_contains_remove,\n arguments: [\n 0u8,\n 0u8\n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. - verified: true execute: mapping_operations.aleo/insert_contains_remove: outputs: - - '{"type":"future","id":"7976126249407457464284575267611007374057326939931567034459595303517614384513field","value":"{\n program_id: mapping_operations.aleo,\n function_name: insert_contains_remove,\n arguments: [\n 0u8,\n 0u8\n ]\n}"}' + - '{"type":"future","id":"4691407840608871888428340061515213816979609712949925756564814279452199679886field","value":"{\n program_id: mapping_operations.aleo,\n function_name: insert_contains_remove,\n arguments: [\n 0u8,\n 0u8\n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. - verified: true execute: mapping_operations.aleo/insert_contains_remove: outputs: - - '{"type":"future","id":"7584999017838461056060100707559452462656710499900127442904227073384510302747field","value":"{\n program_id: mapping_operations.aleo,\n function_name: insert_contains_remove,\n arguments: [\n 0u8,\n 1u8\n ]\n}"}' + - '{"type":"future","id":"1376837211363430068653312021356042012328839054002272482440237208239311509555field","value":"{\n program_id: mapping_operations.aleo,\n function_name: insert_contains_remove,\n arguments: [\n 0u8,\n 1u8\n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. additional: - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"3701652920213282423281084685169254121653756184853703028504071363673532942725field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1eakarna6a70pg9r0l9qal20faejwctgur5xt7lnc2a42wj2yssfqc89rk8,\n 11245u64\n ]\n}"}' + - '{"type":"future","id":"765274853018791932597982874333036008771579256261317466733767488861755463898field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1eakarna6a70pg9r0l9qal20faejwctgur5xt7lnc2a42wj2yssfqc89rk8,\n 11277u64\n ]\n}"}' - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"767852843394263062723803642109980847781175859546892255347263461730875281315field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1eakarna6a70pg9r0l9qal20faejwctgur5xt7lnc2a42wj2yssfqc89rk8,\n 154810u64\n ]\n}"}' + - '{"type":"future","id":"3702624994201751869571637613043506547844907566047297879155547309912750338743field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1eakarna6a70pg9r0l9qal20faejwctgur5xt7lnc2a42wj2yssfqc89rk8,\n 53072u64\n ]\n}"}' - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"5831877738131393412656336446760308055442933218729238434398743654782252530700field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1eakarna6a70pg9r0l9qal20faejwctgur5xt7lnc2a42wj2yssfqc89rk8,\n 154810u64\n ]\n}"}' + - '{"type":"future","id":"2880164867086873472928666458045989541371543910520545574666913914061154311961field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1eakarna6a70pg9r0l9qal20faejwctgur5xt7lnc2a42wj2yssfqc89rk8,\n 53072u64\n ]\n}"}' - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"3924911723698610328779426182874581891939297874519691347932588542992608923909field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1eakarna6a70pg9r0l9qal20faejwctgur5xt7lnc2a42wj2yssfqc89rk8,\n 154810u64\n ]\n}"}' + - '{"type":"future","id":"731712670790521506884462270784414260536578431010638989688535042138119508642field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1eakarna6a70pg9r0l9qal20faejwctgur5xt7lnc2a42wj2yssfqc89rk8,\n 53072u64\n ]\n}"}' diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/mint_and_split.out b/synthesizer/tests/expectations/vm/execute_and_finalize/mint_and_split.out index bd63f8cfca..00b684d244 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/mint_and_split.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/mint_and_split.out @@ -13,6 +13,6 @@ additional: - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"2224596965693604846363254284152512550549945382876106932610187515185636813504field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo19e6k5ferx3k8a9k79xtj4uuaztt2jl4eza7k43pygsu977yazypqqwdmw6,\n 1414u64\n ]\n}"}' + - '{"type":"future","id":"8141932365338593422680862019466751805702849444320820698860516208562395953506field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo19e6k5ferx3k8a9k79xtj4uuaztt2jl4eza7k43pygsu977yazypqqwdmw6,\n 1446u64\n ]\n}"}' - {} - {} diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/program_callable.out b/synthesizer/tests/expectations/vm/execute_and_finalize/program_callable.out index 8bb0637e68..2d1c6b81e8 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/program_callable.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/program_callable.out @@ -5,10 +5,10 @@ outputs: execute: parent.aleo/foo: outputs: - - '{"type":"public","id":"7957417389566842019333476383015223465797041221984916169491225413765492389707field","value":"aleo16w8t56s7v6ud7vu33fr388ph0dq0c7yhp597cyjt88rr3nultcyqcyk9yy"}' - - '{"type":"public","id":"5660332966063165816193998255057769236492104556419359071777110117631685203432field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' - - '{"type":"public","id":"119590126009840588550727571915536854356547100414781210870229193044716803923field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' - - '{"type":"public","id":"3955648008862663886784245642019540732803638576128766893102159939289033551109field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + - '{"type":"public","id":"3132791686827287921440743324738703114146701102235145323661431442511856217971field","value":"aleo16w8t56s7v6ud7vu33fr388ph0dq0c7yhp597cyjt88rr3nultcyqcyk9yy"}' + - '{"type":"public","id":"1169777204608013233991632187841309149325186451415097502721101984905963139305field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + - '{"type":"public","id":"1665319193117753448377121751627813108743655828484762770917631655878172393186field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + - '{"type":"public","id":"7758205965922928181208860399725493314521642846958858098822310042398374724396field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' speculate: the execution was accepted add_next_block: succeeded. additional: @@ -16,8 +16,8 @@ additional: - child_outputs: child.aleo/foo: outputs: - - '{"type":"public","id":"5860672233404277218165914850445330702482897594856038385529876412918074003384field","value":"aleo16w8t56s7v6ud7vu33fr388ph0dq0c7yhp597cyjt88rr3nultcyqcyk9yy"}' - - '{"type":"public","id":"7032360703707892728582573080419248600535906704593225990910797295396231122684field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + - '{"type":"public","id":"2993170113733308844367597166852726630975295024179214931455119604247188877620field","value":"aleo16w8t56s7v6ud7vu33fr388ph0dq0c7yhp597cyjt88rr3nultcyqcyk9yy"}' + - '{"type":"public","id":"1950496274064567059462280897914917860554722224455576030212114387721626639734field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' credits.aleo/fee_public: outputs: - - '{"type":"future","id":"3173434315503739455207432985984041544966817001490874630397863189982314711932field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx,\n 2123u64\n ]\n}"}' + - '{"type":"future","id":"2599746364993747569854355360180642623041829224356671742496735219392179674498field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx,\n 2187u64\n ]\n}"}' diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/public_wallet.out b/synthesizer/tests/expectations/vm/execute_and_finalize/public_wallet.out index cbb7f2d77c..5a64cda820 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/public_wallet.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/public_wallet.out @@ -4,14 +4,14 @@ outputs: execute: public_wallet.aleo/init: outputs: - - '{"type":"future","id":"2740109864087873652477151933781698204925175410187376817867987810696050546048field","value":"{\n program_id: public_wallet.aleo,\n function_name: init,\n arguments: [\n {\n program_id: token.aleo,\n function_name: mint_public,\n arguments: [\n aleo1sry3pke49ykrf0aeshf889tr98r4c86p5f4ms766795ssdwfdyqq9jdg0j,\n 10u64\n ]\n }\n \n ]\n}"}' + - '{"type":"future","id":"3857172901441947534526418517380975227797871553595911987239461419522452545082field","value":"{\n program_id: public_wallet.aleo,\n function_name: init,\n arguments: [\n {\n program_id: token.aleo,\n function_name: mint_public,\n arguments: [\n aleo1sry3pke49ykrf0aeshf889tr98r4c86p5f4ms766795ssdwfdyqq9jdg0j,\n 10u64\n ]\n }\n \n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. additional: - child_outputs: token.aleo/mint_public: outputs: - - '{"type":"future","id":"2095235103073153862497986952383880687050623273703041876358116424903602929020field","value":"{\n program_id: token.aleo,\n function_name: mint_public,\n arguments: [\n aleo1sry3pke49ykrf0aeshf889tr98r4c86p5f4ms766795ssdwfdyqq9jdg0j,\n 10u64\n ]\n}"}' + - '{"type":"future","id":"1631423278608052853768107395089521617081238671575890493962924098384161856776field","value":"{\n program_id: token.aleo,\n function_name: mint_public,\n arguments: [\n aleo1sry3pke49ykrf0aeshf889tr98r4c86p5f4ms766795ssdwfdyqq9jdg0j,\n 10u64\n ]\n}"}' credits.aleo/fee_public: outputs: - - '{"type":"future","id":"4373249435479943424484888940718424132561120812144078253060284512525421799293field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1d3e2je2m2hsxwdsvntvf4jnnlj459ywfry6ch2qwrpy6l6r6yvpq8e88h5,\n 131201u64\n ]\n}"}' + - '{"type":"future","id":"7334131816336578548207468749349798727140016102586366303966330861449690845886field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1d3e2je2m2hsxwdsvntvf4jnnlj459ywfry6ch2qwrpy6l6r6yvpq8e88h5,\n 27585u64\n ]\n}"}' diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/read_external_mapping.out b/synthesizer/tests/expectations/vm/execute_and_finalize/read_external_mapping.out index a729b3163e..0844e497c6 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/read_external_mapping.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/read_external_mapping.out @@ -5,7 +5,7 @@ outputs: relay.aleo/send: outputs: - '{"type":"record","id":"5505341694097720023583674648027312667621444458172921945164834002648638744768field","checksum":"4170712463954366904268628656227022271867279479485549214633981747772705648157field","value":"record1qyqsp358e054av498aavwel28wr36tg0ay27k4fc539ffmwz2nddl8gqqyzxgct5vy3sqqspqpfgwnp3rnwprhd2q3h8gmxcnldlczrvszade4vzxlu7dmfeg6j3rd8mwuzysqtgl6603ey2zzry8hjwmn3pt3twclpkkvssc4l4jzsvd6lxar"}' - - '{"type":"future","id":"5336913895922947334887041593466841136470735988519588898509306662059714980450field","value":"{\n program_id: relay.aleo,\n function_name: send,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm\n ]\n}"}' + - '{"type":"future","id":"5717025369252791268307518245044265589645500853607154349985983366013693165029field","value":"{\n program_id: relay.aleo,\n function_name: send,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm\n ]\n}"}' speculate: the execution was rejected add_next_block: succeeded. - verified: true @@ -13,14 +13,14 @@ outputs: relay.aleo/send_without_check: outputs: - '{"type":"record","id":"4755207731349921544198839760105069860415948248486655350742993041864954064196field","checksum":"7848435433502532569425287419063381736913355859517668180377091558079541996646field","value":"record1qyqsp83ncqrtrev57v03h3j8qcysfgef256zh7pmh7zgj83h6g7tfkq0qyzxgct5vy3sqqspqzx4ww05zz3grf6hxgr46csu2vmzr2lgq0f48kxp4j383l68ufqsq45f8wqk6jxfnkm6v92cq48xea0tfrg0fwwr249m95t4eka6jkgv0c5y7k"}' - - '{"type":"future","id":"1027044606530325120447980237911983680107621060206232306337126914234987187002field","value":"{\n program_id: relay.aleo,\n function_name: send_without_check,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm\n ]\n}"}' + - '{"type":"future","id":"7550940621112069147305499283447693470949248949646948758584545929055098614021field","value":"{\n program_id: relay.aleo,\n function_name: send_without_check,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm\n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. - verified: true execute: registry.aleo/register: outputs: - - '{"type":"future","id":"4059159583881077685368973757192878822018897618745592372395499886263264340961field","value":"{\n program_id: registry.aleo,\n function_name: register,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm\n ]\n}"}' + - '{"type":"future","id":"420928543522275050479077069598359906893359132913160778313607215088435256404field","value":"{\n program_id: registry.aleo,\n function_name: register,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm\n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. - verified: true @@ -28,14 +28,14 @@ outputs: relay.aleo/send: outputs: - '{"type":"record","id":"2277384653342632398532359071690090462344215994043547853708800775056671259572field","checksum":"3071210942562837171924171313096615835242397071199450951002063969440885822680field","value":"record1qyqspfwaru0f2lj0s2k6p9jfmmkzyvkzl5qpagt00edyuf9qn3gnu5g9qyzxgct5vy3sqqspqrncgctd3wfmz2ggx0v7l5cggxxad49wcmtlyrjnk8fqulmkg3h3rleuqh8nmwn5d9z8cpf6z75sy880xenua6hu9wk6ptzwh9vnzps3l7743a"}' - - '{"type":"future","id":"6015012441862221318333000102440691156905727650418067306609473392233853855381field","value":"{\n program_id: relay.aleo,\n function_name: send,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm\n ]\n}"}' + - '{"type":"future","id":"7335072283454266955486193272021538348385359506102454702232503952941871822416field","value":"{\n program_id: relay.aleo,\n function_name: send,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm\n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. - verified: true execute: registry.aleo/unregister: outputs: - - '{"type":"future","id":"621057053984946494815874859056940220465065220086041076777338967969133345871field","value":"{\n program_id: registry.aleo,\n function_name: unregister,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm\n ]\n}"}' + - '{"type":"future","id":"679464137653274742839187887301618622489786113106422850487639713737535385053field","value":"{\n program_id: registry.aleo,\n function_name: unregister,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm\n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. - verified: true @@ -43,31 +43,31 @@ outputs: relay.aleo/send: outputs: - '{"type":"record","id":"6497977440830787207175874226764101265608813002804421333613230199582364410758field","checksum":"319323911748946858530605909565888788506340329996151513367076865761846915611field","value":"record1qyqsqnajqear5neee3l8fykp4vcq35sgwreyz7hz3png3cn2yyljdscfqyzxgct5vy3sqqspqzu6lezptk9xjpx35xdrv5tztz0v9qs9xx803pyqury2j47x2d5seymhf3xa2wefz7mkas7r7m3uf4kte7fdwm00ral53q2mhclx95qte8mpvc"}' - - '{"type":"future","id":"2216932771373637316148105432054544027092193801977530259105019952220093166242field","value":"{\n program_id: relay.aleo,\n function_name: send,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm\n ]\n}"}' + - '{"type":"future","id":"884722454089253418562221490807303959161101695210458740892906535295075161672field","value":"{\n program_id: relay.aleo,\n function_name: send,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm\n ]\n}"}' speculate: the execution was rejected add_next_block: succeeded. additional: - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"2373837014611692049497129045871775574464197133932453792739782919776486496194field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1xe2fps8f9xpdas2q0fqy22uraenk84tvvzetrsyxgnwy6445h59s6wv78x,\n 28479u64\n ]\n}"}' + - '{"type":"future","id":"7648175304675096026780640150249050430126313932796261601585627346676503665056field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1xe2fps8f9xpdas2q0fqy22uraenk84tvvzetrsyxgnwy6445h59s6wv78x,\n 12331u64\n ]\n}"}' - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"6963949699870804211203514659901328830518734684604845622658837353595728006898field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1xe2fps8f9xpdas2q0fqy22uraenk84tvvzetrsyxgnwy6445h59s6wv78x,\n 28507u64\n ]\n}"}' + - '{"type":"future","id":"2705483676500556524709771070827454100315478149315997882559815259752103335543field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1xe2fps8f9xpdas2q0fqy22uraenk84tvvzetrsyxgnwy6445h59s6wv78x,\n 12359u64\n ]\n}"}' - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"786151097471386478439918490898626420968604200995134718973623517242949574field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm,\n 101210u64\n ]\n}"}' + - '{"type":"future","id":"1411848222023701190996666942616875099282931632258684196395264413190693640893field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm,\n 14542u64\n ]\n}"}' - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"7962216909726487379370954492051267200961073450060603523391007597642835489177field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1xe2fps8f9xpdas2q0fqy22uraenk84tvvzetrsyxgnwy6445h59s6wv78x,\n 28479u64\n ]\n}"}' + - '{"type":"future","id":"1868190452431317368813291334581792128122726398918592355342406544035130142983field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1xe2fps8f9xpdas2q0fqy22uraenk84tvvzetrsyxgnwy6445h59s6wv78x,\n 12331u64\n ]\n}"}' - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"5340444358291789813118792762028331134214990505407681376089964565359528622453field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm,\n 101214u64\n ]\n}"}' + - '{"type":"future","id":"4477898748688807061769744441075637584405202918505613760790829764406622025408field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm,\n 14546u64\n ]\n}"}' - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"7708776674386621879381619680665250794376507748822342974632850445134733330595field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1xe2fps8f9xpdas2q0fqy22uraenk84tvvzetrsyxgnwy6445h59s6wv78x,\n 28479u64\n ]\n}"}' + - '{"type":"future","id":"1737368985169748291589889371295386187060392770099481900284782778606372269731field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1xe2fps8f9xpdas2q0fqy22uraenk84tvvzetrsyxgnwy6445h59s6wv78x,\n 12331u64\n ]\n}"}' diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/test_branch.out b/synthesizer/tests/expectations/vm/execute_and_finalize/test_branch.out index 7c414c0ce3..31eb448b63 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/test_branch.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/test_branch.out @@ -4,33 +4,33 @@ outputs: execute: test_branch.aleo/run_test: outputs: - - '{"type":"future","id":"6853588955800014673009987953241306389090845327747907984198222141108269232573field","value":"{\n program_id: test_branch.aleo,\n function_name: run_test,\n arguments: [\n 1u8,\n 1u8\n ]\n}"}' + - '{"type":"future","id":"1689952277818654979661096150540017106084479583953159794693528941821121629614field","value":"{\n program_id: test_branch.aleo,\n function_name: run_test,\n arguments: [\n 1u8,\n 1u8\n ]\n}"}' speculate: the execution was rejected add_next_block: succeeded. - verified: true execute: test_branch.aleo/run_test: outputs: - - '{"type":"future","id":"7316910653703512796159979382480893246542312648132879967453276886284034879075field","value":"{\n program_id: test_branch.aleo,\n function_name: run_test,\n arguments: [\n 0u8,\n 1u8\n ]\n}"}' + - '{"type":"future","id":"114586048401498509272352737885171154770908861875852471025917693936087877358field","value":"{\n program_id: test_branch.aleo,\n function_name: run_test,\n arguments: [\n 0u8,\n 1u8\n ]\n}"}' speculate: the execution was rejected add_next_block: succeeded. - verified: true execute: test_branch.aleo/run_test: outputs: - - '{"type":"future","id":"6402417637041760480107523094357167265585878714433227566435547816691472198663field","value":"{\n program_id: test_branch.aleo,\n function_name: run_test,\n arguments: [\n 0u8,\n 0u8\n ]\n}"}' + - '{"type":"future","id":"7964420694372645950494297905013826833581925240887409965219568939973404172743field","value":"{\n program_id: test_branch.aleo,\n function_name: run_test,\n arguments: [\n 0u8,\n 0u8\n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. additional: - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"8176559465483810586872674176090912007328770812617215482809916166686904238834field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1x3r205zqql5ywy0cqqt74k0r0htuusn0d037ycxe8ftt9ep8hyzsmqz4dh,\n 17268u64\n ]\n}"}' + - '{"type":"future","id":"3742811441854740995256946025007048836334179975183225882601152681493528561258field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1x3r205zqql5ywy0cqqt74k0r0htuusn0d037ycxe8ftt9ep8hyzsmqz4dh,\n 3500u64\n ]\n}"}' - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"885516194992930770292437059317184478627651975125735363573325083543887608918field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1x3r205zqql5ywy0cqqt74k0r0htuusn0d037ycxe8ftt9ep8hyzsmqz4dh,\n 17268u64\n ]\n}"}' + - '{"type":"future","id":"1647838761417122485573508821828299068832334922165753903144172080083427769077field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1x3r205zqql5ywy0cqqt74k0r0htuusn0d037ycxe8ftt9ep8hyzsmqz4dh,\n 3500u64\n ]\n}"}' - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"6884773732489674095657820682011451719106395760464004244662697484163781295818field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1x3r205zqql5ywy0cqqt74k0r0htuusn0d037ycxe8ftt9ep8hyzsmqz4dh,\n 17268u64\n ]\n}"}' + - '{"type":"future","id":"4675644920916319507815616171226090209472553004231457948189653255466652728990field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1x3r205zqql5ywy0cqqt74k0r0htuusn0d037ycxe8ftt9ep8hyzsmqz4dh,\n 3500u64\n ]\n}"}' diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/test_rand.out b/synthesizer/tests/expectations/vm/execute_and_finalize/test_rand.out index 4fefc62cfd..eb372e7191 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/test_rand.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/test_rand.out @@ -4,44 +4,44 @@ outputs: execute: test_rand.aleo/rand_chacha_with_literals: outputs: - - '{"type":"future","id":"859791478012828215720348494076914719205244104520150752280307504054509554398field","value":"{\n program_id: test_rand.aleo,\n function_name: rand_chacha_with_literals,\n arguments: [\n 0scalar,\n 0group,\n 0u8,\n 2i16,\n 4u32,\n 7i64,\n 8u128,\n 10field\n ]\n}"}' + - '{"type":"future","id":"5851936379967939919363011317470385211925863001600978824282354802243328225531field","value":"{\n program_id: test_rand.aleo,\n function_name: rand_chacha_with_literals,\n arguments: [\n 0scalar,\n 0group,\n 0u8,\n 2i16,\n 4u32,\n 7i64,\n 8u128,\n 10field\n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. - verified: true execute: test_rand.aleo/rand_chacha_with_struct: outputs: - - '{"type":"future","id":"1067916594854496467910772380664552622025523070198727493475463622599909707249field","value":"{\n program_id: test_rand.aleo,\n function_name: rand_chacha_with_struct,\n arguments: [\n {\n first: 0field,\n second: 0field,\n third: 0field,\n fourth: 0field,\n fifth: 0field\n}\n ]\n}"}' + - '{"type":"future","id":"3255218993644156872910307787306139629497029688077777497819797270383136364567field","value":"{\n program_id: test_rand.aleo,\n function_name: rand_chacha_with_struct,\n arguments: [\n {\n first: 0field,\n second: 0field,\n third: 0field,\n fourth: 0field,\n fifth: 0field\n}\n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. - verified: true execute: test_rand.aleo/rand_chacha_check: outputs: - - '{"type":"future","id":"3721325135151760660773959530505944451747681933722462808964783147996869797702field","value":"{\n program_id: test_rand.aleo,\n function_name: rand_chacha_check,\n arguments: [\n 0field,\n false\n ]\n}"}' - speculate: the execution was accepted + - '{"type":"future","id":"5655280628674362392666464396476127281186411758739892961608160465159658100070field","value":"{\n program_id: test_rand.aleo,\n function_name: rand_chacha_check,\n arguments: [\n 0field,\n false\n ]\n}"}' + speculate: the execution was rejected add_next_block: succeeded. - verified: true execute: test_rand.aleo/rand_chacha_check: outputs: - - '{"type":"future","id":"887371549615679800380522845098080464570119184210350810479392117984911457950field","value":"{\n program_id: test_rand.aleo,\n function_name: rand_chacha_check,\n arguments: [\n 1field,\n true\n ]\n}"}' + - '{"type":"future","id":"4722955375376605065432422068493514420613444220803270858286854080465504837613field","value":"{\n program_id: test_rand.aleo,\n function_name: rand_chacha_check,\n arguments: [\n 1field,\n true\n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. additional: - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"6314628133780265670801554258125814886017405269745792760682853845340140460175field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1uchf7kruskpp8thlnfeya9qeklcjss27j6rtu74zz7ch559neqystgslsp,\n 601806u64\n ]\n}"}' + - '{"type":"future","id":"1076527458106564529544533915951069356470950455466294891378581697395577060805field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1uchf7kruskpp8thlnfeya9qeklcjss27j6rtu74zz7ch559neqystgslsp,\n 601838u64\n ]\n}"}' - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"3725939744341267737290273038160661629630343114766507174134842826652488781816field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1uchf7kruskpp8thlnfeya9qeklcjss27j6rtu74zz7ch559neqystgslsp,\n 26679u64\n ]\n}"}' + - '{"type":"future","id":"934509585235432931388992469492403334986771615715266644075656706577708720438field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1uchf7kruskpp8thlnfeya9qeklcjss27j6rtu74zz7ch559neqystgslsp,\n 26711u64\n ]\n}"}' - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"5227003534986816857285932061757797688706802206018964764622184983760566708322field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1uchf7kruskpp8thlnfeya9qeklcjss27j6rtu74zz7ch559neqystgslsp,\n 28344u64\n ]\n}"}' + - '{"type":"future","id":"767895526948156364168904176257724171019709225591085577083318751394796758059field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1uchf7kruskpp8thlnfeya9qeklcjss27j6rtu74zz7ch559neqystgslsp,\n 26876u64\n ]\n}"}' - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"5806769723479332130567002952494928256138310337461654699762319212831997850826field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1uchf7kruskpp8thlnfeya9qeklcjss27j6rtu74zz7ch559neqystgslsp,\n 28344u64\n ]\n}"}' + - '{"type":"future","id":"1572717739089618491430428262128578066213813186803348335138976241594053199721field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1uchf7kruskpp8thlnfeya9qeklcjss27j6rtu74zz7ch559neqystgslsp,\n 26876u64\n ]\n}"}' diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/timelock.out b/synthesizer/tests/expectations/vm/execute_and_finalize/timelock.out index 425f80af2e..6d3296cf33 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/timelock.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/timelock.out @@ -4,22 +4,22 @@ outputs: execute: timelock.aleo/lock: outputs: - - '{"type":"future","id":"5726101227699718662507291026879175619949633046158707589853378418659241463316field","value":"{\n program_id: timelock.aleo,\n function_name: lock,\n arguments: []\n}"}' + - '{"type":"future","id":"5672658027601092821150632972624132536122029882218363630138745076773379462255field","value":"{\n program_id: timelock.aleo,\n function_name: lock,\n arguments: []\n}"}' speculate: the execution was rejected add_next_block: succeeded. - verified: true execute: timelock.aleo/lock: outputs: - - '{"type":"future","id":"5825781590715337627504208073275179158827587281138872289977731167576414664969field","value":"{\n program_id: timelock.aleo,\n function_name: lock,\n arguments: []\n}"}' + - '{"type":"future","id":"1309583359781052742370984261699469991508636898906015087862071776472698441892field","value":"{\n program_id: timelock.aleo,\n function_name: lock,\n arguments: []\n}"}' speculate: the execution was rejected add_next_block: succeeded. additional: - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"2868527388214006275127069563021857572887489216649877337285946162120321568912field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo12tksdptp7hvxly8tkm3um08fvf53qpehsgdgqfvy9pe3sewcq5ysjg5myy,\n 5164u64\n ]\n}"}' + - '{"type":"future","id":"651337484339032269160121054560086838303223967284342562550571699484082802926field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo12tksdptp7hvxly8tkm3um08fvf53qpehsgdgqfvy9pe3sewcq5ysjg5myy,\n 2196u64\n ]\n}"}' - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"3666380379303443004933801395245329857516145915761366182794264005536589963556field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo12tksdptp7hvxly8tkm3um08fvf53qpehsgdgqfvy9pe3sewcq5ysjg5myy,\n 5164u64\n ]\n}"}' + - '{"type":"future","id":"7443982931975690101989710049485828676544650952612755258270206826459548145627field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo12tksdptp7hvxly8tkm3um08fvf53qpehsgdgqfvy9pe3sewcq5ysjg5myy,\n 2196u64\n ]\n}"}' diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/unused_position.out b/synthesizer/tests/expectations/vm/execute_and_finalize/unused_position.out index c5e300b026..7acc9e1b28 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/unused_position.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/unused_position.out @@ -4,11 +4,11 @@ outputs: execute: unused_position.aleo/foo: outputs: - - '{"type":"future","id":"4435915382452600913825742955271157728527943603774006701552876898718102875463field","value":"{\n program_id: unused_position.aleo,\n function_name: foo,\n arguments: []\n}"}' + - '{"type":"future","id":"5408452314004637538444583211608650550215632668705730253710414606897907094286field","value":"{\n program_id: unused_position.aleo,\n function_name: foo,\n arguments: []\n}"}' speculate: the execution was accepted add_next_block: succeeded. additional: - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"5889749875317192883762347751185109427367185401929794748301981981444845203330field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo12tksdptp7hvxly8tkm3um08fvf53qpehsgdgqfvy9pe3sewcq5ysjg5myy,\n 2176u64\n ]\n}"}' + - '{"type":"future","id":"1846547935819125611375261116748293171392625542993437934741572770467926190067field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo12tksdptp7hvxly8tkm3um08fvf53qpehsgdgqfvy9pe3sewcq5ysjg5myy,\n 1308u64\n ]\n}"}' diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/user_callable.out b/synthesizer/tests/expectations/vm/execute_and_finalize/user_callable.out index 85f3df23fb..72c6cdb93e 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/user_callable.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/user_callable.out @@ -4,8 +4,8 @@ outputs: execute: child.aleo/foo: outputs: - - '{"type":"public","id":"3583507900097573902692207210661581535840809808651900827750728854102720512424field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' - - '{"type":"public","id":"476166291720572191849579987891810720100233870490756615272004665719966045283field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + - '{"type":"public","id":"5080102022926418909778330219071921101316828719441748927127931330249058015974field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + - '{"type":"public","id":"5521854961454308608590219862110836142563484399396636760251296039833599837132field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' speculate: the execution was accepted add_next_block: succeeded. - execute: 'Failed to evaluate instruction (call child.aleo/foo into r0 r1;): Failed to evaluate instruction (assert.eq self.caller self.signer ;): ''assert.eq'' failed: ''aleo16w8t56s7v6ud7vu33fr388ph0dq0c7yhp597cyjt88rr3nultcyqcyk9yy'' is not equal to ''aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx'' (should be equal)' @@ -13,5 +13,5 @@ additional: - child_outputs: credits.aleo/fee_public: outputs: - - '{"type":"future","id":"5245767978479482276373144091068362056657622227760198296183689243703275814117field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx,\n 1244u64\n ]\n}"}' + - '{"type":"future","id":"3347872470791009142460537022787342626917524637524821339588032366241763021507field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx,\n 1276u64\n ]\n}"}' - {} diff --git a/synthesizer/tests/test_vm_execute_and_finalize.rs b/synthesizer/tests/test_vm_execute_and_finalize.rs index 21a5b4e234..d887ba43f4 100644 --- a/synthesizer/tests/test_vm_execute_and_finalize.rs +++ b/synthesizer/tests/test_vm_execute_and_finalize.rs @@ -90,8 +90,9 @@ fn run_test(test: &ProgramTest) -> serde_yaml::Mapping { rng, ) .unwrap(); - let (ratifications, transactions, aborted_transaction_ids, ratified_finalize_operations) = - vm.speculate(construct_finalize_global_state(&vm), Some(0u64), vec![], None, [transaction].iter()).unwrap(); + let (ratifications, transactions, aborted_transaction_ids, ratified_finalize_operations) = vm + .speculate(construct_finalize_global_state(&vm), Some(0u64), vec![], &None.into(), [transaction].iter()) + .unwrap(); assert!(aborted_transaction_ids.is_empty()); let block = construct_next_block( @@ -126,8 +127,9 @@ fn run_test(test: &ProgramTest) -> serde_yaml::Mapping { } }; - let (ratifications, transactions, aborted_transaction_ids, ratified_finalize_operations) = - vm.speculate(construct_finalize_global_state(&vm), Some(0u64), vec![], None, [transaction].iter()).unwrap(); + let (ratifications, transactions, aborted_transaction_ids, ratified_finalize_operations) = vm + .speculate(construct_finalize_global_state(&vm), Some(0u64), vec![], &None.into(), [transaction].iter()) + .unwrap(); assert!(aborted_transaction_ids.is_empty()); let block = construct_next_block( @@ -265,7 +267,7 @@ fn run_test(test: &ProgramTest) -> serde_yaml::Mapping { // Speculate on the ratifications, solutions, and transaction. let (ratifications, transactions, aborted_transaction_ids, ratified_finalize_operations) = match vm - .speculate(construct_finalize_global_state(&vm), Some(0u64), vec![], None, [transaction].iter()) + .speculate(construct_finalize_global_state(&vm), Some(0u64), vec![], &None.into(), [transaction].iter()) { Ok((ratifications, transactions, aborted_transaction_ids, ratified_finalize_operations)) => { result.insert( @@ -400,8 +402,9 @@ fn construct_fee_records, R: Rng + CryptoRng } } - let (ratifications, transactions, aborted_transaction_ids, ratified_finalize_operations) = - vm.speculate(construct_finalize_global_state(vm), Some(0u64), vec![], None, transactions.iter()).unwrap(); + let (ratifications, transactions, aborted_transaction_ids, ratified_finalize_operations) = vm + .speculate(construct_finalize_global_state(vm), Some(0u64), vec![], &None.into(), transactions.iter()) + .unwrap(); assert!(aborted_transaction_ids.is_empty()); // Create a block for the fee transactions and add them to the VM. @@ -468,7 +471,8 @@ fn construct_next_block, R: Rng + CryptoRng> previous_block.hash(), header, ratifications, - None, + None.into(), + vec![], transactions, aborted_transaction_ids, rng, diff --git a/synthesizer/tests/tests/process/execute/lossy_casts.aleo b/synthesizer/tests/tests/process/execute/lossy_casts.aleo new file mode 100644 index 0000000000..6513c1bb00 --- /dev/null +++ b/synthesizer/tests/tests/process/execute/lossy_casts.aleo @@ -0,0 +1,50 @@ +/* +randomness: 902384 +cases: + - program: lossy_casts.aleo + function: test_lossy_cast + inputs: [79363714989903307245735717098563574705733591463163614225748337416674727625843187853442697973404985688481508350822field] + - program: lossy_casts.aleo + function: test_lossy_cast + inputs: [0field] + - program: lossy_casts.aleo + function: test_lossy_cast + inputs: [1field] + - program: lossy_casts.aleo + function: test_lossy_cast + inputs: [340_282_366_920_938_463_463_374_607_431_768_211_456field] + - program: lossy_casts.aleo + function: test_lossy_cast + inputs: [340_282_366_920_938_463_463_374_607_431_768_211_457field] + + +*/ + +program lossy_casts.aleo; + +function test_lossy_cast: + input r0 as field.private; + cast.lossy r0 into r1 as u128; + cast.lossy r0 into r2 as i128; + cast.lossy r0 into r3 as u64; + cast.lossy r0 into r4 as i64; + cast.lossy r0 into r5 as u32; + cast.lossy r0 into r6 as i32; + cast.lossy r0 into r7 as u16; + cast.lossy r0 into r8 as i16; + cast.lossy r0 into r9 as u8; + cast.lossy r0 into r10 as i8; + cast.lossy r0 into r11 as boolean; + cast.lossy r0 into r12 as group; + output r1 as u128.private; + output r2 as i128.private; + output r3 as u64.private; + output r4 as i64.private; + output r5 as u32.private; + output r6 as i32.private; + output r7 as u16.private; + output r8 as i16.private; + output r9 as u8.private; + output r10 as i8.private; + output r11 as boolean.private; + output r12 as group.private; diff --git a/synthesizer/tests/tests/vm/execute_and_finalize/many_input_and_output.aleo b/synthesizer/tests/tests/vm/execute_and_finalize/many_input_and_output.aleo new file mode 100644 index 0000000000..94f680ded5 --- /dev/null +++ b/synthesizer/tests/tests/vm/execute_and_finalize/many_input_and_output.aleo @@ -0,0 +1,226 @@ +/* +randomness: 12345 +cases: + - program: gas_dos.aleo + function: make_trash_empty + inputs: [] + - program: gas_dos.aleo + function: make_trash + inputs: [0u8, 1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, 8u8, 9u8, 10u8, 11u8, 12u8, 13u8, 14u8, 15u8] + - program: gas_dos.aleo + function: make_trash_private + inputs: [0u8, 1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, 8u8, 9u8, 10u8, 11u8, 12u8, 13u8, 14u8, 15u8] + - program: gas_dos.aleo + function: make_trash_u64 + inputs: [0u64, 1u64, 2u64, 3u64, 4u64, 5u64, 6u64, 7u64, 8u64, 9u64, 10u64, 11u64, 12u64, 13u64, 14u64, 15u64] + - program: gas_dos.aleo + function: make_trash_call_inner + inputs: [] + - program: gas_dos.aleo + function: make_trash_call_inner_private + inputs: [] +*/ + + +program child.aleo; + +function inner_trash_single: + input r0 as u8.public; + output r0 as u8.public; + +function inner_trash: + input r0 as u8.public; + input r1 as u8.public; + input r2 as u8.public; + input r3 as u8.public; + input r4 as u8.public; + input r5 as u8.public; + input r6 as u8.public; + input r7 as u8.public; + input r8 as u8.public; + input r9 as u8.public; + input r10 as u8.public; + input r11 as u8.public; + input r12 as u8.public; + input r13 as u8.public; + input r14 as u8.public; + input r15 as u8.public; + + output r0 as u8.public; + output r1 as u8.public; + output r2 as u8.public; + output r3 as u8.public; + output r4 as u8.public; + output r5 as u8.public; + output r6 as u8.public; + output r7 as u8.public; + output r8 as u8.public; + output r9 as u8.public; + output r10 as u8.public; + output r11 as u8.public; + output r12 as u8.public; + output r13 as u8.public; + output r14 as u8.public; + output r15 as u8.public; + +function inner_trash_private: + input r0 as u8.private; + input r1 as u8.private; + input r2 as u8.private; + input r3 as u8.private; + input r4 as u8.private; + input r5 as u8.private; + input r6 as u8.private; + input r7 as u8.private; + input r8 as u8.private; + input r9 as u8.private; + input r10 as u8.private; + input r11 as u8.private; + input r12 as u8.private; + input r13 as u8.private; + input r14 as u8.private; + input r15 as u8.private; + + output r0 as u8.private; + output r1 as u8.private; + output r2 as u8.private; + output r3 as u8.private; + output r4 as u8.private; + output r5 as u8.private; + output r6 as u8.private; + output r7 as u8.private; + output r8 as u8.private; + output r9 as u8.private; + output r10 as u8.private; + output r11 as u8.private; + output r12 as u8.private; + output r13 as u8.private; + output r14 as u8.private; + output r15 as u8.private; + + +///////////////////////////////////////////////// + +import child.aleo; + +program gas_dos.aleo; + +function make_trash_empty: + +function make_trash: + input r0 as u8.public; + input r1 as u8.public; + input r2 as u8.public; + input r3 as u8.public; + input r4 as u8.public; + input r5 as u8.public; + input r6 as u8.public; + input r7 as u8.public; + input r8 as u8.public; + input r9 as u8.public; + input r10 as u8.public; + input r11 as u8.public; + input r12 as u8.public; + input r13 as u8.public; + input r14 as u8.public; + input r15 as u8.public; + + output r0 as u8.public; + output r1 as u8.public; + output r2 as u8.public; + output r3 as u8.public; + output r4 as u8.public; + output r5 as u8.public; + output r6 as u8.public; + output r7 as u8.public; + output r8 as u8.public; + output r9 as u8.public; + output r10 as u8.public; + output r11 as u8.public; + output r12 as u8.public; + output r13 as u8.public; + output r14 as u8.public; + output r15 as u8.public; + +function make_trash_private: + input r0 as u8.private; + input r1 as u8.private; + input r2 as u8.private; + input r3 as u8.private; + input r4 as u8.private; + input r5 as u8.private; + input r6 as u8.private; + input r7 as u8.private; + input r8 as u8.private; + input r9 as u8.private; + input r10 as u8.private; + input r11 as u8.private; + input r12 as u8.private; + input r13 as u8.private; + input r14 as u8.private; + input r15 as u8.private; + + output r0 as u8.private; + output r1 as u8.private; + output r2 as u8.private; + output r3 as u8.private; + output r4 as u8.private; + output r5 as u8.private; + output r6 as u8.private; + output r7 as u8.private; + output r8 as u8.private; + output r9 as u8.private; + output r10 as u8.private; + output r11 as u8.private; + output r12 as u8.private; + output r13 as u8.private; + output r14 as u8.private; + output r15 as u8.private; + + +function make_trash_u64: + input r0 as u64.public; + input r1 as u64.public; + input r2 as u64.public; + input r3 as u64.public; + input r4 as u64.public; + input r5 as u64.public; + input r6 as u64.public; + input r7 as u64.public; + input r8 as u64.public; + input r9 as u64.public; + input r10 as u64.public; + input r11 as u64.public; + input r12 as u64.public; + input r13 as u64.public; + input r14 as u64.public; + input r15 as u64.public; + + output r0 as u64.public; + output r1 as u64.public; + output r2 as u64.public; + output r3 as u64.public; + output r4 as u64.public; + output r5 as u64.public; + output r6 as u64.public; + output r7 as u64.public; + output r8 as u64.public; + output r9 as u64.public; + output r10 as u64.public; + output r11 as u64.public; + output r12 as u64.public; + output r13 as u64.public; + output r14 as u64.public; + output r15 as u64.public; + +function make_trash_call_inner: + call child.aleo/inner_trash 0u8 1u8 2u8 3u8 4u8 5u8 6u8 7u8 8u8 9u8 10u8 11u8 12u8 13u8 14u8 15u8 into r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15; + call child.aleo/inner_trash 0u8 1u8 2u8 3u8 4u8 5u8 6u8 7u8 8u8 9u8 10u8 11u8 12u8 13u8 14u8 15u8 into r16 r17 r18 r19 r20 r21 r22 r23 r24 r25 r26 r27 r28 r29 r30 r31; + call child.aleo/inner_trash 0u8 1u8 2u8 3u8 4u8 5u8 6u8 7u8 8u8 9u8 10u8 11u8 12u8 13u8 14u8 15u8 into r32 r33 r34 r35 r36 r37 r38 r39 r40 r41 r42 r43 r44 r45 r46 r47; + call child.aleo/inner_trash 0u8 1u8 2u8 3u8 4u8 5u8 6u8 7u8 8u8 9u8 10u8 11u8 12u8 13u8 14u8 15u8 into r48 r49 r50 r51 r52 r53 r54 r55 r56 r57 r58 r59 r60 r61 r62 r63; + +function make_trash_call_inner_private: + call child.aleo/inner_trash_private 0u8 1u8 2u8 3u8 4u8 5u8 6u8 7u8 8u8 9u8 10u8 11u8 12u8 13u8 14u8 15u8 into r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15; + call child.aleo/inner_trash_private 0u8 1u8 2u8 3u8 4u8 5u8 6u8 7u8 8u8 9u8 10u8 11u8 12u8 13u8 14u8 15u8 into r16 r17 r18 r19 r20 r21 r22 r23 r24 r25 r26 r27 r28 r29 r30 r31; + call child.aleo/inner_trash_private 0u8 1u8 2u8 3u8 4u8 5u8 6u8 7u8 8u8 9u8 10u8 11u8 12u8 13u8 14u8 15u8 into r32 r33 r34 r35 r36 r37 r38 r39 r40 r41 r42 r43 r44 r45 r46 r47; + call child.aleo/inner_trash_private 0u8 1u8 2u8 3u8 4u8 5u8 6u8 7u8 8u8 9u8 10u8 11u8 12u8 13u8 14u8 15u8 into r48 r49 r50 r51 r52 r53 r54 r55 r56 r57 r58 r59 r60 r61 r62 r63; diff --git a/synthesizer/tests/utilities/mod.rs b/synthesizer/tests/utilities/mod.rs index 36bbebaadc..665327b579 100644 --- a/synthesizer/tests/utilities/mod.rs +++ b/synthesizer/tests/utilities/mod.rs @@ -25,7 +25,7 @@ #![allow(unused)] pub type CurrentAleo = circuit::network::AleoV0; -pub type CurrentNetwork = console::network::Testnet3; +pub type CurrentNetwork = console::network::MainnetV0; pub mod expectation; pub use expectation::*; diff --git a/utilities/Cargo.toml b/utilities/Cargo.toml index bbced72fca..0614b4f1f9 100644 --- a/utilities/Cargo.toml +++ b/utilities/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-utilities" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Utilities for a decentralized virtual machine" homepage = "https://aleo.org" @@ -25,11 +25,11 @@ edition = "2021" [dependencies.snarkvm-utilities-derives] path = "./derives" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.aleo-std] -version = "0.1.18" +version = "0.1.24" optional = true default-features = false diff --git a/utilities/derives/Cargo.toml b/utilities/derives/Cargo.toml index 29d966060b..560b7cfdff 100644 --- a/utilities/derives/Cargo.toml +++ b/utilities/derives/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-utilities-derives" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "Canonical serialization for a decentralized virtual machine" homepage = "https://aleo.org" diff --git a/utilities/src/serialize/impls.rs b/utilities/src/serialize/impls.rs index dccc02981e..ee09a23478 100644 --- a/utilities/src/serialize/impls.rs +++ b/utilities/src/serialize/impls.rs @@ -13,7 +13,7 @@ // limitations under the License. pub use crate::{ - io::{self, Read, Write}, + io::{Read, Write}, FromBytes, ToBytes, Vec, diff --git a/utilities/src/serialize/mod.rs b/utilities/src/serialize/mod.rs index 8147e6f1a7..00048a9ea2 100644 --- a/utilities/src/serialize/mod.rs +++ b/utilities/src/serialize/mod.rs @@ -19,6 +19,7 @@ mod helpers; pub use helpers::*; mod impls; +#[allow(unused_imports)] pub use impls::*; mod flags; diff --git a/utilities/src/serialize/traits.rs b/utilities/src/serialize/traits.rs index ae6ca9b58d..373ca02abd 100644 --- a/utilities/src/serialize/traits.rs +++ b/utilities/src/serialize/traits.rs @@ -12,13 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +pub use crate::io::{Read, Write}; use crate::SerializationError; -pub use crate::{ - io::{self, Read, Write}, - FromBytes, - ToBytes, - Vec, -}; use serde::de::{self, DeserializeOwned, Deserializer}; diff --git a/vm/cli/commands/build.rs b/vm/cli/commands/build.rs index 671ca61554..ac72b101f8 100644 --- a/vm/cli/commands/build.rs +++ b/vm/cli/commands/build.rs @@ -41,7 +41,7 @@ impl Build { // package.build::(match self.offline { // true => None, - // false => Some(endpoint.unwrap_or("https://vm.aleo.org/testnet3/build".to_string())), + // false => Some(endpoint.unwrap_or("https://api.explorer.aleo.org/v0/mainnet/build".to_string())), // })?; // Prepare the path string. diff --git a/vm/cli/commands/mod.rs b/vm/cli/commands/mod.rs index 68f71186e3..93475a3e48 100644 --- a/vm/cli/commands/mod.rs +++ b/vm/cli/commands/mod.rs @@ -44,5 +44,5 @@ use std::collections::HashMap; pub const LOCALE: &num_format::Locale = &num_format::Locale::en; -pub(crate) type CurrentNetwork = crate::prelude::Testnet3; +pub(crate) type CurrentNetwork = crate::prelude::MainnetV0; pub(crate) type Aleo = crate::circuit::AleoV0; diff --git a/vm/cli/helpers/env.rs b/vm/cli/helpers/env.rs index ed41cafc72..8e8c725ac0 100644 --- a/vm/cli/helpers/env.rs +++ b/vm/cli/helpers/env.rs @@ -18,7 +18,7 @@ use anyhow::{anyhow, Result}; fn env_template() -> String { r#" -NETWORK=testnet3 +NETWORK=mainnet PRIVATE_KEY={{PASTE_YOUR_PRIVATE_KEY_HERE}} "# .to_string() diff --git a/vm/file/aleo.rs b/vm/file/aleo.rs index bae28c6b2c..4d22626117 100644 --- a/vm/file/aleo.rs +++ b/vm/file/aleo.rs @@ -241,7 +241,7 @@ mod tests { use super::*; use crate::prelude::Parser; - type CurrentNetwork = snarkvm_console::network::Testnet3; + type CurrentNetwork = snarkvm_console::network::MainnetV0; fn temp_dir() -> std::path::PathBuf { tempfile::tempdir().expect("Failed to open temporary directory").into_path() diff --git a/vm/file/avm.rs b/vm/file/avm.rs index ac252d87ed..2fbdd1af40 100644 --- a/vm/file/avm.rs +++ b/vm/file/avm.rs @@ -181,7 +181,7 @@ mod tests { use super::*; use crate::prelude::Parser; - type CurrentNetwork = snarkvm_console::network::Testnet3; + type CurrentNetwork = snarkvm_console::network::MainnetV0; fn temp_dir() -> std::path::PathBuf { tempfile::tempdir().expect("Failed to open temporary directory").into_path() diff --git a/vm/file/prover.rs b/vm/file/prover.rs index 69d4ad8369..740971849d 100644 --- a/vm/file/prover.rs +++ b/vm/file/prover.rs @@ -198,7 +198,7 @@ mod tests { synthesizer::Process, }; - type CurrentNetwork = snarkvm_console::network::Testnet3; + type CurrentNetwork = snarkvm_console::network::MainnetV0; type CurrentAleo = snarkvm_circuit::AleoV0; fn temp_dir() -> std::path::PathBuf { diff --git a/vm/file/verifier.rs b/vm/file/verifier.rs index aaa664bd43..2def859ed1 100644 --- a/vm/file/verifier.rs +++ b/vm/file/verifier.rs @@ -198,7 +198,7 @@ mod tests { synthesizer::Process, }; - type CurrentNetwork = snarkvm_console::network::Testnet3; + type CurrentNetwork = snarkvm_console::network::MainnetV0; type CurrentAleo = snarkvm_circuit::AleoV0; fn temp_dir() -> std::path::PathBuf { diff --git a/vm/package/clean.rs b/vm/package/clean.rs index 561041c6d1..0d1859a78c 100644 --- a/vm/package/clean.rs +++ b/vm/package/clean.rs @@ -49,7 +49,7 @@ impl Package { mod tests { use super::*; - type CurrentNetwork = snarkvm_console::network::Testnet3; + type CurrentNetwork = snarkvm_console::network::MainnetV0; type CurrentAleo = snarkvm_circuit::network::AleoV0; #[test] diff --git a/vm/package/deploy.rs b/vm/package/deploy.rs index cc3ec45644..ebc04a447e 100644 --- a/vm/package/deploy.rs +++ b/vm/package/deploy.rs @@ -168,7 +168,7 @@ impl Package { mod tests { use super::*; - type CurrentNetwork = snarkvm_console::network::Testnet3; + type CurrentNetwork = snarkvm_console::network::MainnetV0; type CurrentAleo = snarkvm_circuit::network::AleoV0; #[test] diff --git a/vm/package/execute.rs b/vm/package/execute.rs index e075e8de86..190ef66199 100644 --- a/vm/package/execute.rs +++ b/vm/package/execute.rs @@ -117,7 +117,7 @@ mod tests { type CurrentAleo = snarkvm_circuit::network::AleoV0; - // TODO: Re-enable this test after `staging` is merged into `testnet3` for the October 18, 2023 calibration reset. + // TODO: Re-enable this test after `mainnet`. #[test] #[ignore] fn test_execute() { diff --git a/vm/package/is_build_required.rs b/vm/package/is_build_required.rs index 0ce4a9253f..a7cec05183 100644 --- a/vm/package/is_build_required.rs +++ b/vm/package/is_build_required.rs @@ -65,17 +65,17 @@ impl Package { #[cfg(test)] mod tests { use super::*; - use snarkvm_console::network::Testnet3; + use snarkvm_console::network::MainnetV0; use std::{fs::File, io::Write}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; type Aleo = crate::circuit::AleoV0; fn temp_dir() -> PathBuf { tempfile::tempdir().expect("Failed to open temporary directory").into_path() } - fn initialize_unbuilt_package(valid: bool) -> Result> { + fn initialize_unbuilt_package(valid: bool) -> Result> { // Initialize a temporary directory. let directory = temp_dir(); @@ -99,7 +99,7 @@ mod tests { std::fs::create_dir_all(build_directory).unwrap(); // Open the package at the temporary directory. - Package::::open(&directory) + Package::::open(&directory) } fn program_with_id(id: &str) -> String { diff --git a/vm/package/mod.rs b/vm/package/mod.rs index 87f383df83..7568a01e5a 100644 --- a/vm/package/mod.rs +++ b/vm/package/mod.rs @@ -180,11 +180,11 @@ impl Package { #[cfg(test)] pub(crate) mod test_helpers { use super::*; - use snarkvm_console::{account::Address, network::Testnet3, prelude::TestRng}; + use snarkvm_console::{account::Address, network::MainnetV0, prelude::TestRng}; use std::{fs::File, io::Write}; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; fn temp_dir() -> PathBuf { tempfile::tempdir().expect("Failed to open temporary directory").into_path() @@ -389,7 +389,7 @@ function main: let _manifest_file = Manifest::create(&directory, main_program_id).unwrap(); // Open the package at the temporary directory. - let package = Package::::open(&directory).unwrap(); + let package = Package::::open(&directory).unwrap(); assert_eq!(package.program_id(), main_program_id); // Return the temporary directory and the package. @@ -465,11 +465,11 @@ function main: #[cfg(test)] mod tests { use super::*; - use crate::prelude::Testnet3; + use crate::prelude::MainnetV0; use snarkvm_utilities::TestRng; type CurrentAleo = snarkvm_circuit::network::AleoV0; - type CurrentNetwork = Testnet3; + type CurrentNetwork = MainnetV0; #[test] fn test_imports_directory() { diff --git a/vm/package/run.rs b/vm/package/run.rs index 54b1520ead..59ace04ac4 100644 --- a/vm/package/run.rs +++ b/vm/package/run.rs @@ -53,7 +53,7 @@ impl Package { // Initialize the call stack. let call_stack = CallStack::PackageRun(vec![request], *private_key, assignments.clone()); // Synthesize the circuit. - let response = stack.execute_function::(call_stack, None, rng)?; + let response = stack.execute_function::(call_stack, None, None, rng)?; // Retrieve the call metrics. let call_metrics = assignments.read().iter().map(|(_, metrics)| *metrics).collect::>(); // Return the response and call metrics. diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index 0ab51f4d5a..4183bbf38c 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snarkvm-wasm" -version = "0.16.15" +version = "0.16.19" authors = [ "The Aleo Team " ] description = "WASM for a decentralized virtual machine" homepage = "https://aleo.org" @@ -51,54 +51,54 @@ utilities = [ "snarkvm-utilities" ] [dependencies.snarkvm-circuit-network] path = "../circuit/network" -version = "=0.16.15" +version = "=0.16.19" features = [ "wasm" ] optional = true [dependencies.snarkvm-console] path = "../console" -version = "=0.16.15" +version = "=0.16.19" features = [ "wasm" ] optional = true [dependencies.snarkvm-curves] path = "../curves" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-fields] path = "../fields" -version = "=0.16.15" +version = "=0.16.19" optional = true [dependencies.snarkvm-ledger-block] path = "../ledger/block" -version = "=0.16.15" +version = "=0.16.19" features = [ "wasm" ] optional = true [dependencies.snarkvm-ledger-query] path = "../ledger/query" -version = "=0.16.15" +version = "=0.16.19" features = [ "async", "wasm" ] optional = true [dependencies.snarkvm-ledger-store] path = "../ledger/store" -version = "=0.16.15" +version = "=0.16.19" features = [ "wasm" ] optional = true [dependencies.snarkvm-synthesizer] path = "../synthesizer" -version = "=0.16.15" +version = "=0.16.19" default-features = false features = [ "async", "wasm" ] optional = true [dependencies.snarkvm-utilities] path = "../utilities" -version = "=0.16.15" +version = "=0.16.19" features = [ "wasm" ] optional = true diff --git a/wasm/src/tests.rs b/wasm/src/tests.rs index 8cdc5e17f8..5610df5b39 100644 --- a/wasm/src/tests.rs +++ b/wasm/src/tests.rs @@ -14,7 +14,7 @@ use snarkvm_console::{ account::{Address, PrivateKey, ViewKey}, - network::Testnet3, + network::MainnetV0, }; use snarkvm_utilities::TestRng; @@ -29,7 +29,7 @@ fn test_account() { const ALEO_VIEW_KEY: &str = "AViewKey1n1n3ZbnVEtXVe3La2xWkUvY3EY7XaCG6RZJJ3tbvrrrD"; const ALEO_ADDRESS: &str = "aleo1wvgwnqvy46qq0zemj0k6sfp3zv0mp77rw97khvwuhac05yuwscxqmfyhwf"; - let private_key = PrivateKey::::from_str(ALEO_PRIVATE_KEY).unwrap(); + let private_key = PrivateKey::::from_str(ALEO_PRIVATE_KEY).unwrap(); assert_eq!(ALEO_PRIVATE_KEY, private_key.to_string()); let view_key = ViewKey::try_from(&private_key).unwrap(); @@ -45,7 +45,7 @@ fn test_account_sign() { for _ in 0..ITERATIONS { // Sample a new private key and address. - let private_key = PrivateKey::::new(&mut rng).unwrap(); + let private_key = PrivateKey::::new(&mut rng).unwrap(); let address = Address::try_from(&private_key).unwrap(); // Sign a message with the account private key.