@@ -189,19 +189,24 @@ var (
189189
190190// ===================== Top-level create transaction ======================
191191
192- // A creation tx's intrinsic gas pre-charges one account creation as state gas.
193- func TestCreateTxIntrinsicChargesAccountUnconditionally (t * testing.T ) {
192+ // A creation tx's intrinsic gas is state-independent: the new-account state
193+ // charge depends on whether the deployment target exists and is charged at
194+ // runtime (EIP-2780), not intrinsically.
195+ func TestCreateTxIntrinsicNoStateGas (t * testing.T ) {
194196 cost , err := IntrinsicGas (nil , nil , nil , common.Address {}, nil , nil , rules8037 , params .CostPerStateByte )
195197 if err != nil {
196198 t .Fatal (err )
197199 }
198- if cost .StateGas != newAccountState {
199- t .Fatalf ("intrinsic state gas = %d, want %d" , cost .StateGas , newAccountState )
200+ if cost .StateGas != 0 {
201+ t .Fatalf ("intrinsic state gas = %d, want 0" , cost .StateGas )
202+ }
203+ if want := params .TxBaseCost2780 + params .CreateAccessAmsterdam ; cost .RegularGas != want {
204+ t .Fatalf ("intrinsic regular gas = %d, want %d" , cost .RegularGas , want )
200205 }
201206}
202207
203- // Creating onto a pre-existing (balance-only) address refills the account
204- // portion ; only the code deposit is charged as state gas.
208+ // Creating onto a pre-existing (balance-only) address incurs no new- account
209+ // runtime charge ; only the code deposit is charged as state gas.
205210func TestCreateTxPreexistingDestRefill (t * testing.T ) {
206211 derived := crypto .CreateAddress (senderAddr , 0 )
207212 sdb := mkState (senderAlloc (types.GenesisAlloc {derived : {Balance : big .NewInt (1 )}}))
@@ -214,7 +219,8 @@ func TestCreateTxPreexistingDestRefill(t *testing.T) {
214219 }
215220}
216221
217- // A creation tx that reverts refills the account-creation charge.
222+ // A creation tx that reverts refills the account-creation charge applied at
223+ // runtime.
218224func TestCreateTxRevertRefill (t * testing.T ) {
219225 sdb := mkState (senderAlloc (nil ))
220226 res , gp , err := applyMsg (t , sdb , createTx (0 , 1_000_000 , revertI ))
@@ -229,7 +235,8 @@ func TestCreateTxRevertRefill(t *testing.T) {
229235 }
230236}
231237
232- // An address collision burns gas_left while refilling the account charge.
238+ // An address collision burns gas_left. The colliding target exists, so no
239+ // new-account state gas is charged at runtime in the first place.
233240func TestCreateTxCollisionConsumesGasLeft (t * testing.T ) {
234241 const gas = 1_000_000
235242 derived := crypto .CreateAddress (senderAddr , 0 )
@@ -242,12 +249,11 @@ func TestCreateTxCollisionConsumesGasLeft(t *testing.T) {
242249 t .Fatal ("expected collision failure" )
243250 }
244251 if gp .cumulativeState != 0 {
245- t .Fatalf ("state gas = %d, want 0 (refilled )" , gp .cumulativeState )
252+ t .Fatalf ("state gas = %d, want 0 (never charged )" , gp .cumulativeState )
246253 }
247- // All forwarded gas_left is burned; only the refilled account charge (which
248- // had spilled into regular) returns to gas_left. So regular gas consumed is
249- // exactly tx.gas - newAccountState, with no other refund.
250- if want := uint64 (gas ) - newAccountState ; gp .cumulativeRegular != want {
254+ // All forwarded gas_left is burned: the whole gas limit is consumed as
255+ // regular gas.
256+ if want := uint64 (gas ); gp .cumulativeRegular != want {
251257 t .Fatalf ("regular gas = %d, want %d" , gp .cumulativeRegular , want )
252258 }
253259}
@@ -472,18 +478,26 @@ const authKeyA = "02020202020202020202020202020202020202020202020202020020202020
472478
473479var delegate8037 = common .HexToAddress ("0xde1e8a7e" )
474480
475- // Intrinsic gas pre-charges the worst-case (account + indicator) per auth.
476- func TestAuthIntrinsicWorstCase (t * testing.T ) {
481+ // Intrinsic gas charges only the state-independent per-authorization base;
482+ // the state-dependent charges are applied at runtime (EIP-2780).
483+ func TestAuthIntrinsicBaseOnly (t * testing.T ) {
477484 cost , err := IntrinsicGas (nil , nil , []types.SetCodeAuthorization {{}}, common.Address {}, & delegate8037 , nil , rules8037 , params .CostPerStateByte )
478485 if err != nil {
479486 t .Fatal (err )
480487 }
481- if cost .StateGas != authWorstState {
482- t .Fatalf ("intrinsic state gas = %d, want %d" , cost .StateGas , authWorstState )
488+ if cost .StateGas != 0 {
489+ t .Fatalf ("intrinsic state gas = %d, want 0" , cost .StateGas )
490+ }
491+ // The recipient touch and the per-authorization authority access (priced
492+ // into RegularPerAuthBaseCost) are both charged at the cold rate
493+ // unconditionally at the intrinsic phase (EIP-2780).
494+ want := params .TxBaseCost2780 + params .ColdAccountAccessAmsterdam + params .RegularPerAuthBaseCost
495+ if cost .RegularGas != want {
496+ t .Fatalf ("intrinsic regular gas = %d, want %d" , cost .RegularGas , want )
483497 }
484498}
485499
486- // An invalid authorization refills its entire intrinsic state-gas charge.
500+ // An invalid authorization incurs no runtime state-gas charge.
487501func TestAuthInvalidRefillFull (t * testing.T ) {
488502 k , _ := crypto .HexToECDSA (authKeyA )
489503 bad , _ := types .SignSetCode (k , types.SetCodeAuthorization {
@@ -499,7 +513,8 @@ func TestAuthInvalidRefillFull(t *testing.T) {
499513 }
500514}
501515
502- // A pre-existing authority refills the account portion (indicator stands).
516+ // A pre-existing authority is not charged for an account leaf; only the
517+ // net-new indicator bytes are charged at runtime.
503518func TestAuthAccountExistsRefill (t * testing.T ) {
504519 auth , authority := signAuth (t , authKeyA , delegate8037 , 0 )
505520 sdb := mkState (senderAlloc (types.GenesisAlloc {authority : {Balance : big .NewInt (1 )}}))
@@ -508,12 +523,12 @@ func TestAuthAccountExistsRefill(t *testing.T) {
508523 t .Fatal (err )
509524 }
510525 if gp .cumulativeState != authBaseState {
511- t .Fatalf ("state gas = %d, want %d (account refilled )" , gp .cumulativeState , authBaseState )
526+ t .Fatalf ("state gas = %d, want %d (indicator only )" , gp .cumulativeState , authBaseState )
512527 }
513528}
514529
515- // Setting a delegation on an already-delegated authority refills the indicator
516- // portion (and the account portion , since the authority already exists).
530+ // Setting a delegation on an already-delegated authority writes no net-new
531+ // bytes (and no account leaf , since the authority exists): no state charge .
517532func TestAuthSetOnDelegatedRefillBase (t * testing.T ) {
518533 auth , authority := signAuth (t , authKeyA , delegate8037 , 0 )
519534 pre := types .AddressToDelegation (common .HexToAddress ("0xabcd" ))
@@ -523,11 +538,12 @@ func TestAuthSetOnDelegatedRefillBase(t *testing.T) {
523538 t .Fatal (err )
524539 }
525540 if gp .cumulativeState != 0 {
526- t .Fatalf ("state gas = %d, want 0 (account+indicator refilled )" , gp .cumulativeState )
541+ t .Fatalf ("state gas = %d, want 0 (nothing net-new )" , gp .cumulativeState )
527542 }
528543}
529544
530- // A net-new delegation on a fresh authority keeps the full worst-case charge.
545+ // A net-new delegation on a fresh authority is charged the account leaf plus
546+ // the indicator bytes at runtime.
531547func TestAuthSetNetNewNoRefill (t * testing.T ) {
532548 auth , _ := signAuth (t , authKeyA , delegate8037 , 0 )
533549 sdb := mkState (senderAlloc (nil ))
@@ -536,11 +552,12 @@ func TestAuthSetNetNewNoRefill(t *testing.T) {
536552 t .Fatal (err )
537553 }
538554 if gp .cumulativeState != authWorstState {
539- t .Fatalf ("state gas = %d, want %d (no refill )" , gp .cumulativeState , authWorstState )
555+ t .Fatalf ("state gas = %d, want %d (leaf + indicator )" , gp .cumulativeState , authWorstState )
540556 }
541557}
542558
543- // Clearing a delegation writes no indicator, so the indicator portion refills.
559+ // Clearing a delegation writes no indicator, so only the (new) account leaf is
560+ // charged at runtime.
544561func TestAuthClearRefillBase (t * testing.T ) {
545562 auth , _ := signAuth (t , authKeyA , common.Address {}, 0 ) // clear (address ZERO)
546563 sdb := mkState (senderAlloc (nil ))
@@ -549,12 +566,12 @@ func TestAuthClearRefillBase(t *testing.T) {
549566 t .Fatal (err )
550567 }
551568 if want := newAccountState ; gp .cumulativeState != want {
552- t .Fatalf ("state gas = %d, want %d (indicator refilled )" , gp .cumulativeState , want )
569+ t .Fatalf ("state gas = %d, want %d (account leaf only )" , gp .cumulativeState , want )
553570 }
554571}
555572
556573// 0->a->0 in one tx: the indicator created by an earlier auth and cleared by a
557- // later one writes zero net bytes, so both indicator charges refill .
574+ // later one writes zero net bytes; the earlier indicator charge is refilled .
558575func TestAuthClearSameTxDoubleRefill (t * testing.T ) {
559576 set , authority := signAuth (t , authKeyA , delegate8037 , 0 )
560577 clr , _ := signAuth (t , authKeyA , common.Address {}, 1 )
0 commit comments