Loading
[P1] No validation of network fee values before saving to state
Resolve #2457
This MR implements the changes described in issue #2457.
Summary
This MR addresses the security finding that network fee values were being saved without upper bound validation, potentially allowing Byzantine validators (if they control >66% consensus) to attest extreme values that could manipulate fees.
Changes Made
-
Upper Bound Validation for Fee Rates
- Added chain-specific maximum fee rate limits in
DefaultMaxNetworkFeeRate - Values are set high enough to accommodate market volatility while preventing clearly malicious values
- Examples: BTC 10,000 sats/byte, ETH 100,000 gwei, DOGE 100,000 sats/byte
- Added chain-specific maximum fee rate limits in
-
Upper Bound Validation for Transaction Sizes
- Added chain-specific maximum transaction size limits in
DefaultMaxNetworkFeeTransactionSize - Examples: UTXO chains 100KB, EVM chains 10M gas limit
- Added chain-specific maximum transaction size limits in
-
Rate-of-Change Limits
- Added
NetworkFeeMaxChangePercentconstant (default 500%) - Prevents sudden extreme changes in fee values
- Both fee rate and transaction size changes are validated
- Added
-
Logging for Anomalous Values
- Added
logNetworkFeeAnomalies()function - Logs info messages when fees change by more than 100% (even if within validation limits)
- Helps operators monitor for suspicious patterns
- Added
-
Mimir-Controllable Overrides
-
MaxNetworkFeeRate-{CHAIN}: Override max fee rate for a specific chain -
MaxNetworkFeeTransactionSize-{CHAIN}: Override max tx size for a specific chain -
NetworkFeeMaxChangePercent: Override global rate-of-change limit - Setting rate-of-change limit to 0 disables the check
-
Files Changed
-
constants/constant_values.go: AddedNetworkFeeMaxChangePercentconstant -
constants/constantname_string.go: Regenerated for new constant -
constants/constants_v1.go: Added default value (500%) -
constants/mimir_strings.go: Added mimir key templates -
x/thorchain/handler_network_fee_helpers.go: Added validation logic -
x/thorchain/handler_network_fee_helpers_test.go: Added comprehensive tests
Testing
Unit tests have been added to cover:
- Fee rate upper bound validation
- Transaction size upper bound validation
- Rate-of-change limit validation
- Mimir override functionality
- Per-chain validation with different limits