Skip to content

Commit 07ec6b5

Browse files
committed
fix: Update multisig handling for optional since value
1 parent f6ad162 commit 07ec6b5

File tree

3 files changed

+40
-52
lines changed

3 files changed

+40
-52
lines changed

build.rs

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

c/secp256k1_blake160_multisig_all.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,13 @@ int main() {
114114
return ERROR_ARGUMENTS_LEN;
115115
}
116116
// Extract optional since value.
117-
uint64_t since = 0;
118-
bool has_since = false;
119117
if (args_bytes_seg.size == BLAKE160_SIZE + sizeof(uint64_t)) {
120-
since = *(uint64_t *)&args_bytes_seg.ptr[BLAKE160_SIZE];
121-
has_since = true;
118+
uint64_t since = *(uint64_t *)&args_bytes_seg.ptr[BLAKE160_SIZE];
119+
// Check lock period logic, we have prepared a handy utility function for this.
120+
ret = check_since(since);
121+
if (ret != CKB_SUCCESS) {
122+
return ret;
123+
}
122124
}
123125

124126
// Load the first witness, or the witness of the same index as the first input using
@@ -197,14 +199,6 @@ int main() {
197199
return ERROR_MULTSIG_SCRIPT_HASH;
198200
}
199201

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-
}
206-
}
207-
208202
// Load the current transaction hash.
209203
unsigned char tx_hash[BLAKE2B_BLOCK_SIZE];
210204
len = BLAKE2B_BLOCK_SIZE;

docs/c/secp256k1_blake160_multisig_all.html

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,8 @@ <h1 id="secp256k1-blake160-multisig-all">secp256k1-blake160-multisig-all</h1>
270270

271271
</div>
272272

273-
<div class="content"><div class='highlight'><pre> <span class="hljs-type">uint64_t</span> since = <span class="hljs-number">0</span>;
274-
<span class="hljs-type">bool</span> has_since = <span class="hljs-literal">false</span>;
275-
<span class="hljs-keyword">if</span> (args_bytes_seg.size == BLAKE160_SIZE + <span class="hljs-keyword">sizeof</span>(<span class="hljs-type">uint64_t</span>)) {
276-
since = *(<span class="hljs-type">uint64_t</span> *)&amp;args_bytes_seg.ptr[BLAKE160_SIZE];
277-
has_since = <span class="hljs-literal">true</span>;
278-
}</pre></div></div>
273+
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (args_bytes_seg.size == BLAKE160_SIZE + <span class="hljs-keyword">sizeof</span>(<span class="hljs-type">uint64_t</span>)) {
274+
<span class="hljs-type">uint64_t</span> since = *(<span class="hljs-type">uint64_t</span> *)&amp;args_bytes_seg.ptr[BLAKE160_SIZE];</pre></div></div>
279275

280276
</li>
281277

@@ -286,6 +282,25 @@ <h1 id="secp256k1-blake160-multisig-all">secp256k1-blake160-multisig-all</h1>
286282
<div class="sswrap ">
287283
<a class="ss" href="#section-11">&#x00a7;</a>
288284
</div>
285+
<p>Check lock period logic, we have prepared a handy utility function for this.</p>
286+
287+
</div>
288+
289+
<div class="content"><div class='highlight'><pre> ret = check_since(since);
290+
<span class="hljs-keyword">if</span> (ret != CKB_SUCCESS) {
291+
<span class="hljs-keyword">return</span> ret;
292+
}
293+
}</pre></div></div>
294+
295+
</li>
296+
297+
298+
<li id="section-12">
299+
<div class="annotation">
300+
301+
<div class="sswrap ">
302+
<a class="ss" href="#section-12">&#x00a7;</a>
303+
</div>
289304
<p>Load the first witness, or the witness of the same index as the first input using
290305
current script.</p>
291306

@@ -304,11 +319,11 @@ <h1 id="secp256k1-blake160-multisig-all">secp256k1-blake160-multisig-all</h1>
304319
</li>
305320

306321

307-
<li id="section-12">
322+
<li id="section-13">
308323
<div class="annotation">
309324

