@@ -339,7 +339,7 @@ static void update_hash(btc_verify_input_t *verify_input_data,
339
339
}
340
340
switch (update ) {
341
341
case FIRST_CHUNK_HASH : {
342
- if (verify_input_data -> isSegwit ) {
342
+ if (verify_input_data -> is_segwit ) {
343
343
sha256_Update (& (verify_input_data -> sha_256_ctx ), raw_txn_chunk , 4 );
344
344
// skip marker and flag
345
345
sha256_Update (
@@ -361,7 +361,7 @@ static void update_hash(btc_verify_input_t *verify_input_data,
361
361
static void update_locktime (btc_verify_input_t * verify_input_data ,
362
362
const uint8_t * raw_txn_chunk ,
363
363
int chunk_index ) {
364
- if (verify_input_data -> isLocktimeSplit ) {
364
+ if (verify_input_data -> is_locktime_split ) {
365
365
// last second chunk
366
366
if (chunk_index + 2 == verify_input_data -> chunk_total ) {
367
367
memcpy (
@@ -374,7 +374,7 @@ static void update_locktime(btc_verify_input_t *verify_input_data,
374
374
verify_input_data -> locktime + 4 - verify_input_data -> size_last_chunk ,
375
375
raw_txn_chunk ,
376
376
verify_input_data -> size_last_chunk );
377
- verify_input_data -> hasLocktime = true;
377
+ verify_input_data -> has_locktime = true;
378
378
return ;
379
379
} else {
380
380
// wait for subsequent chunks
@@ -384,7 +384,7 @@ static void update_locktime(btc_verify_input_t *verify_input_data,
384
384
memcpy (verify_input_data -> locktime ,
385
385
raw_txn_chunk + verify_input_data -> size_last_chunk - 4 ,
386
386
4 );
387
- verify_input_data -> hasLocktime = true;
387
+ verify_input_data -> has_locktime = true;
388
388
} else {
389
389
// wait for subsequent chunks
390
390
return ;
@@ -425,16 +425,18 @@ int btc_verify_input(const uint8_t *raw_txn_chunk,
425
425
// ignore network version (4-bytes), skip marker & flag (in segwit)
426
426
offset += (raw_txn_chunk [4 ] == 0 ? 6 : 4 );
427
427
if (6 == offset ) {
428
- verify_input_data -> isSegwit = true;
428
+ verify_input_data -> is_segwit = true;
429
429
}
430
430
431
- // store the number of inputs in the raw_txn
432
- verify_input_data -> count = raw_txn_chunk [offset ++ ];
433
431
// TODO: Improve varint decode.
434
432
// size of variable containing script size and ip-count/op-count
435
433
// varies (1-9 Bytes) depending on its value.
436
434
// refer:
437
435
// https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer
436
+ verify_input_data -> count =
437
+ raw_txn_chunk [offset ++ ]; ///< store the number of inputs in the
438
+ ///< raw_txn
439
+
438
440
verify_input_data -> parsetype = INPUT ;
439
441
sha256_Init (& (verify_input_data -> sha_256_ctx ));
440
442
} else {
@@ -447,7 +449,7 @@ int btc_verify_input(const uint8_t *raw_txn_chunk,
447
449
input_case ip_case = verify_input_data -> input_parse ;
448
450
switch (ip_case ) {
449
451
case PREVIOUS_TX_HASH_PLUS_OP_INDEX_CASE : {
450
- if (offset + 36 > CHUNK_SIZE ) {
452
+ if (offset + 36 >= CHUNK_SIZE ) {
451
453
verify_input_data -> prev_offset = (offset + 36 ) - CHUNK_SIZE ;
452
454
update_hash (
453
455
verify_input_data , raw_txn_chunk , chunk_index , CHUNK_SIZE );
@@ -460,7 +462,7 @@ int btc_verify_input(const uint8_t *raw_txn_chunk,
460
462
461
463
case SCRIPT_LENGTH_CASE : {
462
464
int64_t script_length = varint_decode (raw_txn_chunk , & offset );
463
- if (offset + script_length + 1 + 4 > CHUNK_SIZE ) {
465
+ if (offset + script_length + 1 + 4 >= CHUNK_SIZE ) {
464
466
verify_input_data -> prev_offset =
465
467
(offset + script_length + 1 + 4 ) - CHUNK_SIZE ;
466
468
update_hash (
@@ -485,9 +487,11 @@ int btc_verify_input(const uint8_t *raw_txn_chunk,
485
487
}
486
488
487
489
case OP_COUNT : {
488
- if (offset + 1 > CHUNK_SIZE ) {
490
+ if (offset + 1 >= CHUNK_SIZE ) {
489
491
// reset prev offset
490
- verify_input_data -> prev_offset = -1 ;
492
+ verify_input_data -> prev_offset =
493
+ offset - CHUNK_SIZE ; ///< Did not add +1 as returning back to
494
+ ///< this stage to read op count
491
495
update_hash (verify_input_data , raw_txn_chunk , chunk_index , CHUNK_SIZE );
492
496
return 4 ;
493
497
} else {
@@ -503,21 +507,21 @@ int btc_verify_input(const uint8_t *raw_txn_chunk,
503
507
switch (op_case ) {
504
508
case VALUE_CASE : {
505
509
if (verify_input_data -> output_index == input -> prev_output_index ) {
506
- if (offset + 8 > CHUNK_SIZE ) {
510
+ if (offset + 8 >= CHUNK_SIZE ) {
507
511
verify_input_data -> prev_offset = (offset + 8 ) - CHUNK_SIZE ;
508
512
memcpy (verify_input_data -> value ,
509
513
raw_txn_chunk + offset ,
510
514
CHUNK_SIZE - offset );
511
515
update_hash (
512
516
verify_input_data , raw_txn_chunk , chunk_index , CHUNK_SIZE );
513
517
verify_input_data -> output_parse = VALUE_SPLIT_CASE ;
514
- verify_input_data -> isSplit = 1 ;
518
+ verify_input_data -> is_split = 1 ;
515
519
return 4 ;
516
520
} else {
517
521
memcpy (verify_input_data -> value , raw_txn_chunk + offset , 8 );
518
522
}
519
523
}
520
- if (offset + 8 > CHUNK_SIZE ) {
524
+ if (offset + 8 >= CHUNK_SIZE ) {
521
525
verify_input_data -> prev_offset = (offset + 8 ) - CHUNK_SIZE ;
522
526
update_hash (
523
527
verify_input_data , raw_txn_chunk , chunk_index , CHUNK_SIZE );
@@ -529,17 +533,17 @@ int btc_verify_input(const uint8_t *raw_txn_chunk,
529
533
}
530
534
531
535
case VALUE_SPLIT_CASE : {
532
- if (verify_input_data -> isSplit ) {
536
+ if (verify_input_data -> is_split ) {
533
537
memcpy (verify_input_data -> value + (8 - offset ),
534
538
raw_txn_chunk ,
535
539
offset );
536
540
verify_input_data -> output_parse = SCRIPT_PUBKEY_CASE ;
537
- verify_input_data -> isSplit = 0 ;
541
+ verify_input_data -> is_split = 0 ;
538
542
}
539
543
}
540
544
541
545
case SCRIPT_PUBKEY_CASE : {
542
- if (offset + raw_txn_chunk [offset ] + 1 > CHUNK_SIZE ) {
546
+ if (offset + raw_txn_chunk [offset ] + 1 >= CHUNK_SIZE ) {
543
547
verify_input_data -> prev_offset =
544
548
(offset + raw_txn_chunk [offset ] + 1 ) - CHUNK_SIZE ;
545
549
update_hash (
@@ -565,7 +569,7 @@ int btc_verify_input(const uint8_t *raw_txn_chunk,
565
569
566
570
case LOCK_TIME : {
567
571
update_locktime (verify_input_data , raw_txn_chunk , chunk_index );
568
- if (false == verify_input_data -> hasLocktime ) {
572
+ if (false == verify_input_data -> has_locktime ) {
569
573
return 4 ;
570
574
}
571
575
sha256_Update (
0 commit comments