Skip to content

Commit

Permalink
vm fix stack valid
Browse files Browse the repository at this point in the history
  • Loading branch information
findbug2019 committed Aug 16, 2019
1 parent 4b55885 commit 0a3c8eb
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 68 deletions.
20 changes: 10 additions & 10 deletions processor/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,16 @@ func (in *Interpreter) GetGasTable() params.GasTable {

func (in *Interpreter) enforceRestrictions(op OpCode, operation operation, stack *Stack) error {
//if in.evm.chainRules.IsByzantium {
// if in.readOnly {
// // If the interpreter is operating in readonly mode, make sure no
// // state-modifying operation is performed. The 3rd stack item
// // for a call operation is the value. Transferring value from one
// // account to the others means the state is modified and should also
// // return with an error.
// if operation.writes || (op == CALL && stack.Back(2).BitLen() > 0) {
// return errWriteProtection
// }
// }
if in.readOnly {
// If the interpreter is operating in readonly mode, make sure no
// state-modifying operation is performed. The 3rd stack item
// for a call operation is the value. Transferring value from one
// account to the others means the state is modified and should also
// return with an error.
if operation.writes || (op == CALL && stack.Back(2).BitLen() > 0) {
return errWriteProtection
}
}
//}
return nil
}
Expand Down
92 changes: 40 additions & 52 deletions processor/vm/jump_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,33 +94,29 @@ func NewByzantiumInstructionSet() [256]operation {
instructionSet[GETEPCHO] = operation{
execute: opGetEpoch,
gasCost: gasGetEpoch,
validateStack: makeStackFunc(1, 1),
validateStack: makeStackFunc(2, 2),
valid: true,
returns: true,
}

instructionSet[GETCANDIDATENUM] = operation{
execute: opGetCandidateNum,
gasCost: gasGetCandidateNum,
validateStack: makeStackFunc(2, 1),
validateStack: makeStackFunc(2, 2),
valid: true,
returns: true,
}

instructionSet[GETCANDIDATE] = operation{
execute: opGetCandidate,
gasCost: gasGetCandidate,
validateStack: makeStackFunc(2, 1),
validateStack: makeStackFunc(2, 7),
valid: true,
returns: true,
}

instructionSet[GETVOTERSTAKE] = operation{
execute: opGetVoterStake,
gasCost: gasGetVoterStake,
validateStack: makeStackFunc(2, 1),
validateStack: makeStackFunc(3, 1),
valid: true,
returns: true,
}
instructionSet[RECIPIENT] = operation{
execute: opRecipient,
Expand All @@ -133,118 +129,112 @@ func NewByzantiumInstructionSet() [256]operation {
gasCost: gasGetAccountTime,
validateStack: makeStackFunc(1, 1),
valid: true,
returns: true,
}

instructionSet[SNAPSHOTTIME] = operation{
execute: opGetSnapshotTime,
gasCost: gasGetSnapshotTime,
validateStack: makeStackFunc(2, 1),
valid: true,
returns: true,
}

instructionSet[CRYPTOCALC] = operation{
execute: opCryptoCalc,
gasCost: gasCryptoCalc,
validateStack: makeStackFunc(2, 1),
validateStack: makeStackFunc(7, 1),
valid: true,
returns: true,
}

instructionSet[DEDUCTGAS] = operation{
execute: opDeductGas,
gasCost: gasDeductGas,
validateStack: makeStackFunc(2, 1),
validateStack: makeStackFunc(1, 1),
valid: true,
returns: true,
writes: true,
}

instructionSet[ASSETINFO] = operation{
execute: opGetAssetInfo,
gasCost: gasGetAssetInfo,
validateStack: makeStackFunc(2, 2),
validateStack: makeStackFunc(4, 2),
valid: true,
returns: true,
}

instructionSet[SNAPBALANCE] = operation{
execute: opSnapBalance,
gasCost: gasSnapBalance,
validateStack: makeStackFunc(3, 1),
validateStack: makeStackFunc(4, 1),
valid: true,
returns: true,
}

instructionSet[BALANCEEX] = operation{
execute: opBalanceex,
gasCost: gasBalanceex,
validateStack: makeStackFunc(1, 0),
validateStack: makeStackFunc(2, 1),
valid: true,
returns: true,
}

instructionSet[ADDASSET] = operation{
execute: opAddAsset,
gasCost: gasAddAsset,
validateStack: makeStackFunc(2, 1),
validateStack: makeStackFunc(3, 1),
valid: true,
returns: true,
writes: true,
}

instructionSet[ISSUEASSET] = operation{
execute: opIssueAsset,
gasCost: gasIssueAsset,
validateStack: makeStackFunc(1, 1),
memorySize: memoryReturn,
validateStack: makeStackFunc(2, 1),
memorySize: memoryIssueAsset,
valid: true,
returns: true,
writes: true,
}

instructionSet[DESTROYASSET] = operation{
execute: opDestroyAsset,
gasCost: gasDestroyAsset,
validateStack: makeStackFunc(1, 1),
validateStack: makeStackFunc(2, 1),
valid: true,
returns: true,
writes: true,
}

instructionSet[GETACCOUNTID] = operation{
execute: opGetAccountID,
gasCost: gasGetAccountID,
validateStack: makeStackFunc(2, 1),
memorySize: memoryGetAccountID,
valid: true,
returns: true,
}

instructionSet[GETASSETID] = operation{
execute: opGetAssetID,
gasCost: gasGetAssetID,
validateStack: makeStackFunc(2, 1),
memorySize: memoryGetAssetID,
valid: true,
returns: true,
}

instructionSet[SETASSETOWNER] = operation{
execute: opSetAssetOwner,
gasCost: gasSetAssetOwner,
validateStack: makeStackFunc(2, 1),
valid: true,
returns: true,
writes: true,
}

instructionSet[WITHDRAWFEE] = operation{
execute: opWithdrawFee,
gasCost: gasWithdrawFee,
validateStack: makeStackFunc(2, 1),
valid: true,
returns: true,
writes: true,
}

instructionSet[CALLEX] = operation{
execute: opCallEx,
gasCost: gasCallEx,
validateStack: makeStackFunc(7, 1),
validateStack: makeStackFunc(8, 1),
memorySize: memoryCallEx,
valid: true,
returns: true,
Expand Down Expand Up @@ -285,7 +275,6 @@ func NewByzantiumInstructionSet() [256]operation {
validateStack: makeStackFunc(0, 0),
valid: false,
reverts: true,
returns: true,
}
return instructionSet
}
Expand Down Expand Up @@ -603,8 +592,7 @@ func NewFrontierInstructionSet() [256]operation {
gasCost: gasMStore8,
memorySize: memoryMStore8,
validateStack: makeStackFunc(2, 0),

valid: true,
valid: true,
},
SLOAD: {
execute: opSload,
Expand Down Expand Up @@ -1081,15 +1069,15 @@ func NewFrontierInstructionSet() [256]operation {
valid: true,
writes: true,
},
CREATE: {
execute: opCreate,
gasCost: gasCreate,
validateStack: makeStackFunc(3, 1),
memorySize: memoryCreate,
valid: true,
writes: true,
returns: true,
},
// CREATE: {
// execute: opCreate,
// gasCost: gasCreate,
// validateStack: makeStackFunc(3, 1),
// memorySize: memoryCreate,
// valid: true,
// writes: true,
// returns: true,
// },
CALL: {
execute: opCall,
gasCost: gasCall,
Expand Down Expand Up @@ -1122,13 +1110,13 @@ func NewFrontierInstructionSet() [256]operation {
halts: true,
valid: true,
},
SELFDESTRUCT: {
execute: opSuicide,
gasCost: gasSuicide,
validateStack: makeStackFunc(1, 0),
halts: true,
valid: true,
writes: true,
},
// SELFDESTRUCT: {
// execute: opSuicide,
// gasCost: gasSuicide,
// validateStack: makeStackFunc(0, 0),
// halts: true,
// valid: true,
// writes: true,
// },
}
}
12 changes: 12 additions & 0 deletions processor/vm/memory_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,15 @@ func memoryCallEx(stack *Stack) *big.Int {

return math.BigMax(x, y)
}

func memoryGetAssetID(stack *Stack) *big.Int {
return calcMemSize(stack.Back(0), big.NewInt(1))
}

func memoryGetAccountID(stack *Stack) *big.Int {
return calcMemSize(stack.Back(0), big.NewInt(1))
}

func memoryIssueAsset(stack *Stack) *big.Int {
return calcMemSize(stack.Back(0), big.NewInt(1))
}
12 changes: 6 additions & 6 deletions processor/vm/opcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,12 @@ var stringToOp = map[string]OpCode{
"RECIPIENT": RECIPIENT,
// "CALLWITHPAY": CALLWITHPAY,

"CREATE": CREATE,
"CALL": CALL,
"RETURN": RETURN,
"CALLCODE": CALLCODE,
"REVERT": REVERT,
"SELFDESTRUCT": SELFDESTRUCT,
//"CREATE": CREATE,
"CALL": CALL,
"RETURN": RETURN,
"CALLCODE": CALLCODE,
"REVERT": REVERT,
//"SELFDESTRUCT": SELFDESTRUCT,
}

func StringToOp(str string) OpCode {
Expand Down

0 comments on commit 0a3c8eb

Please sign in to comment.