Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

[Superhack-01]Add opcode to geth: experiment with constant return value #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions core/vm/gas_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,10 @@ func gasSelfdestruct(evm *EVM, contract *Contract, stack *Stack, mem *Memory, me
}
return gas, nil
}

// add gas function for inferCall
func gasInferCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
//return constant gas
var gas uint64 = 20
return gas, nil
}
5 changes: 5 additions & 0 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,11 @@ func opSelfdestruct6780(pc *uint64, interpreter *EVMInterpreter, scope *ScopeCon
return nil, errStopToken
}

func opInferCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
ret := 5
return []byte{byte(ret)}, nil
}

// following functions are used by the instruction jump table

// make log instruction function
Expand Down
8 changes: 8 additions & 0 deletions core/vm/jump_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func newByzantiumInstructionSet() JumpTable {
func newSpuriousDragonInstructionSet() JumpTable {
instructionSet := newTangerineWhistleInstructionSet()
instructionSet[EXP].dynamicGas = gasExpEIP158

return validate(instructionSet)
}

Expand Down Expand Up @@ -1051,6 +1052,13 @@ func newFrontierInstructionSet() JumpTable {
minStack: minStack(1, 0),
maxStack: maxStack(1, 0),
},
// make infercall min max stack equal to call for now.
INFERCALL: {
execute: opInferCall,
dynamicGas: gasInferCall,
minStack: minStack(7, 1),
maxStack: maxStack(7, 1),
},
}

// Fill all unassigned slots with opUndefined.
Expand Down
5 changes: 5 additions & 0 deletions core/vm/opcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ const (
LOG4
)

// 0xb0 range - infercall ops
const (
INFERCALL OpCode = 0xb0
)

// 0xf0 range - closures.
const (
CREATE OpCode = 0xf0
Expand Down