diff --git a/applications/minotari_console_wallet/src/automation/commands.rs b/applications/minotari_console_wallet/src/automation/commands.rs index 94d8385299..60a552e953 100644 --- a/applications/minotari_console_wallet/src/automation/commands.rs +++ b/applications/minotari_console_wallet/src/automation/commands.rs @@ -1205,7 +1205,7 @@ pub async fn command_runner( &TransactionOutputVersion::get_current_version(), &script!(PushPubKey(Box::new( session_info.recipient_address.public_spend_key().clone() - ))), + )))?, &leader_info.output_features, &leader_info.sender_offset_pubkey, &leader_info.metadata_signature_ephemeral_commitment, diff --git a/applications/minotari_console_wallet/src/automation/error.rs b/applications/minotari_console_wallet/src/automation/error.rs index ceda7bf287..c2405a42a6 100644 --- a/applications/minotari_console_wallet/src/automation/error.rs +++ b/applications/minotari_console_wallet/src/automation/error.rs @@ -37,6 +37,7 @@ use tari_common_types::types::FixedHashSizeError; use tari_core::transactions::{tari_amount::MicroMinotariError, transaction_components::TransactionError}; use tari_crypto::signatures::SchnorrSignatureError; use tari_key_manager::key_manager_service::KeyManagerServiceError; +use tari_script::ScriptError; use tari_utilities::{hex::HexError, ByteArrayError}; use thiserror::Error; use tokio::task::JoinError; @@ -92,6 +93,8 @@ pub enum CommandError { GrpcTlsError(#[from] GrpcTlsError), #[error("Invalid signature: `{0}`")] FailedSignature(#[from] SchnorrSignatureError), + #[error("Tari script error: {0}")] + ScriptError(#[from] ScriptError), } impl From for CommandError { diff --git a/applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs b/applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs index a39ee4cbd0..98a164e1f1 100644 --- a/applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs +++ b/applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs @@ -976,7 +976,7 @@ impl wallet_server::Wallet for WalletGrpcServer { .await .map_err(|e| Status::internal(e.to_string()))?; - output = output.with_script(script![Nop]); + output = output.with_script(script![Nop].map_err(|e| Status::internal(e.to_string()))?); let (tx_id, transaction) = output_manager .create_send_to_self_with_output(vec![output], fee_per_gram.into(), UtxoSelectionCriteria::default()) diff --git a/applications/minotari_ledger_wallet/comms/Cargo.toml b/applications/minotari_ledger_wallet/comms/Cargo.toml index 2bdfe689eb..92f5dd7a51 100644 --- a/applications/minotari_ledger_wallet/comms/Cargo.toml +++ b/applications/minotari_ledger_wallet/comms/Cargo.toml @@ -8,6 +8,7 @@ edition = "2021" [dependencies] tari_crypto = { version = "0.20.2", default-features = false } tari_utilities = { version = "0.7" } + tari_common = { path = "../../../common" } tari_common_types = { path = "../../../base_layer/common_types" } tari_script = { path = "../../../infrastructure/tari_script" } diff --git a/applications/minotari_ledger_wallet/comms/src/accessor_methods.rs b/applications/minotari_ledger_wallet/comms/src/accessor_methods.rs index c236e5b745..76ee35847c 100644 --- a/applications/minotari_ledger_wallet/comms/src/accessor_methods.rs +++ b/applications/minotari_ledger_wallet/comms/src/accessor_methods.rs @@ -581,7 +581,7 @@ pub fn ledger_get_one_sided_metadata_signature( // Ensure that the serialized script produce expected results let test_key = RistrettoPublicKey::from_secret_key(&RistrettoSecretKey::random(&mut OsRng)); - let script = script!(PushPubKey(Box::new(test_key.clone()))); + let script = script!(PushPubKey(Box::new(test_key.clone())))?; let mut serialized_script = Vec::new(); script .serialize(&mut serialized_script) diff --git a/applications/minotari_ledger_wallet/comms/src/error.rs b/applications/minotari_ledger_wallet/comms/src/error.rs index 350be4584d..284006e2b9 100644 --- a/applications/minotari_ledger_wallet/comms/src/error.rs +++ b/applications/minotari_ledger_wallet/comms/src/error.rs @@ -22,6 +22,7 @@ use serde::{Deserialize, Serialize}; use tari_crypto::tari_utilities::ByteArrayError; +use tari_script::ScriptError; use thiserror::Error; /// Ledger device errors. @@ -50,6 +51,8 @@ pub enum LedgerDeviceError { NotSupported, #[error("User cancelled the transaction")] UserCancelled, + #[error("Tari script error: {0}")] + ScriptError(#[from] ScriptError), } impl From for LedgerDeviceError { diff --git a/applications/minotari_ledger_wallet/comms/src/lib.rs b/applications/minotari_ledger_wallet/comms/src/lib.rs index da517546d5..42a27d1a88 100644 --- a/applications/minotari_ledger_wallet/comms/src/lib.rs +++ b/applications/minotari_ledger_wallet/comms/src/lib.rs @@ -60,15 +60,15 @@ mod test { fn test_push_pub_key_serialized_byte_representation() { let mut scripts = Vec::new(); - scripts.push((script!(Nop), NOP_IDENTIFIER, "".to_string())); - scripts.push((script!(PushOne), PUSH_ONE_IDENTIFIER, "".to_string())); + scripts.push((script!(Nop).unwrap(), NOP_IDENTIFIER, "".to_string())); + scripts.push((script!(PushOne).unwrap(), PUSH_ONE_IDENTIFIER, "".to_string())); for pub_key in [ RistrettoPublicKey::default(), RistrettoPublicKey::from_secret_key(&RistrettoSecretKey::random(&mut OsRng)), ] { scripts.push(( - script!(PushPubKey(Box::new(pub_key.clone()))), + script!(PushPubKey(Box::new(pub_key.clone()))).unwrap(), PUSH_PUBKEY_IDENTIFIER, pub_key.to_hex(), )); @@ -76,7 +76,11 @@ mod test { let key = RistrettoSecretKey::random(&mut OsRng); let msg = slice_to_boxed_message(key.as_bytes()); - scripts.push((script!(CheckSigVerify(msg)), CHECK_SIG_VERIFY_IDENTIFIER, key.to_hex())); + scripts.push(( + script!(CheckSigVerify(msg)).unwrap(), + CHECK_SIG_VERIFY_IDENTIFIER, + key.to_hex(), + )); for (script, hex_identifier, hex_payload) in scripts { let mut serialized = Vec::new(); diff --git a/base_layer/core/src/blocks/pre_mine/mod.rs b/base_layer/core/src/blocks/pre_mine/mod.rs index c3d16e2d5b..de52d00aa9 100644 --- a/base_layer/core/src/blocks/pre_mine/mod.rs +++ b/base_layer/core/src/blocks/pre_mine/mod.rs @@ -378,7 +378,7 @@ pub async fn create_pre_mine_genesis_block_info( Else PushPubKey(Box::new(backup_key.clone())) EndIf - ); + ).map_err(|e| e.to_string())?; let output = WalletOutputBuilder::new(item.value, commitment_mask.key_id) .with_features(OutputFeatures::new( OutputFeaturesVersion::get_current_version(), diff --git a/base_layer/core/src/common/mod.rs b/base_layer/core/src/common/mod.rs index dfdd7aa37b..4f9a6b1c23 100644 --- a/base_layer/core/src/common/mod.rs +++ b/base_layer/core/src/common/mod.rs @@ -22,9 +22,7 @@ use blake2::Blake2b; use digest::consts::U64; -#[cfg(feature = "base_node")] use tari_hashing::ConfidentialOutputHashDomain; -use tari_max_size::MaxSizeVec; use crate::consensus::DomainSeparatedConsensusHasher; @@ -68,6 +66,8 @@ impl BanReason { } } +#[cfg(feature = "base_node")] +use tari_max_size::MaxSizeVec; /// AuxChainHashes is a vector of limited size #[cfg(feature = "base_node")] pub type AuxChainHashes = MaxSizeVec; diff --git a/base_layer/core/src/consensus/consensus_constants.rs b/base_layer/core/src/consensus/consensus_constants.rs index 3f4a0c54c0..82da0a419b 100644 --- a/base_layer/core/src/consensus/consensus_constants.rs +++ b/base_layer/core/src/consensus/consensus_constants.rs @@ -242,7 +242,7 @@ impl ConsensusConstants { let features_and_scripts_size = self.transaction_weight.round_up_features_and_scripts_size( output_features.get_serialized_size()? + CoinBaseExtra::default().max_size() + - script![Nop].get_serialized_size()?, + script![Nop].map_err(|e| e.to_std_io_error())?.get_serialized_size()?, ); Ok(self.transaction_weight.calculate(1, 0, 1, features_and_scripts_size)) } diff --git a/base_layer/core/src/consensus/consensus_encoding/hashing.rs b/base_layer/core/src/consensus/consensus_encoding/hashing.rs index 93abebc848..f0606e9450 100644 --- a/base_layer/core/src/consensus/consensus_encoding/hashing.rs +++ b/base_layer/core/src/consensus/consensus_encoding/hashing.rs @@ -120,7 +120,7 @@ mod tests { let network = Network::get_current_or_user_setting_or_default(); // Script is chosen because the consensus encoding impl for TariScript has 2 writes - let test_subject = script!(Nop); + let test_subject = script!(Nop).unwrap(); let mut hasher = Blake2b::::default(); TestHashDomain::add_domain_separation_tag(&mut hasher, &format!("{}.n{}", "foo", network.as_byte())); diff --git a/base_layer/core/src/covenants/arguments.rs b/base_layer/core/src/covenants/arguments.rs index 1db3ee10c4..79c4860559 100644 --- a/base_layer/core/src/covenants/arguments.rs +++ b/base_layer/core/src/covenants/arguments.rs @@ -318,7 +318,11 @@ mod test { CovenantArg::Hash(FixedHash::zero()), &from_hex("010000000000000000000000000000000000000000000000000000000000000000").unwrap(), ); - test_case(CovenantArg::TariScript(script!(Nop)), &[ARG_TARI_SCRIPT, 0x01, 0x73]); + test_case(CovenantArg::TariScript(script!(Nop).unwrap()), &[ + ARG_TARI_SCRIPT, + 0x01, + 0x73, + ]); test_case(CovenantArg::OutputField(OutputField::Covenant), &[ ARG_OUTPUT_FIELD, FIELD_COVENANT, diff --git a/base_layer/core/src/covenants/fields.rs b/base_layer/core/src/covenants/fields.rs index 5074342f0f..d2cb621fba 100644 --- a/base_layer/core/src/covenants/fields.rs +++ b/base_layer/core/src/covenants/fields.rs @@ -410,7 +410,7 @@ mod test { sidechain_feature: Some(side_chain_features), ..Default::default() }, - script: script![Drop Nop], + script: script![Drop Nop].unwrap(), ..Default::default() }, &key_manager, @@ -455,7 +455,7 @@ mod test { output_type: OutputType::Burn, ..Default::default() }, - script: script![Drop Nop], + script: script![Drop Nop].unwrap(), minimum_value_promise: MicroMinotari(123456), value: MicroMinotari(123456), ..Default::default() @@ -466,7 +466,7 @@ mod test { .remove(0); assert!(!OutputField::Commitment.is_eq(&output, &Commitment::default()).unwrap()); - assert!(!OutputField::Script.is_eq(&output, &script![Nop Drop]).unwrap()); + assert!(!OutputField::Script.is_eq(&output, &script![Nop Drop].unwrap()).unwrap()); assert!(!OutputField::SenderOffsetPublicKey .is_eq(&output, &PublicKey::default()) .unwrap()); @@ -504,7 +504,7 @@ mod test { maturity: 42, ..Default::default() }, - script: script![Drop Nop], + script: script![Drop Nop].unwrap(), ..Default::default() }, &key_manager, @@ -584,7 +584,7 @@ mod test { 1, UtxoTestParams { features, - script: script![Drop Nop], + script: script![Drop Nop].unwrap(), minimum_value_promise: MicroMinotari(123456), value: MicroMinotari(123456), ..Default::default() diff --git a/base_layer/core/src/covenants/filters/and.rs b/base_layer/core/src/covenants/filters/and.rs index 56bbab98e8..eab9c23a5a 100644 --- a/base_layer/core/src/covenants/filters/and.rs +++ b/base_layer/core/src/covenants/filters/and.rs @@ -54,7 +54,7 @@ mod test { #[tokio::test] async fn it_filters_outputset_using_intersection() -> Result<(), Box> { let key_manager = create_memory_db_key_manager().unwrap(); - let script = script!(CheckHeight(101)); + let script = script!(CheckHeight(101)).unwrap(); let covenant = covenant!(and(field_eq(@field::features_maturity, @uint(42),), field_eq(@field::script, @script(script.clone())))).unwrap(); let input = create_input(&key_manager).await; let (mut context, outputs) = setup_filter_test( @@ -64,7 +64,7 @@ mod test { |outputs| { // output satisfying maturity only outputs[2].features.maturity = 42; - outputs[2].script = script!(CheckHeight(102)); + outputs[2].script = script!(CheckHeight(102)).unwrap(); // output satisfying maturity and script outputs[5].features.maturity = 42; outputs[5].script = script.clone(); diff --git a/base_layer/core/src/covenants/filters/field_eq.rs b/base_layer/core/src/covenants/filters/field_eq.rs index f4d78be6a2..c1eda3f487 100644 --- a/base_layer/core/src/covenants/filters/field_eq.rs +++ b/base_layer/core/src/covenants/filters/field_eq.rs @@ -157,7 +157,7 @@ mod test { #[tokio::test] async fn it_filters_tari_script() -> Result<(), Box> { let key_manager = create_memory_db_key_manager().unwrap(); - let script = script!(CheckHeight(100)); + let script = script!(CheckHeight(100)).unwrap(); let covenant = covenant!(field_eq( @field::script, @script(script.clone()) diff --git a/base_layer/core/src/covenants/filters/not.rs b/base_layer/core/src/covenants/filters/not.rs index 866b285188..bab283545f 100644 --- a/base_layer/core/src/covenants/filters/not.rs +++ b/base_layer/core/src/covenants/filters/not.rs @@ -51,7 +51,7 @@ mod test { #[tokio::test] async fn it_filters_compliment_of_filter() -> Result<(), Box> { let key_manager = create_memory_db_key_manager().unwrap(); - let script = script!(CheckHeight(100)); + let script = script!(CheckHeight(100)).unwrap(); let covenant = covenant!(not(or(field_eq(@field::features_maturity, @uint(42),), field_eq(@field::script, @script(script.clone()))))).unwrap(); let input = create_input(&key_manager).await; let (mut context, outputs) = setup_filter_test( diff --git a/base_layer/core/src/covenants/filters/or.rs b/base_layer/core/src/covenants/filters/or.rs index c9bf754945..3f4189f424 100644 --- a/base_layer/core/src/covenants/filters/or.rs +++ b/base_layer/core/src/covenants/filters/or.rs @@ -57,7 +57,7 @@ mod test { #[tokio::test] async fn it_filters_outputset_using_union() -> Result<(), Box> { let key_manager = create_memory_db_key_manager().unwrap(); - let script = script!(CheckHeight(100)); + let script = script!(CheckHeight(100)).unwrap(); let covenant = covenant!(or(field_eq(@field::features_maturity, @uint(42),), field_eq(@field::script, @script(script.clone())))).unwrap(); let input = create_input(&key_manager).await; let (mut context, outputs) = setup_filter_test( diff --git a/base_layer/core/src/covenants/filters/xor.rs b/base_layer/core/src/covenants/filters/xor.rs index 38309676db..c083079ffc 100644 --- a/base_layer/core/src/covenants/filters/xor.rs +++ b/base_layer/core/src/covenants/filters/xor.rs @@ -59,7 +59,7 @@ mod test { #[tokio::test] async fn it_filters_outputset_using_symmetric_difference() -> Result<(), Box> { let key_manager = create_memory_db_key_manager().unwrap(); - let script = script!(CheckHeight(100)); + let script = script!(CheckHeight(100)).unwrap(); let covenant = covenant!(and(field_eq(@field::features_maturity, @uint(42),), field_eq(@field::script, @script(script.clone())))).unwrap(); let input = create_input(&key_manager).await; let (mut context, outputs) = setup_filter_test( diff --git a/base_layer/core/src/covenants/macros.rs b/base_layer/core/src/covenants/macros.rs index ac92125534..1b60fb0768 100644 --- a/base_layer/core/src/covenants/macros.rs +++ b/base_layer/core/src/covenants/macros.rs @@ -199,7 +199,7 @@ mod test { }; let dest_pk = PublicKey::from_hex("b0c1f788f137ba0cdc0b61e89ee43b80ebf5cca4136d3229561bf11eba347849").unwrap(); let sender_pk = dest_pk.clone(); - let script = script!(HashSha256 PushHash(Box::new(hash)) Equal IfThen PushPubKey(Box::new(dest_pk)) Else CheckHeightVerify(100) PushPubKey(Box::new(sender_pk)) EndIf); + let script = script!(HashSha256 PushHash(Box::new(hash)) Equal IfThen PushPubKey(Box::new(dest_pk)) Else CheckHeightVerify(100) PushPubKey(Box::new(sender_pk)) EndIf).unwrap(); let covenant = covenant!(field_eq(@field::script, @script(script.clone()))).unwrap(); let decoded = Covenant::from_bytes(&mut covenant.to_bytes().as_bytes()).unwrap(); diff --git a/base_layer/core/src/transactions/test_helpers.rs b/base_layer/core/src/transactions/test_helpers.rs index 1ba4ccc333..e2ded3c714 100644 --- a/base_layer/core/src/transactions/test_helpers.rs +++ b/base_layer/core/src/transactions/test_helpers.rs @@ -203,7 +203,8 @@ impl TestParams { pub fn get_size_for_default_features_and_scripts(&self, num_outputs: usize) -> std::io::Result { let output_features = OutputFeatures { ..Default::default() }; Ok(self.fee().weighting().round_up_features_and_scripts_size( - script![Nop].get_serialized_size()? + output_features.get_serialized_size()?, + script![Nop].map_err(|e| e.to_std_io_error())?.get_serialized_size()? + + output_features.get_serialized_size()?, ) * num_outputs) } } @@ -232,7 +233,7 @@ impl Default for UtxoTestParams { fn default() -> Self { Self { value: 10.into(), - script: script![Nop], + script: script![Nop].unwrap(), features: OutputFeatures::default(), input_data: None, covenant: Covenant::default(), @@ -438,7 +439,7 @@ macro_rules! txn_schema { fee: $fee, lock_height: $lock, features: $features.clone(), - script: tari_script::script![Nop], + script: tari_script::script![Nop].unwrap(), covenant: Default::default(), input_data: None, input_version: $input_version.clone(), @@ -540,7 +541,7 @@ pub async fn create_tx( output_count, fee_per_gram, &output_features, - &script![Nop], + &script![Nop].unwrap(), &Default::default(), key_manager, ) @@ -717,7 +718,7 @@ pub async fn create_stx_protocol_internal( .with_lock_height(schema.lock_height) .with_fee_per_gram(schema.fee) .with_change_data( - script!(PushPubKey(Box::new(script_public_key))), + script!(PushPubKey(Box::new(script_public_key))).unwrap(), ExecutionStack::default(), change.script_key_id, change.commitment_mask_key_id, diff --git a/base_layer/core/src/transactions/transaction_components/test.rs b/base_layer/core/src/transactions/transaction_components/test.rs index 267bdcaedb..76b5f594ab 100644 --- a/base_layer/core/src/transactions/transaction_components/test.rs +++ b/base_layer/core/src/transactions/transaction_components/test.rs @@ -132,7 +132,7 @@ async fn range_proof_verification() { test_params_2.commitment_mask_key_id.clone(), ) .with_features(OutputFeatures::default()) - .with_script(script![Nop]) + .with_script(script![Nop].unwrap()) .encrypt_data_for_recovery(&key_manager, None, PaymentId::Empty) .await .unwrap() @@ -524,7 +524,7 @@ async fn inputs_not_malleable() { 2, 15.into(), &Default::default(), - &script![Nop], + &script![Nop].unwrap(), &Default::default(), &key_manager, ) @@ -538,7 +538,7 @@ async fn inputs_not_malleable() { .unwrap(); let mut inputs = tx.body().inputs().clone(); - inputs[0].set_script(script![Drop]).unwrap(); + inputs[0].set_script(script![Drop].unwrap()).unwrap(); inputs[0].input_data = stack; tx.body = AggregateBody::new(inputs, tx.body.outputs().clone(), tx.body().kernels().clone()); diff --git a/base_layer/core/src/transactions/transaction_components/wallet_output_builder.rs b/base_layer/core/src/transactions/transaction_components/wallet_output_builder.rs index 5a0622a2df..fff2dbcf37 100644 --- a/base_layer/core/src/transactions/transaction_components/wallet_output_builder.rs +++ b/base_layer/core/src/transactions/transaction_components/wallet_output_builder.rs @@ -361,7 +361,7 @@ mod test { let (commitment_mask_key, script_key_id) = key_manager.get_next_commitment_mask_and_script_key().await.unwrap(); let value = MicroMinotari(100); let kmob = WalletOutputBuilder::new(value, commitment_mask_key.key_id.clone()); - let kmob = kmob.with_script(TariScript::new(vec![])); + let kmob = kmob.with_script(TariScript::new(vec![]).unwrap()); assert!(kmob.clone().try_build(&key_manager).await.is_err()); let sender_offset = key_manager .get_next_key(TransactionKeyManagerBranch::SenderOffset.get_branch_key()) @@ -403,7 +403,7 @@ mod test { let (commitment_mask_key, script_key) = key_manager.get_next_commitment_mask_and_script_key().await.unwrap(); let value = MicroMinotari(100); let kmob = WalletOutputBuilder::new(value, commitment_mask_key.key_id.clone()); - let kmob = kmob.with_script(TariScript::new(vec![])); + let kmob = kmob.with_script(TariScript::new(vec![]).unwrap()); let sender_offset = key_manager .get_next_key(TransactionKeyManagerBranch::SenderOffset.get_branch_key()) .await diff --git a/base_layer/core/src/transactions/transaction_protocol/sender.rs b/base_layer/core/src/transactions/transaction_protocol/sender.rs index dc34b9b93b..808509d123 100644 --- a/base_layer/core/src/transactions/transaction_protocol/sender.rs +++ b/base_layer/core/src/transactions/transaction_protocol/sender.rs @@ -1119,7 +1119,7 @@ mod test { let bob_key = TestParams::new(&key_manager).await; let input = create_test_input(MicroMinotari(1200), 0, &key_manager, vec![]).await; let utxo = input.to_transaction_input(&key_manager).await.unwrap(); - let script = script!(Nop); + let script = script!(Nop).unwrap(); let consensus_constants = create_consensus_constants(0); let mut builder = SenderTransactionProtocol::builder(consensus_constants.clone(), key_manager.clone()); let fee_per_gram = MicroMinotari(4); @@ -1230,7 +1230,7 @@ mod test { let input = create_test_input(MicroMinotari(25000), 0, &key_manager, vec![]).await; let consensus_constants = create_consensus_constants(0); let mut builder = SenderTransactionProtocol::builder(consensus_constants.clone(), key_manager.clone()); - let script = script!(Nop); + let script = script!(Nop).unwrap(); let expected_fee = builder.fee().calculate( MicroMinotari(20), 1, @@ -1345,7 +1345,7 @@ mod test { let input3 = create_test_input(MicroMinotari(15000), 0, &key_manager, vec![]).await; let consensus_constants = create_consensus_constants(0); let mut builder = SenderTransactionProtocol::builder(consensus_constants.clone(), key_manager.clone()); - let script = script!(Nop); + let script = script!(Nop).unwrap(); let change = TestParams::new(&key_manager).await; builder .with_lock_height(0) @@ -1450,7 +1450,7 @@ mod test { let key_manager = create_memory_db_key_manager().unwrap(); let (utxo_amount, fee_per_gram, amount) = (MicroMinotari(2500), MicroMinotari(10), MicroMinotari(500)); let input = create_test_input(utxo_amount, 0, &key_manager, vec![]).await; - let script = script!(Nop); + let script = script!(Nop).unwrap(); let mut builder = SenderTransactionProtocol::builder(create_consensus_constants(0), key_manager.clone()); let change = TestParams::new(&key_manager).await; builder @@ -1489,7 +1489,7 @@ mod test { let key_manager = create_memory_db_key_manager().unwrap(); let (utxo_amount, fee_per_gram, amount) = (MicroMinotari(2500), MicroMinotari(10), MicroMinotari(500)); let input = create_test_input(utxo_amount, 0, &key_manager, vec![]).await; - let script = script!(Nop); + let script = script!(Nop).unwrap(); let mut builder = SenderTransactionProtocol::builder(create_consensus_constants(0), key_manager.clone()); let change = TestParams::new(&key_manager).await; builder @@ -1532,7 +1532,7 @@ mod test { let bob_test_params = TestParams::new(&key_manager_bob).await; let alice_value = MicroMinotari(25000); let input = create_test_input(alice_value, 0, &key_manager_alice, vec![]).await; - let script = script!(Nop); + let script = script!(Nop).unwrap(); let consensus_constants = create_consensus_constants(0); let mut builder = SenderTransactionProtocol::builder(consensus_constants.clone(), key_manager_alice.clone()); @@ -1542,7 +1542,7 @@ mod test { .with_fee_per_gram(MicroMinotari(20)) .with_change_data( // "colour" this output so that we can find it later - script!(PushInt(1) Drop Nop), + script!(PushInt(1) Drop Nop).unwrap(), inputs!(change_params.script_key_pk), change_params.script_key_id.clone(), change_params.commitment_mask_key_id.clone(), diff --git a/base_layer/core/src/transactions/transaction_protocol/single_receiver.rs b/base_layer/core/src/transactions/transaction_protocol/single_receiver.rs index c5c5c4573b..4b45fa3b68 100644 --- a/base_layer/core/src/transactions/transaction_protocol/single_receiver.rs +++ b/base_layer/core/src/transactions/transaction_protocol/single_receiver.rs @@ -184,7 +184,7 @@ mod test { MicroMinotari(5000), test_params.commitment_mask_key_id, OutputFeatures::default(), - script!(Nop), + script!(Nop).unwrap(), ExecutionStack::default(), test_params.script_key_id, PublicKey::default(), @@ -225,7 +225,7 @@ mod test { MicroMinotari(5000), test_params.commitment_mask_key_id, OutputFeatures::default(), - script!(Nop), + script!(Nop).unwrap(), ExecutionStack::default(), test_params.script_key_id, PublicKey::default(), @@ -262,7 +262,7 @@ mod test { let m = TransactionMetadata::new(MicroMinotari(100), 0); let test_params = TestParams::new(&key_manager).await; let test_params2 = TestParams::new(&key_manager).await; - let script = script!(Nop); + let script = script!(Nop).unwrap(); let sender_offset_public_key = key_manager .get_public_key_at_key_id(&test_params.sender_offset_key_id) .await diff --git a/base_layer/core/src/transactions/transaction_protocol/transaction_initializer.rs b/base_layer/core/src/transactions/transaction_protocol/transaction_initializer.rs index dae717fb5f..9842f7d1d9 100644 --- a/base_layer/core/src/transactions/transaction_protocol/transaction_initializer.rs +++ b/base_layer/core/src/transactions/transaction_protocol/transaction_initializer.rs @@ -634,7 +634,7 @@ mod test { // Start the builder let builder = SenderTransactionInitializer::new(&create_consensus_constants(0), key_manager.clone()); let err = builder.build().await.unwrap_err(); - let script = script!(Nop); + let script = script!(Nop).unwrap(); // We should have a bunch of fields missing still, but we can recover and continue assert_eq!(err.message, "Missing Lock Height,Missing Fee per gram"); @@ -681,7 +681,7 @@ mod test { let mut builder = err.builder; let change = TestParams::new(&key_manager).await; builder.with_change_data( - script!(Nop), + script!(Nop).unwrap(), Default::default(), change.script_key_id.clone(), change.commitment_mask_key_id.clone(), @@ -721,7 +721,7 @@ mod test { ); let output = create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &p, MicroMinotari(5000) - expected_fee, @@ -817,7 +817,7 @@ mod test { let p = TestParams::new(&key_manager).await; let output = create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &p, MicroMinotari(500), @@ -856,7 +856,7 @@ mod test { .expect("Failed to borsh serialized size"), ); let input = create_test_input(500 * uT + tx_fee, 0, &key_manager, vec![]).await; - let script = script!(Nop); + let script = script!(Nop).unwrap(); // Start the builder let constants = create_consensus_constants(0); let mut builder = SenderTransactionInitializer::new(&constants, key_manager.clone()); @@ -867,7 +867,7 @@ mod test { .await .unwrap() .with_change_data( - script!(Nop), + script!(Nop).unwrap(), inputs!(change.script_key_pk), change.script_key_id.clone(), change.commitment_mask_key_id.clone(), @@ -894,7 +894,7 @@ mod test { let key_manager = create_memory_db_key_manager().unwrap(); let p = TestParams::new(&key_manager).await; let input = create_test_input(MicroMinotari(400), 0, &key_manager, vec![]).await; - let script = script!(Nop); + let script = script!(Nop).unwrap(); let output = create_wallet_output_with_data( script.clone(), OutputFeatures::default(), @@ -917,7 +917,7 @@ mod test { .await .unwrap() .with_change_data( - script!(Nop), + script!(Nop).unwrap(), inputs!(change.script_key_pk), change.script_key_id.clone(), change.commitment_mask_key_id.clone(), @@ -950,7 +950,7 @@ mod test { let input2 = create_test_input(MicroMinotari(3000), 0, &key_manager, vec![]).await; let fee_per_gram = MicroMinotari(6); - let script = script!(Nop); + let script = script!(Nop).unwrap(); let constants = create_consensus_constants(0); let expected_fee = Fee::from(*constants.transaction_weight_params()).calculate( fee_per_gram, @@ -984,7 +984,7 @@ mod test { .await .unwrap() .with_change_data( - script!(Nop), + script!(Nop).unwrap(), inputs!(change.script_key_pk), change.script_key_id.clone(), change.commitment_mask_key_id.clone(), diff --git a/base_layer/core/src/validation/aggregate_body/aggregate_body_internal_validator.rs b/base_layer/core/src/validation/aggregate_body/aggregate_body_internal_validator.rs index b5e84ad8fd..0a9fd46ada 100644 --- a/base_layer/core/src/validation/aggregate_body/aggregate_body_internal_validator.rs +++ b/base_layer/core/src/validation/aggregate_body/aggregate_body_internal_validator.rs @@ -520,7 +520,7 @@ mod test { 100.into(), &key_manager, &OutputFeatures::create_burn_output(), - &script!(Nop), + &script!(Nop).unwrap(), &Covenant::default(), 0.into(), ) @@ -529,7 +529,7 @@ mod test { 101.into(), &key_manager, &OutputFeatures::create_burn_output(), - &script!(Nop), + &script!(Nop).unwrap(), &Covenant::default(), 0.into(), ) @@ -538,7 +538,7 @@ mod test { 102.into(), &key_manager, &OutputFeatures::create_burn_output(), - &script!(Nop), + &script!(Nop).unwrap(), &Covenant::default(), 0.into(), ) @@ -583,7 +583,7 @@ mod test { 100.into(), &key_manager, &OutputFeatures::create_burn_output(), - &script!(Nop), + &script!(Nop).unwrap(), &Covenant::default(), 0.into(), ) diff --git a/base_layer/core/src/validation/block_body/test.rs b/base_layer/core/src/validation/block_body/test.rs index f6d8d7b2e8..fede6a9984 100644 --- a/base_layer/core/src/validation/block_body/test.rs +++ b/base_layer/core/src/validation/block_body/test.rs @@ -407,7 +407,7 @@ async fn it_limits_the_script_byte_size() { let (_, coinbase_a) = blockchain.add_next_tip(block_spec!("A")).await.unwrap(); let mut schema1 = txn_schema!(from: vec![coinbase_a.clone()], to: vec![50 * T, 12 * T]); - schema1.script = script!(Nop Nop Nop); + schema1.script = script!(Nop Nop Nop).unwrap(); let (txs, _) = schema_to_transaction(&[schema1], &blockchain.km).await; let txs = txs.into_iter().map(|t| Arc::try_unwrap(t).unwrap()).collect::>(); let (block, _) = blockchain.create_next_tip(block_spec!("B", transactions: txs)).await; @@ -433,7 +433,7 @@ async fn it_limits_the_encrypted_data_byte_size() { let (_, coinbase_a) = blockchain.add_next_tip(block_spec!("A")).await.unwrap(); let mut schema1 = txn_schema!(from: vec![coinbase_a.clone()], to: vec![50 * T, 12 * T]); - schema1.script = script!(Nop Nop Nop); + schema1.script = script!(Nop Nop Nop).unwrap(); let (txs, _) = schema_to_transaction(&[schema1], &blockchain.km).await; let mut txs = txs.into_iter().map(|t| Arc::try_unwrap(t).unwrap()).collect::>(); let mut outputs = txs[0].body.outputs().clone(); diff --git a/base_layer/core/tests/chain_storage_tests/chain_backend.rs b/base_layer/core/tests/chain_storage_tests/chain_backend.rs index 590219de03..609d8ebc9a 100644 --- a/base_layer/core/tests/chain_storage_tests/chain_backend.rs +++ b/base_layer/core/tests/chain_storage_tests/chain_backend.rs @@ -126,7 +126,7 @@ fn test_utxo_order() { let mut utxos = Vec::with_capacity(2000); let version = TransactionOutputVersion::V0; let features = OutputFeatures::default(); - let script = script!(Nop); + let script = script!(Nop).unwrap(); let proof = RangeProof::default(); let sig = ComAndPubSignature::default(); let covenant = Covenant::default(); diff --git a/base_layer/core/tests/helpers/block_builders.rs b/base_layer/core/tests/helpers/block_builders.rs index 655aef8f1d..3d31058a06 100644 --- a/base_layer/core/tests/helpers/block_builders.rs +++ b/base_layer/core/tests/helpers/block_builders.rs @@ -109,7 +109,7 @@ pub async fn create_coinbase( .unwrap(); let wallet_output = create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::create_coinbase(maturity_height, extra, RangeProofType::BulletProofPlus), &p, value, @@ -238,7 +238,7 @@ pub async fn create_genesis_block_with_utxos( key_manager: &MemoryDbKeyManager, ) -> (ChainBlock, Vec) { let (mut template, coinbase) = genesis_template(100_000_000.into(), consensus_constants, key_manager).await; - let script = script!(Nop); + let script = script!(Nop).unwrap(); let output_features = OutputFeatures::default(); let mut outputs = Vec::new(); outputs.push(coinbase); diff --git a/base_layer/core/tests/tests/block_validation.rs b/base_layer/core/tests/tests/block_validation.rs index 3658ef6d14..4f04f1af38 100644 --- a/base_layer/core/tests/tests/block_validation.rs +++ b/base_layer/core/tests/tests/block_validation.rs @@ -586,7 +586,7 @@ OutputFeatures::default()), // We dont need proper utxo's with signatures as the post_orphan validator does not check accounting balance + // signatures. let key_manager_utxo = create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &test_params1, outputs[1].value, @@ -595,7 +595,7 @@ OutputFeatures::default()), .await .unwrap(); let key_manager_utxo2 = create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &test_params2, outputs[2].value, @@ -958,7 +958,7 @@ async fn test_block_sync_body_validator() { // We dont need proper utxo's with signatures as the post_orphan validator does not check accounting balance + // signatures. let unblinded_utxo = create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &test_params1, outputs[1].value, @@ -967,7 +967,7 @@ async fn test_block_sync_body_validator() { .await .unwrap(); let unblinded_utxo2 = create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &test_params2, outputs[2].value, diff --git a/base_layer/core/tests/tests/mempool.rs b/base_layer/core/tests/tests/mempool.rs index 1532414fa5..023fa5faf2 100644 --- a/base_layer/core/tests/tests/mempool.rs +++ b/base_layer/core/tests/tests/mempool.rs @@ -1236,7 +1236,7 @@ async fn consensus_validation_large_tx() { amount_for_last_output }; let output = create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &test_params, output_amount, @@ -1398,7 +1398,7 @@ async fn validation_reject_min_fee() { let test_params = TestParams::new(&key_manager).await; let wallet_output = create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &test_params, input.value, @@ -1604,7 +1604,7 @@ async fn consensus_validation_versions() { fee: 25.into(), lock_height: 0, features: Default::default(), - script: script![Nop], + script: script![Nop].unwrap(), input_data: None, covenant: Default::default(), input_version: Some(TransactionInputVersion::V1), @@ -1621,7 +1621,7 @@ async fn consensus_validation_versions() { fee: 25.into(), lock_height: 0, features: Default::default(), - script: script![Nop], + script: script![Nop].unwrap(), input_data: None, covenant: Default::default(), input_version: None, @@ -1639,7 +1639,7 @@ async fn consensus_validation_versions() { fee: 25.into(), lock_height: 0, features: Default::default(), - script: script![Nop], + script: script![Nop].unwrap(), input_data: None, covenant: Default::default(), input_version: None, diff --git a/base_layer/core/tests/tests/node_comms_interface.rs b/base_layer/core/tests/tests/node_comms_interface.rs index be07a36f0e..c67ede3ce7 100644 --- a/base_layer/core/tests/tests/node_comms_interface.rs +++ b/base_layer/core/tests/tests/node_comms_interface.rs @@ -206,7 +206,7 @@ async fn inbound_fetch_utxos() { MicroMinotari(10_000), &key_manager, &Default::default(), - &script!(Nop), + &script!(Nop).unwrap(), &Covenant::default(), MicroMinotari::zero(), ) @@ -281,7 +281,7 @@ async fn initialize_sender_transaction_protocol_for_overflow_test( .with_lock_height(txn_schema.lock_height) .with_fee_per_gram(txn_schema.fee) .with_change_data( - script!(PushPubKey(Box::new(script_public_key))), + script!(PushPubKey(Box::new(script_public_key))).unwrap(), ExecutionStack::default(), change.script_key_id, change.commitment_mask_key_id, @@ -362,7 +362,7 @@ async fn initialize_sender_transaction_protocol_for_overflow_test( #[tokio::test] async fn test_sender_transaction_protocol_for_overflow() { let key_manager = create_memory_db_key_manager().unwrap(); - let script = script!(Nop); + let script = script!(Nop).unwrap(); let amount = MicroMinotari(u64::MAX); // This is the adversary's attack! let output_features = OutputFeatures::default(); let covenant = Covenant::default(); diff --git a/base_layer/wallet/src/output_manager_service/recovery/standard_outputs_recoverer.rs b/base_layer/wallet/src/output_manager_service/recovery/standard_outputs_recoverer.rs index 57f9ed914e..ded84fe641 100644 --- a/base_layer/wallet/src/output_manager_service/recovery/standard_outputs_recoverer.rs +++ b/base_layer/wallet/src/output_manager_service/recovery/standard_outputs_recoverer.rs @@ -81,10 +81,10 @@ where let known_scripts = self.db.get_all_known_one_sided_payment_scripts()?; let mut rewound_outputs: Vec<(WalletOutput, bool, FixedHash)> = Vec::new(); - let push_pub_key_script = script!(PushPubKey(Box::default())); + let push_pub_key_script = script!(PushPubKey(Box::default()))?; for output in outputs { let known_script_index = known_scripts.iter().position(|s| s.script == output.script); - if output.script != script!(Nop) && + if output.script != script!(Nop)? && known_script_index.is_none() && !output.script.pattern_match(&push_pub_key_script) { @@ -201,7 +201,7 @@ where known_script_index: Option, known_scripts: &[KnownOneSidedPaymentScript], ) -> Result, OutputManagerError> { - let (input_data, script_key) = if script == &script!(Nop) { + let (input_data, script_key) = if script == &script!(Nop)? { // This is a nop, so we can just create a new key for the input stack. let key = if let KeyId::Derived { key } = spending_key { TariKeyId::from_str(&key.to_string()).map_err(OutputManagerError::BuildError)? diff --git a/base_layer/wallet/src/output_manager_service/service.rs b/base_layer/wallet/src/output_manager_service/service.rs index a51fac74c9..71c952ac73 100644 --- a/base_layer/wallet/src/output_manager_service/service.rs +++ b/base_layer/wallet/src/output_manager_service/service.rs @@ -781,10 +781,10 @@ where // Confirm script hash is for the expected script, at the moment assuming Nop or Push_pubkey // if the script is Push_pubkey(default_key) we know we have to fill it in. - let script = if single_round_sender_data.script == script!(Nop) { + let script = if single_round_sender_data.script == script!(Nop)? { single_round_sender_data.script.clone() - } else if single_round_sender_data.script == script!(PushPubKey(Box::default())) { - script!(PushPubKey(Box::new(script_public_key.pub_key.clone()))) + } else if single_round_sender_data.script == script!(PushPubKey(Box::default()))? { + script!(PushPubKey(Box::new(script_public_key.pub_key.clone())))? } else { return Err(OutputManagerError::InvalidScriptHash); }; @@ -1032,7 +1032,7 @@ where .get_next_commitment_mask_and_script_key() .await?; builder.with_change_data( - script!(PushPubKey(Box::new(change_script_key.pub_key.clone()))), + script!(PushPubKey(Box::new(change_script_key.pub_key.clone())))?, ExecutionStack::default(), change_script_key.key_id, change_commitment_mask_key.key_id, @@ -1085,7 +1085,7 @@ where fee_per_gram: MicroMinotari, ) -> Result<(TxId, Transaction), OutputManagerError> { let total_value = outputs.iter().map(|o| o.value()).sum(); - let nop_script = script![Nop]; + let nop_script = script![Nop]?; let weighting = self.resources.consensus_constants.transaction_weight_params(); let mut features_and_scripts_byte_size = 0; for output in &outputs { @@ -1140,7 +1140,7 @@ where .get_next_commitment_mask_and_script_key() .await?; builder.with_change_data( - script!(PushPubKey(Box::new(change_script_key.pub_key))), + script!(PushPubKey(Box::new(change_script_key.pub_key)))?, ExecutionStack::default(), change_script_key.key_id, change_commitment_mask_key.key_id, @@ -1365,7 +1365,7 @@ where range_proof_type, ..Default::default() }; - let script = script!(PushPubKey(Box::new(recipient_address.public_spend_key().clone()))); + let script = script!(PushPubKey(Box::new(recipient_address.public_spend_key().clone())))?; let metadata_byte_size = self .resources .consensus_constants @@ -1401,7 +1401,7 @@ where ) .await? .with_change_data( - script!(PushPubKey(Box::default())), + script!(PushPubKey(Box::default()))?, ExecutionStack::default(), TariKeyId::default(), TariKeyId::default(), @@ -1663,7 +1663,7 @@ where range_proof_type, ..Default::default() }; - let script = script!(PushPubKey(Box::new(recipient_address.public_spend_key().clone()))); + let script = script!(PushPubKey(Box::new(recipient_address.public_spend_key().clone())))?; let metadata_byte_size = self .resources .consensus_constants @@ -1699,7 +1699,7 @@ where ) .await? .with_change_data( - script!(PushPubKey(Box::default())), + script!(PushPubKey(Box::default()))?, ExecutionStack::default(), TariKeyId::default(), TariKeyId::default(), @@ -1895,7 +1895,7 @@ where .get_next_commitment_mask_and_script_key() .await?; builder.with_change_data( - script!(PushPubKey(Box::new(change_script_public_key.pub_key.clone()))), + script!(PushPubKey(Box::new(change_script_public_key.pub_key.clone())))?, ExecutionStack::default(), change_script_public_key.key_id.clone(), change_commitment_mask_key_id.key_id, @@ -2530,7 +2530,7 @@ where .get_next_commitment_mask_and_script_key() .await?; tx_builder.with_change_data( - script!(PushPubKey(Box::new(change_script.pub_key))), + script!(PushPubKey(Box::new(change_script.pub_key)))?, ExecutionStack::default(), change_script.key_id, change_mask.key_id, @@ -2612,7 +2612,7 @@ where .key_manager .get_next_commitment_mask_and_script_key() .await?; - let script = script!(PushPubKey(Box::new(script_key.pub_key.clone()))); + let script = script!(PushPubKey(Box::new(script_key.pub_key.clone())))?; let payment_id = PaymentId::Address(self.resources.interactive_tari_address.clone()); let encrypted_data = self .resources @@ -2870,7 +2870,7 @@ where .get_next_commitment_mask_and_script_key() .await?; builder.with_change_data( - script!(PushPubKey(Box::new(change_script_key.pub_key.clone()))), + script!(PushPubKey(Box::new(change_script_key.pub_key.clone())))?, ExecutionStack::default(), change_script_key.key_id, change_commitment_mask_key.key_id, @@ -2955,7 +2955,7 @@ where .get_next_commitment_mask_and_script_key() .await?; builder.with_change_data( - script!(PushPubKey(Box::new(change_script_key.pub_key.clone()))), + script!(PushPubKey(Box::new(change_script_key.pub_key.clone())))?, ExecutionStack::default(), change_script_key.key_id, change_commitment_mask_key.key_id, diff --git a/base_layer/wallet/src/output_manager_service/storage/sqlite_db/mod.rs b/base_layer/wallet/src/output_manager_service/storage/sqlite_db/mod.rs index 0cf8498398..6f37852775 100644 --- a/base_layer/wallet/src/output_manager_service/storage/sqlite_db/mod.rs +++ b/base_layer/wallet/src/output_manager_service/storage/sqlite_db/mod.rs @@ -1456,10 +1456,15 @@ mod test { pub async fn make_input(val: MicroMinotari, key_manager: &MemoryDbKeyManager) -> (TransactionInput, WalletOutput) { let test_params = TestParams::new(key_manager).await; - let wallet_output = - create_wallet_output_with_data(script!(Nop), OutputFeatures::default(), &test_params, val, key_manager) - .await - .unwrap(); + let wallet_output = create_wallet_output_with_data( + script!(Nop).unwrap(), + OutputFeatures::default(), + &test_params, + val, + key_manager, + ) + .await + .unwrap(); let input = wallet_output.to_transaction_input(key_manager).await.unwrap(); (input, wallet_output) diff --git a/base_layer/wallet/src/transaction_service/error.rs b/base_layer/wallet/src/transaction_service/error.rs index 5f4479dea9..bacc587b5f 100644 --- a/base_layer/wallet/src/transaction_service/error.rs +++ b/base_layer/wallet/src/transaction_service/error.rs @@ -38,6 +38,7 @@ use tari_core::transactions::{ use tari_crypto::{errors::RangeProofError, signatures::CommitmentSignatureError}; use tari_key_manager::key_manager_service::KeyManagerServiceError; use tari_p2p::services::liveness::error::LivenessError; +use tari_script::ScriptError; use tari_service_framework::reply_channel::TransportChannelError; use tari_utilities::ByteArrayError; use thiserror::Error; @@ -195,6 +196,8 @@ pub enum TransactionServiceError { InvalidAddress(String), #[error("Transaction is not supported: `{0}`")] NotSupported(String), + #[error("Tari script error: {0}")] + ScriptError(#[from] ScriptError), } impl From for TransactionServiceError { diff --git a/base_layer/wallet/src/transaction_service/service.rs b/base_layer/wallet/src/transaction_service/service.rs index 3813882b0e..bdf64f2947 100644 --- a/base_layer/wallet/src/transaction_service/service.rs +++ b/base_layer/wallet/src/transaction_service/service.rs @@ -1428,7 +1428,7 @@ where Else CheckHeightVerify(height) PushPubKey(Box::new(self.resources.one_sided_tari_address.public_spend_key().clone())) EndIf - ); + )?; // Empty covenant let covenant = Covenant::default(); @@ -1937,7 +1937,7 @@ where fee_per_gram, tx_meta, message.clone(), - script!(Nop), + script!(Nop)?, Covenant::default(), MicroMinotari::zero(), ) @@ -2007,7 +2007,7 @@ where .features .clone(), ) - .with_script(script!(Nop)) + .with_script(script!(Nop)?) .encrypt_data_for_recovery( &self.resources.transaction_key_manager_service, Some(&recovery_key_id), diff --git a/base_layer/wallet/src/transaction_service/storage/sqlite_db.rs b/base_layer/wallet/src/transaction_service/storage/sqlite_db.rs index 4ffbcbb224..14cc8ad353 100644 --- a/base_layer/wallet/src/transaction_service/storage/sqlite_db.rs +++ b/base_layer/wallet/src/transaction_service/storage/sqlite_db.rs @@ -2286,7 +2286,7 @@ mod test { let mut builder = SenderTransactionProtocol::builder(constants, key_manager.clone()); let test_params = TestParams::new(&key_manager).await; let input = create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &test_params, MicroMinotari::from(100_000), @@ -2304,7 +2304,7 @@ mod test { .await .unwrap() .with_recipient_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), Default::default(), MicroMinotari::zero(), @@ -2313,7 +2313,7 @@ mod test { .await .unwrap() .with_change_data( - script!(Nop), + script!(Nop).unwrap(), inputs!(change.script_key_pk), change.script_key_id, change.commitment_mask_key_id, @@ -2391,7 +2391,7 @@ mod test { ); let output = create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &test_params, MicroMinotari::from(100_000), diff --git a/base_layer/wallet/tests/other/mod.rs b/base_layer/wallet/tests/other/mod.rs index 91456421cf..1c3389d8a8 100644 --- a/base_layer/wallet/tests/other/mod.rs +++ b/base_layer/wallet/tests/other/mod.rs @@ -729,7 +729,7 @@ async fn test_import_utxo() { .unwrap(); let key = PrivateKey::random(&mut OsRng); let claim = PublicKey::from_secret_key(&key); - let script = script!(Nop); + let script = script!(Nop).unwrap(); let input = inputs!(claim); let temp_features = OutputFeatures::create_coinbase(50, None, RangeProofType::BulletProofPlus); diff --git a/base_layer/wallet/tests/output_manager_service_tests/service.rs b/base_layer/wallet/tests/output_manager_service_tests/service.rs index 42827d0369..a11bf6b820 100644 --- a/base_layer/wallet/tests/output_manager_service_tests/service.rs +++ b/base_layer/wallet/tests/output_manager_service_tests/service.rs @@ -263,7 +263,7 @@ async fn generate_sender_transaction_message( .await .unwrap() .with_recipient_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), Covenant::default(), MicroMinotari::zero(), @@ -274,7 +274,7 @@ async fn generate_sender_transaction_message( let change = TestParams::new(key_manager).await; builder.with_change_data( - script!(Nop), + script!(Nop).unwrap(), inputs!(change.script_key_pk), change.script_key_id, change.commitment_mask_key_id, @@ -400,7 +400,7 @@ async fn test_utxo_selection_no_chain_metadata() { fee_per_gram, TransactionMetadata::default(), "".to_string(), - script!(Nop), + script!(Nop).unwrap(), Covenant::default(), MicroMinotari::zero(), ) @@ -436,7 +436,7 @@ async fn test_utxo_selection_no_chain_metadata() { fee_per_gram, TransactionMetadata::default(), String::new(), - script!(Nop), + script!(Nop).unwrap(), Covenant::default(), MicroMinotari::zero(), ) @@ -530,7 +530,7 @@ async fn test_utxo_selection_with_chain_metadata() { fee_per_gram, TransactionMetadata::default(), "".to_string(), - script!(Nop), + script!(Nop).unwrap(), Covenant::default(), MicroMinotari::zero(), ) @@ -612,7 +612,7 @@ async fn test_utxo_selection_with_chain_metadata() { fee_per_gram, TransactionMetadata::default(), "".to_string(), - script!(Nop), + script!(Nop).unwrap(), Covenant::default(), MicroMinotari::zero(), ) @@ -640,7 +640,7 @@ async fn test_utxo_selection_with_chain_metadata() { fee_per_gram, TransactionMetadata::default(), "".to_string(), - script!(Nop), + script!(Nop).unwrap(), Covenant::default(), MicroMinotari::zero(), ) @@ -735,7 +735,7 @@ async fn test_utxo_selection_with_tx_priority() { fee_per_gram, TransactionMetadata::default(), "".to_string(), - script!(Nop), + script!(Nop).unwrap(), Covenant::default(), MicroMinotari::zero(), ) @@ -781,7 +781,7 @@ async fn send_not_enough_funds() { MicroMinotari::from(4), TransactionMetadata::default(), "".to_string(), - script!(Nop), + script!(Nop).unwrap(), Covenant::default(), MicroMinotari::zero(), ) @@ -810,7 +810,7 @@ async fn send_no_change() { ); let value1 = 5000; let uo_1 = create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &TestParams::new(&oms.key_manager_handle).await, MicroMinotari::from(value1), @@ -825,7 +825,7 @@ async fn send_no_change() { .unwrap(); let value2 = 8000; let uo_2 = create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &TestParams::new(&oms.key_manager_handle).await, MicroMinotari::from(value2), @@ -877,7 +877,7 @@ async fn send_not_enough_for_change() { let fee_without_change = Fee::new(*constants.transaction_weight_params()).calculate(fee_per_gram, 1, 2, 1, 0); let value1 = MicroMinotari(500); let uo_1 = create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &TestParams::new(&oms.key_manager_handle).await, value1, @@ -891,7 +891,7 @@ async fn send_not_enough_for_change() { .unwrap(); let value2 = MicroMinotari(800); let uo_2 = create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &TestParams::new(&oms.key_manager_handle).await, value2, @@ -914,7 +914,7 @@ async fn send_not_enough_for_change() { fee_per_gram, TransactionMetadata::default(), "".to_string(), - script!(Nop), + script!(Nop).unwrap(), Covenant::default(), MicroMinotari::zero(), ) @@ -955,7 +955,7 @@ async fn cancel_transaction() { MicroMinotari::from(4), TransactionMetadata::default(), "".to_string(), - script!(Nop), + script!(Nop).unwrap(), Covenant::default(), MicroMinotari::zero(), ) @@ -1060,7 +1060,7 @@ async fn test_get_balance() { MicroMinotari::from(4), TransactionMetadata::default(), "".to_string(), - script!(Nop), + script!(Nop).unwrap(), Covenant::default(), MicroMinotari::zero(), ) @@ -1131,7 +1131,7 @@ async fn sending_transaction_persisted_while_offline() { MicroMinotari::from(4), TransactionMetadata::default(), "".to_string(), - script!(Nop), + script!(Nop).unwrap(), Covenant::default(), MicroMinotari::zero(), ) @@ -1164,7 +1164,7 @@ async fn sending_transaction_persisted_while_offline() { MicroMinotari::from(4), TransactionMetadata::default(), "".to_string(), - script!(Nop), + script!(Nop).unwrap(), Covenant::default(), MicroMinotari::zero(), ) @@ -1942,7 +1942,7 @@ async fn test_txo_revalidation() { let output1_value = 1_000_000; let key_manager = create_memory_db_key_manager().unwrap(); let output1 = create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &TestParams::new(&key_manager).await, MicroMinotari::from(output1_value), @@ -1958,7 +1958,7 @@ async fn test_txo_revalidation() { let output2_value = 2_000_000; let output2 = create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &TestParams::new(&key_manager).await, MicroMinotari::from(output2_value), @@ -2204,7 +2204,7 @@ async fn scan_for_recovery_test() { MicroMinotari::from(amount), commitment_mask_key.key_id, features, - script!(Nop), + script!(Nop).unwrap(), inputs!(public_script_key), script_key_id, PublicKey::default(), diff --git a/base_layer/wallet/tests/support/utils.rs b/base_layer/wallet/tests/support/utils.rs index 742c28acf3..e2ff34bd37 100644 --- a/base_layer/wallet/tests/support/utils.rs +++ b/base_layer/wallet/tests/support/utils.rs @@ -124,7 +124,7 @@ pub async fn make_input_with_features( key_manager: &MemoryDbKeyManager, ) -> WalletOutput { let test_params = TestParams::new(key_manager).await; - create_wallet_output_with_data(script!(Nop), features, &test_params, value, key_manager) + create_wallet_output_with_data(script!(Nop).unwrap(), features, &test_params, value, key_manager) .await .unwrap() } diff --git a/base_layer/wallet/tests/transaction_service_tests/service.rs b/base_layer/wallet/tests/transaction_service_tests/service.rs index 09fd092737..486d714c72 100644 --- a/base_layer/wallet/tests/transaction_service_tests/service.rs +++ b/base_layer/wallet/tests/transaction_service_tests/service.rs @@ -2546,7 +2546,7 @@ async fn finalize_tx_with_incorrect_pubkey() { MicroMinotari::from(25), TransactionMetadata::default(), "".to_string(), - script!(Nop), + script!(Nop).unwrap(), Covenant::default(), MicroMinotari::zero(), ) @@ -2675,7 +2675,7 @@ async fn finalize_tx_with_missing_output() { MicroMinotari::from(20), TransactionMetadata::default(), "".to_string(), - script!(Nop), + script!(Nop).unwrap(), Covenant::default(), MicroMinotari::zero(), ) @@ -3309,7 +3309,7 @@ async fn test_transaction_cancellation() { let key_manager = create_memory_db_key_manager().unwrap(); let input = create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &TestParams::new(&key_manager).await, MicroMinotari::from(100_000), @@ -3331,7 +3331,7 @@ async fn test_transaction_cancellation() { .await .unwrap() .with_change_data( - script!(Nop), + script!(Nop).unwrap(), inputs!(change.script_key_pk), change.script_key_id.clone(), change.commitment_mask_key_id.clone(), @@ -3339,7 +3339,7 @@ async fn test_transaction_cancellation() { TariAddress::default(), ) .with_recipient_data( - script!(Nop), + script!(Nop).unwrap(), Default::default(), Covenant::default(), MicroMinotari::zero(), @@ -3397,7 +3397,7 @@ async fn test_transaction_cancellation() { // Lets cancel the last one using a Comms stack message let input = create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &TestParams::new(&key_manager.clone()).await, MicroMinotari::from(100_000), @@ -3417,7 +3417,7 @@ async fn test_transaction_cancellation() { .await .unwrap() .with_change_data( - script!(Nop), + script!(Nop).unwrap(), inputs!(change.script_key_pk), change.script_key_id.clone(), change.commitment_mask_key_id.clone(), @@ -3425,7 +3425,7 @@ async fn test_transaction_cancellation() { TariAddress::default(), ) .with_recipient_data( - script!(Nop), + script!(Nop).unwrap(), Default::default(), Covenant::default(), MicroMinotari::zero(), @@ -4189,7 +4189,7 @@ async fn test_restarting_transaction_protocols() { .await .unwrap() .with_recipient_data( - script!(Nop), + script!(Nop).unwrap(), Default::default(), Covenant::default(), MicroMinotari::zero(), @@ -4198,7 +4198,7 @@ async fn test_restarting_transaction_protocols() { .await .unwrap() .with_change_data( - script!(Nop), + script!(Nop).unwrap(), inputs!(change.script_key_pk), change.script_key_id.clone(), change.commitment_mask_key_id.clone(), @@ -4599,7 +4599,7 @@ async fn test_resend_on_startup() { // First we will check the Send Tranasction message let key_manager = create_memory_db_key_manager().unwrap(); let input = create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &TestParams::new(&key_manager).await, MicroMinotari::from(100_000), @@ -4620,7 +4620,7 @@ async fn test_resend_on_startup() { .await .unwrap() .with_change_data( - script!(Nop), + script!(Nop).unwrap(), inputs!(change.script_key_pk), change.script_key_id.clone(), change.commitment_mask_key_id.clone(), @@ -4628,7 +4628,7 @@ async fn test_resend_on_startup() { TariAddress::default(), ) .with_recipient_data( - script!(Nop), + script!(Nop).unwrap(), Default::default(), Covenant::default(), MicroMinotari::zero(), @@ -5128,7 +5128,7 @@ async fn test_transaction_timeout_cancellation() { // First we will check the Send Transction message let key_manager = create_memory_db_key_manager().unwrap(); let input = create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &TestParams::new(&key_manager).await, MicroMinotari::from(100_000), @@ -5149,7 +5149,7 @@ async fn test_transaction_timeout_cancellation() { .await .unwrap() .with_change_data( - script!(Nop), + script!(Nop).unwrap(), inputs!(change.script_key_pk), change.script_key_id.clone(), change.commitment_mask_key_id.clone(), @@ -5157,7 +5157,7 @@ async fn test_transaction_timeout_cancellation() { TariAddress::default(), ) .with_recipient_data( - script!(Nop), + script!(Nop).unwrap(), Default::default(), Covenant::default(), MicroMinotari::zero(), diff --git a/base_layer/wallet/tests/transaction_service_tests/storage.rs b/base_layer/wallet/tests/transaction_service_tests/storage.rs index 7369ceb3b6..41e3401691 100644 --- a/base_layer/wallet/tests/transaction_service_tests/storage.rs +++ b/base_layer/wallet/tests/transaction_service_tests/storage.rs @@ -77,7 +77,7 @@ pub async fn test_db_backend(backend: T) { let mut db = TransactionDatabase::new(backend); let key_manager = create_memory_db_key_manager().unwrap(); let input = create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &TestParams::new(&key_manager).await, MicroMinotari::from(100_000), @@ -97,7 +97,7 @@ pub async fn test_db_backend(backend: T) { .await .unwrap() .with_recipient_data( - script!(Nop), + script!(Nop).unwrap(), Default::default(), Covenant::default(), MicroMinotari::zero(), @@ -107,7 +107,7 @@ pub async fn test_db_backend(backend: T) { .unwrap(); let change = TestParams::new(&key_manager).await; builder.with_change_data( - script!(Nop), + script!(Nop).unwrap(), inputs!(change.script_key_pk), change.script_key_id.clone(), change.commitment_mask_key_id.clone(), diff --git a/base_layer/wallet_ffi/src/lib.rs b/base_layer/wallet_ffi/src/lib.rs index 8795e8414f..d125a5bcfd 100644 --- a/base_layer/wallet_ffi/src/lib.rs +++ b/base_layer/wallet_ffi/src/lib.rs @@ -11602,7 +11602,7 @@ mod test { let key_manager = create_memory_db_key_manager().unwrap(); let utxo_1 = runtime .block_on(create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &runtime.block_on(TestParams::new(&key_manager)), MicroMinotari(1234u64), @@ -11625,7 +11625,7 @@ mod test { let covenant_ptr = Box::into_raw(Box::new(utxo_1.covenant.clone())); let encrypted_data_ptr = Box::into_raw(Box::new(utxo_1.encrypted_data)); let minimum_value_promise = utxo_1.minimum_value_promise.as_u64(); - let script_ptr = CString::into_raw(CString::new(script!(Nop).to_hex()).unwrap()) as *const c_char; + let script_ptr = CString::into_raw(CString::new(script!(Nop).unwrap().to_hex()).unwrap()) as *const c_char; let input_data_ptr = CString::into_raw(CString::new(utxo_1.input_data.to_hex()).unwrap()) as *const c_char; let tari_utxo = create_tari_unblinded_output( @@ -11754,7 +11754,7 @@ mod test { // Test import with bulletproof range proof let utxo_1 = runtime .block_on(create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &runtime.block_on(TestParams::new(key_manager)), MicroMinotari(1234u64), @@ -11805,7 +11805,8 @@ mod test { let covenant_ptr_1 = Box::into_raw(Box::new(utxo_1.covenant.clone())); let encrypted_data_ptr_1 = Box::into_raw(Box::new(utxo_1.encrypted_data)); let minimum_value_promise = utxo_1.minimum_value_promise.as_u64(); - let script_ptr_1 = CString::into_raw(CString::new(script!(Nop).to_hex()).unwrap()) as *const c_char; + let script_ptr_1 = + CString::into_raw(CString::new(script!(Nop).unwrap().to_hex()).unwrap()) as *const c_char; let input_data_ptr_1 = CString::into_raw(CString::new(utxo_1.input_data.to_hex()).unwrap()) as *const c_char; @@ -11847,7 +11848,7 @@ mod test { }; let utxo_2 = runtime .block_on(create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), features, &runtime.block_on(TestParams::new(key_manager)), MicroMinotari(12345u64), @@ -11871,7 +11872,8 @@ mod test { let covenant_ptr_2 = Box::into_raw(Box::new(utxo_2.covenant.clone())); let encrypted_data_ptr_2 = Box::into_raw(Box::new(utxo_2.encrypted_data)); let minimum_value_promise = utxo_2.minimum_value_promise.as_u64(); - let script_ptr_2 = CString::into_raw(CString::new(script!(Nop).to_hex()).unwrap()) as *const c_char; + let script_ptr_2 = + CString::into_raw(CString::new(script!(Nop).unwrap().to_hex()).unwrap()) as *const c_char; let input_data_ptr_2 = CString::into_raw(CString::new(utxo_2.input_data.to_hex()).unwrap()) as *const c_char; @@ -11980,7 +11982,7 @@ mod test { let key_manager = create_memory_db_key_manager().unwrap(); let utxo_1 = runtime .block_on(create_wallet_output_with_data( - script!(Nop), + script!(Nop).unwrap(), OutputFeatures::default(), &runtime.block_on(TestParams::new(&key_manager)), MicroMinotari(1234u64), @@ -12005,7 +12007,7 @@ mod test { let encrypted_data_ptr = Box::into_raw(Box::new(utxo_1.encrypted_data)); let minimum_value_promise = utxo_1.minimum_value_promise.as_u64(); let message_ptr = CString::into_raw(CString::new("For my friend").unwrap()) as *const c_char; - let script_ptr = CString::into_raw(CString::new(script!(Nop).to_hex()).unwrap()) as *const c_char; + let script_ptr = CString::into_raw(CString::new(script!(Nop).unwrap().to_hex()).unwrap()) as *const c_char; let input_data_ptr = CString::into_raw(CString::new(utxo_1.input_data.to_hex()).unwrap()) as *const c_char; let tari_utxo = create_tari_unblinded_output( diff --git a/infrastructure/max_size/src/vec.rs b/infrastructure/max_size/src/vec.rs index 561edc8606..3e5d26ec42 100644 --- a/infrastructure/max_size/src/vec.rs +++ b/infrastructure/max_size/src/vec.rs @@ -193,7 +193,7 @@ impl FromIterator for MaxSizeVec { } } -#[derive(Debug, thiserror::Error)] +#[derive(Clone, Debug, thiserror::Error, Eq, PartialEq, Serialize, Deserialize)] pub enum MaxSizeVecError { #[error("Invalid vector length: expected {expected}, got {actual}")] MaxSizeVecLengthError { expected: usize, actual: usize }, diff --git a/infrastructure/tari_script/src/error.rs b/infrastructure/tari_script/src/error.rs index dd82be7783..16bce63c06 100644 --- a/infrastructure/tari_script/src/error.rs +++ b/infrastructure/tari_script/src/error.rs @@ -18,6 +18,7 @@ use std::num::TryFromIntError; use serde::{Deserialize, Serialize}; +use tari_max_size::MaxSizeVecError; use tari_utilities::ByteArrayError; use thiserror::Error; @@ -51,6 +52,14 @@ pub enum ScriptError { InvalidDigest, #[error("A compare opcode failed, aborting the script immediately with reason: `{0}`")] CompareFailed(String), + #[error("Max sized vector error: {0}")] + MaxSizeVecError(#[from] MaxSizeVecError), +} + +impl ScriptError { + pub fn to_std_io_error(self) -> std::io::Error { + std::io::Error::new(std::io::ErrorKind::Other, self.to_string()) + } } impl From for ScriptError { diff --git a/infrastructure/tari_script/src/lib.rs b/infrastructure/tari_script/src/lib.rs index c3371acf9f..8c71bce6bd 100644 --- a/infrastructure/tari_script/src/lib.rs +++ b/infrastructure/tari_script/src/lib.rs @@ -33,7 +33,7 @@ pub use op_codes::{ OpcodeVersion, ScalarValue, }; -pub use script::TariScript; +pub use script::{ScriptOpcodes, TariScript}; pub use script_context::ScriptContext; pub use stack::{ExecutionStack, StackItem}; use tari_crypto::{ @@ -49,5 +49,5 @@ pub type CheckSigSchnorrSignature = SchnorrSignature TariScript { - script!(PushPubKey(Box::new(destination_public_key.clone()))) + script!(PushPubKey(Box::new(destination_public_key.clone()))).expect("single opcode will not fail") } diff --git a/infrastructure/tari_script/src/script.rs b/infrastructure/tari_script/src/script.rs index 1a7c82d965..31743a151b 100644 --- a/infrastructure/tari_script/src/script.rs +++ b/infrastructure/tari_script/src/script.rs @@ -59,11 +59,12 @@ macro_rules! script { const MAX_MULTISIG_LIMIT: u8 = 32; const MAX_SCRIPT_BYTES: usize = 4096; -pub(crate) type ScriptOpcodes = MaxSizeVec; +/// The sized vector of opcodes that make up a script +pub type ScriptOpcodes = MaxSizeVec; #[derive(Clone, Debug, PartialEq, Eq)] pub struct TariScript { - script: Vec, + script: ScriptOpcodes, } impl BorshSerialize for TariScript { @@ -98,8 +99,9 @@ impl BorshDeserialize for TariScript { } impl TariScript { - pub fn new(script: Vec) -> Self { - TariScript { script } + pub fn new(script: Vec) -> Result { + let script = ScriptOpcodes::try_from(script)?; + Ok(TariScript { script }) } /// This pattern matches two scripts ensure they have the same instructions in the opcodes, but not the same values @@ -147,7 +149,7 @@ impl TariScript { // Local execution state let mut state = ExecutionState::default(); - for opcode in &self.script { + for opcode in self.script.iter() { if self.should_execute(opcode, &state)? { self.execute_opcode(opcode, &mut stack, context, &mut state)? } else { @@ -193,7 +195,7 @@ impl TariScript { } pub fn as_slice(&self) -> &[Opcode] { - self.script.as_slice() + self.script.as_ref() } /// Calculate the hash of the script. @@ -209,7 +211,7 @@ impl TariScript { /// Try to deserialise a byte slice into a valid Tari script pub fn from_bytes(bytes: &[u8]) -> Result { - let script = Opcode::parse(bytes)?; + let script = ScriptOpcodes::try_from(Opcode::parse(bytes)?)?; Ok(TariScript { script }) } @@ -688,7 +690,7 @@ impl Hex for TariScript { /// The default Tari script is to push a sender pubkey onto the stack impl Default for TariScript { fn default() -> Self { - script!(PushPubKey(Box::default())) + script!(PushPubKey(Box::default())).expect("default will not fail") } } @@ -759,28 +761,28 @@ mod test { #[test] fn pattern_match() { - let script_a = script!(Or(1)); - let script_b = script!(Or(1)); + let script_a = script!(Or(1)).unwrap(); + let script_b = script!(Or(1)).unwrap(); assert_eq!(script_a, script_b); assert!(script_a.pattern_match(&script_b)); - let script_b = script!(Or(2)); + let script_b = script!(Or(2)).unwrap(); assert_ne!(script_a, script_b); assert!(script_a.pattern_match(&script_b)); - let script_b = script!(Or(2) Or(2)); + let script_b = script!(Or(2) Or(2)).unwrap(); assert_ne!(script_a, script_b); assert!(!script_a.pattern_match(&script_b)); - let script_a = script!(Or(2) Or(1)); - let script_b = script!(Or(3) Or(5)); + let script_a = script!(Or(2) Or(1)).unwrap(); + let script_b = script!(Or(3) Or(5)).unwrap(); assert_ne!(script_a, script_b); assert!(script_a.pattern_match(&script_b)); } #[test] fn op_or() { - let script = script!(Or(1)); + let script = script!(Or(1)).unwrap(); let inputs = inputs!(4, 4); let result = script.execute(&inputs).unwrap(); @@ -790,7 +792,7 @@ mod test { let result = script.execute(&inputs).unwrap(); assert_eq!(result, Number(0)); - let script = script!(Or(3)); + let script = script!(Or(3)).unwrap(); let inputs = inputs!(1, 2, 1, 3); let result = script.execute(&inputs).unwrap(); @@ -814,7 +816,7 @@ mod test { let err = script.execute(&inputs).unwrap_err(); assert!(matches!(err, ScriptError::StackUnderflow)); - let script = script!(OrVerify(1)); + let script = script!(OrVerify(1)).unwrap(); let inputs = inputs!(1, 4, 4); let result = script.execute(&inputs).unwrap(); @@ -824,7 +826,7 @@ mod test { let err = script.execute(&inputs).unwrap_err(); assert!(matches!(err, ScriptError::VerifyFailed)); - let script = script!(OrVerify(2)); + let script = script!(OrVerify(2)).unwrap(); let inputs = inputs!(1, 2, 2, 3); let result = script.execute(&inputs).unwrap(); @@ -838,7 +840,7 @@ mod test { #[test] fn op_if_then_else() { // basic - let script = script!(IfThen PushInt(420) Else PushInt(66) EndIf); + let script = script!(IfThen PushInt(420) Else PushInt(66) EndIf).unwrap(); let inputs = inputs!(1); let result = script.execute(&inputs); assert_eq!(result.unwrap(), Number(420)); @@ -848,54 +850,57 @@ mod test { assert_eq!(result.unwrap(), Number(66)); // nested - let script = script!(IfThen PushOne IfThen PushInt(420) Else PushInt(555) EndIf Else PushInt(66) EndIf); + let script = + script!(IfThen PushOne IfThen PushInt(420) Else PushInt(555) EndIf Else PushInt(66) EndIf).unwrap(); let inputs = inputs!(1); let result = script.execute(&inputs); assert_eq!(result.unwrap(), Number(420)); - let script = script!(IfThen PushInt(420) Else PushZero IfThen PushInt(111) Else PushInt(66) EndIf Nop EndIf); + let script = + script!(IfThen PushInt(420) Else PushZero IfThen PushInt(111) Else PushInt(66) EndIf Nop EndIf).unwrap(); let inputs = inputs!(0); let result = script.execute(&inputs); assert_eq!(result.unwrap(), Number(66)); // duplicate else - let script = script!(IfThen PushInt(420) Else PushInt(66) Else PushInt(777) EndIf); + let script = script!(IfThen PushInt(420) Else PushInt(66) Else PushInt(777) EndIf).unwrap(); let inputs = inputs!(0); let result = script.execute(&inputs); assert_eq!(result.unwrap_err(), ScriptError::InvalidOpcode); // unexpected else - let script = script!(Else); + let script = script!(Else).unwrap(); let inputs = inputs!(0); let result = script.execute(&inputs); assert_eq!(result.unwrap_err(), ScriptError::InvalidOpcode); // unexpected endif - let script = script!(EndIf); + let script = script!(EndIf).unwrap(); let inputs = inputs!(0); let result = script.execute(&inputs); assert_eq!(result.unwrap_err(), ScriptError::InvalidOpcode); // duplicate endif - let script = script!(IfThen PushInt(420) Else PushInt(66) EndIf EndIf); + let script = script!(IfThen PushInt(420) Else PushInt(66) EndIf EndIf).unwrap(); let inputs = inputs!(0); let result = script.execute(&inputs); assert_eq!(result.unwrap_err(), ScriptError::InvalidOpcode); // no else or endif - let script = script!(IfThen PushOne IfThen PushOne); + let script = script!(IfThen PushOne IfThen PushOne).unwrap(); let inputs = inputs!(1); let result = script.execute(&inputs); assert_eq!(result.unwrap_err(), ScriptError::MissingOpcode); // no else - let script = script!(IfThen PushOne EndIf); + let script = script!(IfThen PushOne EndIf).unwrap(); let inputs = inputs!(1); let result = script.execute(&inputs); assert_eq!(result.unwrap_err(), ScriptError::MissingOpcode); // nested bug - let script = script!(IfThen PushInt(111) Else PushZero IfThen PushInt(222) Else PushInt(333) EndIf EndIf); + let script = + script!(IfThen PushInt(111) Else PushZero IfThen PushInt(222) Else PushInt(333) EndIf EndIf).unwrap(); let inputs = inputs!(1); let result = script.execute(&inputs); assert_eq!(result.unwrap(), Number(111)); @@ -904,7 +909,7 @@ mod test { #[test] fn op_check_height() { let inputs = ExecutionStack::default(); - let script = script!(CheckHeight(5)); + let script = script!(CheckHeight(5)).unwrap(); for block_height in 1..=10 { let ctx = context_with_height(u64::try_from(block_height).unwrap()); @@ -914,12 +919,12 @@ mod test { ); } - let script = script!(CheckHeight(u64::MAX)); + let script = script!(CheckHeight(u64::MAX)).unwrap(); let ctx = context_with_height(i64::MAX as u64); let err = script.execute_with_context(&inputs, &ctx).unwrap_err(); assert!(matches!(err, ScriptError::ValueExceedsBounds)); - let script = script!(CheckHeightVerify(5)); + let script = script!(CheckHeightVerify(5)).unwrap(); let inputs = inputs!(1); for block_height in 1..5 { @@ -937,7 +942,7 @@ mod test { #[test] fn op_compare_height() { - let script = script!(CompareHeight); + let script = script!(CompareHeight).unwrap(); let inputs = inputs!(5); for block_height in 1..=10 { @@ -948,7 +953,7 @@ mod test { ); } - let script = script!(CompareHeightVerify); + let script = script!(CompareHeightVerify).unwrap(); let inputs = inputs!(1, 5); for block_height in 1..5 { @@ -967,37 +972,37 @@ mod test { #[test] fn op_drop_push() { let inputs = inputs!(420); - let script = script!(Drop PushOne); + let script = script!(Drop PushOne).unwrap(); assert_eq!(script.execute(&inputs).unwrap(), Number(1)); - let script = script!(Drop PushZero); + let script = script!(Drop PushZero).unwrap(); assert_eq!(script.execute(&inputs).unwrap(), Number(0)); - let script = script!(Drop PushInt(5)); + let script = script!(Drop PushInt(5)).unwrap(); assert_eq!(script.execute(&inputs).unwrap(), Number(5)); } #[test] fn op_comparison_to_zero() { - let script = script!(GeZero); + let script = script!(GeZero).unwrap(); let inputs = inputs!(1); assert_eq!(script.execute(&inputs).unwrap(), Number(1)); let inputs = inputs!(0); assert_eq!(script.execute(&inputs).unwrap(), Number(1)); - let script = script!(GtZero); + let script = script!(GtZero).unwrap(); let inputs = inputs!(1); assert_eq!(script.execute(&inputs).unwrap(), Number(1)); let inputs = inputs!(0); assert_eq!(script.execute(&inputs).unwrap(), Number(0)); - let script = script!(LeZero); + let script = script!(LeZero).unwrap(); let inputs = inputs!(-1); assert_eq!(script.execute(&inputs).unwrap(), Number(1)); let inputs = inputs!(0); assert_eq!(script.execute(&inputs).unwrap(), Number(1)); - let script = script!(LtZero); + let script = script!(LtZero).unwrap(); let inputs = inputs!(-1); assert_eq!(script.execute(&inputs).unwrap(), Number(1)); let inputs = inputs!(0); @@ -1009,7 +1014,7 @@ mod test { let mut rng = rand::thread_rng(); let (_, p) = RistrettoPublicKey::random_keypair(&mut rng); let c = PedersenCommitment::from_public_key(&p); - let script = script!(HashSha256); + let script = script!(HashSha256).unwrap(); let hash = Sha256::digest(p.as_bytes()); let inputs = inputs!(p.clone()); @@ -1019,7 +1024,7 @@ mod test { let inputs = inputs!(c.clone()); assert_eq!(script.execute(&inputs).unwrap(), Hash(hash.into())); - let script = script!(HashSha3); + let script = script!(HashSha3).unwrap(); let hash = Sha3::digest(p.as_bytes()); let inputs = inputs!(p); @@ -1032,14 +1037,14 @@ mod test { #[test] fn op_return() { - let script = script!(Return); + let script = script!(Return).unwrap(); let inputs = ExecutionStack::default(); assert_eq!(script.execute(&inputs), Err(ScriptError::Return)); } #[test] fn op_add() { - let script = script!(Add); + let script = script!(Add).unwrap(); let inputs = inputs!(3, 2); assert_eq!(script.execute(&inputs).unwrap(), Number(5)); let inputs = inputs!(3, -3); @@ -1052,7 +1057,7 @@ mod test { #[test] fn op_add_commitments() { - let script = script!(Add); + let script = script!(Add).unwrap(); let mut rng = rand::thread_rng(); let (_, c1) = RistrettoPublicKey::random_keypair(&mut rng); let (_, c2) = RistrettoPublicKey::random_keypair(&mut rng); @@ -1068,19 +1073,19 @@ mod test { #[test] fn op_sub() { use crate::StackItem::Number; - let script = script!(Add Sub); + let script = script!(Add Sub).unwrap(); let inputs = inputs!(5, 3, 2); assert_eq!(script.execute(&inputs).unwrap(), Number(0)); let inputs = inputs!(i64::MAX, 1); assert_eq!(script.execute(&inputs), Err(ScriptError::ValueExceedsBounds)); - let script = script!(Sub); + let script = script!(Sub).unwrap(); let inputs = inputs!(5, 3); assert_eq!(script.execute(&inputs).unwrap(), Number(2)); } #[test] fn serialisation() { - let script = script!(Add Sub Add); + let script = script!(Add Sub Add).unwrap(); assert_eq!(&script.to_bytes(), &[0x93, 0x94, 0x93]); assert_eq!(TariScript::from_bytes(&[0x93, 0x94, 0x93]).unwrap(), script); assert_eq!(script.to_hex(), "939493"); @@ -1095,14 +1100,14 @@ mod test { let m_key = RistrettoSecretKey::random(&mut rng); let sig = CheckSigSchnorrSignature::sign(&pvt_key, m_key.as_bytes(), &mut rng).unwrap(); let msg = slice_to_boxed_message(m_key.as_bytes()); - let script = script!(CheckSig(msg)); + let script = script!(CheckSig(msg)).unwrap(); let inputs = inputs!(sig.clone(), pub_key.clone()); let result = script.execute(&inputs).unwrap(); assert_eq!(result, Number(1)); let n_key = RistrettoSecretKey::random(&mut rng); let msg = slice_to_boxed_message(n_key.as_bytes()); - let script = script!(CheckSig(msg)); + let script = script!(CheckSig(msg)).unwrap(); let inputs = inputs!(sig, pub_key); let result = script.execute(&inputs).unwrap(); assert_eq!(result, Number(0)); @@ -1116,14 +1121,14 @@ mod test { let m_key = RistrettoSecretKey::random(&mut rng); let sig = CheckSigSchnorrSignature::sign(&pvt_key, m_key.as_bytes(), &mut rng).unwrap(); let msg = slice_to_boxed_message(m_key.as_bytes()); - let script = script!(CheckSigVerify(msg) PushOne); + let script = script!(CheckSigVerify(msg) PushOne).unwrap(); let inputs = inputs!(sig.clone(), pub_key.clone()); let result = script.execute(&inputs).unwrap(); assert_eq!(result, Number(1)); let n_key = RistrettoSecretKey::random(&mut rng); let msg = slice_to_boxed_message(n_key.as_bytes()); - let script = script!(CheckSigVerify(msg)); + let script = script!(CheckSigVerify(msg)).unwrap(); let inputs = inputs!(sig, pub_key); let err = script.execute(&inputs).unwrap_err(); assert!(matches!(err, ScriptError::VerifyFailed)); @@ -1169,7 +1174,7 @@ mod test { // 1 of 2 let keys = vec![p_alice.clone(), p_bob.clone()]; let ops = vec![CheckMultiSig(1, 2, keys, msg.clone())]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); let inputs = inputs!(s_alice.clone()); let result = script.execute(&inputs).unwrap(); @@ -1184,7 +1189,7 @@ mod test { // 2 of 2 let keys = vec![p_alice.clone(), p_bob.clone()]; let ops = vec![CheckMultiSig(2, 2, keys, msg.clone())]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); let inputs = inputs!(s_alice.clone(), s_bob.clone()); let result = script.execute(&inputs).unwrap(); @@ -1204,7 +1209,7 @@ mod test { // 1 of 3 let keys = vec![p_alice.clone(), p_bob.clone(), p_carol.clone()]; let ops = vec![CheckMultiSig(1, 3, keys, msg.clone())]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); let inputs = inputs!(s_alice.clone()); let result = script.execute(&inputs).unwrap(); @@ -1222,7 +1227,7 @@ mod test { // 2 of 3 let keys = vec![p_alice.clone(), p_bob.clone(), p_carol.clone()]; let ops = vec![CheckMultiSig(2, 3, keys, msg.clone())]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); let inputs = inputs!(s_alice.clone(), s_bob.clone()); let result = script.execute(&inputs).unwrap(); @@ -1243,7 +1248,7 @@ mod test { // check that sigs are only counted once let keys = vec![p_alice.clone(), p_bob.clone(), p_alice.clone()]; let ops = vec![CheckMultiSig(2, 3, keys, msg.clone())]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); let inputs = inputs!(s_alice.clone(), s_carol.clone()); let result = script.execute(&inputs).unwrap(); @@ -1262,7 +1267,7 @@ mod test { // 3 of 3 let keys = vec![p_alice.clone(), p_bob.clone(), p_carol]; let ops = vec![CheckMultiSig(3, 3, keys, msg.clone())]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); let inputs = inputs!(s_alice.clone(), s_bob.clone(), s_carol.clone()); let result = script.execute(&inputs).unwrap(); @@ -1280,21 +1285,21 @@ mod test { // errors let keys = vec![p_alice.clone(), p_bob.clone()]; let ops = vec![CheckMultiSig(0, 2, keys, msg.clone())]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); let inputs = inputs!(s_alice.clone()); let err = script.execute(&inputs).unwrap_err(); assert_eq!(err, ScriptError::ValueExceedsBounds); let keys = vec![p_alice.clone(), p_bob.clone()]; let ops = vec![CheckMultiSig(1, 0, keys, msg.clone())]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); let inputs = inputs!(s_alice.clone()); let err = script.execute(&inputs).unwrap_err(); assert_eq!(err, ScriptError::ValueExceedsBounds); let keys = vec![p_alice, p_bob]; let ops = vec![CheckMultiSig(2, 1, keys, msg)]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); let inputs = inputs!(s_alice); let err = script.execute(&inputs).unwrap_err(); assert_eq!(err, ScriptError::ValueExceedsBounds); @@ -1303,7 +1308,7 @@ mod test { let (msg, data) = multisig_data(33); let keys = data.iter().map(|(_, p, _)| p.clone()).collect(); let sigs = data.iter().take(17).map(|(_, _, s)| s.clone()); - let script = script!(CheckMultiSig(17, 33, keys, msg)); + let script = script!(CheckMultiSig(17, 33, keys, msg)).unwrap(); let items = sigs.map(StackItem::Signature).collect(); let inputs = ExecutionStack::new(items); let err = script.execute(&inputs).unwrap_err(); @@ -1318,7 +1323,7 @@ mod test { data[3].1.clone(), ]; let ops = vec![CheckMultiSig(3, 4, keys, msg)]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); let inputs = inputs!(data[0].2.clone(), data[1].2.clone(), data[2].2.clone()); let result = script.execute(&inputs).unwrap(); assert_eq!(result, Number(1)); @@ -1335,7 +1340,7 @@ mod test { data[6].1.clone(), ]; let ops = vec![CheckMultiSig(5, 7, keys, msg)]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); let inputs = inputs!( data[0].2.clone(), data[1].2.clone(), @@ -1366,7 +1371,7 @@ mod test { // 1 of 2 let keys = vec![p_alice.clone(), p_bob.clone()]; let ops = vec![CheckMultiSigVerify(1, 2, keys, msg.clone())]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); let inputs = inputs!(Number(1), s_alice.clone()); let result = script.execute(&inputs).unwrap(); @@ -1381,7 +1386,7 @@ mod test { // 2 of 2 let keys = vec![p_alice.clone(), p_bob.clone()]; let ops = vec![CheckMultiSigVerify(2, 2, keys, msg.clone())]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); let inputs = inputs!(Number(1), s_alice.clone(), s_bob.clone()); let result = script.execute(&inputs).unwrap(); @@ -1396,7 +1401,7 @@ mod test { // 1 of 3 let keys = vec![p_alice.clone(), p_bob.clone(), p_carol.clone()]; let ops = vec![CheckMultiSigVerify(1, 3, keys, msg.clone())]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); let inputs = inputs!(Number(1), s_alice.clone()); let result = script.execute(&inputs).unwrap(); @@ -1414,7 +1419,7 @@ mod test { // 2 of 3 let keys = vec![p_alice.clone(), p_bob.clone(), p_carol.clone()]; let ops = vec![CheckMultiSigVerify(2, 3, keys, msg.clone())]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); let inputs = inputs!(Number(1), s_alice.clone(), s_bob.clone()); let result = script.execute(&inputs).unwrap(); @@ -1435,7 +1440,7 @@ mod test { // 2 of 3 (returning the aggregate public key of the signatories) let keys = vec![p_alice.clone(), p_bob.clone(), p_carol.clone()]; let ops = vec![CheckMultiSigVerifyAggregatePubKey(2, 3, keys, msg.clone())]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); let inputs = inputs!(s_alice.clone(), s_bob.clone()); let agg_pub_key = script.execute(&inputs).unwrap(); @@ -1464,7 +1469,7 @@ mod test { // 3 of 3 let keys = vec![p_alice.clone(), p_bob.clone(), p_carol]; let ops = vec![CheckMultiSigVerify(3, 3, keys, msg.clone())]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); let inputs = inputs!(Number(1), s_alice.clone(), s_bob.clone(), s_carol.clone()); let result = script.execute(&inputs).unwrap(); @@ -1482,21 +1487,21 @@ mod test { // errors let keys = vec![p_alice.clone(), p_bob.clone()]; let ops = vec![CheckMultiSigVerify(0, 2, keys, msg.clone())]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); let inputs = inputs!(s_alice.clone()); let err = script.execute(&inputs).unwrap_err(); assert_eq!(err, ScriptError::ValueExceedsBounds); let keys = vec![p_alice.clone(), p_bob.clone()]; let ops = vec![CheckMultiSigVerify(1, 0, keys, msg.clone())]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); let inputs = inputs!(s_alice.clone()); let err = script.execute(&inputs).unwrap_err(); assert_eq!(err, ScriptError::ValueExceedsBounds); let keys = vec![p_alice, p_bob]; let ops = vec![CheckMultiSigVerify(2, 1, keys, msg)]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); let inputs = inputs!(s_alice); let err = script.execute(&inputs).unwrap_err(); assert_eq!(err, ScriptError::ValueExceedsBounds); @@ -1510,7 +1515,7 @@ mod test { data[3].1.clone(), ]; let ops = vec![CheckMultiSigVerify(3, 4, keys, msg)]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); let inputs = inputs!(Number(1), data[0].2.clone(), data[1].2.clone(), data[2].2.clone()); let result = script.execute(&inputs).unwrap(); assert_eq!(result, Number(1)); @@ -1527,7 +1532,7 @@ mod test { data[6].1.clone(), ]; let ops = vec![CheckMultiSigVerify(5, 7, keys, msg)]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); let inputs = inputs!( Number(1), data[0].2.clone(), @@ -1551,7 +1556,7 @@ mod test { // Unlike in Bitcoin where P2PKH includes a CheckSig at the end of the script, that part of the process is built // into definition of how TariScript is evaluated by a base node or wallet - let script = script!(Dup HashBlake256 PushHash(pkh) EqualVerify); + let script = script!(Dup HashBlake256 PushHash(pkh) EqualVerify).unwrap(); let hex_script = "71b07aae2337ce44f9ebb6169c863ec168046cb35ab4ef7aa9ed4f5f1f669bb74b09e581"; // Test serialisation assert_eq!(script.to_hex(), hex_script); @@ -1574,7 +1579,7 @@ mod test { let sig = CheckSigSchnorrSignature::sign(&secret_key, message, &mut rng).unwrap(); // Produce a script using the signature - let script = script!(CheckSig(slice_to_boxed_message(message.as_bytes()))); + let script = script!(CheckSig(slice_to_boxed_message(message.as_bytes()))).unwrap(); // Produce input satisfying the script let input = inputs!(sig, public_key); @@ -1629,7 +1634,7 @@ mod test { let lock_height = 4000u64; - let script = script!(Dup PushPubKey(Box::new(p_bob.clone())) CheckHeight(lock_height) GeZero IfThen PushPubKey(Box::new(p_alice.clone())) OrVerify(2) Else EqualVerify EndIf ); + let script = script!(Dup PushPubKey(Box::new(p_bob.clone())) CheckHeight(lock_height) GeZero IfThen PushPubKey(Box::new(p_alice.clone())) OrVerify(2) Else EqualVerify EndIf ).unwrap(); // Alice tries to spend the output before the height is reached let inputs_alice_spends_early = inputs!(p_alice.clone()); @@ -1698,7 +1703,7 @@ mod test { EndIf, EndIf, ]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); // alice let inputs = inputs!(s_alice); @@ -1726,7 +1731,7 @@ mod test { // Generate a test script let ops = vec![ToRistrettoPoint]; - let script = TariScript::new(ops); + let script = TariScript::new(ops).unwrap(); // Invalid stack type let inputs = inputs!(RistrettoPublicKey::default()); @@ -1774,7 +1779,7 @@ mod test { #[test] fn test_compare_height_block_height_exceeds_bounds() { - let script = script!(CompareHeight); + let script = script!(CompareHeight).unwrap(); let inputs = inputs!(0); let ctx = context_with_height(u64::MAX); @@ -1784,7 +1789,7 @@ mod test { #[test] fn test_compare_height_underflows() { - let script = script!(CompareHeight); + let script = script!(CompareHeight).unwrap(); let inputs = ExecutionStack::new(vec![Number(i64::MIN)]); let ctx = context_with_height(i64::MAX as u64); @@ -1794,7 +1799,7 @@ mod test { #[test] fn test_compare_height_underflows_on_empty_stack() { - let script = script!(CompareHeight); + let script = script!(CompareHeight).unwrap(); let inputs = ExecutionStack::new(vec![]); let ctx = context_with_height(i64::MAX as u64); @@ -1804,7 +1809,7 @@ mod test { #[test] fn test_compare_height_valid_with_uint_result() { - let script = script!(CompareHeight); + let script = script!(CompareHeight).unwrap(); let inputs = inputs!(100); let ctx = context_with_height(24_u64); @@ -1815,7 +1820,7 @@ mod test { #[test] fn test_compare_height_valid_with_int_result() { - let script = script!(CompareHeight); + let script = script!(CompareHeight).unwrap(); let inputs = inputs!(100); let ctx = context_with_height(110_u64); @@ -1826,7 +1831,7 @@ mod test { #[test] fn test_check_height_block_height_exceeds_bounds() { - let script = script!(CheckHeight(0)); + let script = script!(CheckHeight(0)).unwrap(); let inputs = ExecutionStack::new(vec![]); let ctx = context_with_height(u64::MAX); @@ -1836,7 +1841,7 @@ mod test { #[test] fn test_check_height_exceeds_bounds() { - let script = script!(CheckHeight(u64::MAX)); + let script = script!(CheckHeight(u64::MAX)).unwrap(); let inputs = ExecutionStack::new(vec![]); let ctx = context_with_height(10_u64); @@ -1846,7 +1851,7 @@ mod test { #[test] fn test_check_height_overflows_on_max_stack() { - let script = script!(CheckHeight(0)); + let script = script!(CheckHeight(0)).unwrap(); let mut inputs = ExecutionStack::new(vec![]); @@ -1861,7 +1866,7 @@ mod test { #[test] fn test_check_height_valid_with_uint_result() { - let script = script!(CheckHeight(24)); + let script = script!(CheckHeight(24)).unwrap(); let inputs = ExecutionStack::new(vec![]); let ctx = context_with_height(100_u64); @@ -1872,7 +1877,7 @@ mod test { #[test] fn test_check_height_valid_with_int_result() { - let script = script!(CheckHeight(100)); + let script = script!(CheckHeight(100)).unwrap(); let inputs = ExecutionStack::new(vec![]); let ctx = context_with_height(24_u64); diff --git a/integration_tests/src/transaction.rs b/integration_tests/src/transaction.rs index 98ca4e333e..7029a92963 100644 --- a/integration_tests/src/transaction.rs +++ b/integration_tests/src/transaction.rs @@ -106,7 +106,7 @@ impl TestTransactionBuilder { } async fn create_utxo(&mut self, key_manager: &MemoryDbKeyManager, num_inputs: usize) { - let script = script!(Nop); + let script = script!(Nop).expect("Single opcode will not fail"); let features = OutputFeatures::default(); let covenant = Covenant::default(); let value = self.amount -