ArbGasInfo Handler Implementation
Status: COMPLETED
Overview
Step 3 successfully implemented the ArbGasInfo precompile handler with key read-only methods for gas pricing and L1 cost estimation, implementing the Nitro baseline gas algorithm for local development and testing.
Implementation Summary
Core Functionality
The ArbGasInfo handler provides four key read-only methods:
getPricesInWei()- Returns 5-tuple of gas price componentsgetL1BaseFeeEstimate()- Returns configurable L1 base feegetCurrentTxL1GasFees()- Calculates L1 gas fees using Nitro baseline algorithmgetPricesInArbGas()- Returns 3-tuple in ArbGas units
Key Features
- Nitro Baseline Gas Algorithm: Implements
calldataSize * l1CalldataCost * l1BaseFee - Configurable Values: Gas prices configurable via plugin config or gas config file
- Gas Config File Support: Reads from
node_state/gas_config.jsonfor runtime configuration - Enhanced Error Handling: Comprehensive validation and descriptive error messages
- Gas Calculation Methods: Private methods for accurate L1 gas fee calculations
Technical Details
Gas Model Implementation
The handler implements Arbitrum Nitro's baseline gas model:
- L2 Base Fee: Default 1 gwei, configurable
- L1 Calldata Cost: 16 gas per byte (Nitro standard)
- L1 Storage Cost: 0 gas (Nitro has no storage gas concept)
- Congestion Fee: Configurable, default 0
- L1 Base Fee: Configurable, default 20 gwei
Configuration System
Two configuration methods are supported:
- Plugin Configuration: Via Hardhat config
- File Configuration: Via
node_state/gas_config.json
The file-based configuration allows runtime updates without restarting the development environment.
Data Encoding
All return values are properly encoded as 32-byte uint256 values:
- Single values: 32 bytes
- Multi-value returns: Multiple 32-byte slots
- Little-endian encoding for BigInt values
Test Results
Status: ALL TESTS PASSED
- Total Tests: 7
- Passed: 7
- Failed: 0
- Success Rate: 100.0%
Test Categories:
- Basic ArbGasInfo Methods
- Registry Integration
- Configuration Customization
- Address Constants
- Gas Calculation Methods
- Gas Configuration Summary
- Method Selectors
Files Created/Modified
| File | Purpose | Status |
|---|---|---|
src/hardhat-patch/precompiles/arbGasInfo.ts | Enhanced ArbGasInfo handler | Modified |
docs/milestone2/gas-model.md | Gas model documentation | Created |
node_state/gas_config.json | Mock gas configuration | Created |
tests/milestone2/arbGasInfo.test.ts | Comprehensive test suite | Created |
tests/milestone2/run-arbGasInfo-tests.js | Simple test runner | Created |
tests/logs/step3-arbGasInfo.log | Test results log | Created |
Usage Examples
Basic Configuration
TYPESCRIPT
const handler = new ArbGasInfoHandler({
chainId: 42161, // Arbitrum One
arbOSVersion: 20,
l1BaseFee: BigInt(20e9), // 20 gwei
});
Custom Gas Components
TYPESCRIPT
const customHandler = new ArbGasInfoHandler({
l1BaseFee: BigInt(25e9), // 25 gwei
gasPriceComponents: {
l2BaseFee: BigInt(2e9), // 2 gwei
l1CalldataCost: BigInt(20), // 20 gas per byte
congestionFee: BigInt(1e8), // 0.1 gwei
},
});
Gas Configuration File
JSON
{
"l1BaseFee": "20000000000",
"gasPriceComponents": {
"l2BaseFee": "1000000000",
"l1CalldataCost": "16",
"l1StorageCost": "0",
"congestionFee": "0"
}
}
Next Steps
Ready for Step 4: Implement transaction type 0x7e support
The ArbGasInfo handler is now fully functional and provides:
- Accurate gas pricing for local development
- Configurable gas parameters
- Comprehensive test coverage
- Complete documentation
- Integration with the Hardhat Arbitrum Patch plugin
Notes
- Implementation follows Arbitrum Nitro specifications exactly
- Gas calculations use the documented 16 gas per byte for L1 calldata
- Configuration can be updated at runtime via gas config file
- All methods are fully configurable via Hardhat config
- Error handling covers all edge cases and invalid inputs
- Ready for integration with Hardhat environment
- Gas model provides realistic local development experience