@@ -273,12 +273,9 @@ func TestEndTxHookMultiGasRefundRetryableTx(t *testing.T) {
273273 )
274274}
275275
276- // TestEndTxHookMultiGasRefundWithEVMRefundCredit verifies that the multi-gas
277- // refund stays invariant under EVM SSTORE refunds (EIP-3529). usedMultiGas's
278- // per-kind sum is pre-refund (peak); on v61+ MultiDimensionalPriceForRefund
279- // subtracts usedMultiGas.GetRefund() * baseFee from its result so it can be
280- // paired with the net totalCost = baseFee * (gasLimit - gasLeft) computed in
281- // EndTxHook.
276+ // TestEndTxHookMultiGasRefundWithEVMRefundCredit verifies that the EndTxHook doesn't give extra refunds when the EVM
277+ // refunds are greater than the multi-dimensional one.
278+ // The EVM refunds are given back to the user before EndTxHook is called, in stateTransition.returnGas().
282279func TestEndTxHookMultiGasRefundWithEVMRefundCredit (t * testing.T ) {
283280 const gasLimit uint64 = 1_000_000
284281 const evmRefundCredit uint64 = 200_000 // EIP-3529 cap
@@ -302,40 +299,37 @@ func TestEndTxHookMultiGasRefundWithEVMRefundCredit(t *testing.T) {
302299 pricing := txProcessor .state .L2PricingState ()
303300 pricing .ArbosVersion = params .ArbosVersion_MultiGasRefundFix
304301
302+ // Set a 99/100 ratio to make the multi-gas refund smaller than the EVM refunds.
305303 Require (t , pricing .AddMultiGasConstraint (
306304 100_000 ,
307305 10 ,
308306 200_000_000_000 ,
309307 map [uint8 ]uint64 {
310- uint8 (multigas .ResourceKindComputation ): 1 ,
311- uint8 (multigas .ResourceKindStorageGrowth ): 10 ,
308+ uint8 (multigas .ResourceKindComputation ): 99 ,
309+ uint8 (multigas .ResourceKindStorageGrowth ): 100 ,
312310 },
313311 ))
314- pricing .UpdatePricingModel (100 )
312+ pricing .UpdatePricingModel (1 )
315313 require .NoError (t , pricing .CommitMultiGasFees ())
316314
317315 baseFee , err := pricing .BaseFeeWei ()
318316 require .NoError (t , err )
319- evm .Context .BaseFee = new (big. Int ). Set ( baseFee )
317+ evm .Context .BaseFee = baseFee
320318
321319 gasUsed := gasLimit - gasLeft
322320 peakGasUsed := gasUsed + evmRefundCredit
323321 usedMultiGas := multigas .MultiGasFromPairs (
324322 multigas.Pair {Kind : multigas .ResourceKindComputation , Amount : peakGasUsed / 2 },
325- multigas.Pair {Kind : multigas .ResourceKindStorageAccessRead , Amount : peakGasUsed / 2 },
323+ multigas.Pair {Kind : multigas .ResourceKindStorageGrowth , Amount : peakGasUsed / 2 },
326324 ).WithRefund (evmRefundCredit )
327325
328- multiDimensionalCost , err := pricing .MultiDimensionalPriceForRefund (usedMultiGas , baseFee )
326+ multiGasFee , err := pricing .MultiDimensionalPriceForRefund (usedMultiGas , baseFee )
329327 require .NoError (t , err )
330- totalCost := new (big.Int ).Mul (baseFee , new (big.Int ).SetUint64 (gasUsed ))
331- expectedRefund := new (big.Int ).Sub (totalCost , multiDimensionalCost )
332- require .True (t , expectedRefund .Sign () > 0 , "expected positive multi-gas refund, got %v" , expectedRefund )
328+ singleGasFee := new (big.Int ).Mul (baseFee , new (big.Int ).SetUint64 (gasUsed ))
329+ require .Negative (t , singleGasFee .Cmp (multiGasFee ), "expected singleGasFee < multiGasFee" )
333330
331+ // Expect zero balance because the EVM refunds are given before EndTxHook is called.
334332 txProcessor .EndTxHook (gasLeft , usedMultiGas , true )
335-
336- require .True (t ,
337- arbmath .BigEquals (expectedRefund , evm .StateDB .GetBalance (from ).ToBig ()),
338- "refund mismatch under EVM refund credit: got %v, want %v" ,
339- evm .StateDB .GetBalance (from ).ToBig (), expectedRefund ,
340- )
333+ balance := evm .StateDB .GetBalance (from ).ToBig ()
334+ require .Zero (t , balance .Sign (), "unexpected refund in EndTxHook" )
341335}
0 commit comments