Skip to content

Commit

Permalink
fix DUP opcode validation (DNAProject#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
laizy authored Jun 26, 2018
1 parent c3246be commit aab38e3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions smartcontract/test/panic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/ontio/ontology/common/log"
"github.com/ontio/ontology/core/types"
. "github.com/ontio/ontology/smartcontract"
"github.com/ontio/ontology/vm/neovm"
"github.com/stretchr/testify/assert"
"os"
"testing"
)
Expand Down Expand Up @@ -71,3 +73,29 @@ func TestRandomCodeCrash(t *testing.T) {
}
}
}

func TestOpCodeDUP(t *testing.T) {
log.InitLog(4)
defer func() {
os.RemoveAll("Log")
}()

config := &Config{
Time: 10,
Height: 10,
Tx: &types.Transaction{},
}

var code = []byte{byte(neovm.DUP)}

sc := SmartContract{
Config: config,
Gas: 10000,
CloneCache: nil,
}
engine, _ := sc.NewExecuteEngine(code)
_, err := engine.Invoke()

assert.NotNil(t, err)

}
2 changes: 1 addition & 1 deletion vm/neovm/opcode_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var (
XTUCK: {Opcode: XTUCK, Name: "XTUCK", Exec: opXTuck, Validator: validateXTuck},
DEPTH: {Opcode: DEPTH, Name: "DEPTH", Exec: opDepth},
DROP: {Opcode: DROP, Name: "DROP", Exec: opDrop, Validator: validateCount1},
DUP: {Opcode: DUP, Name: "DUP", Exec: opDup},
DUP: {Opcode: DUP, Name: "DUP", Exec: opDup, Validator: validateCount1},
NIP: {Opcode: NIP, Name: "NIP", Exec: opNip, Validator: validateCount2},
OVER: {Opcode: OVER, Name: "OVER", Exec: opOver, Validator: validateCount2},
PICK: {Opcode: PICK, Name: "PICK", Exec: opPick, Validator: validatePick},
Expand Down

0 comments on commit aab38e3

Please sign in to comment.