Skip to content

Commit

Permalink
refactor: pick out Stack changes (backport ethereum#6) (ethereum#15)
Browse files Browse the repository at this point in the history
Co-authored-by: Vladislav Varadinov <vladislav.varadinov@gmail.com>
Co-authored-by: Freddy Caceres <facs95@gmail.com>
Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
  • Loading branch information
4 people authored Feb 1, 2023
1 parent 9590b44 commit 9afd9b4
Show file tree
Hide file tree
Showing 13 changed files with 289 additions and 203 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* [#6](https://github.com/evmos/go-ethereum/pull/6) Refactor `Stack` implementation
* [#3](https://github.com/evmos/go-ethereum/pull/3) Move the `JumpTable` defaults to a separate function.
* [#2](https://github.com/evmos/go-ethereum/pull/2) Define `Interpreter` interface for the EVM.
8 changes: 4 additions & 4 deletions core/vm/eips.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func enable1884(jt *JumpTable) {

func opSelfBalance(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
balance, _ := uint256.FromBig(interpreter.evm.StateDB.GetBalance(scope.Contract.Address()))
scope.Stack.push(balance)
scope.Stack.Push(balance)
return nil, nil
}

Expand All @@ -100,7 +100,7 @@ func enable1344(jt *JumpTable) {
// opChainID implements CHAINID opcode
func opChainID(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
chainId, _ := uint256.FromBig(interpreter.evm.chainConfig.ChainID)
scope.Stack.push(chainId)
scope.Stack.Push(chainId)
return nil, nil
}

Expand Down Expand Up @@ -172,7 +172,7 @@ func enable3198(jt *JumpTable) {
// opBaseFee implements BASEFEE opcode
func opBaseFee(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
baseFee, _ := uint256.FromBig(interpreter.evm.Context.BaseFee)
scope.Stack.push(baseFee)
scope.Stack.Push(baseFee)
return nil, nil
}

Expand All @@ -189,6 +189,6 @@ func enable3855(jt *JumpTable) {

// opPush0 implements the PUSH0 opcode
func opPush0(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
scope.Stack.push(new(uint256.Int))
scope.Stack.Push(new(uint256.Int))
return nil, nil
}
4 changes: 2 additions & 2 deletions core/vm/gas_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func gasCreate2(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memoryS
}

func gasExpFrontier(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
expByteLen := uint64((stack.data[stack.len()-2].BitLen() + 7) / 8)
expByteLen := uint64((stack.Data[stack.Len()-2].BitLen() + 7) / 8)

var (
gas = expByteLen * params.ExpByteFrontier // no overflow check required. Max is 256 * ExpByte gas
Expand All @@ -313,7 +313,7 @@ func gasExpFrontier(evm *EVM, contract *Contract, stack *Stack, mem *Memory, mem
}

func gasExpEIP158(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
expByteLen := uint64((stack.data[stack.len()-2].BitLen() + 7) / 8)
expByteLen := uint64((stack.Data[stack.Len()-2].BitLen() + 7) / 8)

var (
gas = expByteLen * params.ExpByteEIP158 // no overflow check required. Max is 256 * ExpByte gas
Expand Down
Loading

0 comments on commit 9afd9b4

Please sign in to comment.