Skip to content

Commit d367149

Browse files
committed
fix: Enhance multisig handling for optional since value
* Update the C implementation to conditionally check the lock period logic based on the presence of a since value. * Add a new test case to verify multisig unlocking behavior without a since value.
1 parent 9341664 commit d367149

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const BINARIES: &[(&str, &str)] = &[
2727
),
2828
(
2929
"secp256k1_blake160_multisig_all",
30-
"50c8623ef5112510ccdf2d8e480d02d0de7288eb9968f8b019817340c3991145",
30+
"3c6acb16b3f7487e3e74e8c424737fa910900a4b167f246d100ac2bee667c29b",
3131
),
3232
];
3333

c/secp256k1_blake160_multisig_all.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ int main() {
115115
}
116116
// Extract optional since value.
117117
uint64_t since = 0;
118+
bool has_since = false;
118119
if (args_bytes_seg.size == BLAKE160_SIZE + sizeof(uint64_t)) {
119120
since = *(uint64_t *)&args_bytes_seg.ptr[BLAKE160_SIZE];
121+
has_since = true;
120122
}
121123

122124
// Load the first witness, or the witness of the same index as the first input using
@@ -195,10 +197,12 @@ int main() {
195197
return ERROR_MULTSIG_SCRIPT_HASH;
196198
}
197199

198-
// Check lock period logic, we have prepared a handy utility function for this.
199-
ret = check_since(since);
200-
if (ret != CKB_SUCCESS) {
201-
return ret;
200+
if (has_since) {
201+
// Check lock period logic, we have prepared a handy utility function for this.
202+
ret = check_since(since);
203+
if (ret != CKB_SUCCESS) {
204+
return ret;
205+
}
202206
}
203207

204208
// Load the current transaction hash.

src/tests/secp256k1_blake160_multisig_all.rs

+36
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,42 @@ fn test_multisig_0_2_3_unlock_with_since() {
465465
}
466466
}
467467

468+
#[test]
469+
fn test_multisig_0_2_3_unlock_without_since() {
470+
let mut data_loader = DummyDataLoader::new();
471+
let keys = generate_keys(3);
472+
let multi_sign_script = gen_multi_sign_script(&keys, 2, 0);
473+
// no since value
474+
let args = blake160(&multi_sign_script);
475+
let _lock_script = gen_multi_sign_lock_script(args.clone());
476+
let raw_tx = gen_tx(&mut data_loader, args);
477+
478+
{
479+
// relative since
480+
let since = 0x8000_0000_8888_8888u64;
481+
let inputs: Vec<CellInput> = raw_tx
482+
.inputs()
483+
.into_iter()
484+
.map(|i| i.as_builder().since(since.pack()).build())
485+
.collect();
486+
let raw_tx = raw_tx.as_advanced_builder().set_inputs(inputs).build();
487+
let tx = multi_sign_tx(raw_tx, &multi_sign_script, &[&keys[1], &keys[2]]);
488+
verify(&data_loader, &tx).expect("pass verification");
489+
}
490+
{
491+
// absolute since
492+
let since = 0x2000_0000_0000_0000u64;
493+
let inputs: Vec<CellInput> = raw_tx
494+
.inputs()
495+
.into_iter()
496+
.map(|i| i.as_builder().since(since.pack()).build())
497+
.collect();
498+
let raw_tx = raw_tx.as_advanced_builder().set_inputs(inputs).build();
499+
let tx = multi_sign_tx(raw_tx, &multi_sign_script, &[&keys[1], &keys[2]]);
500+
verify(&data_loader, &tx).expect("pass verification");
501+
}
502+
}
503+
468504
#[test]
469505
fn test_multisig_0_2_3_unlock_with_since_epoch() {
470506
let mut data_loader = DummyDataLoader::new();

0 commit comments

Comments
 (0)