Skip to content

Commit

Permalink
execute+mod: don't expect witness from callback
Browse files Browse the repository at this point in the history
  • Loading branch information
halseth committed May 11, 2023
1 parent 8e6bcd1 commit d746c3c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ require (
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 // indirect
)

replace github.com/btcsuite/btcd => github.com/halseth/btcd v0.0.0-20230509090317-4c4732b4c40f
replace github.com/btcsuite/btcd => github.com/halseth/btcd v0.0.0-20230511104228-d1cb5debf406
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/halseth/btcd v0.0.0-20230509090317-4c4732b4c40f h1:dhClQItD1uhZfyL3nZqCvhcFGSVuSOpmJD15vOfcLio=
github.com/halseth/btcd v0.0.0-20230509090317-4c4732b4c40f/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY=
github.com/halseth/btcd v0.0.0-20230511104228-d1cb5debf406 h1:7BJJA3hcT8hYzKE9Bm0uWPO+hRdwsynUZDn/fcRweEA=
github.com/halseth/btcd v0.0.0-20230511104228-d1cb5debf406/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
Expand Down
12 changes: 9 additions & 3 deletions script/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ func Execute(pkScript, witness []byte, interactive bool) error {

// Based on the current step counter, we execute up until that
// step, then print the state table.
table, vmErr := StepScript(setupFunc, currentStep)
table, vmErr := StepScript(
setupFunc, txCopy.TxIn[0].Witness, currentStep,
)

// Before handling any error, we draw the state table for the
// step.
Expand Down Expand Up @@ -154,7 +156,8 @@ func Execute(pkScript, witness []byte, interactive bool) error {

var errAbortVM = fmt.Errorf("aborting vm execution")

func StepScript(setupFunc func() (*txscript.Engine, error), numSteps int) (string, error) {
func StepScript(setupFunc func() (*txscript.Engine, error), witness [][]byte,
numSteps int) (string, error) {

vm, err := setupFunc()
if err != nil {
Expand All @@ -176,6 +179,7 @@ func StepScript(setupFunc func() (*txscript.Engine, error), numSteps int) (strin
)
vm.StepCallback = func(step *txscript.StepInfo) error {
finalState = ""
var showWitness [][]byte

switch step.ScriptIndex {
// Script sig is empty and uninteresting under segwit, so we
Expand All @@ -195,6 +199,8 @@ func StepScript(setupFunc func() (*txscript.Engine, error), numSteps int) (strin
return nil
}

showWitness = witness

// Execution of the witness script is the interesting part.
case SCRIPT_WITNESS_SCRIPT:
if currentScript != step.ScriptIndex &&
Expand All @@ -213,7 +219,7 @@ func StepScript(setupFunc func() (*txscript.Engine, error), numSteps int) (strin
scriptStr,
output.StackToString(step.Stack),
output.StackToString(step.AltStack),
output.StackToString(step.Witness),
output.StackToString(showWitness),
)

finalState += table
Expand Down

0 comments on commit d746c3c

Please sign in to comment.