fix: api: Length check the array sent to eth_feeHistory RPC (#11696)

Co-authored-by: Rod Vagg <rod@vagg.org>
Co-authored-by: Steven Allen <steven@stebalien.com>
This commit is contained in:
parthshah1 2024-03-10 18:43:45 -07:00 committed by GitHub
parent d9a0040573
commit 7516aff220
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -41,6 +41,8 @@ import (
var ErrUnsupported = errors.New("unsupported method")
const maxEthFeeHistoryRewardPercentiles = 100
type EthModuleAPI interface {
EthBlockNumber(ctx context.Context) (ethtypes.EthUint64, error)
EthAccounts(ctx context.Context) ([]ethtypes.EthAddress, error)
@ -689,6 +691,9 @@ func (a *EthModule) EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (eth
}
rewardPercentiles := make([]float64, 0)
if params.RewardPercentiles != nil {
if len(*params.RewardPercentiles) > maxEthFeeHistoryRewardPercentiles {
return ethtypes.EthFeeHistory{}, errors.New("length of the reward percentile array cannot be greater than 100")
}
rewardPercentiles = append(rewardPercentiles, *params.RewardPercentiles...)
}
for i, rp := range rewardPercentiles {