libsv / go-bt

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

OP_INVERT was modifying bytes in place, now they are popped, modified, and pushed back onto the stack #169

Closed sirdeggen closed 11 months ago

sirdeggen commented 11 months ago

Seems like it's only OP_INVERT which was causing this strange bug.

Scenario

PushTx methodology is used across a number of smart contracts. Optimized code uses a public key associated with the private key Bn(1). The unlocking script contains a complete preimage for the sake of forward enforcement among other things. That preimage has its nSequence inverted somewhere in the example script, but while it's inverted on the stack, the other items on the stack containing the same bytes are also inverted.

Fix

Rather than Peek, we Pop the byte array, clone it, invert the clone and push that on to the stack. It might not be as memory efficient, but it at leasts solves this bizarre problem.

codecov-commenter commented 11 months ago

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (51c16ed) 80.63% compared to head (4df7aed) 80.64%. Report is 1 commits behind head on master.

:exclamation: Current head 4df7aed differs from pull request most recent head e45ae11. Consider uploading reports for the commit e45ae11 to get more accurate results

:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #169 +/- ## ======================================= Coverage 80.63% 80.64% ======================================= Files 38 38 Lines 4115 4117 +2 ======================================= + Hits 3318 3320 +2 Misses 546 546 Partials 251 251 ``` | [Files Changed](https://app.codecov.io/gh/libsv/go-bt/pull/169?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=libsv) | Coverage Δ | | |---|---|---| | [bscript/interpreter/operations.go](https://app.codecov.io/gh/libsv/go-bt/pull/169?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=libsv#diff-YnNjcmlwdC9pbnRlcnByZXRlci9vcGVyYXRpb25zLmdv) | `96.55% <100.00%> (+<0.01%)` | :arrow_up: |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.