From 3774f40a6813264b6467bebc404be70a472f9f0f Mon Sep 17 00:00:00 2001 From: joii2020 Date: Mon, 4 Mar 2024 18:09:38 +0800 Subject: [PATCH 1/3] Fix incorrect shrinking --- c/basic.mol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/c/basic.mol b/c/basic.mol index 59cc5b2..21a2242 100644 --- a/c/basic.mol +++ b/c/basic.mol @@ -32,14 +32,14 @@ table ScriptInfo { vector ScriptInfoVec ; table ResolvedInputs { - outputs: CellOutputVec, - outputs_data: BytesVec, + outputs: CellOutputVec, + outputs_data: BytesVec, } table BuildingPacketV1 { message: Message, payload: Transaction, - resolved_inputs: ResolvedInputs, + resolved_inputs: ResolvedInputs, change_output: Uint32Opt, script_infos: ScriptInfoVec, lock_actions: ActionVec, From 75eab549806f81863766d56df439d444e8acc063 Mon Sep 17 00:00:00 2001 From: joii2020 Date: Tue, 5 Mar 2024 10:05:53 +0800 Subject: [PATCH 2/3] Add testcase: * The witnesses is none * The output data is big enough(16M) * Add a 16M witness * Args is big enough (16M) --- tests/omni_lock_rust/tests/misc.rs | 3 + tests/omni_lock_rust/tests/test_omni_lock.rs | 84 +++++++++++++++++++- 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/tests/omni_lock_rust/tests/misc.rs b/tests/omni_lock_rust/tests/misc.rs index d017f4c..cbf3c27 100644 --- a/tests/omni_lock_rust/tests/misc.rs +++ b/tests/omni_lock_rust/tests/misc.rs @@ -89,6 +89,9 @@ pub const ERROR_COBUILD_MOL2_ERR_DATA: i8 = 0x07; pub const ERROR_SIGHASHALL_DUP: i8 = 113; pub const MOL2_ERR_OVERFLOW: i8 = 8; // parse witnesses error +pub const ERROR_IDENTITY_WRONG_ARGS: i8 = 71; +pub const ERROR_ARGS_FORMAT: i8 = 87; + // https://github.com/bitcoin-core/secp256k1/blob/d373bf6d08c82ac5496bf8103698c9f54d8d99d2/include/secp256k1.h#L219 pub const SECP256K1_TAG_PUBKEY_EVEN: u8 = 0x02; pub const SECP256K1_TAG_PUBKEY_ODD: u8 = 0x03; diff --git a/tests/omni_lock_rust/tests/test_omni_lock.rs b/tests/omni_lock_rust/tests/test_omni_lock.rs index e67e8c4..6d87e41 100644 --- a/tests/omni_lock_rust/tests/test_omni_lock.rs +++ b/tests/omni_lock_rust/tests/test_omni_lock.rs @@ -18,7 +18,7 @@ use ckb_types::{ bytes::Bytes, bytes::BytesMut, core::{cell::ResolvedTransaction, EpochNumberWithFraction, HeaderView}, - packed::WitnessArgs, + packed::{CellInput, WitnessArgs}, prelude::*, H256, }; @@ -1205,3 +1205,85 @@ fn test_cobuild_check_action_script_hash_is_in_2_outputs() { let verify_result = verifier.verify(MAX_CYCLES); verify_result.expect("pass verification"); } + +#[test] +fn test_none_witness() { + let mut data_loader = DummyDataLoader::new(); + + let mut config = TestConfig::new(IDENTITY_FLAGS_BITCOIN, false); + config + .set_chain_config(Box::new(BitcoinConfig { sign_vtype: BITCOIN_V_TYPE_P2PKHUNCOMPRESSED, pubkey_err: false })); + + let tx = gen_tx(&mut data_loader, &mut config); + let tx = sign_tx(&mut data_loader, tx, &mut config); + let tx = tx.as_advanced_builder().set_witnesses(Vec::new()).build(); + + let resolved_tx: ResolvedTransaction = build_resolved_tx(&data_loader, &tx); + + let mut verifier = verify_tx(resolved_tx, data_loader); + verifier.set_debug_printer(debug_printer); + let verify_result = verifier.verify(MAX_CYCLES); + assert_script_error(verify_result.unwrap_err(), ERROR_IDENTITY_WRONG_ARGS); +} + +#[test] +fn test_big_output_data() { + let mut data_loader = DummyDataLoader::new(); + + let mut config = TestConfig::new(IDENTITY_FLAGS_BITCOIN, false); + config + .set_chain_config(Box::new(BitcoinConfig { sign_vtype: BITCOIN_V_TYPE_P2PKHUNCOMPRESSED, pubkey_err: false })); + + let tx = gen_tx(&mut data_loader, &mut config); + let tx = tx.as_advanced_builder().set_outputs_data(vec![[0u8; 1024 * 1024 * 16].pack()]).build(); + + let tx = sign_tx(&mut data_loader, tx, &mut config); + let resolved_tx: ResolvedTransaction = build_resolved_tx(&data_loader, &tx); + + let mut verifier = verify_tx(resolved_tx, data_loader); + verifier.set_debug_printer(debug_printer); + let verify_result = verifier.verify(MAX_CYCLES); + verify_result.expect("pass verification"); +} + +#[test] +fn test_big_witness() { + let mut data_loader = DummyDataLoader::new(); + + let mut config = TestConfig::new(IDENTITY_FLAGS_BITCOIN, false); + config + .set_chain_config(Box::new(BitcoinConfig { sign_vtype: BITCOIN_V_TYPE_P2PKHUNCOMPRESSED, pubkey_err: false })); + + let tx = gen_tx(&mut data_loader, &mut config); + let tx = tx.as_advanced_builder().witness([0u8; 1024 * 1024 * 16].pack()).build(); + + let tx = sign_tx(&mut data_loader, tx, &mut config); + let resolved_tx: ResolvedTransaction = build_resolved_tx(&data_loader, &tx); + + let mut verifier = verify_tx(resolved_tx, data_loader); + verifier.set_debug_printer(debug_printer); + let verify_result = verifier.verify(MAX_CYCLES); + verify_result.expect("pass verification"); +} + +#[test] +fn test_big_script() { + let mut data_loader = DummyDataLoader::new(); + + let mut config = TestConfig::new(IDENTITY_FLAGS_BITCOIN, false); + config + .set_chain_config(Box::new(BitcoinConfig { sign_vtype: BITCOIN_V_TYPE_P2PKHUNCOMPRESSED, pubkey_err: false })); + + let lock_args = config.gen_args(); + + let lock_args = Bytes::from(vec![lock_args.to_vec(), vec![0u8; 1024 * 1024 * 16]].concat()); + + let tx = gen_tx_with_grouped_args(&mut data_loader, vec![(lock_args, 1)], &mut config); + let tx = sign_tx(&mut data_loader, tx, &mut config); + let resolved_tx: ResolvedTransaction = build_resolved_tx(&data_loader, &tx); + + let mut verifier = verify_tx(resolved_tx, data_loader); + verifier.set_debug_printer(debug_printer); + let verify_result = verifier.verify(MAX_CYCLES); + assert_script_error(verify_result.unwrap_err(), ERROR_ARGS_FORMAT); +} From 072b858bf8931254f5e4d0375bb592f16bf8c4c0 Mon Sep 17 00:00:00 2001 From: joii2020 Date: Tue, 5 Mar 2024 16:06:43 +0800 Subject: [PATCH 3/3] Testdata length changed from 16M to 700k --- tests/omni_lock_rust/tests/test_omni_lock.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/omni_lock_rust/tests/test_omni_lock.rs b/tests/omni_lock_rust/tests/test_omni_lock.rs index 6d87e41..8203f46 100644 --- a/tests/omni_lock_rust/tests/test_omni_lock.rs +++ b/tests/omni_lock_rust/tests/test_omni_lock.rs @@ -1235,7 +1235,7 @@ fn test_big_output_data() { .set_chain_config(Box::new(BitcoinConfig { sign_vtype: BITCOIN_V_TYPE_P2PKHUNCOMPRESSED, pubkey_err: false })); let tx = gen_tx(&mut data_loader, &mut config); - let tx = tx.as_advanced_builder().set_outputs_data(vec![[0u8; 1024 * 1024 * 16].pack()]).build(); + let tx = tx.as_advanced_builder().set_outputs_data(vec![[0u8; 1024 * 700].pack()]).build(); let tx = sign_tx(&mut data_loader, tx, &mut config); let resolved_tx: ResolvedTransaction = build_resolved_tx(&data_loader, &tx); @@ -1255,7 +1255,7 @@ fn test_big_witness() { .set_chain_config(Box::new(BitcoinConfig { sign_vtype: BITCOIN_V_TYPE_P2PKHUNCOMPRESSED, pubkey_err: false })); let tx = gen_tx(&mut data_loader, &mut config); - let tx = tx.as_advanced_builder().witness([0u8; 1024 * 1024 * 16].pack()).build(); + let tx = tx.as_advanced_builder().witness([0u8; 1024 * 700].pack()).build(); let tx = sign_tx(&mut data_loader, tx, &mut config); let resolved_tx: ResolvedTransaction = build_resolved_tx(&data_loader, &tx); @@ -1276,7 +1276,7 @@ fn test_big_script() { let lock_args = config.gen_args(); - let lock_args = Bytes::from(vec![lock_args.to_vec(), vec![0u8; 1024 * 1024 * 16]].concat()); + let lock_args = Bytes::from(vec![lock_args.to_vec(), vec![0u8; 1024 * 700]].concat()); let tx = gen_tx_with_grouped_args(&mut data_loader, vec![(lock_args, 1)], &mut config); let tx = sign_tx(&mut data_loader, tx, &mut config);