Skip to content

Commit

Permalink
Merge pull request #371 from gcash/rb
Browse files Browse the repository at this point in the history
Fix stack mutation bug
  • Loading branch information
cpacia authored May 15, 2020
2 parents 8c0c2ed + ecf4ae6 commit 7ac5f23
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions blockchain/fullblocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"path/filepath"
"testing"
"time"

"github.com/gcash/bchd/blockchain"
"github.com/gcash/bchd/blockchain/fullblocktests"
Expand Down Expand Up @@ -140,6 +141,8 @@ func TestFullBlocks(t *testing.T) {
}

// Create a new database and chain instance to run tests against.
params := &chaincfg.RegressionNetParams
params.PhononActivationTime = uint64(time.Now().Add(time.Hour).Unix())
chain, teardownFunc, err := chainSetup("fullblocktest",
&chaincfg.RegressionNetParams, 1000000)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions txscript/data/script_tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@
["0x04 0xDEADBEEF REVERSEBYTES", "0x04 0xEFBEADDE EQUAL", "P2SH,STRICTENC,REVERSEBYTES", "OK"],
["0x03 0x123456 REVERSEBYTES", "0x03 0x563412 EQUAL", "P2SH,STRICTENC,REVERSEBYTES", "OK"],
["0x03 0x123456 REVERSEBYTES", "0x03 0x563412 EQUAL", "P2SH,STRICTENC", "DISABLED_OPCODE"],
[
"0x41 0x1052a02f76cf6c3bc43e4671af4c6065f6d918c79f58ad7f90a49c4e2603a4728fc6d81d49087dd97bc43ae184da55dc5195553526ce076df092be27a398b68f41",
"0x21 0xa8f459fbe84e0568ff03454d438183b0464e0c18ff73658ec0d2619b20ff29e502 REVERSEBYTES CHECKSIG",
"NULLFAIL,STRICTENC,SCHNORR,REVERSEBYTES,SIGHASH_FORKID",
"OK",
"Reversed pubkey"
],

["42", "SIZE 1 EQUALVERIFY 42 EQUAL", "P2SH,STRICTENC", "OK", "SIZE does not consume argument"],

Expand Down
11 changes: 5 additions & 6 deletions txscript/opcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -1552,11 +1552,12 @@ func opcodeReverseBytes(op *parsedOpcode, vm *Engine) error {
if err != nil {
return err
}
for i := len(a)/2 - 1; i >= 0; i-- {
x := len(a) - 1 - i
a[i], a[x] = a[x], a[i]
b := make([]byte, len(a))

for i := 0; i < len(a); i++ {
b[i] = a[len(a)-i-1]
}
vm.dstack.PushByteArray(a)
vm.dstack.PushByteArray(b)
return nil
}

Expand Down Expand Up @@ -2327,7 +2328,6 @@ func opcodeCheckSig(op *parsedOpcode, vm *Engine) error {
signature, err = bchec.ParseSchnorrSignature(sigBytes)
} else if vm.hasFlag(ScriptVerifyStrictEncoding) ||
vm.hasFlag(ScriptVerifyDERSignatures) {

signature, err = bchec.ParseDERSignature(sigBytes, bchec.S256())
} else {
signature, err = bchec.ParseBERSignature(sigBytes, bchec.S256())
Expand All @@ -2352,7 +2352,6 @@ func opcodeCheckSig(op *parsedOpcode, vm *Engine) error {
}
if len(sigBytes) > 0 {
vm.sigChecks++

if !valid && vm.hasFlag(ScriptVerifyNullFail) {
str := "signature not empty on failed checksig"
return scriptError(ErrNullFail, str)
Expand Down
1 change: 1 addition & 0 deletions txscript/reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ func testScripts(t *testing.T, tests [][]interface{}, useSigCache bool) {
// used, then create a new engine to execute the scripts.
tx := createSpendingTx(scriptSig, scriptPubKey,
int64(inputAmt))

vm, err := NewEngine(scriptPubKey, tx, 0, flags, sigCache, nil,
int64(inputAmt))
if err == nil {
Expand Down

0 comments on commit 7ac5f23

Please sign in to comment.