Skip to content

Conversation

@MishkaRogachev
Copy link
Contributor

@MishkaRogachev MishkaRogachev commented Nov 27, 2025

Close NIT-4109
Depends on OffchainLabs/go-ethereum#594

Changes:

  • Introduce MultiDimensionalPriceForRefund to calculate multi-dimensional price (with a test)
  • Add multi gas refund for normal tx path (with a test)
  • Add multi gas refund for retryable tx path (with a test)

@github-actions
Copy link

github-actions bot commented Nov 27, 2025

❌ 212 Tests Failed:

Tests completed Failed Passed Skipped
2136 212 1924 0
View the top 3 failed tests by shortest run time
TestBlockValidatorSimpleOnchainWithRedisStreams
Stack Traces | -0.000s run time
=== RUN   TestBlockValidatorSimpleOnchainWithRedisStreams
=== PAUSE TestBlockValidatorSimpleOnchainWithRedisStreams
TestDASRekey
Stack Traces | -0.000s run time
=== RUN   TestDASRekey
=== PAUSE TestDASRekey
TestGasEstimationWithRPCGasLimit
Stack Traces | -0.000s run time
=== RUN   TestGasEstimationWithRPCGasLimit
=== PAUSE TestGasEstimationWithRPCGasLimit

📣 Thoughts on this report? Let Codecov know! | Powered by Codecov

@MishkaRogachev MishkaRogachev force-pushed the issue-refunds-based-on-multi-dimensinal-base-fee branch from d448d36 to 31f7320 Compare November 28, 2025 13:01
@MishkaRogachev MishkaRogachev force-pushed the issue-refunds-based-on-multi-dimensinal-base-fee branch from e5f5f4d to 8c1113f Compare December 5, 2025 13:14
@MishkaRogachev MishkaRogachev force-pushed the issue-refunds-based-on-multi-dimensinal-base-fee branch 4 times, most recently from f672189 to 459947c Compare December 9, 2025 11:32
@MishkaRogachev MishkaRogachev marked this pull request as ready for review December 9, 2025 11:34
@MishkaRogachev
Copy link
Contributor Author

MishkaRogachev commented Dec 9, 2025

There is a flaky test TestMultiGasConstraintsStorage, it's fixed in another PR: d0f94df

Comment on lines 355 to 365
if ps.ArbosVersion < ArbosMultiGasConstraintsVersion {
baseFeeWei, err := ps.BaseFeeWei()
if err != nil {
return nil, err
}

return new(big.Int).Mul(
new(big.Int).SetUint64(gasUsed.SingleGas()),
baseFeeWei,
), nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is risky to keep the old behaviour by returning baseFee*gasUsed. If there is a minor mismatch in the calculations that we are not seeing, there will be a divergence in the chain. Instead, the ArbOS check should be in the EndTxHook, and, if we are in an old ArbOS version, the code shouldn't do any calculations at all. I know that approach doesn't look as clean, but it guarantees we won't mess up.

return nil, err
}
// Override zero with minimum base fee,
// it may happen if there is no constraint configured for this resource kind
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could not happen unless it is a bug. Also, it is better to set the default as the single-dimensional/max baseFee instead of the minBaseFee, so we don't give free refunds in case there is a bug.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the comment is misleading - I'll fix it and replace default with max fee of all constraints.

baseFee, _ := ps.calcBaseFeeFromExponent(exp)

// #nosec G115 safe: kind < multigas.NumResourceKind
_ = ps.multiGasBaseFees.Set(multigas.ResourceKind(kind), baseFee)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResourceKindL1Calldata is a special case that won't have L2 constraints. When computing the L1-calldata gas, the L1-pricing model uses the single-dimensional base fee, which is the max base fee. (Roughly, gasUsed[ResourceKindL1Calldata] = posterFee / baseFee). So, this dimension should be maxBaseFee as well, otherwise we will be refunding almost all L1-calldata gas.

Copy link
Contributor Author

@MishkaRogachev MishkaRogachev Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At present, GrowBacklog does not receive gas in this dimension, and there should be no constraints on L1-calldata (I would suggest prohibiting this in ArbOwner). So I would suggest to work-around it in MultiDimensionalPriceForRefund together with zero-fee check

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At present, GrowBacklog does not receive gas in this dimension, and there should be no constraints on L1-calldata

That is correct.

I would suggest prohibiting this in ArbOwner

I agree.

As a result, the base fee should always be minBaseFee and L1-calldata gas will never be refunded.

We can solve this problem in two ways.

  • The first one that I proposed was setting the base fee for this dimension as the maxBaseFee. Then, MultiDimensionalPriceForRefund doesn't need to handle any special case and naturally won't give a refund to L1-calldata.
  • The second one is letting the base fee for this dimension be the min base fee since it won't have any constraint. Then, in MultiDimensionalPriceForRefund, we should handle this dimension separately to ensure we won't give a refund.

I'm fine with either approach.

}
}

func TestEndTxHookMultiGasRefundNormalTx(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change also deserves system tests. (Both for the normal case and for retryables).

@gligneul gligneul assigned MishkaRogachev and unassigned gligneul Dec 9, 2025
@MishkaRogachev MishkaRogachev force-pushed the issue-refunds-based-on-multi-dimensinal-base-fee branch from 459947c to 63e9b9a Compare December 10, 2025 11:43
@MishkaRogachev MishkaRogachev force-pushed the issue-refunds-based-on-multi-dimensinal-base-fee branch from 63e9b9a to cf1867f Compare December 10, 2025 13:08
@MishkaRogachev MishkaRogachev marked this pull request as draft December 12, 2025 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants