-
Notifications
You must be signed in to change notification settings - Fork 4
Closed
Description
Summary
Replace/enhance current Uint256 implementation with the comprehensive, well-tested UInt256 library from EVMYulLean.
Motivation
- EVMYulLean has mature UInt256 library with proven properties
- DumbContracts has basic Uint256 (
DumbContracts/EVM/Uint256.lean) - Code reuse opportunity for better-tested arithmetic
- Cross-project validation reduces verification burden
Current State
DumbContracts Uint256:
- Basic operations (add, sub, mul, div, mod)
- Limited lemmas
- ~200 LOC
EVMYulLean Uint256:
- Comprehensive modular arithmetic
- Overflow/underflow semantics
- Well-tested properties
- ~500 LOC + lemmas
Implementation Plan
Phase 1: Extract (1 day)
cp EVMYulLean/EvmYul/UInt256.lean DumbContracts/EVM/Uint256Verified.lean
# Review and adapt to DumbContracts naming conventionsPhase 2: Integration (1 day)
Integrate verified lemmas:
-- EVMYulLean provides:
theorem add_mod : (a + b) % 2^256 = ...
theorem sub_underflow : a < b → (a - b) % 2^256 = 2^256 - (b - a)
theorem mul_overflow : ...
theorem div_by_zero : ...Phase 3: Update Automation (1 day)
-- Update Automation.lean to use verified arithmetic
theorem safeAdd_some_iff_le (a b : Uint256Verified) :
(safeAdd a b).isSome ↔ (a : Nat) + (b : Nat) ≤ MAX_UINT256 := by
-- Now proven using EVMYulLean lemmasBenefits
✅ Reduces verification burden (arithmetic proven once)
✅ Catches edge cases in modular arithmetic
✅ Improves trust in numeric operations
✅ Cross-project validation
✅ Leverages EVMYulLean's extensive testing
Risks & Mitigation
-
Risk: API differences between implementations
-
Mitigation: Adapter layer if needed, gradual migration
-
Risk: Increased dependencies
-
Mitigation: Vendor the code (copy, don't link)
Files Affected
- Extract:
EVMYulLean/EvmYul/UInt256.lean - Create:
DumbContracts/EVM/Uint256Verified.lean - Update:
DumbContracts/EVM/Uint256.lean(compatibility layer) - Update:
DumbContracts/Proofs/Stdlib/Automation.lean
Estimated Effort
3 days
Dependencies
- Access to EVMYulLean repository (already cloned)
- None blocking
Success Criteria
- ✅
lake buildpasses with new Uint256 - ✅ All existing proofs still work
- ✅ New arithmetic lemmas available in Automation.lean
- ✅ Documentation updated
Related
- Part of EVMYulLean integration strategy
- Enables more robust arithmetic-heavy contracts (ERC20, ERC721)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels