Successfully added a feature flag to enable/disable precompiled contracts in EVM.lua.
Location: evm.lua (line ~11)
-- Feature flags
EVM.ENABLE_PRECOMPILES = true -- Set to false to disable precompiled contractsDefault: true (precompiles are ENABLED by default)
Location: evm.lua in execute_contract_call() function
-- Check if this is a precompiled contract (if feature is enabled)
local addr_num = tonumber(addr_str, 16)
if EVM.ENABLE_PRECOMPILES and is_precompile(addr_num) then
-- Execute precompiled contract
-- ...
endThe check ensures precompiles are only executed when the flag is true.
File: tests/test-precompile-flag.sh
Tests:
- ✅ Precompiles work when enabled (default behavior)
- ✅ Precompiles are bypassed when disabled (treated as EOA)
- ✅ Precompiles work again when re-enabled
Run with:
make test-precompile-flag
# or
cd tests && ./test-precompile-flag.shFiles Created:
docs/PRECOMPILE_FEATURE_FLAG.md- Comprehensive feature flag guide- Configuration instructions
- Use cases
- Testing procedures
- Troubleshooting
- Best practices
Files Updated:
PRECOMPILES.md- Added feature flag sectionPRECOMPILE_IMPLEMENTATION_SUMMARY.md- Updated with feature flag infoMakefile- Addedtest-precompile-flagtarget
Call to 0x01-0x09
↓
Precompile detected
↓
Execute precompile function
↓
Return result
Result: Precompiles execute normally
Call to 0x01-0x09
↓
Precompile check skipped
↓
Treat as regular account
↓
No code found (EOA)
↓
Return success (empty result)
Result: Precompile addresses treated as empty accounts
- Isolate issues in precompile implementations
- Test contract behavior without precompiles
- Debug step-by-step without cryptographic complexity
- Verify contracts handle missing precompiles gracefully
- Test fallback behavior
- Compare performance with/without precompiles
- Start with precompiles disabled
- Enable when implementations are complete
- Test incrementally during development
- Disable problematic precompiles temporarily
- Work around implementation issues
- Maintain compatibility with different environments
EVM.ENABLE_PRECOMPILES = trueThen reload:
cat evm.lua | redis-cli -x FUNCTION LOAD REPLACEEVM.ENABLE_PRECOMPILES = falseThen reload:
cat evm.lua | redis-cli -x FUNCTION LOAD REPLACE# Disable
cat evm.lua | sed 's/EVM.ENABLE_PRECOMPILES = true/EVM.ENABLE_PRECOMPILES = false/' | redis-cli -x FUNCTION LOAD REPLACE
# Re-enable
cat evm.lua | redis-cli -x FUNCTION LOAD REPLACEAll tests passing ✅
Testing Precompile Feature Flag...
✓ Precompiles ENABLED: Identity precompile executed successfully
✓ Precompiles DISABLED: Call to 0x04 treated as EOA (no precompile execution)
✓ Precompiles RE-ENABLED: Identity precompile works again
File: evm.lua
Lines Changed: 2 locations
- Added feature flag definition (1 line)
- Added feature flag check (1 condition)
Total Impact: Minimal, non-breaking change
✅ Fully backward compatible
- Default behavior unchanged (precompiles enabled)
- Existing contracts work without modification
- No breaking changes to API
Negligible
- Single boolean check per call
- No performance degradation when enabled
- Minimal overhead when disabled
- ✅ Feature flag enabled (default)
- ✅ Feature flag disabled
- ✅ Feature flag re-enabled
- ✅ All precompiles still work when enabled
- ✅ Works with existing test suite
- ✅ Compatible with all opcodes
- ✅ No conflicts with other features
- ✅ Feature flag guide (
docs/PRECOMPILE_FEATURE_FLAG.md) - ✅ Updated precompile documentation
- ✅ Usage examples
- ✅ Troubleshooting guide
- ✅ Implementation details
- ✅ Code location references
- ✅ Testing procedures
- ✅ Best practices
-
Per-Precompile Flags
EVM.ENABLE_ECRECOVER = true EVM.ENABLE_SHA256 = true -- etc.
-
Runtime Configuration
- Change flag without reloading
- Redis key-based configuration
- Dynamic enable/disable
-
Logging & Monitoring
- Log precompile calls
- Track usage statistics
- Performance metrics
-
Custom Fallback Behavior
- Return specific error codes
- Custom error messages
- Configurable responses
# Run feature flag tests
make test-precompile-flag
# Run all precompile tests
make test-precompiles
# Run all tests
make test-all
# Reload EVM with default settings
cat evm.lua | redis-cli -x FUNCTION LOAD REPLACE
# Reload EVM with precompiles disabled
cat evm.lua | sed 's/EVM.ENABLE_PRECOMPILES = true/EVM.ENABLE_PRECOMPILES = false/' | redis-cli -x FUNCTION LOAD REPLACE- ✅
evm.lua- Added feature flag and check - ✅
tests/test-precompile-flag.sh- New test file - ✅
docs/PRECOMPILE_FEATURE_FLAG.md- New documentation - ✅
PRECOMPILES.md- Updated with feature flag info - ✅
PRECOMPILE_IMPLEMENTATION_SUMMARY.md- Updated - ✅
Makefile- Added test target - ✅
FEATURE_FLAG_IMPLEMENTATION.md- This file
The precompile feature flag is now fully implemented and tested. It provides:
- ✅ Simple on/off control for all precompiles
- ✅ Default behavior unchanged (enabled)
- ✅ Comprehensive testing
- ✅ Complete documentation
- ✅ Zero performance impact
- ✅ Backward compatible
The feature is production-ready and can be used immediately for development, testing, and debugging purposes.