Skip to content

Commit

Permalink
Merge pull request #5 from quilt/paygas-mode
Browse files Browse the repository at this point in the history
Make PAYGAS an invalid opcode in most cases
  • Loading branch information
SamWilsn authored May 27, 2020
2 parents bfe712a + bd81e01 commit 0d45538
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 12 deletions.
7 changes: 6 additions & 1 deletion core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,12 @@ func makeLog(size int) executionFunc {
}

func opPaygas(pc *uint64, interpreter *EVMInterpreter, callContext *callCtx) ([]byte, error) {
interpreter.evm.snapshots[len(interpreter.evm.snapshots)-1] = interpreter.evm.StateDB.Snapshot()

// TODO: Store the popped value
if interpreter.paygasMode != PaygasNoOp {
interpreter.evm.snapshots[len(interpreter.evm.snapshots)-1] = interpreter.evm.StateDB.Snapshot()
interpreter.paygasMode = PaygasNoOp
}
interpreter.intPool.put(callContext.stack.pop())
return nil, nil
}
Expand Down
5 changes: 4 additions & 1 deletion core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter {
var jt JumpTable
switch {
case evm.chainRules.IsAccountAbstraction:
jt = accountAbstractionInstructionSet
jt = newAccountAbstractionInstructionSet(cfg.PaygasMode)
case evm.chainRules.IsIstanbul:
jt = istanbulInstructionSet
case evm.chainRules.IsConstantinople:
Expand Down Expand Up @@ -232,6 +232,9 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
if !operation.valid {
return nil, &ErrInvalidOpCode{opcode: op}
}
if in.paygasMode != PaygasNoOp && operation.internal {
return nil, &ErrInvalidOpCode{opcode: op}
}
// Validate stack
if sLen := stack.len(); sLen < operation.minStack {
return nil, &ErrStackUnderflow{stackLen: sLen, required: operation.minStack}
Expand Down
Loading

0 comments on commit 0d45538

Please sign in to comment.