libsv / go-bt

The go-to Bitcoin Transaction (BT) Go library.
https://pkg.go.dev/mod/github.com/libsv/go-bt
ISC License
66 stars 26 forks source link

Fix: Binary Maths #82

Closed tigh-latte closed 2 years ago

tigh-latte commented 2 years ago

Currently, arithmeitc that overflows math.MaxInt64 and underflows math.MinInt64 just causes integer overflows within the script, meaning maths that should be compatible with large numbers just does not work on our interpreter.

Also, OP_NUM2BIN and OP_BIN2NUM are implemented incorrectly.

To fix this, I've fixed the implementations of the two aforementioned opcodes, and changed the scriptNum data type to wrap big.Int, implementing the correct math functions and byte conversion both to and from consensus, to and from standard big endian.

codecov-commenter commented 2 years ago

Codecov Report

Merging #82 (7a9c1d1) into master (4f458d2) will increase coverage by 0.58%. The diff coverage is 98.90%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #82      +/-   ##
==========================================
+ Coverage   83.94%   84.53%   +0.58%     
==========================================
  Files          35       35              
  Lines        3370     3504     +134     
==========================================
+ Hits         2829     2962     +133     
- Misses        394      395       +1     
  Partials      147      147              
Impacted Files Coverage Δ
bscript/interpreter/thread.go 94.30% <ø> (ø)
bscript/interpreter/number.go 97.94% <97.94%> (ø)
bscript/interpreter/config.go 100.00% <100.00%> (ø)
bscript/interpreter/operations.go 96.54% <100.00%> (+0.38%) :arrow_up:
bscript/interpreter/stack.go 93.56% <100.00%> (+0.03%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 4f458d2...7a9c1d1. Read the comment docs.