MCPcopy Create free account
hub / github.com/copernet/copernicus / EvalScript

Function EvalScript

logic/lscript/lscript.go:87–1580  ·  view source on GitHub ↗
(stack *util.Stack, s *script.Script, transaction *tx.Tx, nIn int,
	money amount.Amount, flags uint32, scriptChecker Checker)

Source from the content-addressed store, hash-verified

85}
86
87func EvalScript(stack *util.Stack, s *script.Script, transaction *tx.Tx, nIn int,
88 money amount.Amount, flags uint32, scriptChecker Checker) error {
89
90 if s.GetBadOpCode() {
91 log.Debug("ScriptErrBadOpCode, txid: %s, input: %d", transaction.GetHash().String(), nIn)
92 return errcode.New(errcode.ScriptErrBadOpCode)
93 }
94 if s.Size() > script.MaxScriptSize {
95 log.Debug("ScriptErrScriptSize, txid: %s, input: %d", transaction.GetHash().String(), nIn)
96 return errcode.New(errcode.ScriptErrScriptSize)
97 }
98
99 nOpCount := 0
100
101 bnZero := script.ScriptNum{Value: 0}
102 bnOne := script.ScriptNum{Value: 1}
103 bnFalse := script.ScriptNum{Value: 0}
104 bnTrue := script.ScriptNum{Value: 1}
105
106 beginCodeHash := 0
107 var fRequireMinimal bool
108 if flags&script.ScriptVerifyMinmalData == script.ScriptVerifyMinmalData {
109 fRequireMinimal = true
110 } else {
111 fRequireMinimal = false
112 }
113
114 var fExec bool
115 stackExec := util.NewStack()
116 stackAlt := util.NewStack()
117
118 for i, e := range s.ParsedOpCodes {
119 if stackExec.CountBool(false) == 0 {
120 fExec = true
121 } else {
122 fExec = false
123 }
124 if len(e.Data) > script.MaxScriptElementSize {
125 log.Debug("ScriptErrElementSize")
126 return errcode.New(errcode.ScriptErrPushSize)
127 }
128
129 // Note how OP_RESERVED does not count towards the opCode limit.
130 if e.OpValue > opcodes.OP_16 {
131 nOpCount++
132 if nOpCount > script.MaxOpsPerScript {
133 log.Debug("ScriptErrOpCount")
134 return errcode.New(errcode.ScriptErrOpCount)
135 }
136 }
137
138 if script.IsOpCodeDisabled(e.OpValue, flags) {
139 // Disabled opcodes.
140 log.Debug("ScriptDisabledOpCode:%d, flags:%d", e.OpValue, flags)
141 return errcode.New(errcode.ScriptErrDisabledOpCode)
142 }
143
144 if fExec && 0 <= e.OpValue && e.OpValue <= opcodes.OP_PUSHDATA4 {

Callers 2

TestScriptPushDataFunction · 0.85
VerifyScriptFunction · 0.85

Calls 15

SizeMethod · 0.95
CountBoolMethod · 0.95
SerializeMethod · 0.95
TopMethod · 0.95
PopMethod · 0.95
PushMethod · 0.95
EmptyMethod · 0.95
SetTopMethod · 0.95
GetBadOpCodeMethod · 0.80
CheckMinimalDataPushMethod · 0.80
GetLockTimeMethod · 0.80
GetInsMethod · 0.80

Tested by 1

TestScriptPushDataFunction · 0.68