From 8ace3471176fc232ada1be3b75576232384d18a9 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Wed, 25 Oct 2023 12:50:18 +0200 Subject: [PATCH 01/20] tests: remove flakiness caused by subslice assertions Signed-off-by: ljedrz --- console/program/src/data/ciphertext/bytes.rs | 1 - console/program/src/data/future/bytes.rs | 1 - console/program/src/data/identifier/bytes.rs | 1 - console/program/src/data/literal/bytes.rs | 2 -- console/program/src/data/plaintext/bytes.rs | 5 ----- console/program/src/data/record/bytes.rs | 1 - console/program/src/data/value/bytes.rs | 2 -- console/program/src/request/bytes.rs | 4 ---- console/program/src/state_path/header_leaf/bytes.rs | 4 ---- console/program/src/state_path/transaction_leaf/bytes.rs | 4 ---- console/program/src/state_path/transition_leaf/bytes.rs | 4 ---- console/types/string/src/bytes.rs | 1 - ledger/authority/src/bytes.rs | 5 +---- ledger/block/src/bytes.rs | 2 -- ledger/block/src/ratifications/bytes.rs | 4 ---- ledger/block/src/ratify/bytes.rs | 4 ---- ledger/block/src/transaction/bytes.rs | 4 ---- ledger/block/src/transaction/deployment/bytes.rs | 4 ---- ledger/block/src/transaction/execution/bytes.rs | 4 ---- ledger/block/src/transaction/fee/bytes.rs | 5 ----- ledger/block/src/transactions/bytes.rs | 4 ---- ledger/block/src/transactions/confirmed/bytes.rs | 4 ---- ledger/block/src/transactions/rejected/bytes.rs | 4 ---- ledger/block/src/transition/bytes.rs | 4 ---- ledger/block/src/transition/input/bytes.rs | 4 ---- ledger/block/src/transition/output/bytes.rs | 4 ---- ledger/committee/src/bytes.rs | 4 ---- ledger/narwhal/batch-certificate/src/bytes.rs | 4 ---- ledger/narwhal/batch-header/src/bytes.rs | 4 ---- ledger/narwhal/subdag/src/bytes.rs | 4 ---- ledger/narwhal/transmission/src/bytes.rs | 4 ---- synthesizer/process/src/stack/authorization/bytes.rs | 4 ---- synthesizer/program/src/logic/instruction/operation/call.rs | 1 - synthesizer/snark/src/certificate/bytes.rs | 4 ---- synthesizer/snark/src/proof/bytes.rs | 4 ---- 35 files changed, 1 insertion(+), 118 deletions(-) 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..7342dd07ab 100644 --- a/console/program/src/data/identifier/bytes.rs +++ b/console/program/src/data/identifier/bytes.rs @@ -72,7 +72,6 @@ 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(()) } 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/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 d7dbd25dc2..aa204b010c 100644 --- a/ledger/narwhal/batch-certificate/src/bytes.rs +++ b/ledger/narwhal/batch-certificate/src/bytes.rs @@ -70,9 +70,6 @@ impl ToBytes for BatchCertificate { #[cfg(test)] mod tests { use super::*; - use console::network::Testnet3; - - type CurrentNetwork = Testnet3; #[test] fn test_bytes() { @@ -82,7 +79,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/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/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(()) } From 31661bd3047f2820a2c49d074b18349f3e70fec7 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Fri, 27 Oct 2023 10:24:47 +0200 Subject: [PATCH 02/20] tests: remove confirmed flakiness caused by subslice assertions Signed-off-by: ljedrz --- ledger/narwhal/transmission-id/src/bytes.rs | 4 ---- synthesizer/program/src/logic/finalize_operation/bytes.rs | 4 ---- 2 files changed, 8 deletions(-) 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/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()); } } } From 4ae1043a6acb65aef435bf57df29f04d96043b5d Mon Sep 17 00:00:00 2001 From: Sukey <35202440+sukey2008@users.noreply.github.com> Date: Sat, 28 Oct 2023 22:46:16 +0200 Subject: [PATCH 03/20] fix minor typo Signed-off-by: Sukey <35202440+sukey2008@users.noreply.github.com> --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From dc2f4ba0d3bcdbdc4accf91bc238d86b29806b65 Mon Sep 17 00:00:00 2001 From: Alessandro Coglio Date: Sat, 28 Oct 2023 14:11:07 -0700 Subject: [PATCH 04/20] Fix variable name and comments. --- console/types/scalar/src/from_bits.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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"))? }) From 32f49653f41a8a5e9f04b1c84e83c06e8a8ca3c4 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu Date: Mon, 23 Oct 2023 21:08:02 -0400 Subject: [PATCH 05/20] WIP --- .../src/stack/finalize_types/initialize.rs | 98 +++++++++++++++---- synthesizer/program/src/logic/command/get.rs | 36 ++++--- .../program/src/logic/command/get_or_use.rs | 36 +++++-- 3 files changed, 128 insertions(+), 42 deletions(-) diff --git a/synthesizer/process/src/stack/finalize_types/initialize.rs b/synthesizer/process/src/stack/finalize_types/initialize.rs index 77c1ee2893..bab87294a9 100644 --- a/synthesizer/process/src/stack/finalize_types/initialize.rs +++ b/synthesizer/process/src/stack/finalize_types/initialize.rs @@ -17,6 +17,7 @@ use crate::RegisterTypes; use synthesizer_program::{ Await, Branch, + CallOperator, CastType, Contains, Get, @@ -174,7 +175,7 @@ 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::Get(get) => self.check_get(stack, get)?, Command::GetOrUse(get_or_use) => self.check_get_or_use(stack, finalize.name(), 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)?, @@ -287,19 +288,44 @@ 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() { + CallOperator::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 program."); + } + // 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. + // Note that the unwrap is safe, as we have already checked the mapping exists. + external.get_mapping(mapping_name).unwrap() + } + CallOperator::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. + // Note that the unwrap is safe, as we have already checked the mapping exists. + stack.program().get_mapping(mapping_name).unwrap() + } + }; + // Get the mapping key type. let mapping_key_type = mapping.key().plaintext_type(); // Get the mapping value type. @@ -332,13 +358,43 @@ impl FinalizeTypes { 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() { + CallOperator::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 program."); + } + // 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. + // Note that the unwrap is safe, as we have already checked the mapping exists. + external.get_mapping(mapping_name).unwrap() + } + CallOperator::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. + // Note that the unwrap is safe, as we have already checked the mapping exists. + stack.program().get_mapping(mapping_name).unwrap() + } + }; + // Get the mapping key type. let mapping_key_type = mapping.key().plaintext_type(); // Get the mapping value type. diff --git a/synthesizer/program/src/logic/command/get.rs b/synthesizer/program/src/logic/command/get.rs index fc698a0969..2af220ab64 100644 --- a/synthesizer/program/src/logic/command/get.rs +++ b/synthesizer/program/src/logic/command/get.rs @@ -14,12 +14,13 @@ use crate::{ traits::{FinalizeStoreTrait, RegistersLoad, RegistersStore, StackMatches, StackProgram}, + CallOperator, Opcode, Operand, }; use console::{ network::prelude::*, - program::{Identifier, Register, Value}, + program::{Register, Value}, }; /// A get command, e.g. `get accounts[r0] into r1;`. @@ -27,7 +28,7 @@ use console::{ #[derive(Clone, PartialEq, Eq, Hash)] pub struct Get { /// The mapping name. - mapping: Identifier, + mapping: CallOperator, /// The key to access the mapping. key: Operand, /// The destination register. @@ -47,9 +48,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) -> &CallOperator { &self.mapping } @@ -75,21 +76,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 { + CallOperator::Locator(locator) => (*locator.program_id(), *locator.resource()), + CallOperator::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 +118,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) = CallOperator::parse(string)?; // Parse the "[" from the string. let (string, _) = tag("[")(string)?; // Parse the whitespace from the string. @@ -182,7 +189,7 @@ 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)?; + let mapping = CallOperator::read_le(&mut reader)?; // Read the key operand. let key = Operand::read_le(&mut reader)?; // Read the destination register. @@ -215,7 +222,14 @@ mod tests { 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, CallOperator::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, CallOperator::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"); diff --git a/synthesizer/program/src/logic/command/get_or_use.rs b/synthesizer/program/src/logic/command/get_or_use.rs index 27c0e6faec..15ed3365f4 100644 --- a/synthesizer/program/src/logic/command/get_or_use.rs +++ b/synthesizer/program/src/logic/command/get_or_use.rs @@ -14,12 +14,13 @@ use crate::{ traits::{FinalizeStoreTrait, RegistersLoad, RegistersStore, StackMatches, StackProgram}, + CallOperator, Opcode, Operand, }; use console::{ network::prelude::*, - program::{Identifier, Register, Value}, + program::{Register, Value}, }; /// A get command that uses the provided default in case of failure, e.g. `get.or_use accounts[r0] r1 into r2;`. @@ -28,7 +29,7 @@ use console::{ #[derive(Clone, PartialEq, Eq, Hash)] pub struct GetOrUse { /// The mapping name. - mapping: Identifier, + mapping: CallOperator, /// The key to access the mapping. key: Operand, /// The default value. @@ -50,9 +51,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) -> &CallOperator { &self.mapping } @@ -84,16 +85,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 { + CallOperator::Locator(locator) => (*locator.program_id(), *locator.resource()), + CallOperator::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 +128,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) = CallOperator::parse(string)?; // Parse the "[" from the string. let (string, _) = tag("[")(string)?; // Parse the whitespace from the string. @@ -196,7 +203,7 @@ 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)?; + let mapping = CallOperator::read_le(&mut reader)?; // Read the key operand. let key = Operand::read_le(&mut reader)?; // Read the default value. @@ -233,7 +240,16 @@ mod tests { 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, CallOperator::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, CallOperator::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"); From 884507837ddff5c86ae4bac00574fa166186b967 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu Date: Thu, 26 Oct 2023 19:26:01 -0400 Subject: [PATCH 06/20] Use public fees in integration tests; fund user defined private keys --- .../tests/test_vm_execute_and_finalize.rs | 110 +++++++++++------- .../tests/utilities/tests/program_test.rs | 26 ++++- 2 files changed, 90 insertions(+), 46 deletions(-) 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/utilities/tests/program_test.rs b/synthesizer/tests/utilities/tests/program_test.rs index 77a031aa92..64607f26f3 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,27 @@ 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 +132,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<()> { From aa925ab1f1d897ffefc9fc58e70f3f8819bf272b Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu Date: Thu, 26 Oct 2023 19:26:41 -0400 Subject: [PATCH 07/20] Add tests using external mappings --- .../execute_and_finalize/mint_and_split.aleo | 3 + .../read_external_mapping.aleo | 68 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 synthesizer/tests/tests/vm/execute_and_finalize/read_external_mapping.aleo 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/read_external_mapping.aleo b/synthesizer/tests/tests/vm/execute_and_finalize/read_external_mapping.aleo new file mode 100644 index 0000000000..a8c5185d59 --- /dev/null +++ b/synthesizer/tests/tests/vm/execute_and_finalize/read_external_mapping.aleo @@ -0,0 +1,68 @@ +/* +randomness: 9086185409 +keys: + - APrivateKey1zkpABon5degxuW8JnBniSXgN1C4eAGKfDH8qRPZe1geHpWp +cases: + - program: relay.aleo + function: send + 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; From f226eb56746df23ffeeca1f5ab5ec7c6cdc0ec95 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu Date: Thu, 26 Oct 2023 19:42:48 -0400 Subject: [PATCH 08/20] Add negative tests --- .../src/stack/finalize_types/initialize.rs | 3 +- .../read_external_mapping.out | 61 +++++++++++++++++++ .../no_import_external_read_fail.aleo | 32 ++++++++++ .../unknown_external_mapping_fail.aleo | 34 +++++++++++ .../unknown_mapping_fail.aleo | 18 ++++++ .../tests/utilities/tests/program_test.rs | 20 +++--- 6 files changed, 155 insertions(+), 13 deletions(-) create mode 100644 synthesizer/tests/expectations/vm/execute_and_finalize/read_external_mapping.out create mode 100644 synthesizer/tests/tests/vm/execute_and_finalize/no_import_external_read_fail.aleo create mode 100644 synthesizer/tests/tests/vm/execute_and_finalize/unknown_external_mapping_fail.aleo create mode 100644 synthesizer/tests/tests/vm/execute_and_finalize/unknown_mapping_fail.aleo diff --git a/synthesizer/process/src/stack/finalize_types/initialize.rs b/synthesizer/process/src/stack/finalize_types/initialize.rs index bab87294a9..eae60281de 100644 --- a/synthesizer/process/src/stack/finalize_types/initialize.rs +++ b/synthesizer/process/src/stack/finalize_types/initialize.rs @@ -176,7 +176,7 @@ impl FinalizeTypes { 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, get)?, - Command::GetOrUse(get_or_use) => self.check_get_or_use(stack, finalize.name(), get_or_use)?, + 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)?, @@ -355,7 +355,6 @@ impl FinalizeTypes { fn check_get_or_use( &mut self, stack: &(impl StackMatches + StackProgram), - finalize_name: &Identifier, get_or_use: &GetOrUse, ) -> Result<()> { // Retrieve the mapping. 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..277a2e1bcd --- /dev/null +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/read_external_mapping.out @@ -0,0 +1,61 @@ +errors: [] +outputs: +- verified: true + execute: + relay.aleo/send: + outputs: + - '{"type":"record","id":"2317537586898875003527911595881250652314627769570172347256550518017872557697field","checksum":"5016557145498331574642320031968331291285347334593139541782766783223318670648field","value":"record1qyqsp8ch07pqnhwum52l685x8yelm2xhwevs9lh9gfmx2zpz26kff5g0qyzxgct5vy3sqqspqz337ysk89zjy89u65led0e7y0wj7p5ejdwhatq68zcdagqkwl9sdnqms8z3y6lnck4kzukmh5769mg0933thnfetskqguycewflh4qflw82vn"}' + - '{"type":"future","id":"6060171713510534514143443306903785915198276713047207513053052324882806972526field","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: + registry.aleo/register: + outputs: + - '{"type":"future","id":"4912027766578041258717763414531570075203769145029783107169756543671526859063field","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":"7570363776723556048515317606603820932475200424645714329992113285075479807481field","checksum":"2640827483033329518607665013126665825734877898317823925445957258899070118927field","value":"record1qyqsqhp6suzyvpvf5cqtf8k5lj7j6vgljvn83knvx6z429zhxp5fgmqdqyzxgct5vy3sqqspqqj9pn534vyqvqvfk5lygrc7cqj6rx8tcmgdkmus0kfw9y5csygqdmx09zv7xawh9s9e7d2x5l6j20wfxuk4r9z6vtrg7gh7q6pv3tg8xfuuru"}' + - '{"type":"future","id":"8396346733807272095051892936411848657999314439834335427243101849411797227479field","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":"4916621928718597326453327850342432807913183863515286820927876893411281241764field","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":"5530328758191127651605502960961789058994029742872360714815774182797261982763field","checksum":"2945321521037774393869829376179129152338156532812236337422211831315443690211field","value":"record1qyqsqel2rux546nzp57eh38k24xfflptvpyzegcxxwugj097vkvjukstqyzxgct5vy3sqqspqzhhjatdt09f8lxsaukt4njxeql4my8p86fw2r4jxc3scdez8asqs3hpuh9taf46gyltxxh22qp9x4xzjtmaq0ung8adtumsw94cecs0x0xqkl"}' + - '{"type":"future","id":"6830445503994857147753329697934978051706269651779887682757924869644027854312field","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":"4960890695745452772232908991619728704202417459002410486474521601906731342806field","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":"8430479447748956098157716177872888769234364744387596392617360355542856164660field","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":"4502206432380012456604755847468214248986763931949891558228458881027814975027field","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":"3161662896320756371352352358177196789819155276370479628395808356491575243730field","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":"7835046846960912856976978166201827944679821834273867346502722712552318601688field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1xe2fps8f9xpdas2q0fqy22uraenk84tvvzetrsyxgnwy6445h59s6wv78x,\n 28479u64\n ]\n}"}' 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/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 64607f26f3..71290b0a0b 100644 --- a/synthesizer/tests/utilities/tests/program_test.rs +++ b/synthesizer/tests/utilities/tests/program_test.rs @@ -94,17 +94,15 @@ impl ExpectedTest for ProgramTest { // 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::>() - } + 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. From 47355a52b95345e9a3df75adbdf97bee8b17bc47 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu Date: Thu, 26 Oct 2023 19:59:36 -0400 Subject: [PATCH 09/20] Regen expectations --- .../src/stack/finalize_types/initialize.rs | 2 +- .../arrays_in_finalize.out | 14 +++++----- .../execute_and_finalize/child_and_parent.out | 24 ++++++++-------- .../complex_finalization.out | 14 +++++----- .../vm/execute_and_finalize/count_usages.out | 16 +++++------ .../vm/execute_and_finalize/hello.out | 28 +++++++++---------- .../mapping_operations.out | 24 ++++++++-------- .../execute_and_finalize/mint_and_split.out | 6 ++-- .../no_import_external_read_fail.out | 3 ++ .../execute_and_finalize/program_callable.out | 16 +++++------ .../vm/execute_and_finalize/public_wallet.out | 8 +++--- .../vm/execute_and_finalize/test_branch.out | 18 ++++++------ .../vm/execute_and_finalize/test_rand.out | 26 ++++++++--------- .../vm/execute_and_finalize/timelock.out | 12 ++++---- .../unknown_external_mapping_fail.out | 3 ++ .../unknown_mapping_fail.out | 3 ++ .../execute_and_finalize/unused_position.out | 6 ++-- .../vm/execute_and_finalize/user_callable.out | 8 +++--- 18 files changed, 120 insertions(+), 111 deletions(-) create mode 100644 synthesizer/tests/expectations/vm/execute_and_finalize/no_import_external_read_fail.out create mode 100644 synthesizer/tests/expectations/vm/execute_and_finalize/unknown_external_mapping_fail.out create mode 100644 synthesizer/tests/expectations/vm/execute_and_finalize/unknown_mapping_fail.out diff --git a/synthesizer/process/src/stack/finalize_types/initialize.rs b/synthesizer/process/src/stack/finalize_types/initialize.rs index eae60281de..db664b0a0d 100644 --- a/synthesizer/process/src/stack/finalize_types/initialize.rs +++ b/synthesizer/process/src/stack/finalize_types/initialize.rs @@ -303,7 +303,7 @@ impl FinalizeTypes { } // 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}'."); + bail!("External program '{program_id}' is not imported by '{}'.", stack.program_id()); } // Retrieve the program. let external = stack.get_external_program(program_id)?; 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 a33be90307..919b9291a5 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":"994990058621570799386345097567825463488929977263218477287025824851872546446field","value":"aleo16w8t56s7v6ud7vu33fr388ph0dq0c7yhp597cyjt88rr3nultcyqcyk9yy"}' - - '{"type":"public","id":"2256104170911230762284986427287133867149405204422634231010917189963141359010field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' - credits.aleo/fee_private: + - '{"type":"public","id":"2459501703788162014390032218062615187041680109741533589876416940768900522799field","value":"aleo16w8t56s7v6ud7vu33fr388ph0dq0c7yhp597cyjt88rr3nultcyqcyk9yy"}' + - '{"type":"public","id":"4059102611680484817772932189626681723346184344473090391520905329315796272971field","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 62b00223bd..16fed64edf 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":"6952696836717992189844193836164206763601783392883300349164619423689411832957field","value":"{\n program_id: zero_program.aleo,\n function_name: c,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n}"}' + - '{"type":"future","id":"868980695576387061465481340013995581415399669646103119988420471982198353684field","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":"3375358791246667464469024643039205630228640255715459354259647324302115771724field","value":"{\n program_id: one_program.aleo,\n function_name: d,\n arguments: [\n aleo1kw4knandael9qcpxs6g36rr6h7dwvjz6q25ueah6zz9v57zjlvxsx5llq8\n ]\n}"}' + - '{"type":"future","id":"7019513656735375987781202584670889731433817481734857255379784812609399295012field","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":"364582187421035500339943835636532028870700065252111564274460853535036892560field","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":"3159380222510695027024010240323042120907966737357325980281186387999863524975field","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":"5353639949292491626228591653810953466693160316414035702266036019526362677427field","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":"2107445810553019850887004032370986179841471500877564050507038295661575797827field","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 3a80e7786a..7933b15076 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":"2189963205002380951731804610675645921799015755766185151265166514396381689207field","value":"ciphertext1qyqwpu5p92d4lrcfhthx0emqpj6cldsty3ghv6mhztl69wyk7j42cpqpq2uaz"}' - - '{"type":"future","id":"1762068320811124981245699286589805951610339834807816585249322967070273785765field","value":"{\n program_id: basic_math.aleo,\n function_name: add_and_count,\n arguments: [\n aleo1mrughg5ssadd9fc2uwve7l6u24xn76kyz24zsjtzta03vgkq4vpqggl6fg\n ]\n}"}' + - '{"type":"private","id":"2687119938526671223430712275520099287526474990567687943355031309835685603554field","value":"ciphertext1qyqp0gkmren9kcflhxpg3v9e2cw97um7lu4tfwuh7w5h5nk4mpvjjpquaydnu"}' + - '{"type":"future","id":"4247717008565083288734190529633596823232122291180671236322823911170152094500field","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":"3237068809383979468892967123729721371250496145349751597456577370896562797315field","value":"ciphertext1qyqrqc0329zggejxfkdju3e5ng8cahudh6gmmwcu9kvhp2x784lrqqgfua69p"}' - - '{"type":"future","id":"4237975671848212071086918441612015189870459327089330453971374309755212325698field","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":"7992464697490466293984943598604231412571016633865588345761260178196099457747field","value":"ciphertext1qyqxeag0ujtnn39yp0x9qryt77fkcklyc466cp3l7g8wgt4524jngzqz5ask9"}' + - '{"type":"future","id":"6594089907002769296322737141374301940875927088813929000246625002187630516842field","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/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 150420a0fa..17a70a1d39 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":"5601132905719769837487481041811167147031721408864816226961174115045250639394field","value":"aleo16w8t56s7v6ud7vu33fr388ph0dq0c7yhp597cyjt88rr3nultcyqcyk9yy"}' - - '{"type":"public","id":"4866955403610457225216600968672882719581841491915839063024906456611968828355field","value":"aleo1qr2ha4pfs5l28aze88yn6fhleeythklkczrule2v838uwj65n5gqxt9djx"}' - credits.aleo/fee_private: + - '{"type":"public","id":"6570086835149819439219303224003492878705751026121012692011734299993965867007field","value":"aleo16w8t56s7v6ud7vu33fr388ph0dq0c7yhp597cyjt88rr3nultcyqcyk9yy"}' + - '{"type":"public","id":"2866009676898789345591427281882170655806617413858789892357234972821058149651field","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 83bd95ab4c..1276dd48c4 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":"4537627763763327286502315223758961709385837795977680378235435937164895010454field","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":"3687815127788961249655268422309693065088885703875160126919606715756865244929field","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/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 f31addd98f..d1a041cc47 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}"}' - speculate: the execution was rejected + - '{"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}"}' + - '{"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 rejected 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}"}' - {} From 7c8fa073bf4e753ba63623b0ab6d3b80bac01269 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu Date: Thu, 26 Oct 2023 20:13:50 -0400 Subject: [PATCH 10/20] Improve test --- .../read_external_mapping.out | 38 ++++++++++++------- .../read_external_mapping.aleo | 16 ++++++++ 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/read_external_mapping.out b/synthesizer/tests/expectations/vm/execute_and_finalize/read_external_mapping.out index 277a2e1bcd..a729b3163e 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/read_external_mapping.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/read_external_mapping.out @@ -4,58 +4,70 @@ outputs: execute: relay.aleo/send: outputs: - - '{"type":"record","id":"2317537586898875003527911595881250652314627769570172347256550518017872557697field","checksum":"5016557145498331574642320031968331291285347334593139541782766783223318670648field","value":"record1qyqsp8ch07pqnhwum52l685x8yelm2xhwevs9lh9gfmx2zpz26kff5g0qyzxgct5vy3sqqspqz337ysk89zjy89u65led0e7y0wj7p5ejdwhatq68zcdagqkwl9sdnqms8z3y6lnck4kzukmh5769mg0933thnfetskqguycewflh4qflw82vn"}' - - '{"type":"future","id":"6060171713510534514143443306903785915198276713047207513053052324882806972526field","value":"{\n program_id: relay.aleo,\n function_name: send,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm\n ]\n}"}' + - '{"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":"4912027766578041258717763414531570075203769145029783107169756543671526859063field","value":"{\n program_id: registry.aleo,\n function_name: register,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm\n ]\n}"}' + - '{"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":"7570363776723556048515317606603820932475200424645714329992113285075479807481field","checksum":"2640827483033329518607665013126665825734877898317823925445957258899070118927field","value":"record1qyqsqhp6suzyvpvf5cqtf8k5lj7j6vgljvn83knvx6z429zhxp5fgmqdqyzxgct5vy3sqqspqqj9pn534vyqvqvfk5lygrc7cqj6rx8tcmgdkmus0kfw9y5csygqdmx09zv7xawh9s9e7d2x5l6j20wfxuk4r9z6vtrg7gh7q6pv3tg8xfuuru"}' - - '{"type":"future","id":"8396346733807272095051892936411848657999314439834335427243101849411797227479field","value":"{\n program_id: relay.aleo,\n function_name: send,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm\n ]\n}"}' + - '{"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":"4916621928718597326453327850342432807913183863515286820927876893411281241764field","value":"{\n program_id: registry.aleo,\n function_name: unregister,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm\n ]\n}"}' + - '{"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":"5530328758191127651605502960961789058994029742872360714815774182797261982763field","checksum":"2945321521037774393869829376179129152338156532812236337422211831315443690211field","value":"record1qyqsqel2rux546nzp57eh38k24xfflptvpyzegcxxwugj097vkvjukstqyzxgct5vy3sqqspqzhhjatdt09f8lxsaukt4njxeql4my8p86fw2r4jxc3scdez8asqs3hpuh9taf46gyltxxh22qp9x4xzjtmaq0ung8adtumsw94cecs0x0xqkl"}' - - '{"type":"future","id":"6830445503994857147753329697934978051706269651779887682757924869644027854312field","value":"{\n program_id: relay.aleo,\n function_name: send,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm\n ]\n}"}' + - '{"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":"4960890695745452772232908991619728704202417459002410486474521601906731342806field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1xe2fps8f9xpdas2q0fqy22uraenk84tvvzetrsyxgnwy6445h59s6wv78x,\n 28479u64\n ]\n}"}' + - '{"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":"8430479447748956098157716177872888769234364744387596392617360355542856164660field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm,\n 101210u64\n ]\n}"}' + - '{"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":"4502206432380012456604755847468214248986763931949891558228458881027814975027field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1xe2fps8f9xpdas2q0fqy22uraenk84tvvzetrsyxgnwy6445h59s6wv78x,\n 28479u64\n ]\n}"}' + - '{"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":"3161662896320756371352352358177196789819155276370479628395808356491575243730field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1f6eg623knp66cwx0926w3plgdgzcmfpgyrzgnjz90mucgs3z7s9qls4upm,\n 101214u64\n ]\n}"}' + - '{"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":"7835046846960912856976978166201827944679821834273867346502722712552318601688field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1xe2fps8f9xpdas2q0fqy22uraenk84tvvzetrsyxgnwy6445h59s6wv78x,\n 28479u64\n ]\n}"}' + - '{"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/tests/vm/execute_and_finalize/read_external_mapping.aleo b/synthesizer/tests/tests/vm/execute_and_finalize/read_external_mapping.aleo index a8c5185d59..20ad427064 100644 --- a/synthesizer/tests/tests/vm/execute_and_finalize/read_external_mapping.aleo +++ b/synthesizer/tests/tests/vm/execute_and_finalize/read_external_mapping.aleo @@ -6,6 +6,9 @@ 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: [] @@ -66,3 +69,16 @@ 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; From d7ee8692d1c3adac2260bc5b5db9486c3a903463 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu Date: Thu, 26 Oct 2023 20:36:04 -0400 Subject: [PATCH 11/20] Add negative test --- .../src/stack/finalize_types/initialize.rs | 4 +- synthesizer/program/src/logic/command/get.rs | 2 +- .../program/src/logic/command/get_or_use.rs | 2 +- .../external_read_with_local_fail.out | 3 ++ .../external_read_with_local_fail.aleo | 38 +++++++++++++++++++ 5 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 synthesizer/tests/expectations/vm/execute_and_finalize/external_read_with_local_fail.out create mode 100644 synthesizer/tests/tests/vm/execute_and_finalize/external_read_with_local_fail.aleo diff --git a/synthesizer/process/src/stack/finalize_types/initialize.rs b/synthesizer/process/src/stack/finalize_types/initialize.rs index db664b0a0d..ce6ccb0ee7 100644 --- a/synthesizer/process/src/stack/finalize_types/initialize.rs +++ b/synthesizer/process/src/stack/finalize_types/initialize.rs @@ -299,7 +299,7 @@ impl FinalizeTypes { // Ensure the locator does not reference the current program. if stack.program_id() == program_id { - bail!("Locator '{locator}' does not reference an external program."); + 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) { @@ -367,7 +367,7 @@ impl FinalizeTypes { // Ensure the locator does not reference the current program. if stack.program_id() == program_id { - bail!("Locator '{locator}' does not reference an external program."); + 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) { diff --git a/synthesizer/program/src/logic/command/get.rs b/synthesizer/program/src/logic/command/get.rs index 2af220ab64..8122d7998c 100644 --- a/synthesizer/program/src/logic/command/get.rs +++ b/synthesizer/program/src/logic/command/get.rs @@ -48,7 +48,7 @@ impl Get { vec![self.key.clone()] } - /// Returns the mapping. + /// Returns the mapping name. #[inline] pub const fn mapping(&self) -> &CallOperator { &self.mapping diff --git a/synthesizer/program/src/logic/command/get_or_use.rs b/synthesizer/program/src/logic/command/get_or_use.rs index 15ed3365f4..26c74ff5c0 100644 --- a/synthesizer/program/src/logic/command/get_or_use.rs +++ b/synthesizer/program/src/logic/command/get_or_use.rs @@ -51,7 +51,7 @@ impl GetOrUse { vec![self.key.clone(), self.default.clone()] } - /// Returns the mapping. + /// Returns the mapping name. #[inline] pub const fn mapping(&self) -> &CallOperator { &self.mapping 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/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; From 33c19135a045744991a7b618ea33abd14fd81f40 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu Date: Thu, 26 Oct 2023 20:42:57 -0400 Subject: [PATCH 12/20] Cleanup --- synthesizer/process/src/stack/finalize_types/initialize.rs | 2 +- synthesizer/program/src/logic/command/get.rs | 4 ++-- synthesizer/program/src/logic/command/get_or_use.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/synthesizer/process/src/stack/finalize_types/initialize.rs b/synthesizer/process/src/stack/finalize_types/initialize.rs index ce6ccb0ee7..e12b45f527 100644 --- a/synthesizer/process/src/stack/finalize_types/initialize.rs +++ b/synthesizer/process/src/stack/finalize_types/initialize.rs @@ -384,7 +384,7 @@ impl FinalizeTypes { external.get_mapping(mapping_name).unwrap() } CallOperator::Resource(mapping_name) => { - // Ensure the declared mapping in `get` is defined in the current program. + // 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()) } diff --git a/synthesizer/program/src/logic/command/get.rs b/synthesizer/program/src/logic/command/get.rs index 8122d7998c..ef33b4c608 100644 --- a/synthesizer/program/src/logic/command/get.rs +++ b/synthesizer/program/src/logic/command/get.rs @@ -27,7 +27,7 @@ use console::{ /// Gets the value stored at `operand` in `mapping` and stores the result in `destination`. #[derive(Clone, PartialEq, Eq, Hash)] pub struct Get { - /// The mapping name. + /// The mapping. mapping: CallOperator, /// The key to access the mapping. key: Operand, @@ -48,7 +48,7 @@ impl Get { vec![self.key.clone()] } - /// Returns the mapping name. + /// Returns the mapping. #[inline] pub const fn mapping(&self) -> &CallOperator { &self.mapping diff --git a/synthesizer/program/src/logic/command/get_or_use.rs b/synthesizer/program/src/logic/command/get_or_use.rs index 26c74ff5c0..de7a2b729a 100644 --- a/synthesizer/program/src/logic/command/get_or_use.rs +++ b/synthesizer/program/src/logic/command/get_or_use.rs @@ -28,7 +28,7 @@ use console::{ /// If the key is not present, `default` is stored in `destination`. #[derive(Clone, PartialEq, Eq, Hash)] pub struct GetOrUse { - /// The mapping name. + /// The mapping. mapping: CallOperator, /// The key to access the mapping. key: Operand, @@ -51,7 +51,7 @@ impl GetOrUse { vec![self.key.clone(), self.default.clone()] } - /// Returns the mapping name. + /// Returns the mapping. #[inline] pub const fn mapping(&self) -> &CallOperator { &self.mapping From cc68bb0d4093a06899605bba857a84a393125925 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Mon, 30 Oct 2023 12:16:38 -0400 Subject: [PATCH 13/20] Introduce MappingLocator; update serialization --- .../src/stack/finalize_types/initialize.rs | 10 +- synthesizer/program/src/logic/command/get.rs | 137 ++++++++++++++++-- .../program/src/logic/command/get_or_use.rs | 37 +++-- 3 files changed, 156 insertions(+), 28 deletions(-) diff --git a/synthesizer/process/src/stack/finalize_types/initialize.rs b/synthesizer/process/src/stack/finalize_types/initialize.rs index e12b45f527..ae17caf484 100644 --- a/synthesizer/process/src/stack/finalize_types/initialize.rs +++ b/synthesizer/process/src/stack/finalize_types/initialize.rs @@ -17,11 +17,11 @@ use crate::RegisterTypes; use synthesizer_program::{ Await, Branch, - CallOperator, CastType, Contains, Get, GetOrUse, + MappingLocator, RandChaCha, Remove, Set, @@ -291,7 +291,7 @@ impl FinalizeTypes { fn check_get(&mut self, stack: &(impl StackMatches + StackProgram), get: &Get) -> Result<()> { // Retrieve the mapping. let mapping = match get.mapping() { - CallOperator::Locator(locator) => { + MappingLocator::Locator(locator) => { // Retrieve the program ID. let program_id = locator.program_id(); // Retrieve the mapping_name. @@ -315,7 +315,7 @@ impl FinalizeTypes { // Note that the unwrap is safe, as we have already checked the mapping exists. external.get_mapping(mapping_name).unwrap() } - CallOperator::Resource(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()) @@ -359,7 +359,7 @@ impl FinalizeTypes { ) -> Result<()> { // Retrieve the mapping. let mapping = match get_or_use.mapping() { - CallOperator::Locator(locator) => { + MappingLocator::Locator(locator) => { // Retrieve the program ID. let program_id = locator.program_id(); // Retrieve the mapping_name. @@ -383,7 +383,7 @@ impl FinalizeTypes { // Note that the unwrap is safe, as we have already checked the mapping exists. external.get_mapping(mapping_name).unwrap() } - CallOperator::Resource(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()) diff --git a/synthesizer/program/src/logic/command/get.rs b/synthesizer/program/src/logic/command/get.rs index ef33b4c608..f51423ab61 100644 --- a/synthesizer/program/src/logic/command/get.rs +++ b/synthesizer/program/src/logic/command/get.rs @@ -14,21 +14,122 @@ use crate::{ traits::{FinalizeStoreTrait, RegistersLoad, RegistersStore, StackMatches, StackProgram}, - CallOperator, Opcode, Operand, }; use console::{ network::prelude::*, - program::{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)] pub struct Get { /// The mapping. - mapping: CallOperator, + // TODO (howardwu): For mainnet - Use `CallOperator`, delete the above `MappingLocator`. + mapping: MappingLocator, /// The key to access the mapping. key: Operand, /// The destination register. @@ -50,7 +151,7 @@ impl Get { /// Returns the mapping. #[inline] - pub const fn mapping(&self) -> &CallOperator { + pub const fn mapping(&self) -> &MappingLocator { &self.mapping } @@ -78,8 +179,8 @@ impl Get { ) -> Result<()> { // Determine the program ID and mapping name. let (program_id, mapping_name) = match self.mapping { - CallOperator::Locator(locator) => (*locator.program_id(), *locator.resource()), - CallOperator::Resource(mapping_name) => (*stack.program_id(), mapping_name), + MappingLocator::Locator(locator) => (*locator.program_id(), *locator.resource()), + MappingLocator::Resource(mapping_name) => (*stack.program_id(), mapping_name), }; // Ensure the mapping exists in storage. @@ -118,7 +219,7 @@ impl Parser for Get { let (string, _) = Sanitizer::parse_whitespaces(string)?; // Parse the mapping name from the string. - let (string, mapping) = CallOperator::parse(string)?; + let (string, mapping) = MappingLocator::parse(string)?; // Parse the "[" from the string. let (string, _) = tag("[")(string)?; // Parse the whitespace from the string. @@ -187,9 +288,21 @@ 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 = CallOperator::read_le(&mut reader)?; + fn read_le(reader: R) -> IoResult { + // Peek at the first byte. + // TODO (howardwu): For mainnet - Read a `MappingLocator`. + let mut buffered = BufReader::new(reader); + let first_byte = { + let buffer = buffered.fill_buf()?; + buffer.first().copied() + }; + let mut reader = buffered.into_inner(); + // If the first byte is zero, then read a `MappingLocator`, otherwise read an `Identifier`. + let mapping = match first_byte { + Some(0u8) => MappingLocator::read_le(&mut reader)?, + Some(_) => MappingLocator::Resource(Identifier::read_le(&mut reader)?), + None => return Err(error("Failed to read `get`. Expected byte.")), + }; // Read the key operand. let key = Operand::read_le(&mut reader)?; // Read the destination register. @@ -222,14 +335,14 @@ mod tests { 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, CallOperator::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, CallOperator::from_str("token.aleo/balances").unwrap()); + 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"); diff --git a/synthesizer/program/src/logic/command/get_or_use.rs b/synthesizer/program/src/logic/command/get_or_use.rs index de7a2b729a..593d95ef7a 100644 --- a/synthesizer/program/src/logic/command/get_or_use.rs +++ b/synthesizer/program/src/logic/command/get_or_use.rs @@ -14,7 +14,7 @@ use crate::{ traits::{FinalizeStoreTrait, RegistersLoad, RegistersStore, StackMatches, StackProgram}, - CallOperator, + MappingLocator, Opcode, Operand, }; @@ -23,13 +23,16 @@ use console::{ 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)] pub struct GetOrUse { /// The mapping. - mapping: CallOperator, + mapping: MappingLocator, /// The key to access the mapping. key: Operand, /// The default value. @@ -53,7 +56,7 @@ impl GetOrUse { /// Returns the mapping. #[inline] - pub const fn mapping(&self) -> &CallOperator { + pub const fn mapping(&self) -> &MappingLocator { &self.mapping } @@ -87,8 +90,8 @@ impl GetOrUse { ) -> Result<()> { // Determine the program ID and mapping name. let (program_id, mapping_name) = match self.mapping { - CallOperator::Locator(locator) => (*locator.program_id(), *locator.resource()), - CallOperator::Resource(mapping_name) => (*stack.program_id(), mapping_name), + MappingLocator::Locator(locator) => (*locator.program_id(), *locator.resource()), + MappingLocator::Resource(mapping_name) => (*stack.program_id(), mapping_name), }; // Ensure the mapping exists in storage. @@ -128,7 +131,7 @@ impl Parser for GetOrUse { let (string, _) = Sanitizer::parse_whitespaces(string)?; // Parse the mapping name from the string. - let (string, mapping) = CallOperator::parse(string)?; + let (string, mapping) = MappingLocator::parse(string)?; // Parse the "[" from the string. let (string, _) = tag("[")(string)?; // Parse the whitespace from the string. @@ -201,9 +204,21 @@ 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 = CallOperator::read_le(&mut reader)?; + fn read_le(reader: R) -> IoResult { + // Peek at the first byte. + // TODO (howardwu): For mainnet - Read a `MappingLocator`. + let mut buffered = BufReader::new(reader); + let first_byte = { + let buffer = buffered.fill_buf()?; + buffer.first().copied() + }; + let mut reader = buffered.into_inner(); + // If the first byte is zero, then read a `MappingLocator`, otherwise read an `Identifier`. + let mapping = match first_byte { + Some(0u8) => MappingLocator::read_le(&mut reader)?, + Some(_) => MappingLocator::Resource(Identifier::read_le(&mut reader)?), + None => return Err(error("Failed to read `get.or_use`. Expected byte.")), + }; // Read the key operand. let key = Operand::read_le(&mut reader)?; // Read the default value. @@ -240,7 +255,7 @@ mod tests { 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, CallOperator::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"); @@ -249,7 +264,7 @@ mod tests { 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, CallOperator::from_str("token.aleo/balances").unwrap()); + 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"); From 54d70975326a89d3d754563f6d555746ab860c24 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Mon, 30 Oct 2023 12:58:13 -0400 Subject: [PATCH 14/20] Add test --- synthesizer/program/src/logic/command/get.rs | 112 +++++++++++++++- .../program/src/logic/command/get_or_use.rs | 123 +++++++++++++++++- 2 files changed, 229 insertions(+), 6 deletions(-) diff --git a/synthesizer/program/src/logic/command/get.rs b/synthesizer/program/src/logic/command/get.rs index f51423ab61..38a2a304d0 100644 --- a/synthesizer/program/src/logic/command/get.rs +++ b/synthesizer/program/src/logic/command/get.rs @@ -291,12 +291,11 @@ impl FromBytes for Get { fn read_le(reader: R) -> IoResult { // Peek at the first byte. // TODO (howardwu): For mainnet - Read a `MappingLocator`. - let mut buffered = BufReader::new(reader); + let mut reader = BufReader::new(reader); let first_byte = { - let buffer = buffered.fill_buf()?; + let buffer = reader.fill_buf()?; buffer.first().copied() }; - let mut reader = buffered.into_inner(); // If the first byte is zero, then read a `MappingLocator`, otherwise read an `Identifier`. let mapping = match first_byte { Some(0u8) => MappingLocator::read_le(&mut reader)?, @@ -331,6 +330,98 @@ mod tests { type CurrentNetwork = Testnet3; + struct OldGet { + mapping: Identifier, + key: Operand, + destination: Register, + } + + impl Parser for OldGet { + #[inline] + fn parse(string: &str) -> ParserResult { + // Parse the whitespace and comments from the string. + let (string, _) = Sanitizer::parse(string)?; + // Parse the opcode from the string. + let (string, _) = tag("get")(string)?; + // Parse the whitespace from the string. + let (string, _) = Sanitizer::parse_whitespaces(string)?; + + // Parse the mapping name from the string. + let (string, mapping) = Identifier::parse(string)?; + // Parse the "[" from the string. + let (string, _) = tag("[")(string)?; + // Parse the whitespace from the string. + let (string, _) = Sanitizer::parse_whitespaces(string)?; + // Parse the key operand from the string. + let (string, key) = Operand::parse(string)?; + // Parse the whitespace from the string. + let (string, _) = Sanitizer::parse_whitespaces(string)?; + // Parse the "]" from the string. + let (string, _) = tag("]")(string)?; + + // Parse the whitespace from the string. + let (string, _) = Sanitizer::parse_whitespaces(string)?; + // Parse the "into" keyword from the string. + let (string, _) = tag("into")(string)?; + // Parse the whitespace from the string. + let (string, _) = Sanitizer::parse_whitespaces(string)?; + // Parse the destination register from the string. + let (string, destination) = Register::parse(string)?; + + // Parse the whitespace from the string. + let (string, _) = Sanitizer::parse_whitespaces(string)?; + // Parse the ";" from the string. + let (string, _) = tag(";")(string)?; + + Ok((string, Self { mapping, key, destination })) + } + } + + impl FromStr for OldGet { + type Err = Error; + + #[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 Display for OldGet { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + // Print the command. + write!(f, "get ")?; + // Print the mapping and key operand. + write!(f, "{}[{}] into ", self.mapping, self.key)?; + // Print the destination register. + write!(f, "{};", self.destination) + } + } + + 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(); @@ -347,4 +438,19 @@ mod tests { 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 (string, old_get) = OldGet::::parse("get account[r0] into r1;").unwrap(); + assert!(string.is_empty()); + + 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 593d95ef7a..9d59675e7a 100644 --- a/synthesizer/program/src/logic/command/get_or_use.rs +++ b/synthesizer/program/src/logic/command/get_or_use.rs @@ -207,12 +207,11 @@ impl FromBytes for GetOrUse { fn read_le(reader: R) -> IoResult { // Peek at the first byte. // TODO (howardwu): For mainnet - Read a `MappingLocator`. - let mut buffered = BufReader::new(reader); + let mut reader = BufReader::new(reader); let first_byte = { - let buffer = buffered.fill_buf()?; + let buffer = reader.fill_buf()?; buffer.first().copied() }; - let mut reader = buffered.into_inner(); // If the first byte is zero, then read a `MappingLocator`, otherwise read an `Identifier`. let mapping = match first_byte { Some(0u8) => MappingLocator::read_le(&mut reader)?, @@ -251,6 +250,108 @@ mod tests { type CurrentNetwork = Testnet3; + pub struct OldGetOrUse { + mapping: Identifier, + key: Operand, + default: Operand, + destination: Register, + } + + impl Parser for OldGetOrUse { + #[inline] + fn parse(string: &str) -> ParserResult { + // Parse the whitespace and comments from the string. + let (string, _) = Sanitizer::parse(string)?; + // Parse the opcode from the string. + let (string, _) = tag("get.or_use")(string)?; + // Parse the whitespace from the string. + let (string, _) = Sanitizer::parse_whitespaces(string)?; + + // Parse the mapping name from the string. + let (string, mapping) = Identifier::parse(string)?; + // Parse the "[" from the string. + let (string, _) = tag("[")(string)?; + // Parse the whitespace from the string. + let (string, _) = Sanitizer::parse_whitespaces(string)?; + // Parse the key operand from the string. + let (string, key) = Operand::parse(string)?; + // Parse the whitespace from the string. + let (string, _) = Sanitizer::parse_whitespaces(string)?; + // Parse the "]" from the string. + let (string, _) = tag("]")(string)?; + // Parse the whitespace from the string. + let (string, _) = Sanitizer::parse_whitespaces(string)?; + // Parse the default value from the string. + let (string, default) = Operand::parse(string)?; + + // Parse the whitespace from the string. + let (string, _) = Sanitizer::parse_whitespaces(string)?; + // Parse the "into" keyword from the string. + let (string, _) = tag("into")(string)?; + // Parse the whitespace from the string. + let (string, _) = Sanitizer::parse_whitespaces(string)?; + // Parse the destination register from the string. + let (string, destination) = Register::parse(string)?; + + // Parse the whitespace from the string. + let (string, _) = Sanitizer::parse_whitespaces(string)?; + // Parse the ";" from the string. + let (string, _) = tag(";")(string)?; + + Ok((string, Self { mapping, key, default, destination })) + } + } + + impl FromStr for OldGetOrUse { + type Err = Error; + + #[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 OldGetOrUse { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + Display::fmt(self, f) + } + } + + impl Display for OldGetOrUse { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + // Print the command. + write!(f, "get.or_use ")?; + // Print the mapping and key operand. + write!(f, "{}[{}] {} into ", self.mapping, self.key, self.default)?; + // Print the destination register. + write!(f, "{};", self.destination) + } + } + + 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(); @@ -270,4 +371,20 @@ mod tests { 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 (string, old_get_or_use) = + OldGetOrUse::::parse("get.or_use account[r0] r1 into r2;").unwrap(); + assert!(string.is_empty()); + + 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); + } } From fa3dbfbf4584f41f104c3c4e4cf07191b0ba01ca Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Mon, 30 Oct 2023 13:01:02 -0400 Subject: [PATCH 15/20] Update test --- synthesizer/program/src/logic/command/get.rs | 80 ++------------ .../program/src/logic/command/get_or_use.rs | 100 ++---------------- 2 files changed, 17 insertions(+), 163 deletions(-) diff --git a/synthesizer/program/src/logic/command/get.rs b/synthesizer/program/src/logic/command/get.rs index 38a2a304d0..e0173487bd 100644 --- a/synthesizer/program/src/logic/command/get.rs +++ b/synthesizer/program/src/logic/command/get.rs @@ -336,78 +336,6 @@ mod tests { destination: Register, } - impl Parser for OldGet { - #[inline] - fn parse(string: &str) -> ParserResult { - // Parse the whitespace and comments from the string. - let (string, _) = Sanitizer::parse(string)?; - // Parse the opcode from the string. - let (string, _) = tag("get")(string)?; - // Parse the whitespace from the string. - let (string, _) = Sanitizer::parse_whitespaces(string)?; - - // Parse the mapping name from the string. - let (string, mapping) = Identifier::parse(string)?; - // Parse the "[" from the string. - let (string, _) = tag("[")(string)?; - // Parse the whitespace from the string. - let (string, _) = Sanitizer::parse_whitespaces(string)?; - // Parse the key operand from the string. - let (string, key) = Operand::parse(string)?; - // Parse the whitespace from the string. - let (string, _) = Sanitizer::parse_whitespaces(string)?; - // Parse the "]" from the string. - let (string, _) = tag("]")(string)?; - - // Parse the whitespace from the string. - let (string, _) = Sanitizer::parse_whitespaces(string)?; - // Parse the "into" keyword from the string. - let (string, _) = tag("into")(string)?; - // Parse the whitespace from the string. - let (string, _) = Sanitizer::parse_whitespaces(string)?; - // Parse the destination register from the string. - let (string, destination) = Register::parse(string)?; - - // Parse the whitespace from the string. - let (string, _) = Sanitizer::parse_whitespaces(string)?; - // Parse the ";" from the string. - let (string, _) = tag(";")(string)?; - - Ok((string, Self { mapping, key, destination })) - } - } - - impl FromStr for OldGet { - type Err = Error; - - #[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 Display for OldGet { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - // Print the command. - write!(f, "get ")?; - // Print the mapping and key operand. - write!(f, "{}[{}] into ", self.mapping, self.key)?; - // Print the destination register. - write!(f, "{};", self.destination) - } - } - impl ToBytes for OldGet { fn write_le(&self, mut writer: W) -> IoResult<()> where @@ -443,8 +371,12 @@ mod tests { fn test_from_bytes() { let (string, get) = Get::::parse("get account[r0] into r1;").unwrap(); assert!(string.is_empty()); - let (string, old_get) = OldGet::::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(); diff --git a/synthesizer/program/src/logic/command/get_or_use.rs b/synthesizer/program/src/logic/command/get_or_use.rs index 9d59675e7a..7900b79eeb 100644 --- a/synthesizer/program/src/logic/command/get_or_use.rs +++ b/synthesizer/program/src/logic/command/get_or_use.rs @@ -251,92 +251,10 @@ mod tests { type CurrentNetwork = Testnet3; pub struct OldGetOrUse { - mapping: Identifier, - key: Operand, - default: Operand, - destination: Register, - } - - impl Parser for OldGetOrUse { - #[inline] - fn parse(string: &str) -> ParserResult { - // Parse the whitespace and comments from the string. - let (string, _) = Sanitizer::parse(string)?; - // Parse the opcode from the string. - let (string, _) = tag("get.or_use")(string)?; - // Parse the whitespace from the string. - let (string, _) = Sanitizer::parse_whitespaces(string)?; - - // Parse the mapping name from the string. - let (string, mapping) = Identifier::parse(string)?; - // Parse the "[" from the string. - let (string, _) = tag("[")(string)?; - // Parse the whitespace from the string. - let (string, _) = Sanitizer::parse_whitespaces(string)?; - // Parse the key operand from the string. - let (string, key) = Operand::parse(string)?; - // Parse the whitespace from the string. - let (string, _) = Sanitizer::parse_whitespaces(string)?; - // Parse the "]" from the string. - let (string, _) = tag("]")(string)?; - // Parse the whitespace from the string. - let (string, _) = Sanitizer::parse_whitespaces(string)?; - // Parse the default value from the string. - let (string, default) = Operand::parse(string)?; - - // Parse the whitespace from the string. - let (string, _) = Sanitizer::parse_whitespaces(string)?; - // Parse the "into" keyword from the string. - let (string, _) = tag("into")(string)?; - // Parse the whitespace from the string. - let (string, _) = Sanitizer::parse_whitespaces(string)?; - // Parse the destination register from the string. - let (string, destination) = Register::parse(string)?; - - // Parse the whitespace from the string. - let (string, _) = Sanitizer::parse_whitespaces(string)?; - // Parse the ";" from the string. - let (string, _) = tag(";")(string)?; - - Ok((string, Self { mapping, key, default, destination })) - } - } - - impl FromStr for OldGetOrUse { - type Err = Error; - - #[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 OldGetOrUse { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - Display::fmt(self, f) - } - } - - impl Display for OldGetOrUse { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - // Print the command. - write!(f, "get.or_use ")?; - // Print the mapping and key operand. - write!(f, "{}[{}] {} into ", self.mapping, self.key, self.default)?; - // Print the destination register. - write!(f, "{};", self.destination) - } + pub mapping: Identifier, + pub key: Operand, + pub default: Operand, + pub destination: Register, } impl ToBytes for OldGetOrUse { @@ -376,9 +294,13 @@ mod tests { 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 (string, old_get_or_use) = - OldGetOrUse::::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(); From fc202d94402d9c2e53979f246ce5afded436040d Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Mon, 30 Oct 2023 18:03:33 -0400 Subject: [PATCH 16/20] Fix --- console/program/src/data/identifier/bytes.rs | 7 +++++++ synthesizer/program/src/finalize/bytes.rs | 4 +++- synthesizer/program/src/logic/command/get.rs | 2 +- synthesizer/program/src/logic/command/get_or_use.rs | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/console/program/src/data/identifier/bytes.rs b/console/program/src/data/identifier/bytes.rs index e90d7fbae3..05f1fb0dc4 100644 --- a/console/program/src/data/identifier/bytes.rs +++ b/console/program/src/data/identifier/bytes.rs @@ -22,9 +22,11 @@ impl FromBytes for Identifier { // Read the identifier bytes. let mut buffer = vec![0u8; size as usize]; + 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}"))) } @@ -76,4 +78,9 @@ mod tests { } Ok(()) } + + #[test] + fn test_zero_identifier_fails() { + assert!(Identifier::::read_le(&[0u8; 1][..]).is_err()) + } } 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 e0173487bd..f2d0dda5a1 100644 --- a/synthesizer/program/src/logic/command/get.rs +++ b/synthesizer/program/src/logic/command/get.rs @@ -291,7 +291,7 @@ impl FromBytes for Get { fn read_le(reader: R) -> IoResult { // Peek at the first byte. // TODO (howardwu): For mainnet - Read a `MappingLocator`. - let mut reader = BufReader::new(reader); + let mut reader = BufReader::with_capacity(1, reader); let first_byte = { let buffer = reader.fill_buf()?; buffer.first().copied() diff --git a/synthesizer/program/src/logic/command/get_or_use.rs b/synthesizer/program/src/logic/command/get_or_use.rs index 7900b79eeb..466c9949c8 100644 --- a/synthesizer/program/src/logic/command/get_or_use.rs +++ b/synthesizer/program/src/logic/command/get_or_use.rs @@ -207,7 +207,7 @@ impl FromBytes for GetOrUse { fn read_le(reader: R) -> IoResult { // Peek at the first byte. // TODO (howardwu): For mainnet - Read a `MappingLocator`. - let mut reader = BufReader::new(reader); + let mut reader = BufReader::with_capacity(1, reader); let first_byte = { let buffer = reader.fill_buf()?; buffer.first().copied() From 59e3ec535fde17114734740c202a6c15c36f6b0f Mon Sep 17 00:00:00 2001 From: Howard Wu <9260812+howardwu@users.noreply.github.com> Date: Tue, 31 Oct 2023 13:55:22 -0700 Subject: [PATCH 17/20] Update console/program/src/data/identifier/bytes.rs Signed-off-by: Howard Wu <9260812+howardwu@users.noreply.github.com> --- console/program/src/data/identifier/bytes.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/console/program/src/data/identifier/bytes.rs b/console/program/src/data/identifier/bytes.rs index 05f1fb0dc4..b286e5ec5a 100644 --- a/console/program/src/data/identifier/bytes.rs +++ b/console/program/src/data/identifier/bytes.rs @@ -22,7 +22,6 @@ impl FromBytes for Identifier { // Read the identifier bytes. let mut buffer = vec![0u8; size as usize]; - reader.read_exact(&mut buffer)?; // from_str the identifier. From 6d34d6e6355562c62da427b1d3b74a26f5b008f4 Mon Sep 17 00:00:00 2001 From: raychu86 <14917648+raychu86@users.noreply.github.com> Date: Tue, 31 Oct 2023 17:11:02 -0400 Subject: [PATCH 18/20] Remove kary benchmarks in CB --- .github/workflows/benchmarks.yml | 1 - 1 file changed, 1 deletion(-) 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 From aa473471f8b42133ee9958a676f6e241591add57 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Tue, 31 Oct 2023 18:10:31 -0400 Subject: [PATCH 19/20] Remove unwrap --- .../process/src/stack/finalize_types/initialize.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/synthesizer/process/src/stack/finalize_types/initialize.rs b/synthesizer/process/src/stack/finalize_types/initialize.rs index ae17caf484..e36fe3d552 100644 --- a/synthesizer/process/src/stack/finalize_types/initialize.rs +++ b/synthesizer/process/src/stack/finalize_types/initialize.rs @@ -312,8 +312,7 @@ impl FinalizeTypes { bail!("Mapping '{mapping_name}' in '{program_id}' is not defined.") } // Retrieve the mapping from the program. - // Note that the unwrap is safe, as we have already checked the mapping exists. - external.get_mapping(mapping_name).unwrap() + external.get_mapping(mapping_name)? } MappingLocator::Resource(mapping_name) => { // Ensure the declared mapping in `get` is defined in the current program. @@ -321,8 +320,7 @@ impl FinalizeTypes { bail!("Mapping '{mapping_name}' in '{}' is not defined.", stack.program_id()) } // Retrieve the mapping from the program. - // Note that the unwrap is safe, as we have already checked the mapping exists. - stack.program().get_mapping(mapping_name).unwrap() + stack.program().get_mapping(mapping_name)? } }; @@ -380,8 +378,7 @@ impl FinalizeTypes { bail!("Mapping '{mapping_name}' in '{program_id}' is not defined.") } // Retrieve the mapping from the program. - // Note that the unwrap is safe, as we have already checked the mapping exists. - external.get_mapping(mapping_name).unwrap() + external.get_mapping(mapping_name)? } MappingLocator::Resource(mapping_name) => { // Ensure the declared mapping in `get.or_use` is defined in the current program. @@ -389,8 +386,7 @@ impl FinalizeTypes { bail!("Mapping '{mapping_name}' in '{}' is not defined.", stack.program_id()) } // Retrieve the mapping from the program. - // Note that the unwrap is safe, as we have already checked the mapping exists. - stack.program().get_mapping(mapping_name).unwrap() + stack.program().get_mapping(mapping_name)? } }; From cee951cf2c07ee93553d389cd4d996162068c472 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Tue, 31 Oct 2023 18:52:57 -0400 Subject: [PATCH 20/20] Implement fix --- synthesizer/program/src/logic/command/get.rs | 48 ++++++++++++++--- .../program/src/logic/command/get_or_use.rs | 51 ++++++++++++++++--- 2 files changed, 83 insertions(+), 16 deletions(-) diff --git a/synthesizer/program/src/logic/command/get.rs b/synthesizer/program/src/logic/command/get.rs index f2d0dda5a1..3537877ff3 100644 --- a/synthesizer/program/src/logic/command/get.rs +++ b/synthesizer/program/src/logic/command/get.rs @@ -125,7 +125,7 @@ impl ToBytes for MappingLocator { /// 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. // TODO (howardwu): For mainnet - Use `CallOperator`, delete the above `MappingLocator`. @@ -134,6 +134,28 @@ pub struct Get { 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 { @@ -245,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 })) } } @@ -294,20 +316,22 @@ impl FromBytes for Get { let mut reader = BufReader::with_capacity(1, reader); let first_byte = { let buffer = reader.fill_buf()?; - buffer.first().copied() + 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 { - Some(0u8) => MappingLocator::read_le(&mut reader)?, - Some(_) => MappingLocator::Resource(Identifier::read_le(&mut reader)?), - None => return Err(error("Failed to read `get`. Expected 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() }) } } @@ -315,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. diff --git a/synthesizer/program/src/logic/command/get_or_use.rs b/synthesizer/program/src/logic/command/get_or_use.rs index 466c9949c8..a78deaa1c5 100644 --- a/synthesizer/program/src/logic/command/get_or_use.rs +++ b/synthesizer/program/src/logic/command/get_or_use.rs @@ -29,9 +29,10 @@ 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. + // TODO (howardwu): For mainnet - Use `CallOperator`, delete the above `MappingLocator`. mapping: MappingLocator, /// The key to access the mapping. key: Operand, @@ -39,6 +40,30 @@ pub struct GetOrUse { 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 { @@ -161,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 })) } } @@ -210,13 +235,15 @@ impl FromBytes for GetOrUse { let mut reader = BufReader::with_capacity(1, reader); let first_byte = { let buffer = reader.fill_buf()?; - buffer.first().copied() + 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 { - Some(0u8) => MappingLocator::read_le(&mut reader)?, - Some(_) => MappingLocator::Resource(Identifier::read_le(&mut reader)?), - None => return Err(error("Failed to read `get.or_use`. Expected 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)?; @@ -225,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() }) } } @@ -233,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.