Skip to content

Commit 998d721

Browse files
authored
Merge pull request #48 from bitcoin-sv/script-tester
Fix OP_BIN2NUM
2 parents c36564f + 9c53b66 commit 998d721

File tree

3 files changed

+58
-26
lines changed

3 files changed

+58
-26
lines changed

CHANGELOG.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,30 @@ All notable changes to this project will be documented in this file. The format
55
## Table of Contents
66

77
- [Unreleased](#unreleased)
8-
- [1.0.0 - YYYY-MM-DD](#100---yyyy-mm-dd)
8+
- [1.1.2 - 2024-09-02](#111---2024-09-02)
9+
- [1.1.1 - 2024-mm-dd](#111---2024-08-28)
10+
- [1.1.0 - 2024-mm-dd](#110---2024-08-19)
11+
- [1.0.0 - 2024-06-06](#100---2024-06-06)
912

10-
## [Unreleased]
13+
## [1.1.2] - 2024-09-02
14+
- Fix OP_BIN2NUM to copy bytes and prevent stack corruption & add corresponding test
15+
16+
### Changed
17+
- `opcodeNum2bin` now copies value before minimally encoding
18+
19+
## [1.1.1] - 2024-08-28
20+
- Fix OP_RETURN data & add corresponding test
21+
- update release instructions
22+
23+
### Added
24+
- add additional test transaction
25+
- add additional script tests, fix test code
26+
27+
### Changed
28+
- `opcodeReturn` now includes any `parsedOp.Data` present after `OP_RETURN`
29+
- Changed RELEASE.md instructions
30+
31+
## [1.1.0] - 2024-08-19
1132
- porting in all optimizations by Teranode team to their active go-bt fork
1233
- introducing chainhash to remove type coercion on tx hashes through the project
1334
- remove ByteStringLE (replaced by chainhash)
@@ -41,7 +62,7 @@ All notable changes to this project will be documented in this file. The format
4162

4263
---
4364

44-
## [1.0.0] - YYYY-MM-DD
65+
## [1.0.0] - 2024-06-06
4566

4667
### Added
4768
- Initial release

script/interpreter/example_test.go

Lines changed: 30 additions & 1 deletion
Large diffs are not rendered by default.

script/interpreter/operations.go

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,10 @@ func opcodeBin2num(op *ParsedOpcode, t *thread) error {
10691069
return err
10701070
}
10711071

1072-
b := minimallyEncode(a)
1072+
b := make([]byte, len(a))
1073+
// Copy the bytes so that we don't corrupt the original stack value
1074+
copy(b, a)
1075+
b = minimallyEncode(b)
10731076
if len(b) > t.cfg.MaxScriptNumberLength() {
10741077
return errs.NewError(errs.ErrNumberTooBig, "script numbers are limited to %d bytes", t.cfg.MaxScriptNumberLength())
10751078
}
@@ -1456,27 +1459,6 @@ func opcodeLShift(op *ParsedOpcode, t *thread) error {
14561459
return err
14571460
}
14581461

1459-
// uint8_t mask = make_lshift_mask(bit_shift);
1460-
// uint8_t overflow_mask = ~mask;
1461-
1462-
// valtype result(x.size(), 0x00);
1463-
// for (valtype::size_type index = x.size(); index > 0; index--) {
1464-
// valtype::size_type i = index - 1;
1465-
// // make sure that k is always >= 0
1466-
// if (byte_shift <= i)
1467-
// {
1468-
// valtype::size_type k = i - byte_shift;
1469-
// uint8_t val = (x[i] & mask);
1470-
// val <<= bit_shift;
1471-
// result[k] |= val;
1472-
1473-
// if (k >= 1) {
1474-
// uint8_t carryval = (x[i] & overflow_mask);
1475-
// carryval >>= 8 - bit_shift;
1476-
// result[k - 1] |= carryval;
1477-
// }
1478-
// }
1479-
// }
14801462
bitShift := n % 8
14811463
byteShift := n / 8
14821464
mask := []byte{0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01}[bitShift]

0 commit comments

Comments
 (0)