docs(FLOW-16): Document precision loss in cross-VM amount conversions#37
docs(FLOW-16): Document precision loss in cross-VM amount conversions#37
Conversation
EVM uses uint256 with 18 decimals while Cadence uses UFix64 with 8 decimals. Converting between formats truncates precision beyond 8 decimal places. This is not exploitable (truncation favors protocol) and minimum deposit mitigates dust loss. Added precision warnings to: - Cadence contract header - Cadence ufix64FromUInt256() function docstring - Solidity contract header Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Code Review SummaryThis PR effectively documents an important precision loss limitation in cross-VM amount conversions. The documentation is clear, accurate, and addresses issue #31. ✅ Strengths1. Clear DocumentationThe precision loss is documented in three strategic locations:
2. Accurate Technical Details
3. Security AnalysisThe documentation correctly notes:
📝 Minor Suggestions1. Math Precision in ExampleIn Example: 1.123456789012345678 FLOW → 1.12345678 FLOW (loss of ~9e-9 FLOW).The stated loss
Suggestion: Consider being more precise: Example: 1.123456789012345678 FLOW → 1.12345678 FLOW (loss of 9.01...e-9 FLOW, ~0.0000008%).2. Consistency Between CommentsThe Cadence contract (line 33) states: This percentage seems to be calculated as Suggestion: Verify and align the percentage calculations:
3. Return Value Documentation EnhancementIn Suggestion: Consider adding that precision beyond 8 decimals is permanently lost: This emphasizes the irreversibility of the conversion. 🔍 Code Quality Assessment
✅ RecommendationAPPROVE with minor suggestions for mathematical precision in the examples. The changes are:
The minor suggestions above are optional refinements and don't block merging. 🔒 Security ValidationI verified that:
Great work documenting this limitation! 🚀 |
Summary
Fixes #31
Documents the precision loss that occurs when converting between EVM's
uint256(18 decimals) and Cadence'sUFix64(8 decimals).Key points:
1.123456789012345678FLOW →1.12345678FLOWChanges:
ufix64FromUInt256()docstringTest plan
🤖 Generated with Claude Code