From d654fa0d4eb547880acc55caed85de7ea5f466a8 Mon Sep 17 00:00:00 2001 From: facuMH Date: Wed, 11 Sep 2024 16:25:19 +0200 Subject: [PATCH] adjust berlin stati costs to not account for warm access --- go/interpreter/lfvm/gas.go | 14 ++++++------ go/interpreter/lfvm/instructions.go | 4 ++-- go/interpreter/lfvm/instructions_test.go | 29 ++++-------------------- 3 files changed, 14 insertions(+), 33 deletions(-) diff --git a/go/interpreter/lfvm/gas.go b/go/interpreter/lfvm/gas.go index 680ac0047..916b7828d 100644 --- a/go/interpreter/lfvm/gas.go +++ b/go/interpreter/lfvm/gas.go @@ -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 } @@ -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: @@ -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 diff --git a/go/interpreter/lfvm/instructions.go b/go/interpreter/lfvm/instructions.go index 5477d026f..4481fbf39 100644 --- a/go/interpreter/lfvm/instructions.go +++ b/go/interpreter/lfvm/instructions.go @@ -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) { diff --git a/go/interpreter/lfvm/instructions_test.go b/go/interpreter/lfvm/instructions_test.go index 530c07646..c8a5775f6 100644 --- a/go/interpreter/lfvm/instructions_test.go +++ b/go/interpreter/lfvm/instructions_test.go @@ -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) } }