Changeset View
Changeset View
Standalone View
Standalone View
src/script/interpreter.cpp
Show First 20 Lines • Show All 329 Lines • ▼ Show 20 Lines | try { | ||||
return set_error(serror, SCRIPT_ERR_PUSH_SIZE); | return set_error(serror, SCRIPT_ERR_PUSH_SIZE); | ||||
} | } | ||||
// Note how OP_RESERVED does not count towards the opcode limit. | // Note how OP_RESERVED does not count towards the opcode limit. | ||||
if (opcode > OP_16 && ++nOpCount > MAX_OPS_PER_SCRIPT) { | if (opcode > OP_16 && ++nOpCount > MAX_OPS_PER_SCRIPT) { | ||||
return set_error(serror, SCRIPT_ERR_OP_COUNT); | return set_error(serror, SCRIPT_ERR_OP_COUNT); | ||||
} | } | ||||
if (opcode == OP_RIGHT || opcode == OP_INVERT || opcode == OP_2MUL || | if (opcode == OP_INVERT || opcode == OP_2MUL || opcode == OP_2DIV || | ||||
opcode == OP_2DIV || opcode == OP_MUL || opcode == OP_LSHIFT || | opcode == OP_MUL || opcode == OP_LSHIFT || opcode == OP_RSHIFT) { | ||||
opcode == OP_RSHIFT) { | |||||
// Disabled opcodes. | // Disabled opcodes. | ||||
return set_error(serror, SCRIPT_ERR_DISABLED_OPCODE); | return set_error(serror, SCRIPT_ERR_DISABLED_OPCODE); | ||||
} | } | ||||
if (fExec && 0 <= opcode && opcode <= OP_PUSHDATA4) { | if (fExec && 0 <= opcode && opcode <= OP_PUSHDATA4) { | ||||
if (fRequireMinimal && | if (fRequireMinimal && | ||||
!CheckMinimalPush(vchPushValue, opcode)) { | !CheckMinimalPush(vchPushValue, opcode)) { | ||||
return set_error(serror, SCRIPT_ERR_MINIMALDATA); | return set_error(serror, SCRIPT_ERR_MINIMALDATA); | ||||
▲ Show 20 Lines • Show All 952 Lines • ▼ Show 20 Lines | try { | ||||
CScriptNum num(bin, false); | CScriptNum num(bin, false); | ||||
if (num > (INT_MAX>>1) || num < (INT_MIN>>1)) { | if (num > (INT_MAX>>1) || num < (INT_MIN>>1)) { | ||||
return set_error(serror, SCRIPT_ERR_INVALID_BIN2NUM_OPERATION); | return set_error(serror, SCRIPT_ERR_INVALID_BIN2NUM_OPERATION); | ||||
} | } | ||||
stack.pop_back(); | stack.pop_back(); | ||||
stack.push_back(num.getvch()); | stack.push_back(num.getvch()); | ||||
} break; | } break; | ||||
case OP_NUM2BIN: { | |||||
jasonbcox: Add a comment for the in/out values:
// (in -- out) | |||||
movrcxUnsubmitted Not Done Inline ActionsWill add this per the spec: // (in size -- out) movrcx: Will add this per the spec: // (in size -- out) | |||||
if (stack.size() < 2) { | |||||
return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION); | |||||
} | |||||
CScriptNum bn(stacktop(-2), fRequireMinimal); | |||||
int64_t sz = CScriptNum(stacktop(-1), fRequireMinimal).getint(); | |||||
if (sz<1 || static_cast<uint64_t>(sz) > CScriptNum::nDefaultMaxNumSize) { | |||||
jasonbcoxUnsubmitted Not Done Inline ActionsI know the other opcode implementations didn't set a good precedence for variable naming, but let's at least start here. Some suggestions: bn -> bin? If it's popping off the stack, shouldn't this be the num in num2bin? jasonbcox: I know the other opcode implementations didn't set a good precedence for variable naming, but… | |||||
movrcxUnsubmitted Not Done Inline Actions
The previous opcodes use bn to stand for bignum.. Will change this to num for better clarity.
Per the spec an input is used to pad the result (which may result in non-minimally encoded numbers)
Correct...changing this to result for clarity
👍 movrcx: > bn -> bin? If it's popping off the stack, shouldn't this be the num in num2bin?
The… | |||||
return set_error(serror, SCRIPT_ERR_INVALID_NUM2BIN_OPERATION); | |||||
} | |||||
valtype v=bn.getvch(); //LE | |||||
if (static_cast<uint64_t>(sz) < v.size()) { | |||||
return set_error(serror, SCRIPT_ERR_INVALID_NUM2BIN_OPERATION); | |||||
} | |||||
valtype ans; | |||||
ans.reserve(sz); | |||||
bool neg{false}; | |||||
if (!v.empty()) { | |||||
neg=*v.rbegin()&0x80; | |||||
*v.rbegin()&=~0x80; //make it positive | |||||
} | |||||
size_t pad=sz-v.size(); | |||||
for (uint8_t i=0; i<pad; ++i) { | |||||
ans.push_back(0); | |||||
} | |||||
for (auto i=v.rbegin(); i!=v.rend(); ++i) { | |||||
ans.push_back(*i); | |||||
} | |||||
if (neg) *ans.begin()|=0x80; | |||||
stack.pop_back(); | |||||
stack.pop_back(); | |||||
stack.push_back(ans); | |||||
} break; | |||||
default: | default: | ||||
return set_error(serror, SCRIPT_ERR_BAD_OPCODE); | return set_error(serror, SCRIPT_ERR_BAD_OPCODE); | ||||
} | } | ||||
// Size limits | // Size limits | ||||
if (stack.size() + altstack.size() > 1000) { | if (stack.size() + altstack.size() > 1000) { | ||||
return set_error(serror, SCRIPT_ERR_STACK_SIZE); | return set_error(serror, SCRIPT_ERR_STACK_SIZE); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 437 Lines • Show Last 20 Lines |
Add a comment for the in/out values:
// (in -- out)