Skip to content

prevent array index out of range in feeHistoryEstimator#500

Merged
amit-momin merged 7 commits into
developfrom
feeHistoryEstimator-bugFix
Jul 10, 2026
Merged

prevent array index out of range in feeHistoryEstimator#500
amit-momin merged 7 commits into
developfrom
feeHistoryEstimator-bugFix

Conversation

@yashnevatia

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings July 10, 2026 15:08
@yashnevatia yashnevatia requested a review from a team as a code owner July 10, 2026 15:08
@github-actions

Copy link
Copy Markdown
Contributor

👋 yashnevatia, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

@yashnevatia yashnevatia changed the title prevent array index out of range prevent array index out of range in feeHistoryEstimator Jul 10, 2026
@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

📊 API Diff Results

No changes detected for module github.com/smartcontractkit/chainlink-evm

View full report

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the EIP-1559 FeeHistoryEstimator against malformed eth_feeHistory responses to avoid runtime panics during dynamic gas price refresh.

Changes:

  • Add a guard to error out when eth_feeHistory returns an empty BaseFee array.
  • Add a unit test covering the empty-BaseFee case.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/gas/fee_history_estimator.go Adds a defensive check to prevent out-of-range access when reading feeHistory.BaseFee[len-1].
pkg/gas/fee_history_estimator_test.go Adds a regression test asserting an error is returned when BaseFee is empty.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/gas/fee_history_estimator.go
Comment thread pkg/gas/fee_history_estimator_test.go Outdated
Comment on lines +262 to +274
t.Run("returns error when fee history has empty base fee", func(t *testing.T) {
client := mocks.NewFeeHistoryEstimatorClient(t)
feeHistoryResult := &ethereum.FeeHistory{
OldestBlock: big.NewInt(1),
BaseFee: []*big.Int{},
}
client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once()

cfg := gas.FeeHistoryEstimatorConfig{BlockHistorySize: 1}
u := gas.NewFeeHistoryEstimator(logger.Test(t), client, cfg, chainID, nil)
err := u.RefreshDynamicPrice()
assert.ErrorContains(t, err, "empty base fee")
})
Comment thread pkg/gas/fee_history_estimator.go Outdated
Comment thread pkg/gas/fee_history_estimator.go Outdated
amit-momin
amit-momin previously approved these changes Jul 10, 2026
@amit-momin amit-momin dismissed their stale review July 10, 2026 16:15

Need to leave another comment

Comment thread pkg/gas/fee_history_estimator.go Outdated
Comment thread pkg/gas/fee_history_estimator.go Outdated
@amit-momin amit-momin merged commit 6417709 into develop Jul 10, 2026
33 checks passed
@amit-momin amit-momin deleted the feeHistoryEstimator-bugFix branch July 10, 2026 18:11
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.

5 participants