Skip to content

Commit

Permalink
adjust berlin stati costs to not account for warm access
Browse files Browse the repository at this point in the history
  • Loading branch information
facuMH committed Sep 11, 2024
1 parent ce9b913 commit d654fa0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 33 deletions.
14 changes: 7 additions & 7 deletions go/interpreter/lfvm/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ func initBerlinGasPrice() {
static_gas_prices_berlin[EXTCODESIZE] = 100
static_gas_prices_berlin[EXTCODEHASH] = 100
static_gas_prices_berlin[BALANCE] = 100
static_gas_prices_berlin[CALL] = 100
static_gas_prices_berlin[CALLCODE] = 100
static_gas_prices_berlin[STATICCALL] = 100
static_gas_prices_berlin[DELEGATECALL] = 100
static_gas_prices_berlin[CALL] = 0
static_gas_prices_berlin[CALLCODE] = 0
static_gas_prices_berlin[STATICCALL] = 0
static_gas_prices_berlin[DELEGATECALL] = 0
static_gas_prices_berlin[SELFDESTRUCT] = 5000
}

Expand Down Expand Up @@ -230,11 +230,11 @@ func getStaticGasPriceInternal(op OpCode) tosca.Gas {
case CREATE2:
return 32000
case CALL:
return 700 // Should be 100 according to evm.code
return 700
case CALLCODE:
return 700
case STATICCALL:
return 700 // Should be 100 according to evm.code
return 700
case RETURN:
return 0
case STOP:
Expand All @@ -244,7 +244,7 @@ func getStaticGasPriceInternal(op OpCode) tosca.Gas {
case INVALID:
return 0
case DELEGATECALL:
return 700 // Should be 100 according to evm.code
return 700
case SELFDESTRUCT:
return 0 // should be 5000 according to evm.code

Expand Down
4 changes: 2 additions & 2 deletions go/interpreter/lfvm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1087,9 +1087,9 @@ func getAccessCost(accessStatus tosca.AccessStatus) tosca.Gas {
// however, the warm access cost is charged as part of the base gas cost.
// (https://eips.ethereum.org/EIPS/eip-2929)
if accessStatus == tosca.ColdAccess {
return tosca.Gas(2500)
return tosca.Gas(2600)
}
return tosca.Gas(0)
return tosca.Gas(100)
}

func genericCall(c *context, kind tosca.CallKind) {
Expand Down
29 changes: 5 additions & 24 deletions go/interpreter/lfvm/instructions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,31 +881,12 @@ func TestExpansionCostOverflow(t *testing.T) {
}
}

func TestCallChargesAppropriatelyForColdWarmAccess(t *testing.T) {

tests := map[string]struct {
accessStatus tosca.AccessStatus
cost tosca.Gas
}{
"warm": {
accessStatus: tosca.WarmAccess,
},
"cold": {
accessStatus: tosca.ColdAccess,
cost: 2500,
},
func TestGetAccessCost_RespondsWithProperGasPrice(t *testing.T) {
if want, got := tosca.Gas(100), getAccessCost(tosca.WarmAccess); want != got {
t.Errorf("unexpected gas cost, wanted %d, got %d", want, got)
}

for name, test := range tests {
t.Run(name, func(t *testing.T) {

cost := getAccessCost(test.accessStatus)

if cost != test.cost {
t.Errorf("unexpected gas cost, wanted %v, got %v", test.cost, cost)
}

})
if want, got := tosca.Gas(2600), getAccessCost(tosca.ColdAccess); want != got {
t.Errorf("unexpected gas cost, wanted %d, got %d", want, got)
}
}

Expand Down

0 comments on commit d654fa0

Please sign in to comment.