diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index f33dfcd481..bd6e7ad390 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -60,7 +60,6 @@ jobs: run: | cd console/collections cargo bench --bench merkle_tree -- --output-format bencher | tee -a ../../output.txt - cargo bench --bench kary_merkle_tree -- --output-format bencher | tee -a ../../output.txt cd ../.. - name: Benchmark curves diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9dda0af373..b0233c6c71 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,7 +20,7 @@ snarkVM is a big project, so (non-)adherence to best practices related to perfor ### Memory handling - if the final size is known, pre-allocate the collections (`Vec`, `HashMap` etc.) using `with_capacity` or `reserve` - this ensures that there are both fewer allocations (which involve system calls) and that the final allocated capacity is as close to the required size as possible - create the collections right before they are populated/used, as opposed to e.g. creating a few big ones at the beginning of a function and only using them later on; this reduces the amount of time they occupy memory -- if an intermediate vector is avoidable, use an `Iterator` instead; most of the time this just amounts to omitting the call to `.collect()` if a single-pass iteraton follows afterwards, or returning an `impl Iterator` from a function when the caller only needs to iterate over that result once +- if an intermediate vector is avoidable, use an `Iterator` instead; most of the time this just amounts to omitting the call to `.collect()` if a single-pass iteration follows afterwards, or returning an `impl Iterator` from a function when the caller only needs to iterate over that result once - when possible, fill/resize collections "in bulk" instead of pushing a single element in a loop; this is usually (but not always) detected by `clippy`, suggesting to create vectors containing a repeated value with `vec![x; N]` or extending them with `.resize(N, x)` - when a value is to eventually be consumed in a chain of function calls, pass it by value instead of by reference; this has the following benefits: * it makes the fact that the value is needed by value clear to the caller, who can then potentially reclaim it from the object afterwards if it is "heavy", limiting allocations diff --git a/console/program/src/data/ciphertext/bytes.rs b/console/program/src/data/ciphertext/bytes.rs index 212a6e84d5..d983d9bb71 100644 --- a/console/program/src/data/ciphertext/bytes.rs +++ b/console/program/src/data/ciphertext/bytes.rs @@ -66,7 +66,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, Ciphertext::read_le(&expected_bytes[..])?); - // assert!(Ciphertext::::read_le(&expected_bytes[1..]).is_err()); } Ok(()) } diff --git a/console/program/src/data/future/bytes.rs b/console/program/src/data/future/bytes.rs index f4e492bdd8..95878055f1 100644 --- a/console/program/src/data/future/bytes.rs +++ b/console/program/src/data/future/bytes.rs @@ -84,7 +84,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, Future::read_le(&expected_bytes[..])?); - assert!(Future::::read_le(&expected_bytes[1..]).is_err()); Ok(()) } diff --git a/console/program/src/data/identifier/bytes.rs b/console/program/src/data/identifier/bytes.rs index e90d7fbae3..757f27ba40 100644 --- a/console/program/src/data/identifier/bytes.rs +++ b/console/program/src/data/identifier/bytes.rs @@ -25,6 +25,7 @@ impl FromBytes for Identifier { reader.read_exact(&mut buffer)?; // from_str the identifier. + // Note: `Self::from_str` ensures that the identifier string is not empty. Self::from_str(&String::from_utf8(buffer).map_err(|e| error(format!("Failed to decode identifier: {e}")))?) .map_err(|e| error(format!("{e}"))) } @@ -72,8 +73,12 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, Identifier::read_le(&expected_bytes[..])?); - assert!(Identifier::::read_le(&expected_bytes[1..]).is_err()); } Ok(()) } + + #[test] + fn test_zero_identifier_fails() { + assert!(Identifier::::read_le(&[0u8; 1][..]).is_err()) + } } diff --git a/console/program/src/data/literal/bytes.rs b/console/program/src/data/literal/bytes.rs index d52f43045b..1f77bf3430 100644 --- a/console/program/src/data/literal/bytes.rs +++ b/console/program/src/data/literal/bytes.rs @@ -132,8 +132,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, Literal::read_le(&expected_bytes[..])?); - assert!(Literal::::read_le(&expected_bytes[1..]).is_err()); - // assert!(Literal::::read_le(&expected_bytes[2..]).is_err()); Ok(()) } diff --git a/console/program/src/data/plaintext/bytes.rs b/console/program/src/data/plaintext/bytes.rs index a6c4867bc4..99cdd82ed4 100644 --- a/console/program/src/data/plaintext/bytes.rs +++ b/console/program/src/data/plaintext/bytes.rs @@ -131,9 +131,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, Plaintext::read_le(&expected_bytes[..])?); - // assert!(Plaintext::::read_le(&expected_bytes[1..]).is_err()); - // assert!(Plaintext::::read_le(&expected_bytes[2..]).is_err()); - // assert!(Plaintext::::read_le(&expected_bytes[3..]).is_err()); Ok(()) } @@ -225,7 +222,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, Plaintext::read_le(&expected_bytes[..])?); - assert!(Plaintext::::read_le(&expected_bytes[1..]).is_err()); // Check the array manually. let expected = Plaintext::::from_str("[ 1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, 8u8, 9u8, 10u8 ]")?; @@ -233,7 +229,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, Plaintext::read_le(&expected_bytes[..])?); - assert!(Plaintext::::read_le(&expected_bytes[1..]).is_err()); Ok(()) } diff --git a/console/program/src/data/record/bytes.rs b/console/program/src/data/record/bytes.rs index 6c74f0b1ad..a787040499 100644 --- a/console/program/src/data/record/bytes.rs +++ b/console/program/src/data/record/bytes.rs @@ -95,7 +95,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, Record::read_le(&expected_bytes[..])?); - assert!(Record::>::read_le(&expected_bytes[1..]).is_err()); Ok(()) } } diff --git a/console/program/src/data/value/bytes.rs b/console/program/src/data/value/bytes.rs index 8bfa9fcade..50e8567f05 100644 --- a/console/program/src/data/value/bytes.rs +++ b/console/program/src/data/value/bytes.rs @@ -67,7 +67,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, Value::read_le(&expected_bytes[..])?); - assert!(Value::::read_le(&expected_bytes[1..]).is_err()); Ok(()) } @@ -81,7 +80,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, Value::read_le(&expected_bytes[..])?); - assert!(Value::::read_le(&expected_bytes[1..]).is_err()); Ok(()) } } diff --git a/console/program/src/request/bytes.rs b/console/program/src/request/bytes.rs index 761b6b1340..ec664b9c48 100644 --- a/console/program/src/request/bytes.rs +++ b/console/program/src/request/bytes.rs @@ -100,9 +100,6 @@ impl ToBytes for Request { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() { @@ -112,7 +109,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le().unwrap(); assert_eq!(expected, Request::read_le(&expected_bytes[..]).unwrap()); - assert!(Request::::read_le(&expected_bytes[1..]).is_err()); } } } diff --git a/console/program/src/state_path/header_leaf/bytes.rs b/console/program/src/state_path/header_leaf/bytes.rs index cde4608989..16f2b03bca 100644 --- a/console/program/src/state_path/header_leaf/bytes.rs +++ b/console/program/src/state_path/header_leaf/bytes.rs @@ -39,9 +39,6 @@ impl ToBytes for HeaderLeaf { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; - - type CurrentNetwork = Testnet3; const ITERATIONS: u64 = 1000; @@ -56,7 +53,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, HeaderLeaf::read_le(&expected_bytes[..])?); - assert!(HeaderLeaf::::read_le(&expected_bytes[1..]).is_err()); } Ok(()) } diff --git a/console/program/src/state_path/transaction_leaf/bytes.rs b/console/program/src/state_path/transaction_leaf/bytes.rs index 602c66689c..db10cf1f90 100644 --- a/console/program/src/state_path/transaction_leaf/bytes.rs +++ b/console/program/src/state_path/transaction_leaf/bytes.rs @@ -43,9 +43,6 @@ impl ToBytes for TransactionLeaf { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; - - type CurrentNetwork = Testnet3; const ITERATIONS: u64 = 1000; @@ -60,7 +57,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, TransactionLeaf::read_le(&expected_bytes[..])?); - assert!(TransactionLeaf::::read_le(&expected_bytes[1..]).is_err()); } Ok(()) } diff --git a/console/program/src/state_path/transition_leaf/bytes.rs b/console/program/src/state_path/transition_leaf/bytes.rs index 90a6ac9beb..b06f9def4e 100644 --- a/console/program/src/state_path/transition_leaf/bytes.rs +++ b/console/program/src/state_path/transition_leaf/bytes.rs @@ -51,9 +51,6 @@ impl ToBytes for TransitionLeaf { #[cfg(test)] mod tests { use super::*; - use snarkvm_console_network::Testnet3; - - type CurrentNetwork = Testnet3; const ITERATIONS: u64 = 1000; @@ -68,7 +65,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, TransitionLeaf::read_le(&expected_bytes[..])?); - assert!(TransitionLeaf::::read_le(&expected_bytes[1..]).is_err()); } Ok(()) } diff --git a/console/types/scalar/src/from_bits.rs b/console/types/scalar/src/from_bits.rs index 7384a5c481..25b98715b7 100644 --- a/console/types/scalar/src/from_bits.rs +++ b/console/types/scalar/src/from_bits.rs @@ -34,9 +34,8 @@ impl FromBits for Scalar { // If `num_bits` is greater than `size_in_data_bits`, check it is less than `Scalar::MODULUS`. if num_bits > size_in_data_bits { - // Retrieve the modulus & subtract by 1 as we'll check `bits_le` is less than or *equal* to this value. - // (For advanced users) Scalar::MODULUS - 1 is equivalent to -1 in the field. - let modulus_minus_one = E::Scalar::modulus(); + // Retrieve the modulus as we'll check `bits_le` is less than this value. + let modulus = E::Scalar::modulus(); // Recover the scalar as a `BigInteger` for comparison. // As `bits_le[size_in_bits..]` is guaranteed to be zero from the above logic, @@ -44,7 +43,7 @@ impl FromBits for Scalar { let scalar = E::BigInteger::from_bits_le(&bits_le[..size_in_bits])?; // Ensure the scalar is less than `Scalar::MODULUS`. - ensure!(scalar < modulus_minus_one, "The scalar is greater than or equal to the modulus."); + ensure!(scalar < modulus, "The scalar is greater than or equal to the modulus."); // Return the scalar. Ok(Scalar { scalar: E::Scalar::from_bigint(scalar).ok_or_else(|| anyhow!("Invalid scalar from bits"))? }) diff --git a/console/types/string/src/bytes.rs b/console/types/string/src/bytes.rs index 137dd5f0ac..46fd7fcf33 100644 --- a/console/types/string/src/bytes.rs +++ b/console/types/string/src/bytes.rs @@ -67,7 +67,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, StringType::read_le(&expected_bytes[..])?); - assert!(StringType::::read_le(&expected_bytes[1..]).is_err()); } Ok(()) } diff --git a/ledger/authority/src/bytes.rs b/ledger/authority/src/bytes.rs index 45ccbe65b4..1d710be1c6 100644 --- a/ledger/authority/src/bytes.rs +++ b/ledger/authority/src/bytes.rs @@ -52,9 +52,7 @@ impl ToBytes for Authority { #[cfg(test)] mod tests { use super::*; - use console::{network::Testnet3, prelude::TestRng}; - - type CurrentNetwork = Testnet3; + use console::prelude::TestRng; #[test] fn test_bytes() { @@ -64,7 +62,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le().unwrap(); assert_eq!(expected, Authority::read_le(&expected_bytes[..]).unwrap()); - assert!(Authority::::read_le(&expected_bytes[1..]).is_err()); } } } diff --git a/ledger/block/src/bytes.rs b/ledger/block/src/bytes.rs index 7c72e849f3..448c24cc3d 100644 --- a/ledger/block/src/bytes.rs +++ b/ledger/block/src/bytes.rs @@ -134,7 +134,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, Block::read_le(&expected_bytes[..])?); - assert!(Block::::read_le(&expected_bytes[1..]).is_err()); } Ok(()) } @@ -147,7 +146,6 @@ mod tests { // Check the byte representation. let expected_bytes = genesis_block.to_bytes_le()?; assert_eq!(genesis_block, Block::read_le(&expected_bytes[..])?); - assert!(Block::::read_le(&expected_bytes[1..]).is_err()); Ok(()) } diff --git a/ledger/block/src/ratifications/bytes.rs b/ledger/block/src/ratifications/bytes.rs index 0db7fd3311..aa8d6f4a9a 100644 --- a/ledger/block/src/ratifications/bytes.rs +++ b/ledger/block/src/ratifications/bytes.rs @@ -53,9 +53,6 @@ impl ToBytes for Ratifications { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; const ITERATIONS: u32 = 100; @@ -68,7 +65,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, Ratifications::read_le(&expected_bytes[..])?); - assert!(Ratifications::::read_le(&expected_bytes[1..]).is_err()); } Ok(()) } diff --git a/ledger/block/src/ratify/bytes.rs b/ledger/block/src/ratify/bytes.rs index 2cd5cad850..bab8503907 100644 --- a/ledger/block/src/ratify/bytes.rs +++ b/ledger/block/src/ratify/bytes.rs @@ -94,9 +94,6 @@ impl ToBytes for Ratify { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() { @@ -106,7 +103,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le().unwrap(); assert_eq!(expected, Ratify::read_le(&expected_bytes[..]).unwrap()); - assert!(Ratify::::read_le(&expected_bytes[1..]).is_err()); } } } diff --git a/ledger/block/src/transaction/bytes.rs b/ledger/block/src/transaction/bytes.rs index ee6c194dcc..299c27be99 100644 --- a/ledger/block/src/transaction/bytes.rs +++ b/ledger/block/src/transaction/bytes.rs @@ -139,9 +139,6 @@ impl ToBytes for Transaction { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() -> Result<()> { @@ -158,7 +155,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, Transaction::read_le(&expected_bytes[..])?); - assert!(Transaction::::read_le(&expected_bytes[1..]).is_err()); } Ok(()) } diff --git a/ledger/block/src/transaction/deployment/bytes.rs b/ledger/block/src/transaction/deployment/bytes.rs index 09a8e90966..e8e97757a6 100644 --- a/ledger/block/src/transaction/deployment/bytes.rs +++ b/ledger/block/src/transaction/deployment/bytes.rs @@ -76,9 +76,6 @@ impl ToBytes for Deployment { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() -> Result<()> { @@ -90,7 +87,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, Deployment::read_le(&expected_bytes[..])?); - assert!(Deployment::::read_le(&expected_bytes[1..]).is_err()); Ok(()) } } diff --git a/ledger/block/src/transaction/execution/bytes.rs b/ledger/block/src/transaction/execution/bytes.rs index 417530360b..c10a8c8fda 100644 --- a/ledger/block/src/transaction/execution/bytes.rs +++ b/ledger/block/src/transaction/execution/bytes.rs @@ -75,9 +75,6 @@ impl ToBytes for Execution { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() -> Result<()> { @@ -89,7 +86,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, Execution::read_le(&expected_bytes[..])?); - assert!(Execution::::read_le(&expected_bytes[1..]).is_err()); Ok(()) } } diff --git a/ledger/block/src/transaction/fee/bytes.rs b/ledger/block/src/transaction/fee/bytes.rs index 42443a9981..1f156f622f 100644 --- a/ledger/block/src/transaction/fee/bytes.rs +++ b/ledger/block/src/transaction/fee/bytes.rs @@ -64,9 +64,6 @@ impl ToBytes for Fee { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() -> Result<()> { @@ -78,7 +75,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, Fee::read_le(&expected_bytes[..])?); - assert!(Fee::::read_le(&expected_bytes[1..]).is_err()); // Construct a new public fee. let expected = crate::transaction::fee::test_helpers::sample_fee_public_hardcoded(rng); @@ -86,7 +82,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, Fee::read_le(&expected_bytes[..])?); - assert!(Fee::::read_le(&expected_bytes[1..]).is_err()); Ok(()) } diff --git a/ledger/block/src/transactions/bytes.rs b/ledger/block/src/transactions/bytes.rs index 99df0668db..d76e8625ba 100644 --- a/ledger/block/src/transactions/bytes.rs +++ b/ledger/block/src/transactions/bytes.rs @@ -53,9 +53,6 @@ impl ToBytes for Transactions { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() -> Result<()> { @@ -65,7 +62,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, Transactions::read_le(&expected_bytes[..])?); - assert!(Transactions::::read_le(&expected_bytes[1..]).is_err()); } Ok(()) } diff --git a/ledger/block/src/transactions/confirmed/bytes.rs b/ledger/block/src/transactions/confirmed/bytes.rs index ff7ceb4772..16f929215c 100644 --- a/ledger/block/src/transactions/confirmed/bytes.rs +++ b/ledger/block/src/transactions/confirmed/bytes.rs @@ -143,9 +143,6 @@ impl ToBytes for ConfirmedTransaction { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() { @@ -153,7 +150,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le().unwrap(); assert_eq!(expected, ConfirmedTransaction::read_le(&expected_bytes[..]).unwrap()); - assert!(ConfirmedTransaction::::read_le(&expected_bytes[1..]).is_err()); } } } diff --git a/ledger/block/src/transactions/rejected/bytes.rs b/ledger/block/src/transactions/rejected/bytes.rs index 402b2daeff..c5cff5fe43 100644 --- a/ledger/block/src/transactions/rejected/bytes.rs +++ b/ledger/block/src/transactions/rejected/bytes.rs @@ -63,9 +63,6 @@ impl ToBytes for Rejected { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() { @@ -73,7 +70,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le().unwrap(); assert_eq!(expected, Rejected::read_le(&expected_bytes[..]).unwrap()); - assert!(Rejected::::read_le(&expected_bytes[1..]).is_err()); } } } diff --git a/ledger/block/src/transition/bytes.rs b/ledger/block/src/transition/bytes.rs index e59403fead..dacc875df8 100644 --- a/ledger/block/src/transition/bytes.rs +++ b/ledger/block/src/transition/bytes.rs @@ -98,9 +98,6 @@ impl ToBytes for Transition { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() -> Result<()> { @@ -112,7 +109,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, Transition::read_le(&expected_bytes[..])?); - assert!(Transition::::read_le(&expected_bytes[1..]).is_err()); Ok(()) } diff --git a/ledger/block/src/transition/input/bytes.rs b/ledger/block/src/transition/input/bytes.rs index e5d53ba277..faceae3a05 100644 --- a/ledger/block/src/transition/input/bytes.rs +++ b/ledger/block/src/transition/input/bytes.rs @@ -115,9 +115,6 @@ impl ToBytes for Input { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() { @@ -125,7 +122,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le().unwrap(); assert_eq!(expected, Input::read_le(&expected_bytes[..]).unwrap()); - assert!(Input::::read_le(&expected_bytes[1..]).is_err()); } } } diff --git a/ledger/block/src/transition/output/bytes.rs b/ledger/block/src/transition/output/bytes.rs index 0ef6003f7e..867b6600d6 100644 --- a/ledger/block/src/transition/output/bytes.rs +++ b/ledger/block/src/transition/output/bytes.rs @@ -148,9 +148,6 @@ impl ToBytes for Output { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() { @@ -158,7 +155,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le().unwrap(); assert_eq!(expected, Output::read_le(&expected_bytes[..]).unwrap()); - assert!(Output::::read_le(&expected_bytes[1..]).is_err()); } } } diff --git a/ledger/committee/src/bytes.rs b/ledger/committee/src/bytes.rs index 9ae159af1f..d55a80ab41 100644 --- a/ledger/committee/src/bytes.rs +++ b/ledger/committee/src/bytes.rs @@ -78,9 +78,6 @@ impl ToBytes for Committee { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() { @@ -90,7 +87,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le().unwrap(); assert_eq!(expected, Committee::read_le(&expected_bytes[..]).unwrap()); - assert!(Committee::::read_le(&expected_bytes[1..]).is_err()); } } } diff --git a/ledger/narwhal/batch-certificate/src/bytes.rs b/ledger/narwhal/batch-certificate/src/bytes.rs index b2638fa557..1de636bf2a 100644 --- a/ledger/narwhal/batch-certificate/src/bytes.rs +++ b/ledger/narwhal/batch-certificate/src/bytes.rs @@ -106,9 +106,6 @@ impl ToBytes for BatchCertificate { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() { @@ -118,7 +115,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le().unwrap(); assert_eq!(expected, BatchCertificate::read_le(&expected_bytes[..]).unwrap()); - assert!(BatchCertificate::::read_le(&expected_bytes[1..]).is_err()); } } } diff --git a/ledger/narwhal/batch-header/src/bytes.rs b/ledger/narwhal/batch-header/src/bytes.rs index 30f7a2cb83..f564e58c19 100644 --- a/ledger/narwhal/batch-header/src/bytes.rs +++ b/ledger/narwhal/batch-header/src/bytes.rs @@ -101,9 +101,6 @@ impl ToBytes for BatchHeader { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() { @@ -113,7 +110,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le().unwrap(); assert_eq!(expected, BatchHeader::read_le(&expected_bytes[..]).unwrap()); - assert!(BatchHeader::::read_le(&expected_bytes[1..]).is_err()); } } } diff --git a/ledger/narwhal/subdag/src/bytes.rs b/ledger/narwhal/subdag/src/bytes.rs index a5cc0e5dc9..c5435663e0 100644 --- a/ledger/narwhal/subdag/src/bytes.rs +++ b/ledger/narwhal/subdag/src/bytes.rs @@ -73,9 +73,6 @@ impl ToBytes for Subdag { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() { @@ -85,7 +82,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le().unwrap(); assert_eq!(expected, Subdag::read_le(&expected_bytes[..]).unwrap()); - assert!(Subdag::::read_le(&expected_bytes[1..]).is_err()); } } } diff --git a/ledger/narwhal/transmission-id/src/bytes.rs b/ledger/narwhal/transmission-id/src/bytes.rs index ed46201b1f..a8a49a3d7b 100644 --- a/ledger/narwhal/transmission-id/src/bytes.rs +++ b/ledger/narwhal/transmission-id/src/bytes.rs @@ -50,9 +50,6 @@ impl ToBytes for TransmissionID { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() { @@ -62,7 +59,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le().unwrap(); assert_eq!(expected, TransmissionID::read_le(&expected_bytes[..]).unwrap()); - assert!(TransmissionID::::read_le(&expected_bytes[1..]).is_err()); } } } diff --git a/ledger/narwhal/transmission/src/bytes.rs b/ledger/narwhal/transmission/src/bytes.rs index f7349fbac3..7d06ef6077 100644 --- a/ledger/narwhal/transmission/src/bytes.rs +++ b/ledger/narwhal/transmission/src/bytes.rs @@ -59,9 +59,6 @@ impl ToBytes for Transmission { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() { @@ -71,7 +68,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le().unwrap(); assert_eq!(expected, Transmission::read_le(&expected_bytes[..]).unwrap()); - assert!(Transmission::::read_le(&expected_bytes[1..]).is_err()); } } } diff --git a/synthesizer/process/src/stack/authorization/bytes.rs b/synthesizer/process/src/stack/authorization/bytes.rs index f2aa2ee130..d9caf4dfea 100644 --- a/synthesizer/process/src/stack/authorization/bytes.rs +++ b/synthesizer/process/src/stack/authorization/bytes.rs @@ -71,9 +71,6 @@ impl ToBytes for Authorization { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() -> Result<()> { @@ -85,7 +82,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, Authorization::read_le(&expected_bytes[..])?); - assert!(Authorization::::read_le(&expected_bytes[1..]).is_err()); Ok(()) } } diff --git a/synthesizer/process/src/stack/finalize_types/initialize.rs b/synthesizer/process/src/stack/finalize_types/initialize.rs index 77c1ee2893..e36fe3d552 100644 --- a/synthesizer/process/src/stack/finalize_types/initialize.rs +++ b/synthesizer/process/src/stack/finalize_types/initialize.rs @@ -21,6 +21,7 @@ use synthesizer_program::{ Contains, Get, GetOrUse, + MappingLocator, RandChaCha, Remove, Set, @@ -174,8 +175,8 @@ impl FinalizeTypes { Command::Instruction(instruction) => self.check_instruction(stack, finalize.name(), instruction)?, Command::Await(await_) => self.check_await(stack, await_)?, Command::Contains(contains) => self.check_contains(stack, finalize.name(), contains)?, - Command::Get(get) => self.check_get(stack, finalize.name(), get)?, - Command::GetOrUse(get_or_use) => self.check_get_or_use(stack, finalize.name(), get_or_use)?, + Command::Get(get) => self.check_get(stack, get)?, + Command::GetOrUse(get_or_use) => self.check_get_or_use(stack, get_or_use)?, Command::RandChaCha(rand_chacha) => self.check_rand_chacha(stack, finalize.name(), rand_chacha)?, Command::Remove(remove) => self.check_remove(stack, finalize.name(), remove)?, Command::Set(set) => self.check_set(stack, finalize.name(), set)?, @@ -287,19 +288,42 @@ impl FinalizeTypes { /// Ensures the given `get` command is well-formed. #[inline] - fn check_get( - &mut self, - stack: &(impl StackMatches + StackProgram), - finalize_name: &Identifier, - get: &Get, - ) -> Result<()> { - // Ensure the declared mapping in `get` is defined in the program. - if !stack.program().contains_mapping(get.mapping_name()) { - bail!("Mapping '{}' in '{}/{finalize_name}' is not defined.", get.mapping_name(), stack.program_id()) - } - // Retrieve the mapping from the program. - // Note that the unwrap is safe, as we have already checked the mapping exists. - let mapping = stack.program().get_mapping(get.mapping_name()).unwrap(); + fn check_get(&mut self, stack: &(impl StackMatches + StackProgram), get: &Get) -> Result<()> { + // Retrieve the mapping. + let mapping = match get.mapping() { + MappingLocator::Locator(locator) => { + // Retrieve the program ID. + let program_id = locator.program_id(); + // Retrieve the mapping_name. + let mapping_name = locator.resource(); + + // Ensure the locator does not reference the current program. + if stack.program_id() == program_id { + bail!("Locator '{locator}' does not reference an external mapping."); + } + // Ensure the current program contains an import for this external program. + if !stack.program().imports().keys().contains(program_id) { + bail!("External program '{program_id}' is not imported by '{}'.", stack.program_id()); + } + // Retrieve the program. + let external = stack.get_external_program(program_id)?; + // Ensure the mapping exists in the program. + if !external.contains_mapping(mapping_name) { + bail!("Mapping '{mapping_name}' in '{program_id}' is not defined.") + } + // Retrieve the mapping from the program. + external.get_mapping(mapping_name)? + } + MappingLocator::Resource(mapping_name) => { + // Ensure the declared mapping in `get` is defined in the current program. + if !stack.program().contains_mapping(mapping_name) { + bail!("Mapping '{mapping_name}' in '{}' is not defined.", stack.program_id()) + } + // Retrieve the mapping from the program. + stack.program().get_mapping(mapping_name)? + } + }; + // Get the mapping key type. let mapping_key_type = mapping.key().plaintext_type(); // Get the mapping value type. @@ -329,16 +353,43 @@ impl FinalizeTypes { fn check_get_or_use( &mut self, stack: &(impl StackMatches + StackProgram), - finalize_name: &Identifier, get_or_use: &GetOrUse, ) -> Result<()> { - // Ensure the declared mapping in `get.or_use` is defined in the program. - if !stack.program().contains_mapping(get_or_use.mapping_name()) { - bail!("Mapping '{}' in '{}/{finalize_name}' is not defined.", get_or_use.mapping_name(), stack.program_id()) - } - // Retrieve the mapping from the program. - // Note that the unwrap is safe, as we have already checked the mapping exists. - let mapping = stack.program().get_mapping(get_or_use.mapping_name()).unwrap(); + // Retrieve the mapping. + let mapping = match get_or_use.mapping() { + MappingLocator::Locator(locator) => { + // Retrieve the program ID. + let program_id = locator.program_id(); + // Retrieve the mapping_name. + let mapping_name = locator.resource(); + + // Ensure the locator does not reference the current program. + if stack.program_id() == program_id { + bail!("Locator '{locator}' does not reference an external mapping."); + } + // Ensure the current program contains an import for this external program. + if !stack.program().imports().keys().contains(program_id) { + bail!("External program '{locator}' is not imported by '{program_id}'."); + } + // Retrieve the program. + let external = stack.get_external_program(program_id)?; + // Ensure the mapping exists in the program. + if !external.contains_mapping(mapping_name) { + bail!("Mapping '{mapping_name}' in '{program_id}' is not defined.") + } + // Retrieve the mapping from the program. + external.get_mapping(mapping_name)? + } + MappingLocator::Resource(mapping_name) => { + // Ensure the declared mapping in `get.or_use` is defined in the current program. + if !stack.program().contains_mapping(mapping_name) { + bail!("Mapping '{mapping_name}' in '{}' is not defined.", stack.program_id()) + } + // Retrieve the mapping from the program. + stack.program().get_mapping(mapping_name)? + } + }; + // Get the mapping key type. let mapping_key_type = mapping.key().plaintext_type(); // Get the mapping value type. diff --git a/synthesizer/program/src/finalize/bytes.rs b/synthesizer/program/src/finalize/bytes.rs index b61eee31f2..df2f1094ce 100644 --- a/synthesizer/program/src/finalize/bytes.rs +++ b/synthesizer/program/src/finalize/bytes.rs @@ -108,7 +108,9 @@ finalize main: add r0 r1 into r8; add r0 r1 into r9; add r0 r1 into r10; - add r0 r1 into r11;"; + add r0 r1 into r11; + get accounts[r0] into r12; + get accounts[r1] into r13;"; let expected = Finalize::::from_str(finalize_string)?; let expected_bytes = expected.to_bytes_le()?; diff --git a/synthesizer/program/src/logic/command/get.rs b/synthesizer/program/src/logic/command/get.rs index fc698a0969..3537877ff3 100644 --- a/synthesizer/program/src/logic/command/get.rs +++ b/synthesizer/program/src/logic/command/get.rs @@ -19,19 +19,143 @@ use crate::{ }; use console::{ network::prelude::*, - program::{Identifier, Register, Value}, + program::{Identifier, Locator, Register, Value}, }; +use std::io::{BufRead, BufReader}; + +/// The operator references a local or external mapping name. +#[derive(Clone, PartialEq, Eq, Hash)] +pub enum MappingLocator { + /// The reference to a non-local mapping name. + Locator(Locator), + /// The reference to a local mapping name. + Resource(Identifier), +} + +impl Parser for MappingLocator { + /// Parses a string into an operator. + #[inline] + fn parse(string: &str) -> ParserResult { + alt(( + map(Locator::parse, |locator| MappingLocator::Locator(locator)), + map(Identifier::parse, |identifier| MappingLocator::Resource(identifier)), + ))(string) + } +} + +impl FromStr for MappingLocator { + type Err = Error; + + /// Parses a string into an operator. + #[inline] + fn from_str(string: &str) -> Result { + match Self::parse(string) { + Ok((remainder, object)) => { + // Ensure the remainder is empty. + ensure!(remainder.is_empty(), "Failed to parse string. Found invalid character in: \"{remainder}\""); + // Return the object. + Ok(object) + } + Err(error) => bail!("Failed to parse string. {error}"), + } + } +} + +impl Debug for MappingLocator { + /// Prints the operator as a string. + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + Display::fmt(self, f) + } +} + +impl Display for MappingLocator { + /// Prints the operator to a string. + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + match self { + MappingLocator::Locator(locator) => Display::fmt(locator, f), + MappingLocator::Resource(resource) => Display::fmt(resource, f), + } + } +} + +impl FromBytes for MappingLocator { + /// Reads the operation from a buffer. + fn read_le(mut reader: R) -> IoResult { + // Read the version. + let version = u8::read_le(&mut reader)?; + // Ensure the version is valid. + if version != 0 { + return Err(error("Failed to read MappingLocator. Invalid version.")); + } + // Read the variant. + let variant = u8::read_le(&mut reader)?; + // Match the variant. + match variant { + 0 => Ok(MappingLocator::Locator(Locator::read_le(&mut reader)?)), + 1 => Ok(MappingLocator::Resource(Identifier::read_le(&mut reader)?)), + _ => Err(error("Failed to read MappingLocator. Invalid variant.")), + } + } +} + +impl ToBytes for MappingLocator { + /// Writes the operation to a buffer. + fn write_le(&self, mut writer: W) -> IoResult<()> { + match self { + MappingLocator::Locator(locator) => { + // Write the version. + 0u8.write_le(&mut writer)?; + // Write the variant. + 0u8.write_le(&mut writer)?; + // Write the locator. + locator.write_le(&mut writer) + } + MappingLocator::Resource(resource) => { + // Write the version. + 0u8.write_le(&mut writer)?; + // Write the variant. + 1u8.write_le(&mut writer)?; + // Write the resource. + resource.write_le(&mut writer) + } + } + } +} + /// A get command, e.g. `get accounts[r0] into r1;`. /// Gets the value stored at `operand` in `mapping` and stores the result in `destination`. -#[derive(Clone, PartialEq, Eq, Hash)] +#[derive(Clone)] pub struct Get { - /// The mapping name. - mapping: Identifier, + /// The mapping. + // TODO (howardwu): For mainnet - Use `CallOperator`, delete the above `MappingLocator`. + mapping: MappingLocator, /// The key to access the mapping. key: Operand, /// The destination register. destination: Register, + // TODO (howardwu): For mainnet - remove `is_old`. + is_old: bool, +} + +impl PartialEq for Get { + /// Returns true if the two objects are equal. + #[inline] + fn eq(&self, other: &Self) -> bool { + self.mapping == other.mapping && self.key == other.key && self.destination == other.destination + } +} + +impl Eq for Get {} + +impl std::hash::Hash for Get { + /// Returns the hash of the object. + #[inline] + fn hash(&self, state: &mut H) { + self.mapping.hash(state); + self.key.hash(state); + self.destination.hash(state); + } } impl Get { @@ -47,9 +171,9 @@ impl Get { vec![self.key.clone()] } - /// Returns the mapping name. + /// Returns the mapping. #[inline] - pub const fn mapping_name(&self) -> &Identifier { + pub const fn mapping(&self) -> &MappingLocator { &self.mapping } @@ -75,21 +199,27 @@ impl Get { store: &impl FinalizeStoreTrait, registers: &mut (impl RegistersLoad + RegistersStore), ) -> Result<()> { + // Determine the program ID and mapping name. + let (program_id, mapping_name) = match self.mapping { + MappingLocator::Locator(locator) => (*locator.program_id(), *locator.resource()), + MappingLocator::Resource(mapping_name) => (*stack.program_id(), mapping_name), + }; + // Ensure the mapping exists in storage. - if !store.contains_mapping_confirmed(stack.program_id(), &self.mapping)? { - bail!("Mapping '{}/{}' does not exist in storage", stack.program_id(), self.mapping); + if !store.contains_mapping_confirmed(&program_id, &mapping_name)? { + bail!("Mapping '{program_id}/{mapping_name}' does not exist in storage"); } // Load the operand as a plaintext. let key = registers.load_plaintext(stack, &self.key)?; // Retrieve the value from storage as a literal. - let value = match store.get_value_speculative(*stack.program_id(), self.mapping, &key)? { + let value = match store.get_value_speculative(program_id, mapping_name, &key)? { Some(Value::Plaintext(plaintext)) => Value::Plaintext(plaintext), Some(Value::Record(..)) => bail!("Cannot 'get' a 'record'"), Some(Value::Future(..)) => bail!("Cannot 'get' a 'future'",), // If a key does not exist, then bail. - None => bail!("Key '{}' does not exist in mapping '{}/{}'", key, stack.program_id(), self.mapping), + None => bail!("Key '{key}' does not exist in mapping '{program_id}/{mapping_name}'"), }; // Assign the value to the destination register. @@ -111,7 +241,7 @@ impl Parser for Get { let (string, _) = Sanitizer::parse_whitespaces(string)?; // Parse the mapping name from the string. - let (string, mapping) = Identifier::parse(string)?; + let (string, mapping) = MappingLocator::parse(string)?; // Parse the "[" from the string. let (string, _) = tag("[")(string)?; // Parse the whitespace from the string. @@ -137,7 +267,7 @@ impl Parser for Get { // Parse the ";" from the string. let (string, _) = tag(";")(string)?; - Ok((string, Self { mapping, key, destination })) + Ok((string, Self { mapping, key, destination, is_old: false })) } } @@ -180,15 +310,28 @@ impl Display for Get { impl FromBytes for Get { /// Reads the command from a buffer. - fn read_le(mut reader: R) -> IoResult { - // Read the mapping name. - let mapping = Identifier::read_le(&mut reader)?; + fn read_le(reader: R) -> IoResult { + // Peek at the first byte. + // TODO (howardwu): For mainnet - Read a `MappingLocator`. + let mut reader = BufReader::with_capacity(1, reader); + let first_byte = { + let buffer = reader.fill_buf()?; + match buffer.first() { + Some(byte) => *byte, + None => return Err(error("Failed to read `get`. Expected byte.")), + } + }; + // If the first byte is zero, then read a `MappingLocator`, otherwise read an `Identifier`. + let mapping = match first_byte { + 0u8 => MappingLocator::read_le(&mut reader)?, + _ => MappingLocator::Resource(Identifier::read_le(&mut reader)?), + }; // Read the key operand. let key = Operand::read_le(&mut reader)?; // Read the destination register. let destination = Register::read_le(&mut reader)?; // Return the command. - Ok(Self { mapping, key, destination }) + Ok(Self { mapping, key, destination, is_old: !first_byte.is_zero() }) } } @@ -196,7 +339,15 @@ impl ToBytes for Get { /// Writes the operation to a buffer. fn write_le(&self, mut writer: W) -> IoResult<()> { // Write the mapping name. - self.mapping.write_le(&mut writer)?; + match self.is_old { + false => self.mapping.write_le(&mut writer)?, + true => match self.mapping { + MappingLocator::Resource(identifier) => identifier.write_le(&mut writer)?, + MappingLocator::Locator(_) => { + return Err(error("Expected `MappingLocator::Resource` for `get`.")); + } + }, + } // Write the key operand. self.key.write_le(&mut writer)?; // Write the destination register. @@ -211,13 +362,59 @@ mod tests { type CurrentNetwork = Testnet3; + struct OldGet { + mapping: Identifier, + key: Operand, + destination: Register, + } + + impl ToBytes for OldGet { + fn write_le(&self, mut writer: W) -> IoResult<()> + where + Self: Sized, + { + // Write the mapping name. + self.mapping.write_le(&mut writer)?; + // Write the key operand. + self.key.write_le(&mut writer)?; + // Write the destination register. + self.destination.write_le(&mut writer) + } + } + #[test] fn test_parse() { let (string, get) = Get::::parse("get account[r0] into r1;").unwrap(); assert!(string.is_empty(), "Parser did not consume all of the string: '{string}'"); - assert_eq!(get.mapping, Identifier::from_str("account").unwrap()); + assert_eq!(get.mapping, MappingLocator::from_str("account").unwrap()); assert_eq!(get.operands().len(), 1, "The number of operands is incorrect"); assert_eq!(get.key, Operand::Register(Register::Locator(0)), "The first operand is incorrect"); assert_eq!(get.destination, Register::Locator(1), "The second operand is incorrect"); + + let (string, get) = Get::::parse("get token.aleo/balances[r0] into r1;").unwrap(); + assert!(string.is_empty(), "Parser did not consume all of the string: '{string}'"); + assert_eq!(get.mapping, MappingLocator::from_str("token.aleo/balances").unwrap()); + assert_eq!(get.operands().len(), 1, "The number of operands is incorrect"); + assert_eq!(get.key, Operand::Register(Register::Locator(0)), "The first operand is incorrect"); + assert_eq!(get.destination, Register::Locator(1), "The second operand is incorrect"); + } + + #[test] + fn test_from_bytes() { + let (string, get) = Get::::parse("get account[r0] into r1;").unwrap(); + assert!(string.is_empty()); + + let old_get = OldGet:: { + mapping: Identifier::from_str("account").unwrap(), + key: Operand::Register(Register::Locator(0)), + destination: Register::Locator(1), + }; + + let get_bytes = get.to_bytes_le().unwrap(); + let old_get_bytes = old_get.to_bytes_le().unwrap(); + + let first = Get::::from_bytes_le(&get_bytes[..]).unwrap(); + let second = Get::::from_bytes_le(&old_get_bytes[..]).unwrap(); + assert_eq!(first, second); } } diff --git a/synthesizer/program/src/logic/command/get_or_use.rs b/synthesizer/program/src/logic/command/get_or_use.rs index 27c0e6faec..a78deaa1c5 100644 --- a/synthesizer/program/src/logic/command/get_or_use.rs +++ b/synthesizer/program/src/logic/command/get_or_use.rs @@ -14,27 +14,56 @@ use crate::{ traits::{FinalizeStoreTrait, RegistersLoad, RegistersStore, StackMatches, StackProgram}, + MappingLocator, Opcode, Operand, }; use console::{ network::prelude::*, - program::{Identifier, Register, Value}, + program::{Register, Value}, }; +use console::program::Identifier; +use std::io::{BufRead, BufReader}; + /// A get command that uses the provided default in case of failure, e.g. `get.or_use accounts[r0] r1 into r2;`. /// Gets the value stored at `operand` in `mapping` and stores the result in `destination`. /// If the key is not present, `default` is stored in `destination`. -#[derive(Clone, PartialEq, Eq, Hash)] +#[derive(Clone)] pub struct GetOrUse { - /// The mapping name. - mapping: Identifier, + /// The mapping. + // TODO (howardwu): For mainnet - Use `CallOperator`, delete the above `MappingLocator`. + mapping: MappingLocator, /// The key to access the mapping. key: Operand, /// The default value. default: Operand, /// The destination register. destination: Register, + // TODO (howardwu): For mainnet - remove `is_old`. + is_old: bool, +} + +impl PartialEq for GetOrUse { + #[inline] + fn eq(&self, other: &Self) -> bool { + self.mapping == other.mapping + && self.key == other.key + && self.default == other.default + && self.destination == other.destination + } +} + +impl Eq for GetOrUse {} + +impl std::hash::Hash for GetOrUse { + #[inline] + fn hash(&self, state: &mut H) { + self.mapping.hash(state); + self.key.hash(state); + self.default.hash(state); + self.destination.hash(state); + } } impl GetOrUse { @@ -50,9 +79,9 @@ impl GetOrUse { vec![self.key.clone(), self.default.clone()] } - /// Returns the mapping name. + /// Returns the mapping. #[inline] - pub const fn mapping_name(&self) -> &Identifier { + pub const fn mapping(&self) -> &MappingLocator { &self.mapping } @@ -84,16 +113,22 @@ impl GetOrUse { store: &impl FinalizeStoreTrait, registers: &mut (impl RegistersLoad + RegistersStore), ) -> Result<()> { + // Determine the program ID and mapping name. + let (program_id, mapping_name) = match self.mapping { + MappingLocator::Locator(locator) => (*locator.program_id(), *locator.resource()), + MappingLocator::Resource(mapping_name) => (*stack.program_id(), mapping_name), + }; + // Ensure the mapping exists in storage. - if !store.contains_mapping_confirmed(stack.program_id(), &self.mapping)? { - bail!("Mapping '{}/{}' does not exist in storage", stack.program_id(), self.mapping); + if !store.contains_mapping_confirmed(&program_id, &mapping_name)? { + bail!("Mapping '{program_id}/{mapping_name}' does not exist in storage"); } // Load the operand as a plaintext. let key = registers.load_plaintext(stack, &self.key)?; // Retrieve the value from storage as a literal. - let value = match store.get_value_speculative(*stack.program_id(), self.mapping, &key)? { + let value = match store.get_value_speculative(program_id, mapping_name, &key)? { Some(Value::Plaintext(plaintext)) => Value::Plaintext(plaintext), Some(Value::Record(..)) => bail!("Cannot 'get.or_use' a 'record'"), Some(Value::Future(..)) => bail!("Cannot 'get.or_use' a 'future'"), @@ -121,7 +156,7 @@ impl Parser for GetOrUse { let (string, _) = Sanitizer::parse_whitespaces(string)?; // Parse the mapping name from the string. - let (string, mapping) = Identifier::parse(string)?; + let (string, mapping) = MappingLocator::parse(string)?; // Parse the "[" from the string. let (string, _) = tag("[")(string)?; // Parse the whitespace from the string. @@ -151,7 +186,7 @@ impl Parser for GetOrUse { // Parse the ";" from the string. let (string, _) = tag(";")(string)?; - Ok((string, Self { mapping, key, default, destination })) + Ok((string, Self { mapping, key, default, destination, is_old: false })) } } @@ -194,9 +229,22 @@ impl Display for GetOrUse { impl FromBytes for GetOrUse { /// Reads the command from a buffer. - fn read_le(mut reader: R) -> IoResult { - // Read the mapping name. - let mapping = Identifier::read_le(&mut reader)?; + fn read_le(reader: R) -> IoResult { + // Peek at the first byte. + // TODO (howardwu): For mainnet - Read a `MappingLocator`. + let mut reader = BufReader::with_capacity(1, reader); + let first_byte = { + let buffer = reader.fill_buf()?; + match buffer.first() { + Some(byte) => *byte, + None => return Err(error("Failed to read `get.or_use`. Expected byte.")), + } + }; + // If the first byte is zero, then read a `MappingLocator`, otherwise read an `Identifier`. + let mapping = match first_byte { + 0u8 => MappingLocator::read_le(&mut reader)?, + _ => MappingLocator::Resource(Identifier::read_le(&mut reader)?), + }; // Read the key operand. let key = Operand::read_le(&mut reader)?; // Read the default value. @@ -204,7 +252,7 @@ impl FromBytes for GetOrUse { // Read the destination register. let destination = Register::read_le(&mut reader)?; // Return the command. - Ok(Self { mapping, key, default, destination }) + Ok(Self { mapping, key, default, destination, is_old: !first_byte.is_zero() }) } } @@ -212,7 +260,15 @@ impl ToBytes for GetOrUse { /// Writes the operation to a buffer. fn write_le(&self, mut writer: W) -> IoResult<()> { // Write the mapping name. - self.mapping.write_le(&mut writer)?; + match self.is_old { + false => self.mapping.write_le(&mut writer)?, + true => match self.mapping { + MappingLocator::Resource(identifier) => identifier.write_le(&mut writer)?, + MappingLocator::Locator(_) => { + return Err(error("Expected `MappingLocator::Resource` for `get.or_use`.")); + } + }, + } // Write the key operand. self.key.write_le(&mut writer)?; // Write the default value. @@ -229,14 +285,63 @@ mod tests { type CurrentNetwork = Testnet3; + pub struct OldGetOrUse { + pub mapping: Identifier, + pub key: Operand, + pub default: Operand, + pub destination: Register, + } + + impl ToBytes for OldGetOrUse { + fn write_le(&self, mut writer: W) -> IoResult<()> { + // Write the mapping name. + self.mapping.write_le(&mut writer)?; + // Write the key operand. + self.key.write_le(&mut writer)?; + // Write the default value. + self.default.write_le(&mut writer)?; + // Write the destination register. + self.destination.write_le(&mut writer) + } + } + #[test] fn test_parse() { let (string, get_or_use) = GetOrUse::::parse("get.or_use account[r0] r1 into r2;").unwrap(); assert!(string.is_empty(), "Parser did not consume all of the string: '{string}'"); - assert_eq!(get_or_use.mapping, Identifier::from_str("account").unwrap()); + assert_eq!(get_or_use.mapping, MappingLocator::from_str("account").unwrap()); + assert_eq!(get_or_use.operands().len(), 2, "The number of operands is incorrect"); + assert_eq!(get_or_use.key, Operand::Register(Register::Locator(0)), "The first operand is incorrect"); + assert_eq!(get_or_use.default, Operand::Register(Register::Locator(1)), "The second operand is incorrect"); + assert_eq!(get_or_use.destination, Register::Locator(2), "The second operand is incorrect"); + + let (string, get_or_use) = + GetOrUse::::parse("get.or_use token.aleo/balances[r0] r1 into r2;").unwrap(); + assert!(string.is_empty(), "Parser did not consume all of the string: '{string}'"); + assert_eq!(get_or_use.mapping, MappingLocator::from_str("token.aleo/balances").unwrap()); assert_eq!(get_or_use.operands().len(), 2, "The number of operands is incorrect"); assert_eq!(get_or_use.key, Operand::Register(Register::Locator(0)), "The first operand is incorrect"); assert_eq!(get_or_use.default, Operand::Register(Register::Locator(1)), "The second operand is incorrect"); assert_eq!(get_or_use.destination, Register::Locator(2), "The second operand is incorrect"); } + + #[test] + fn test_from_bytes() { + let (string, get_or_use) = GetOrUse::::parse("get.or_use account[r0] r1 into r2;").unwrap(); + assert!(string.is_empty()); + + let old_get_or_use = OldGetOrUse:: { + mapping: Identifier::from_str("account").unwrap(), + key: Operand::Register(Register::Locator(0)), + default: Operand::Register(Register::Locator(1)), + destination: Register::Locator(2), + }; + + let get_or_use_bytes = get_or_use.to_bytes_le().unwrap(); + let old_get_or_use_bytes = old_get_or_use.to_bytes_le().unwrap(); + + let first = GetOrUse::::from_bytes_le(&get_or_use_bytes[..]).unwrap(); + let second = GetOrUse::::from_bytes_le(&old_get_or_use_bytes[..]).unwrap(); + assert_eq!(first, second); + } } diff --git a/synthesizer/program/src/logic/finalize_operation/bytes.rs b/synthesizer/program/src/logic/finalize_operation/bytes.rs index 907fa3d750..a88e65a10c 100644 --- a/synthesizer/program/src/logic/finalize_operation/bytes.rs +++ b/synthesizer/program/src/logic/finalize_operation/bytes.rs @@ -134,9 +134,6 @@ impl ToBytes for FinalizeOperation { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() { @@ -144,7 +141,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le().unwrap(); assert_eq!(expected, FinalizeOperation::read_le(&expected_bytes[..]).unwrap()); - assert!(FinalizeOperation::::read_le(&expected_bytes[1..]).is_err()); } } } diff --git a/synthesizer/program/src/logic/instruction/operation/call.rs b/synthesizer/program/src/logic/instruction/operation/call.rs index aa489f5ea8..12cc42168d 100644 --- a/synthesizer/program/src/logic/instruction/operation/call.rs +++ b/synthesizer/program/src/logic/instruction/operation/call.rs @@ -544,7 +544,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le().unwrap(); assert_eq!(expected, Call::read_le(&expected_bytes[..]).unwrap()); - assert!(Call::::read_le(&expected_bytes[1..]).is_err()); } } } diff --git a/synthesizer/snark/src/certificate/bytes.rs b/synthesizer/snark/src/certificate/bytes.rs index 3d21b0ad83..df0ebfecef 100644 --- a/synthesizer/snark/src/certificate/bytes.rs +++ b/synthesizer/snark/src/certificate/bytes.rs @@ -43,9 +43,6 @@ impl ToBytes for Certificate { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() -> Result<()> { @@ -55,7 +52,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, Certificate::read_le(&expected_bytes[..])?); - assert!(Certificate::::read_le(&expected_bytes[1..]).is_err()); Ok(()) } diff --git a/synthesizer/snark/src/proof/bytes.rs b/synthesizer/snark/src/proof/bytes.rs index 88bc0f922a..e343178603 100644 --- a/synthesizer/snark/src/proof/bytes.rs +++ b/synthesizer/snark/src/proof/bytes.rs @@ -43,9 +43,6 @@ impl ToBytes for Proof { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() -> Result<()> { @@ -55,7 +52,6 @@ mod tests { // Check the byte representation. let expected_bytes = expected.to_bytes_le()?; assert_eq!(expected, Proof::read_le(&expected_bytes[..])?); - assert!(Proof::::read_le(&expected_bytes[1..]).is_err()); Ok(()) } 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 24082f1b13..2f99747752 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":"7478840637674867348334152936830348927618689666735497694442760373406118031677field","value":"[\n [\n true,\n false,\n true,\n false\n ]\n]"}' - - '{"type":"public","id":"5497626638973564164115408441431072571251727387638555124557359358862572601150field","value":"[\n [\n false,\n true,\n false,\n true\n ]\n]"}' - - '{"type":"public","id":"6826141182633851685078476561830773249264254215146313720362967764421378578986field","value":"[\n [\n false,\n false,\n false,\n false\n ]\n]"}' - - '{"type":"private","id":"8090041184628455649123912475425661970245522643231603870408821235652148265153field","value":"ciphertext1qvq9rlleav6excsnqaep0h3cztdzpergd8pdrhnrhapvr49kfrws6zwarcw9rxh9q3g0v8e5dutwyw34qslkjeqx6jzexjt2qrthnnazqerfvaxj939casntsm62yke9djhnked6nv4mufg8rmh27macnejpzdgpy4a"}' - - '{"type":"future","id":"3563270012340942054693097512832513108146970497297480667692085200645102263926field","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":"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}"}' speculate: the execution was accepted add_next_block: succeeded. additional: - child_outputs: - credits.aleo/fee_private: + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"2876640636542307658613598456059435130048160510932350003072343205416101435931field","checksum":"5890120327829713381983131988174812000986785644250446148915207626096694862906field","value":"record1qyqspqjnxve39nks4yt3u86vm4xek0q865ggt2x8c8k3at2heq5h9aq9qyxx66trwfhkxun9v35hguerqqpqzqyand8c8jqhkwckph93y0px07mp29ntdxa39egxwxg7rh8p6dcsq83r778w0c6vrawc9c46ueepj7l6793xm98xu82fjfnd2hfsc6ususdswdj"}' + - '{"type":"future","id":"611935698929626281656171069026748974326705967123466685855354594539166326131field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1y9t0y4lvhm43qdzlfjmfzh8985vfnx9ms368p07x5lsemet5ey8qt0ssjn,\n 21758u64\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 46e5687c00..6aab0a972c 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":"4279509780486643035080626777023973066084837379094817161797996960689084569794field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' - - '{"type":"public","id":"4408001848080504344165436121252640202617322612254005793329268580869751931263field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + - '{"type":"public","id":"389051587023874025297792889573178986947322645231926608183742711950919559411field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + - '{"type":"public","id":"764027935495423951991221261588244508770271800988614802602832277026356994499field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' speculate: the execution was accepted add_next_block: succeeded. - verified: true execute: parent.aleo/foo: outputs: - - '{"type":"public","id":"2289465818952696893871478441544321507584149448701746210208386693335929733331field","value":"aleo16w8t56s7v6ud7vu33fr388ph0dq0c7yhp597cyjt88rr3nultcyqcyk9yy"}' - - '{"type":"public","id":"7559709455224489102027191317638535668729648748642786204592894303802312565285field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' - - '{"type":"public","id":"3386671048315419571612162210626560184351583831974432673683170066362200712484field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' - - '{"type":"public","id":"377315782189483434546519951474821036179425135984541742851362035377982852007field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + - '{"type":"public","id":"1750346614465839730584856482412734170916382156473722062953642664481181629739field","value":"aleo16w8t56s7v6ud7vu33fr388ph0dq0c7yhp597cyjt88rr3nultcyqcyk9yy"}' + - '{"type":"public","id":"5344219132331075098560420486516441520509044320380266746188928734352154985147field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + - '{"type":"public","id":"1573682489501842474093724226520469727912427938089152276506875941161556613092field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + - '{"type":"public","id":"5522952276718822387440091782615844704170996655370860689760310532706413315373field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' speculate: the execution was accepted add_next_block: succeeded. additional: - child_outputs: - credits.aleo/fee_private: + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"7306036686667087636279947507997825407084203811048562802739660291735242744444field","checksum":"7132981897182131254956763451386939918007763262893522220397577775796699535598field","value":"record1qyqsqx586v4tjhcdgtvpat2cmz7ztzd7drzm5c04gyeaxqmujgv7ucq3qyxx66trwfhkxun9v35hguerqqpqzqx4pcwh0jc37snpu02y8ujwh2u327ghc6yaeeyc4k74e56uvuhqp0tpta5q5eppwa48pq9eepyuln9ct5qth57klqzf67ewyqn9hresxwalp5l"}' + - '{"type":"future","id":"6557860754730668406004469054379794576334242764827542178306889009454484547032field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx,\n 1244u64\n ]\n}"}' - child_outputs: child.aleo/foo: outputs: - - '{"type":"public","id":"5247898905227353609778507804894201830213116355942129794185831563892847697904field","value":"aleo16w8t56s7v6ud7vu33fr388ph0dq0c7yhp597cyjt88rr3nultcyqcyk9yy"}' - - '{"type":"public","id":"5696731482704228331490606142901378912648054832970914942122047737341299330880field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' - credits.aleo/fee_private: + - '{"type":"public","id":"5712527802009221538913597905008159571083800168555613323828114175105395494302field","value":"aleo16w8t56s7v6ud7vu33fr388ph0dq0c7yhp597cyjt88rr3nultcyqcyk9yy"}' + - '{"type":"public","id":"2170761061395221552321793888804720334493316122331828231173520748015857657389field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"3845927395044855364546905308732895913294823927145229411137666358260055754822field","checksum":"1584433976273241291707799637296934525591046977180320555626848307441674321598field","value":"record1qyqsp3c590shnra6j8rc3ezq5k229gcd8srjpxpf2vn7drkccmrq8tqrqyxx66trwfhkxun9v35hguerqqpqzq9m2h242d3v2sm53yzkqkuu6v2cwaz0jpq7nseh2uxqedph6gz9pmsvcdfnpn0htvu2lvx9cpvs6sssvhj972rpakkdzjmj4n7fhwhs6fjpcap"}' + - '{"type":"future","id":"6934683053495529076879804638371439764251999038469408002617655045734104381794field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx,\n 2123u64\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 efb5cc2e49..968809fe2f 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":"6974972465287288859193039603112863165703788123799484516917687492504306829310field","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":"7070877344843470845071680218340128414876561588663484899722739079133777261690field","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":"1905462962689695038453701745598203401537060599092388120411862554545031055970field","value":"{\n program_id: zero_program.aleo,\n function_name: c,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n}"}' + - '{"type":"future","id":"6477965281694625542813245938794172569328608429706708191922101843636085582648field","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":"6693143058720846069430783074439454880228662860018405276072484028873963650423field","value":"{\n program_id: one_program.aleo,\n function_name: d,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n}"}' + - '{"type":"future","id":"7600562933389723321829659564857024316904973330057294558938622149411503122565field","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":"491254750407294442708769751402250675930358534067257210689773980657773666656field","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":"1088466287454699993852527092566314082160141085274506025284078608454717245108field","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":"3726717185600495415803494559204677788759912659186157220182093722580745931290field","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_private: + - '{"type":"future","id":"7841227793321257675149138943803344962284191528517008231244304707117434937108field","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":"record","id":"5283229445241909733017633528975572727346436141849413233403355092851851760389field","checksum":"799210811176292053431285281723859450131511292642705172333396010564735450437field","value":"record1qyqsqkme4g74y49w7v70p63ywtq5nate5r75dk8m05ss5zmer5zeqrggqyxx66trwfhkxun9v35hguerqqpqzqx2jzxmtf2rksjtwnl4xz5uu33vh0hdl5gys60lw5tdywm6w864qpzvzv6t35yczkzxqpeh7ckc5wtmt5sxynlcz9fy5ellqapnz8squlrzfgw"}' + - '{"type":"future","id":"1237672223493374809326586125815613616482431271830981051687054520069740484800field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8,\n 1312883u64\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 ca1856b203..21f59e8527 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":"5938418890955443794463293173052677473396802601178583117662009125510762112385field","value":"ciphertext1qyqwvmg8ce9sq5ewccjlade56hhmxk4d4j9ec48up7d3mk9q4gwtqzc5kd8jk"}' - - '{"type":"future","id":"5461514865984769926527447907140509355062580300320347542454721592100955559616field","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":"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}"}' speculate: the execution was accepted add_next_block: succeeded. additional: - child_outputs: basic_math.aleo/add_and_count: outputs: - - '{"type":"private","id":"1772315556078612939485167533472365297291684867177607257721621802696977947575field","value":"ciphertext1qyqgcklg8azjw9cvg8ctguretgpwhf6s2wqfy9kcpat8fez58s8zkrsxh67uj"}' - - '{"type":"future","id":"7119746076995582562745785454448389581684828092421379752708247448276937401483field","value":"{\n program_id: basic_math.aleo,\n function_name: add_and_count,\n arguments: [\n aleo1mrughg5ssadd9fc2uwve7l6u24xn76kyz24zsjtzta03vgkq4vpqggl6fg\n ]\n}"}' + - '{"type":"private","id":"4561312717108467882490189383753688162224283446985485227292501566765195528324field","value":"ciphertext1qyqxqf95wz9zvjvpar4mvg0uh8xuc3dwd0g3z7rggzs37wgn59lk5rqeqev0f"}' + - '{"type":"future","id":"1823043499627326708916435552316425587964911687609516559408234217585811375291field","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":"4385798570457226847447139993266058099729895220721504161659868031463911613327field","value":"ciphertext1qyqdtuhzwzdqd0ezjqv0qakjqcwjgnve7u2q0mttr9fhmrfk8lppgrgns3l5x"}' - - '{"type":"future","id":"1481600775514027453204849289042631419545525289712332246758716884227294896058field","value":"{\n program_id: basic_math.aleo,\n function_name: sub_and_count,\n arguments: [\n aleo1mrughg5ssadd9fc2uwve7l6u24xn76kyz24zsjtzta03vgkq4vpqggl6fg\n ]\n}"}' - credits.aleo/fee_private: + - '{"type":"private","id":"6179141860878239968710321244474677697823391063964518415169464613412286673421field","value":"ciphertext1qyqd9vtp4hdlacy9n322hvdywk84crzw47vfygjmxe253v2tgjqpxqcq5jx54"}' + - '{"type":"future","id":"6353584285709285028969780236537279966694496448826640752394833353716781489471field","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":"record","id":"3873686337596264307426391445386469102660995373532676522475799639542084414660field","checksum":"2174613677640073315115047311154070353095418041185484773007639715599946288810field","value":"record1qyqsq758xfnepvvywvf4tjnve5qkfr0hur7gttevq66hpvl97ulxzkgyqyxx66trwfhkxun9v35hguerqqpqzq85ufcypfdv6unklsc9m066e86drkzx32yzj9kwx7enflqv7j6xqz5v6hx0r0qp5r564yuanadwjkhvx4tj3xp407hh058jl7u0v9qq2z6nqqz"}' + - '{"type":"future","id":"1724410343181243501519372165830316719575121816257937877011429517054089311771field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8,\n 263392u64\n ]\n}"}' diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/external_read_with_local_fail.out b/synthesizer/tests/expectations/vm/execute_and_finalize/external_read_with_local_fail.out new file mode 100644 index 0000000000..8c5e3e1a9f --- /dev/null +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/external_read_with_local_fail.out @@ -0,0 +1,3 @@ +errors: +- 'Failed to run `VM::deploy for program relay.aleo: Locator ''relay.aleo/users'' does not reference an external mapping.' +outputs: [] diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/hello.out b/synthesizer/tests/expectations/vm/execute_and_finalize/hello.out index 7c1f6e99ba..4ee4b5c467 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":"8125348741943322686009907907811782653304283628858249042666480861925372544888field","value":"ciphertext1qyqzh0ww4d529sp24xw2c0ek9p3mlh5amc8rlzhudhw6u4e6h9ffuzc4xu63n"}' + - '{"type":"private","id":"6254379462913920094060616443827416926361791013133233839133894947200598009041field","value":"ciphertext1qyqpmnatnq3sjej6qves695qtxu5r6lqnfnx8ck87ce3pez28x90qzgzeh4qh"}' speculate: the execution was accepted add_next_block: succeeded. - verified: true execute: hello.aleo/hello: outputs: - - '{"type":"private","id":"4190523942746941151788535679482167833023294290248250731893857652327309412596field","value":"ciphertext1qyqg0dpeew6mjk7zgcw423k99k74k5nnqpshnjsjvjezfqsfel7q6pq9k0ny2"}' + - '{"type":"private","id":"4161183151518570414349285932182760288961689691043823886807644299644687930091field","value":"ciphertext1qyqreg8a27jzsgm7m5umh98nr9nwyxhkv3aus5htm6vepdkr67zh5zqc4uzpd"}' speculate: the execution was accepted add_next_block: succeeded. - verified: true execute: hello.aleo/goodbye: outputs: - - '{"type":"public","id":"6479967549102698786501355579286201653159194507767944415639092049192937228124field","value":"1u32"}' - - '{"type":"future","id":"3413333273447015937668991532824129740236214843152627847347248311711336145614field","value":"{\n program_id: hello.aleo,\n function_name: goodbye,\n arguments: [\n 1u32,\n 1u32\n ]\n}"}' + - '{"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}"}' speculate: the execution was accepted add_next_block: succeeded. - verified: true execute: hello.aleo/goodbye: outputs: - - '{"type":"public","id":"626299501033028507774181248923989773544577830656010087029558433445349806993field","value":"1u32"}' - - '{"type":"future","id":"3565307659242500881563819123626548100763518079205528385426399960688796421686field","value":"{\n program_id: hello.aleo,\n function_name: goodbye,\n arguments: [\n 0u32,\n 1u32\n ]\n}"}' + - '{"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}"}' speculate: the execution was rejected add_next_block: succeeded. additional: - child_outputs: - credits.aleo/fee_private: + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"1563962924137405178742221846132647984424532842613103093908307558260562727180field","checksum":"5823248983705197503554751176880028590763810324036946942686008195006386919883field","value":"record1qyqsqxplm7g9hnkv0kecp0qyzpcmqssafmu3l63n3rasf5tqn9mg95qxqyxx66trwfhkxun9v35hguerqqpqzqq6096l6jlnt6yw20wxxh5vz8hnau7v7zh0lhgg58t7330fzx2jzqucjp2scympk3qapejn5adphf7vcznjr0h3ar76peu3f74d8jess2usmfv"}' + - '{"type":"future","id":"5633762070565015506869877991983247311752566772551740661334199093127666173285field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo10knkelvnd55fsaarm25wch7p9suf2tqlgwy5k4nxwms6d262xyfqm2tccr,\n 1285u64\n ]\n}"}' - child_outputs: - credits.aleo/fee_private: + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"7418640687872332228724490929058573679078624012230582886849419189302370026910field","checksum":"2288322295066553762968656723772741917161404143341855080238665799645378480682field","value":"record1qyqsq2qp0m80sqnsgn4fdmpwfx7tgwh4cr9nvlejg2arkrn2u43qhpq0qyxx66trwfhkxun9v35hguerqqpqzqx7606fvtdu7h2zqjjxpmn9lhux5ys0hqqlltf2w62p7ukkddhyzpflcm4xfrg65m6y0c6g3xyg5ax25zq7kl5ea269mzpd9m86fz5qk6fhd5c"}' + - '{"type":"future","id":"4168535226825329132770722118865464284070271653060849404506023921600553004505field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo10knkelvnd55fsaarm25wch7p9suf2tqlgwy5k4nxwms6d262xyfqm2tccr,\n 1285u64\n ]\n}"}' - child_outputs: - credits.aleo/fee_private: + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"3460880420858965334724667101702159478601299033919299770846136229938204873952field","checksum":"889185695775021282240580382339319659491334542311157511499897352194166769728field","value":"record1qyqsqgg555pvesq2ss8kth990hv0qsfd7d4k9td00tufe3qzufxdsmsgqyxx66trwfhkxun9v35hguerqqpqzqr95x0pv0jygxkd7txgx8h34sfeducq4vjwvcsfjvn2xe55vht8zzxn40ssvl4eyvd9y3wj2qy47alyc69m0tkftmeuzrvnh6jqupkq20gsf5e"}' + - '{"type":"future","id":"7264507997475302694771209211625280132862970630053323876707987175500028146955field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo10knkelvnd55fsaarm25wch7p9suf2tqlgwy5k4nxwms6d262xyfqm2tccr,\n 5334u64\n ]\n}"}' - child_outputs: - credits.aleo/fee_private: + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"1053040319405423319885581476153506668871260904872026627338166884076666293995field","checksum":"3137133192027913702130513124530902338448032734519979527965593396128027839095field","value":"record1qyqsphyrpqq85txdn28cakkhasnrc5nfw5devjsmmhj3jdgm3eg80nqyqyxx66trwfhkxun9v35hguerqqpqzqyfnegh56dljl46e5p06q86e8fv844xepww7c9rldherdj9l6r0zgvu7qj26zt906m3htewsu4plawunfac2e7vjpre58sqte2n29rs7zaue0v"}' + - '{"type":"future","id":"2296589459402270097535149680764663519350069575816165257148428557434644368237field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo10knkelvnd55fsaarm25wch7p9suf2tqlgwy5k4nxwms6d262xyfqm2tccr,\n 5334u64\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 4bdf331e05..6b2773e6cf 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":"7291478973311998196889109284965727070006803821552839308760042614138648979276field","value":"{\n program_id: mapping_operations.aleo,\n function_name: empty_remove,\n arguments: [\n 10u8\n ]\n}"}' + - '{"type":"future","id":"7635640739633293853436744163909014640199975942090334368682977334784204769011field","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":"8125199181008624196820150111927204421834678204873633176936287270742730215646field","value":"{\n program_id: mapping_operations.aleo,\n function_name: insert_contains_remove,\n arguments: [\n 0u8,\n 0u8\n ]\n}"}' + - '{"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}"}' speculate: the execution was accepted add_next_block: succeeded. - verified: true execute: mapping_operations.aleo/insert_contains_remove: outputs: - - '{"type":"future","id":"564988137123189827911719500643390438805066632168511094429444048054438194661field","value":"{\n program_id: mapping_operations.aleo,\n function_name: insert_contains_remove,\n arguments: [\n 0u8,\n 0u8\n ]\n}"}' + - '{"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}"}' speculate: the execution was accepted add_next_block: succeeded. - verified: true execute: mapping_operations.aleo/insert_contains_remove: outputs: - - '{"type":"future","id":"1504983850261979002191664940947948558038660291110914628083356222450379989621field","value":"{\n program_id: mapping_operations.aleo,\n function_name: insert_contains_remove,\n arguments: [\n 0u8,\n 1u8\n ]\n}"}' + - '{"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}"}' speculate: the execution was accepted add_next_block: succeeded. additional: - child_outputs: - credits.aleo/fee_private: + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"2982975415914840620507158319258878944269906877410766878798891082463802016242field","checksum":"3862090753639563234029083871874631115872354449378325601192947833837837297501field","value":"record1qyqsp3p5w845k0nmwmlwau7zavphxns6rh9nw8tg83ds0cjx2hnmj6qdqyxx66trwfhkxun9v35hguerqqpqzqzfd6xh2zdl25cwy9evykj9s6p90xys775fwzrqws8qn9g44lzfqn3e4cam6huahmz49k20vnssfjs25f4v0huxlpklc0wnyvredep3y4w6r94"}' + - '{"type":"future","id":"3701652920213282423281084685169254121653756184853703028504071363673532942725field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1eakarna6a70pg9r0l9qal20faejwctgur5xt7lnc2a42wj2yssfqc89rk8,\n 11245u64\n ]\n}"}' - child_outputs: - credits.aleo/fee_private: + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"48072890610857571956763071582832119607215592326496047104336441787173630868field","checksum":"7467290380261150018279273531628821954702770589524221500078644428102363349374field","value":"record1qyqsqh45sake5ld7mknnvq6gqz4fnpx5trzu6lmhsfxejf69pm8hfaqpqyxx66trwfhkxun9v35hguerqqpqzqxdhy98teyfl6uz9j434zhapesfd8s9zggu6wmcw8cjuyscgnq9px7a3r4uf4udc98zwvfksj4nqv8ckf0wv8lj6l35zdtm0l7gx6vswyvq76a"}' + - '{"type":"future","id":"767852843394263062723803642109980847781175859546892255347263461730875281315field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1eakarna6a70pg9r0l9qal20faejwctgur5xt7lnc2a42wj2yssfqc89rk8,\n 154810u64\n ]\n}"}' - child_outputs: - credits.aleo/fee_private: + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"4110917071309386297883198571995053247696762203282665069271948556795502494816field","checksum":"5208736060122533898058377411292933064659147009969289502970426241558725961052field","value":"record1qyqspe5yr7j2nej3pg4jr9gd6fn9uzu27gfy29aj3g5spc32tr2dqksqqyxx66trwfhkxun9v35hguerqqpqzq8tq90g30z3r0ll9ffn36cwtwvwmugnh4yak6afr264lzzw3lg4p7dfeqfwzqzuuw084ym2km0um206l4s9lkmw29w4499r422uvy3q6dvnd32"}' + - '{"type":"future","id":"5831877738131393412656336446760308055442933218729238434398743654782252530700field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1eakarna6a70pg9r0l9qal20faejwctgur5xt7lnc2a42wj2yssfqc89rk8,\n 154810u64\n ]\n}"}' - child_outputs: - credits.aleo/fee_private: + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"127003451731600147843337554003537999361398270748193639437833213734975434703field","checksum":"6199041391391566355775171236268799936285239125918398783413624959865612791864field","value":"record1qyqsq3cmtcjcws6hmecvz7wswnhgulm8clv7tjvsnjdrgncamj4sqcqpqyxx66trwfhkxun9v35hguerqqpqzq993fr433kwql98qu7wh083fwed69wt9pk5ftg9cldvymz2eyk9pg8366sccu0as9vjnt0y4nxuw6mzm3g3f4ckjf2q2mkaasy0w0cs634pjhl"}' + - '{"type":"future","id":"3924911723698610328779426182874581891939297874519691347932588542992608923909field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1eakarna6a70pg9r0l9qal20faejwctgur5xt7lnc2a42wj2yssfqc89rk8,\n 154810u64\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 91264a79a7..bd63f8cfca 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 @@ -4,15 +4,15 @@ outputs: execute: mint_and_split.aleo/mint: outputs: - - '{"type":"record","id":"7636508513753843688255477046613755926717864376364314808857555307422986366583field","checksum":"2724303349197854838397688958932042996013299317300510410551052639216931686578field","value":"record1qyqspznunw4usdtcqwznvpm3f73dlfxcmg07emews5rxsvfp8jelaqs3qyxx66trwfhkxun9v35hguerqqpqzqqjmj4kl3w0fh0dhqy67c47xgw7ftfdkhplztykwwr7mgnn8cm3q50aufvdjh84e3325vgsq98uzgdxyscfrymgz6j5p6txj0u06ngskkug8kd"}' + - '{"type":"record","id":"7334558502140616765536611609313499148179717945955456292257315684677266501449field","checksum":"281154250604636828435706866945909260040573817788279288153963030037316744168field","value":"record1qyqsp9pr7qlgedcywvyk5lsnpuqpepyuv9hseec63eacjpn8d0rpmwgsqyxx66trwfhkxun9v35hguerqqpqzq9ql0hu0da6wuzrm0a7ms3kfvj5279e43rulstm9plhzs0z0xe6p52cn7pdz7x5hkwhz905kp56f4fuq08k9maf57qteekdv9yddk8sqxq4d98"}' speculate: the execution was accepted add_next_block: succeeded. - execute: Commitment '1266307482263846358970326041806201638141701138269282465033372005968041137990field' does not exist - execute: Input record for 'mint_and_split.aleo' must belong to the signer additional: - child_outputs: - credits.aleo/fee_private: + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"6034384869866160676195114971378149013303703779101829835678240523345757814679field","checksum":"685010203971891455492083289280654319079811728620135209391715861377156619685field","value":"record1qyqspmum93lsptda6cxy2934329jud5j5d2w974qj980uzacuurkteq0qyxx66trwfhkxun9v35hguerqqpqzq95n3clh78n7alksrkrcwvf0kc5qeej4mmudqf57t7mqt08jd97p4nq3txxlzvtf3hsf093raynhzylqxz8vscq22pc2qaryw7r3qms7wmxm6s"}' + - '{"type":"future","id":"2224596965693604846363254284152512550549945382876106932610187515185636813504field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo19e6k5ferx3k8a9k79xtj4uuaztt2jl4eza7k43pygsu977yazypqqwdmw6,\n 1414u64\n ]\n}"}' - {} - {} diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/no_import_external_read_fail.out b/synthesizer/tests/expectations/vm/execute_and_finalize/no_import_external_read_fail.out new file mode 100644 index 0000000000..817f9c7e2f --- /dev/null +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/no_import_external_read_fail.out @@ -0,0 +1,3 @@ +errors: +- 'Failed to run `VM::deploy for program relay.aleo: External program ''registry.aleo'' is not imported by ''relay.aleo''.' +outputs: [] 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 aefc6c15e6..35b4c94e05 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":"232678181145630788399983360361981778077854318297598920122679715355556018707field","value":"aleo16w8t56s7v6ud7vu33fr388ph0dq0c7yhp597cyjt88rr3nultcyqcyk9yy"}' - - '{"type":"public","id":"307885753616111794499278513815755325774421253222438014088047291626146246158field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' - - '{"type":"public","id":"1260075966251215032940540134753397347255605556303289668063307322367655594483field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' - - '{"type":"public","id":"6132019643538827223159216821616255691562939708927702036224235366852272625285field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + - '{"type":"public","id":"2113639263284598783237184890483589485263377586770518008730201564727239039871field","value":"aleo16w8t56s7v6ud7vu33fr388ph0dq0c7yhp597cyjt88rr3nultcyqcyk9yy"}' + - '{"type":"public","id":"7678040084911633492076681690048450077835769459926508481383981892807233674714field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + - '{"type":"public","id":"4672581957597248464578193953626136889647685708065995338030805320939951875503field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + - '{"type":"public","id":"5713124416526318631344949557472532527559170952243278345561593407764623253620field","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":"5334867623218595534708726257738756067611806976563813684130095277315778727015field","value":"aleo16w8t56s7v6ud7vu33fr388ph0dq0c7yhp597cyjt88rr3nultcyqcyk9yy"}' - - '{"type":"public","id":"1727089994158808720293796677503877381843056781736540181516614343299100979544field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' - credits.aleo/fee_private: + - '{"type":"public","id":"8256096006685601051730823022659471790701845130080598423319521977566444421040field","value":"aleo16w8t56s7v6ud7vu33fr388ph0dq0c7yhp597cyjt88rr3nultcyqcyk9yy"}' + - '{"type":"public","id":"5221989025862141472722693152948767316757289409356062808145501796303456062879field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"3405674025766329369434309421947987188809020226610822755338621799001328840366field","checksum":"2290293865028149494249499535633241867489656506924610383724277827943521435010field","value":"record1qyqsq8u5n9rn77xzqqemfr60lr5gd0kl3kmcr8y4kvf34rtxkn5jzhsyqyxx66trwfhkxun9v35hguerqqpqzqyhetu9jy8vsyeaqsq5thyrj7nldd626s0fgatwpffv5j3hecq6p7pkx5xqz4xfcrlu8u2tz8hew0wuagx3cc0wgzlq7uhr2lrc35nqy7dgy47"}' + - '{"type":"future","id":"2015747658045377273535220569098051012671760616560705166778921345457847058512field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx,\n 2123u64\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 3ac28d5188..96fdcea20c 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":"643313357591837098160410683436104757275790983408765054797072865390269356548field","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":"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}"}' speculate: the execution was accepted add_next_block: succeeded. additional: - child_outputs: token.aleo/mint_public: outputs: - - '{"type":"future","id":"4427917061221785896976649017270098343030953189539524433709150411558826004395field","value":"{\n program_id: token.aleo,\n function_name: mint_public,\n arguments: [\n aleo1sry3pke49ykrf0aeshf889tr98r4c86p5f4ms766795ssdwfdyqq9jdg0j,\n 10u64\n ]\n}"}' - credits.aleo/fee_private: + - '{"type":"future","id":"3040250960739602137216192760697867018750676343790464348994684811613512872895field","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":"record","id":"5907104904483017944370886525724321520913422122645092211228240860024172441663field","checksum":"5028009166132212399635589181092346921835371600420834084268447856042439491field","value":"record1qyqspshxjatwcdkrde0m2rspsm338q8p7s4eru9m8ftjqzf0ttxpkag0qyxx66trwfhkxun9v35hguerqqpqzqqzvfyzxfn5qlq5aewnafp8z576qvqjjx9pup92f6dxywga9qdupchalpjgkqrwva74ssnqjqgewu8xwj285f0c08t6czss5lcftjhqjuazgdk"}' + - '{"type":"future","id":"4373249435479943424484888940718424132561120812144078253060284512525421799293field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1d3e2je2m2hsxwdsvntvf4jnnlj459ywfry6ch2qwrpy6l6r6yvpq8e88h5,\n 131201u64\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 new file mode 100644 index 0000000000..a729b3163e --- /dev/null +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/read_external_mapping.out @@ -0,0 +1,73 @@ +errors: [] +outputs: +- verified: true + execute: + 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}"}' + speculate: the execution was rejected + add_next_block: succeeded. +- verified: true + execute: + 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}"}' + 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}"}' + speculate: the execution was accepted + add_next_block: succeeded. +- verified: true + execute: + 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}"}' + 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}"}' + speculate: the execution was accepted + add_next_block: succeeded. +- verified: true + execute: + 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}"}' + 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}"}' +- 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}"}' +- 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}"}' +- 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}"}' +- 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}"}' +- 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}"}' 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 a41aa6a4f5..7c414c0ce3 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":"4807227403819588684031853679423924290019569164203178974904495218971849247520field","value":"{\n program_id: test_branch.aleo,\n function_name: run_test,\n arguments: [\n 1u8,\n 1u8\n ]\n}"}' + - '{"type":"future","id":"6853588955800014673009987953241306389090845327747907984198222141108269232573field","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":"6578563227874053328775488720373016284038873634029366303301076699226711812107field","value":"{\n program_id: test_branch.aleo,\n function_name: run_test,\n arguments: [\n 0u8,\n 1u8\n ]\n}"}' + - '{"type":"future","id":"7316910653703512796159979382480893246542312648132879967453276886284034879075field","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":"7508008554951635493629769098645178330945961002302110561994738513868095644109field","value":"{\n program_id: test_branch.aleo,\n function_name: run_test,\n arguments: [\n 0u8,\n 0u8\n ]\n}"}' + - '{"type":"future","id":"6402417637041760480107523094357167265585878714433227566435547816691472198663field","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_private: + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"1798938114974546684903209797369438296308320213665197846673649863916852114678field","checksum":"934572607592461135140890365283940117058051001959725525910576582297797621269field","value":"record1qyqspa9fxepth5l9c2u7gj6quuvfpq8wqc9q73p4xqcrmj2nurd7cfq3qyxx66trwfhkxun9v35hguerqqpqzqx9w072uwlffgvu0he36lya458pluymlds8kpv3shjc4asc3wy2zp3rk0fv9mhq6ja45tux30ps2x433ekqdsx967z8ysqp9fk37epqvu520r9"}' + - '{"type":"future","id":"8176559465483810586872674176090912007328770812617215482809916166686904238834field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1x3r205zqql5ywy0cqqt74k0r0htuusn0d037ycxe8ftt9ep8hyzsmqz4dh,\n 17268u64\n ]\n}"}' - child_outputs: - credits.aleo/fee_private: + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"1039543979177875951661037350337722240996003141461618829150227721443832233782field","checksum":"4293043628731843171082705656149326581514713699817730020543476948781408422008field","value":"record1qyqsqaarvryvc8vfqer4jcngz5k9wd6m4dfvwsr4tc43v8ynmc5ny2q0qyxx66trwfhkxun9v35hguerqqpqzqx2mm3lh6vu0f9pmpne0qz5rkr7g26s3et0trj673gff8klmlpqq0r5sjjjncqlvgazec63a0enrf5dfr3n7jczarf0eshvu6d0hx3sztrtu4z"}' + - '{"type":"future","id":"885516194992930770292437059317184478627651975125735363573325083543887608918field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1x3r205zqql5ywy0cqqt74k0r0htuusn0d037ycxe8ftt9ep8hyzsmqz4dh,\n 17268u64\n ]\n}"}' - child_outputs: - credits.aleo/fee_private: + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"145788756097299829231591915301155878379901156732628535292899269362119878286field","checksum":"2449429819506214589213294593178366793060498781467568604016514039430651546570field","value":"record1qyqspttnaxurc3z4pdve7697588gxr5lvrj04m93shwzhr4znh49k9gwqyxx66trwfhkxun9v35hguerqqpqzqrc35k4y2kzu7kvhksvv2yu4t5m680w5u6ykv8cnrprtvfrda27qqt3y37y87fw5crd0efl8elqad36xdqekqr3w020krmj00enuy5pzqylmsv"}' + - '{"type":"future","id":"6884773732489674095657820682011451719106395760464004244662697484163781295818field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1x3r205zqql5ywy0cqqt74k0r0htuusn0d037ycxe8ftt9ep8hyzsmqz4dh,\n 17268u64\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 c5c06ec684..4fefc62cfd 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":"856859213363286889141859059264203066675648340843625883729021378909143418037field","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":"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}"}' speculate: the execution was accepted add_next_block: succeeded. - verified: true execute: test_rand.aleo/rand_chacha_with_struct: outputs: - - '{"type":"future","id":"2863690152286397600239869811553134445139434415556812678934084238826545926808field","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":"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}"}' speculate: the execution was accepted add_next_block: succeeded. - verified: true execute: test_rand.aleo/rand_chacha_check: outputs: - - '{"type":"future","id":"5111075340000719619409954898038080805237607157543987731445343150082162501419field","value":"{\n program_id: test_rand.aleo,\n function_name: rand_chacha_check,\n arguments: [\n 0field,\n false\n ]\n}"}' + - '{"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 add_next_block: succeeded. - verified: true execute: test_rand.aleo/rand_chacha_check: outputs: - - '{"type":"future","id":"6632578043065250671900699630486713707508511783056688582055933257632278653469field","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 rejected + - '{"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}"}' + speculate: the execution was accepted add_next_block: succeeded. additional: - child_outputs: - credits.aleo/fee_private: + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"4381229306463692442497149670614588062764798743790588146804215330229884792339field","checksum":"2138639167265992670566199833999883133869484105738196279078647847384925584310field","value":"record1qyqsq96nqu434vyta43jksy548fdck37rc7kc34494ndwd9xfg9l7zsfqyxx66trwfhkxun9v35hguerqqpqzqp47n5hcfmt2twwyz0wm37mh898yfhr6rw79z026vpnc4v6h5sap3wxhvupx7k4p2jhrwtx5zw6r5t3vuarmsq8n4c4p987z586n6yqzjd7p7w"}' + - '{"type":"future","id":"6314628133780265670801554258125814886017405269745792760682853845340140460175field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1uchf7kruskpp8thlnfeya9qeklcjss27j6rtu74zz7ch559neqystgslsp,\n 601806u64\n ]\n}"}' - child_outputs: - credits.aleo/fee_private: + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"6586316285692512365232256556210792622636286450707813931421762885414931353832field","checksum":"1586190359159798393415585130912439326237257065208437997708789530351085560464field","value":"record1qyqsq4tq08wj70zje3dth93xhcaac25nc7szhtt8egu4h42tln3nh0crqyxx66trwfhkxun9v35hguerqqpqzq96k0cukn8schvjlnjdyf0z0r28yvnlnmpuuj4qhxpwqc8qktc8z9e93akjxefm88vhqxpv7ppqrxp6q8hpvzee72az4mx6k4553tmss23hwgr"}' + - '{"type":"future","id":"3725939744341267737290273038160661629630343114766507174134842826652488781816field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1uchf7kruskpp8thlnfeya9qeklcjss27j6rtu74zz7ch559neqystgslsp,\n 26679u64\n ]\n}"}' - child_outputs: - credits.aleo/fee_private: + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"70907903135321440406346995966772705528708353149493963813138922918859409499field","checksum":"1758155264387920852695791077636953465936690916033386407170194003924917340917field","value":"record1qyqspxy8g4khtakgjt7dk7p3ych5zhqysfp78uh7740jyr4j2q4xu3qxqyxx66trwfhkxun9v35hguerqqpqzqqfgux5pw80dc9xzk0vzklz8v7kt3szhr2h70tt8tj9c2ddgyptppsgj9uj7g0spx3uvw5l7c4ue7qgp948gjcwen4ql5u8fhj3333qjccs5hk"}' + - '{"type":"future","id":"5227003534986816857285932061757797688706802206018964764622184983760566708322field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1uchf7kruskpp8thlnfeya9qeklcjss27j6rtu74zz7ch559neqystgslsp,\n 28344u64\n ]\n}"}' - child_outputs: - credits.aleo/fee_private: + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"5402941757199163131329664269602668871633752908147903083826863058623466909547field","checksum":"6299858438509874984288393356100492859126380436511534635530655092194846486258field","value":"record1qyqsparxz7rjgu5qwj29fp5xspylvxuxumjzpjwp7yahvn09szx0l6g3qyxx66trwfhkxun9v35hguerqqpqzq9vq9pcmuhpxvvrax2n3nht8f9jgdpzt9h9l7w7k5geycwqtypupsuh2lrxq4l7ts96haxgvxkdjvwd42cqpt2l96j9xhw5zlxuu2ssx0gfq8x"}' + - '{"type":"future","id":"5806769723479332130567002952494928256138310337461654699762319212831997850826field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1uchf7kruskpp8thlnfeya9qeklcjss27j6rtu74zz7ch559neqystgslsp,\n 28344u64\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 ade542ee2f..425f80af2e 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":"578152375660960413620944529176838111130558819753119775638549496005056051167field","value":"{\n program_id: timelock.aleo,\n function_name: lock,\n arguments: []\n}"}' + - '{"type":"future","id":"5726101227699718662507291026879175619949633046158707589853378418659241463316field","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":"1153321566575392305875708931221831574430034867281515788213221373067783340857field","value":"{\n program_id: timelock.aleo,\n function_name: lock,\n arguments: []\n}"}' + - '{"type":"future","id":"5825781590715337627504208073275179158827587281138872289977731167576414664969field","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_private: + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"5473322261890369096710391500775021877134453013698547035599192539986067358037field","checksum":"6980374149233505129565181437471791515647159093892921261741246653396495143051field","value":"record1qyqsq40tapm7w0zll08x28yu8ufzs3jqk53ec0pen7vfaeppl2n84jcyqyxx66trwfhkxun9v35hguerqqpqzqzc6xphegrmzxkw8clqe5fsxs7xnqp9f57usrmmyv3gu4ey5d3aplsdq2hkpwzylgwne67j769p77754yqdcam28mh68huzlz74npxsqjwwdtx"}' + - '{"type":"future","id":"2868527388214006275127069563021857572887489216649877337285946162120321568912field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo12tksdptp7hvxly8tkm3um08fvf53qpehsgdgqfvy9pe3sewcq5ysjg5myy,\n 5164u64\n ]\n}"}' - child_outputs: - credits.aleo/fee_private: + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"3500478305510861468600974780645788091574034938191756692997832413371764035285field","checksum":"5270087208881412083504176599993145162545711447694009649032440534082007001776field","value":"record1qyqsqk3tweyvy3x4rsk06umpl3j6ucy7fpk5n8ypafp4vga25asnf0grqyxx66trwfhkxun9v35hguerqqpqzqx0kky3nlgn23x8m0khjmsgh8hmye9m0mpre68zgvysvlz82szuq3vy0ualeusvypmafl9gp97gwv067ljhn9we058mvua74ych7hgqvnj9lc4"}' + - '{"type":"future","id":"3666380379303443004933801395245329857516145915761366182794264005536589963556field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo12tksdptp7hvxly8tkm3um08fvf53qpehsgdgqfvy9pe3sewcq5ysjg5myy,\n 5164u64\n ]\n}"}' diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/unknown_external_mapping_fail.out b/synthesizer/tests/expectations/vm/execute_and_finalize/unknown_external_mapping_fail.out new file mode 100644 index 0000000000..65ce813937 --- /dev/null +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/unknown_external_mapping_fail.out @@ -0,0 +1,3 @@ +errors: +- 'Failed to run `VM::deploy for program relay.aleo: Mapping ''foo'' in ''registry.aleo'' is not defined.' +outputs: [] diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/unknown_mapping_fail.out b/synthesizer/tests/expectations/vm/execute_and_finalize/unknown_mapping_fail.out new file mode 100644 index 0000000000..eb8a147f5c --- /dev/null +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/unknown_mapping_fail.out @@ -0,0 +1,3 @@ +errors: +- 'Failed to run `VM::deploy for program registry.aleo: Mapping ''foo'' in ''registry.aleo/register'' is not defined.' +outputs: [] 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 eb604e54d4..c5e300b026 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":"754819646549188005033265189873387370723612282538036088693249266044696644507field","value":"{\n program_id: unused_position.aleo,\n function_name: foo,\n arguments: []\n}"}' + - '{"type":"future","id":"4435915382452600913825742955271157728527943603774006701552876898718102875463field","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_private: + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"3540562477020683716064470691350628391302941512915750897951711495334005821133field","checksum":"7993988099268814368872113132611442146154220017865766620056128915944022458704field","value":"record1qyqsq40tapm7w0zll08x28yu8ufzs3jqk53ec0pen7vfaeppl2n84jcyqyxx66trwfhkxun9v35hguerqqpqzqzc6xpjenmmzxkw8clqe5fsxs7xnqp9f57usrmmyv3gu4ey5d3aplsdq2hkpwzylgwne67j769p77754yqdcam28mh68huzlz74npxsqylrxra"}' + - '{"type":"future","id":"5889749875317192883762347751185109427367185401929794748301981981444845203330field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo12tksdptp7hvxly8tkm3um08fvf53qpehsgdgqfvy9pe3sewcq5ysjg5myy,\n 2176u64\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 58f4be97a8..77e6a29dd6 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/user_callable.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/user_callable.out @@ -4,14 +4,14 @@ outputs: execute: child.aleo/foo: outputs: - - '{"type":"public","id":"4279509780486643035080626777023973066084837379094817161797996960689084569794field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' - - '{"type":"public","id":"4408001848080504344165436121252640202617322612254005793329268580869751931263field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + - '{"type":"public","id":"389051587023874025297792889573178986947322645231926608183742711950919559411field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' + - '{"type":"public","id":"764027935495423951991221261588244508770271800988614802602832277026356994499field","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)' additional: - child_outputs: - credits.aleo/fee_private: + credits.aleo/fee_public: outputs: - - '{"type":"record","id":"7306036686667087636279947507997825407084203811048562802739660291735242744444field","checksum":"7132981897182131254956763451386939918007763262893522220397577775796699535598field","value":"record1qyqsqx586v4tjhcdgtvpat2cmz7ztzd7drzm5c04gyeaxqmujgv7ucq3qyxx66trwfhkxun9v35hguerqqpqzqx4pcwh0jc37snpu02y8ujwh2u327ghc6yaeeyc4k74e56uvuhqp0tpta5q5eppwa48pq9eepyuln9ct5qth57klqzf67ewyqn9hresxwalp5l"}' + - '{"type":"future","id":"6557860754730668406004469054379794576334242764827542178306889009454484547032field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx,\n 1244u64\n ]\n}"}' - {} diff --git a/synthesizer/tests/test_vm_execute_and_finalize.rs b/synthesizer/tests/test_vm_execute_and_finalize.rs index ce7ff4a93e..23b760cbb2 100644 --- a/synthesizer/tests/test_vm_execute_and_finalize.rs +++ b/synthesizer/tests/test_vm_execute_and_finalize.rs @@ -35,6 +35,7 @@ use snarkvm_synthesizer::{program::FinalizeOperation, VM}; use synthesizer_program::FinalizeGlobalState; use anyhow::Result; +use console::account::Address; use indexmap::IndexMap; use rayon::prelude::*; use std::borrow::Borrow; @@ -69,34 +70,61 @@ fn run_test(test: &ProgramTest) -> serde_yaml::Mapping { let genesis_private_key = PrivateKey::::new(rng).unwrap(); // Initialize the VM. - let (vm, records) = initialize_vm(&genesis_private_key, rng); + let (vm, _) = initialize_vm(&genesis_private_key, rng); + + // Fund the additional keys. + for key in test.keys() { + // Transfer 1_000_000_000_000 + let transaction = vm + .execute( + &genesis_private_key, + ("credits.aleo", "transfer_public"), + vec![ + Value::Plaintext(Plaintext::from(Literal::Address(Address::try_from(key).unwrap()))), + Value::Plaintext(Plaintext::from(Literal::U64(U64::new(1_000_000_000_000)))), + ] + .iter(), + None, + 0, + None, + 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(); + assert!(aborted_transaction_ids.is_empty()); - // Pre-construct the necessary fee records. - let num_fee_records = test.programs().len() + test.cases().len(); - let mut fee_records = construct_fee_records(&vm, &genesis_private_key, records, num_fee_records, rng); + let block = construct_next_block( + &vm, + &genesis_private_key, + ratifications, + transactions, + aborted_transaction_ids, + ratified_finalize_operations, + rng, + ); + vm.add_next_block(&block.unwrap()).unwrap(); + } // Deploy the programs. for program in test.programs() { - let transaction = - match vm.deploy(&genesis_private_key, program, Some(fee_records.pop().unwrap().0), 0, None, rng) { - Ok(transaction) => transaction, - Err(error) => { - let mut output = serde_yaml::Mapping::new(); - output.insert( - serde_yaml::Value::String("errors".to_string()), - serde_yaml::Value::Sequence(vec![serde_yaml::Value::String(format!( - "Failed to run `VM::deploy for program {}: {}", - program.id(), - error - ))]), - ); - output.insert( - serde_yaml::Value::String("outputs".to_string()), - serde_yaml::Value::Sequence(Vec::new()), - ); - return output; - } - }; + let transaction = match vm.deploy(&genesis_private_key, program, None, 0, None, rng) { + Ok(transaction) => transaction, + Err(error) => { + let mut output = serde_yaml::Mapping::new(); + output.insert( + serde_yaml::Value::String("errors".to_string()), + serde_yaml::Value::Sequence(vec![serde_yaml::Value::String(format!( + "Failed to run `VM::deploy for program {}: {}", + program.id(), + error + ))]), + ); + output + .insert(serde_yaml::Value::String("outputs".to_string()), serde_yaml::Value::Sequence(Vec::new())); + return output; + } + }; let (ratifications, transactions, aborted_transaction_ids, ratified_finalize_operations) = vm.speculate(construct_finalize_global_state(&vm), Some(0u64), vec![], None, [transaction].iter()).unwrap(); @@ -168,25 +196,18 @@ fn run_test(test: &ProgramTest) -> serde_yaml::Mapping { let mut other = serde_yaml::Mapping::new(); // Execute the function, extracting the transaction. - let transaction = match vm.execute( - &private_key, - (program_id, function_name), - inputs.iter(), - Some(fee_records.pop().unwrap().0), - 0u64, - None, - rng, - ) { - Ok(transaction) => transaction, - // If the execution fails, return the error. - Err(err) => { - result.insert( - serde_yaml::Value::String("execute".to_string()), - serde_yaml::Value::String(err.to_string()), - ); - return (serde_yaml::Value::Mapping(result), serde_yaml::Value::Mapping(Default::default())); - } - }; + let transaction = + match vm.execute(&private_key, (program_id, function_name), inputs.iter(), None, 0u64, None, rng) { + Ok(transaction) => transaction, + // If the execution fails, return the error. + Err(err) => { + result.insert( + serde_yaml::Value::String("execute".to_string()), + serde_yaml::Value::String(err.to_string()), + ); + return (serde_yaml::Value::Mapping(result), serde_yaml::Value::Mapping(Default::default())); + } + }; // Attempt to verify the transaction. let verified = vm.check_transaction(&transaction, None).is_ok(); @@ -333,6 +354,7 @@ fn initialize_vm( } // A helper function construct the desired number of fee records from an initial record, all owned by the same key. +#[allow(unused)] fn construct_fee_records, R: Rng + CryptoRng>( vm: &VM, private_key: &PrivateKey, @@ -454,7 +476,7 @@ fn construct_next_block, R: Rng + CryptoRng> } // A helper function to invoke `credits.aleo/split`. -#[allow(clippy::type_complexity)] +#[allow(clippy::type_complexity, unused)] fn split, R: Rng + CryptoRng>( vm: &VM, private_key: &PrivateKey, diff --git a/synthesizer/tests/tests/vm/execute_and_finalize/external_read_with_local_fail.aleo b/synthesizer/tests/tests/vm/execute_and_finalize/external_read_with_local_fail.aleo new file mode 100644 index 0000000000..56a3c02c9b --- /dev/null +++ b/synthesizer/tests/tests/vm/execute_and_finalize/external_read_with_local_fail.aleo @@ -0,0 +1,38 @@ +/* +cases: [] +*/ + +program registry.aleo; + +mapping users: + key as address.public; + value as boolean.public; + +function register: + async register self.caller into r0; + output r0 as registry.aleo/register.future; + +finalize register: + input r0 as address.public; + set true into users[r0]; + + +///////////////////////////////////////////////// + +import registry.aleo; + +program relay.aleo; + +mapping users: + key as address.public; + value as boolean.public; + +function send: + input r0 as address.public; + async send r0 into r1; + output r1 as relay.aleo/send.future; + +finalize send: + input r0 as address.public; + get relay.aleo/users[r0] into r1; + assert.eq r1 true; diff --git a/synthesizer/tests/tests/vm/execute_and_finalize/mint_and_split.aleo b/synthesizer/tests/tests/vm/execute_and_finalize/mint_and_split.aleo index 3d69f3c955..c8163d2990 100644 --- a/synthesizer/tests/tests/vm/execute_and_finalize/mint_and_split.aleo +++ b/synthesizer/tests/tests/vm/execute_and_finalize/mint_and_split.aleo @@ -1,5 +1,8 @@ /* randomness: 1337 +keys: + - APrivateKey1zkpFbGDx4znwxo1zrxfUscfGn1Vy3My3ia5gRHx3XwaLtCR + - APrivateKey1zkpJhviKDvvm7yu7SZuhSudVR7zjCRG2HznuAHwuGYc1xqN cases: - program: mint_and_split.aleo function: mint diff --git a/synthesizer/tests/tests/vm/execute_and_finalize/no_import_external_read_fail.aleo b/synthesizer/tests/tests/vm/execute_and_finalize/no_import_external_read_fail.aleo new file mode 100644 index 0000000000..3a64c123d1 --- /dev/null +++ b/synthesizer/tests/tests/vm/execute_and_finalize/no_import_external_read_fail.aleo @@ -0,0 +1,32 @@ +/* +cases: [] +*/ + +program registry.aleo; + +mapping users: + key as address.public; + value as boolean.public; + +function register: + async register self.caller into r0; + output r0 as registry.aleo/register.future; + +finalize register: + input r0 as address.public; + set true into users[r0]; + + +///////////////////////////////////////////////// + +program relay.aleo; + +function send: + input r0 as address.public; + async send r0 into r1; + output r1 as relay.aleo/send.future; + +finalize send: + input r0 as address.public; + get registry.aleo/users[r0] into r1; + assert.eq r1 true; diff --git a/synthesizer/tests/tests/vm/execute_and_finalize/read_external_mapping.aleo b/synthesizer/tests/tests/vm/execute_and_finalize/read_external_mapping.aleo new file mode 100644 index 0000000000..20ad427064 --- /dev/null +++ b/synthesizer/tests/tests/vm/execute_and_finalize/read_external_mapping.aleo @@ -0,0 +1,84 @@ +/* +randomness: 9086185409 +keys: + - APrivateKey1zkpABon5degxuW8JnBniSXgN1C4eAGKfDH8qRPZe1geHpWp +cases: + - program: relay.aleo + function: send + inputs: [aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm, 0u8] + - program: relay.aleo + function: send_without_check + inputs: [aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm, 0u8] + - program: registry.aleo + function: register + inputs: [] + private_key: APrivateKey1zkpABon5degxuW8JnBniSXgN1C4eAGKfDH8qRPZe1geHpWp + - program: relay.aleo + function: send + inputs: [aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm, 1u8] + - program: registry.aleo + function: unregister + inputs: [] + private_key: APrivateKey1zkpABon5degxuW8JnBniSXgN1C4eAGKfDH8qRPZe1geHpWp + - program: relay.aleo + function: send + inputs: [aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm, 2u8] +*/ + +program registry.aleo; + +mapping users: + key as address.public; + value as boolean.public; + +function register: + async register self.caller into r0; + output r0 as registry.aleo/register.future; + +finalize register: + input r0 as address.public; + set true into users[r0]; + +function unregister: + async unregister self.caller into r0; + output r0 as registry.aleo/unregister.future; + +finalize unregister: + input r0 as address.public; + set false into users[r0]; + +///////////////////////////////////////////////// + +import registry.aleo; + +program relay.aleo; + +record message: + owner as address.private; + data as u8.private; + +function send: + input r0 as address.public; + input r1 as u8.public; + cast r0 r1 into r2 as message.record; + async send r0 into r3; + output r2 as message.record; + output r3 as relay.aleo/send.future; + +finalize send: + input r0 as address.public; + get registry.aleo/users[r0] into r1; + assert.eq r1 true; + +function send_without_check: + input r0 as address.public; + input r1 as u8.public; + cast r0 r1 into r2 as message.record; + async send_without_check r0 into r3; + output r2 as message.record; + output r3 as relay.aleo/send_without_check.future; + +finalize send_without_check: + input r0 as address.public; + get.or_use registry.aleo/users[r0] true into r1; + assert.eq r1 true; diff --git a/synthesizer/tests/tests/vm/execute_and_finalize/unknown_external_mapping_fail.aleo b/synthesizer/tests/tests/vm/execute_and_finalize/unknown_external_mapping_fail.aleo new file mode 100644 index 0000000000..05397274d7 --- /dev/null +++ b/synthesizer/tests/tests/vm/execute_and_finalize/unknown_external_mapping_fail.aleo @@ -0,0 +1,34 @@ +/* +cases: [] +*/ + +program registry.aleo; + +mapping users: + key as address.public; + value as boolean.public; + +function register: + async register self.caller into r0; + output r0 as registry.aleo/register.future; + +finalize register: + input r0 as address.public; + set true into users[r0]; + + +///////////////////////////////////////////////// + +import registry.aleo; + +program relay.aleo; + +function send: + input r0 as address.public; + async send r0 into r1; + output r1 as relay.aleo/send.future; + +finalize send: + input r0 as address.public; + get registry.aleo/foo[r0] into r1; + assert.eq r1 true; diff --git a/synthesizer/tests/tests/vm/execute_and_finalize/unknown_mapping_fail.aleo b/synthesizer/tests/tests/vm/execute_and_finalize/unknown_mapping_fail.aleo new file mode 100644 index 0000000000..f344a08a36 --- /dev/null +++ b/synthesizer/tests/tests/vm/execute_and_finalize/unknown_mapping_fail.aleo @@ -0,0 +1,18 @@ +/* +cases: [] +*/ + +program registry.aleo; + +mapping users: + key as address.public; + value as boolean.public; + +function register: + async register self.caller into r0; + output r0 as registry.aleo/register.future; + +finalize register: + input r0 as address.public; + set true into foo[r0]; + diff --git a/synthesizer/tests/utilities/tests/program_test.rs b/synthesizer/tests/utilities/tests/program_test.rs index 77a031aa92..71290b0a0b 100644 --- a/synthesizer/tests/utilities/tests/program_test.rs +++ b/synthesizer/tests/utilities/tests/program_test.rs @@ -43,6 +43,8 @@ pub struct ProgramTest { rewrite: bool, /// The seed for the RNG. randomness: Option, + /// Additional keys for the test. + keys: Vec>, } impl ProgramTest { @@ -60,6 +62,11 @@ impl ProgramTest { pub fn randomness(&self) -> Option { self.randomness } + + /// Returns the additional keys for the test. + pub fn keys(&self) -> &[PrivateKey] { + &self.keys + } } impl ExpectedTest for ProgramTest { @@ -79,12 +86,25 @@ impl ExpectedTest for ProgramTest { let comment = &source[first_comment_start + 2..first_comment_start + 2 + end_first_comment]; // Parse the comment into the test configuration. - println!("comment: {}", comment); let test_config = serde_yaml::from_str::(comment).expect("invalid test configuration"); // If the `randomness` field is present in the config, parse it as a `u64`. let randomness = test_config.get("randomness").map(|value| value.as_u64().expect("`randomness` must be a u64")); + // If the `keys` field is present in the config, parse it as a sequence of `PrivateKey`s. + let keys = match test_config.get("keys") { + None => Vec::new(), + Some(value) => value + .as_sequence() + .expect("`keys` must be a sequence") + .iter() + .map(|value| { + PrivateKey::::from_str(value.as_str().expect("private key must be a string")) + .expect("invalid private key") + }) + .collect::>(), + }; + // Extract the test cases from the config. let cases = test_config .get("cases") @@ -110,7 +130,7 @@ impl ExpectedTest for ProgramTest { } }; - Self { programs, cases, expected, path, rewrite, randomness } + Self { programs, cases, expected, path, rewrite, randomness, keys } } fn check(&self, output: &Self::Output) -> Result<()> {