310325
<div class="sswrap ">
311-
<a class="ss" href="#section-12">&#x00a7;</a>
326+
<a class="ss" href="#section-13">&#x00a7;</a>
312327
</div>
313328
<p>We will treat the first witness as WitnessArgs object, and extract the lock field
314329
from the object.</p>
@@ -328,11 +343,11 @@ <h1 id="secp256k1-blake160-multisig-all">secp256k1-blake160-multisig-all</h1>
328343
</li>
329344

330345

331-
<li id="section-13">
346+
<li id="section-14">
332347
<div class="annotation">
333348

334349
<div class="sswrap ">
335-
<a class="ss" href="#section-13">&#x00a7;</a>
350+
<a class="ss" href="#section-14">&#x00a7;</a>
336351
</div>
337352
<p>This is more of a safe guard, since lock is a field in witness, it
338353
cannot exceed the maximum size of the enclosing witness, this way
@@ -348,11 +363,11 @@ <h1 id="secp256k1-blake160-multisig-all">secp256k1-blake160-multisig-all</h1>
348363
</li>
349364

350365

351-
<li id="section-14">
366+
<li id="section-15">
352367
<div class="annotation">
353368

354369
<div class="sswrap ">
355-
<a class="ss" href="#section-14">&#x00a7;</a>
370+
<a class="ss" href="#section-15">&#x00a7;</a>
356371
</div>
357372
<p>Keep the full lock field somewhere, since later we will modify this field in place.</p>
358373

@@ -365,11 +380,11 @@ <h1 id="secp256k1-blake160-multisig-all">secp256k1-blake160-multisig-all</h1>
365380
</li>
366381

367382

368-
<li id="section-15">
383+
<li id="section-16">
369384
<div class="annotation">
370385

371386
<div class="sswrap ">
372-
<a class="ss" href="#section-15">&#x00a7;</a>
387+
<a class="ss" href="#section-16">&#x00a7;</a>
373388
</div>
374389
<p>Extract multisig script flags.</p>
375390

@@ -398,11 +413,11 @@ <h1 id="secp256k1-blake160-multisig-all">secp256k1-blake160-multisig-all</h1>
398413
</li>
399414

400415

401-
<li id="section-16">
416+
<li id="section-17">
402417
<div class="annotation">
403418

404419
<div class="sswrap ">
405-
<a class="ss" href="#section-16">&#x00a7;</a>
420+
<a class="ss" href="#section-17">&#x00a7;</a>
406421
</div>
407422
<p>Based on the number of public keys and thresholds, we can calculate
408423
the required length of the lock field.</p>
@@ -419,11 +434,11 @@ <h1 id="secp256k1-blake160-multisig-all">secp256k1-blake160-multisig-all</h1>
419434
</li>
420435

421436

422-
<li id="section-17">
437+
<li id="section-18">
423438
<div class="annotation">
424439

425440
<div class="sswrap ">
426-
<a class="ss" href="#section-17">&#x00a7;</a>
441+
<a class="ss" href="#section-18">&#x00a7;</a>
427442
</div>
428443
<p>Perform hash check of the <code>multisig_script</code> part, notice the signature part
429444
is not included here.</p>
@@ -437,27 +452,6 @@ <h1 id="secp256k1-blake160-multisig-all">secp256k1-blake160-multisig-all</h1>
437452

438453
<span class="hljs-keyword">if</span> (<span class="hljs-built_in">memcmp</span>(args_bytes_seg.ptr, temp, BLAKE160_SIZE) != <span class="hljs-number">0</span>) {
439454
<span class="hljs-keyword">return</span> ERROR_MULTSIG_SCRIPT_HASH;
440-
}
441-
442-
<span class="hljs-keyword">if</span> (has_since) {</pre></div></div>
443-
444-
</li>
445-
446-
447-
<li id="section-18">
448-
<div class="annotation">
449-
450-
<div class="sswrap ">
451-
<a class="ss" href="#section-18">&#x00a7;</a>
452-
</div>
453-
<p>Check lock period logic, we have prepared a handy utility function for this.</p>
454-
455-
</div>
456-
457-
<div class="content"><div class='highlight'><pre> ret = check_since(since);
458-
<span class="hljs-keyword">if</span> (ret != CKB_SUCCESS) {
459-
<span class="hljs-keyword">return</span> ret;
460-
}
461455
}</pre></div></div>
462456

463457
</li>

0 commit comments

Comments
 (0)