fix(rips): replace float reward distribution with exact integer arithmetic (#7896)#7999
Conversation
Add test_detect_repo_name_strips_dotgit_suffix_not_chars to verify that
repos like audit, test, gigi are not truncated by the old rstrip('.git')
bug which stripped individual characters instead of the exact suffix.
Refs Scottcjn#7955
…tcjn#7988) - Add new timer module (rips/src/timer.rs) for epoch boundary calculations - Use checked arithmetic (checked_mul, checked_sub, checked_add) throughout to prevent overflow on very large or negative timestamp deltas - Added saturating_sub for elapsed time computation - Provides: epoch_start(), epoch_end(), epoch_range(), current_epoch(), time_to_epoch_boundary(), timestamp_in_epoch(), seconds_into_epoch() - Returns Option<i64> for overflow-safe epoch computation, avoiding panics - Added comprehensive test suite covering: * Normal epoch boundaries (epoch 0, 1, consecutive) * Large epoch numbers near MAX_EPOCH * Overflow epoch numbers (MAX_EPOCH + 100, u64::MAX) * i64::MAX and i64::MIN timestamp edge cases * Large negative timestamp deltas * Current epoch computation * Epoch boundary timing * Epoch start date labels Wallet: RTC995e0893404106dd348cfd0a9f886783d772832d
Implement XAPS (Cross-protocol Audit System) - a security layer that runs before on-chain actions are submitted. Changes: - xaps_audit.py: Full XAPS inspector with signature, target, side-effect, and rate-limit checks; custom policy plugin system; governance vote and attestation audit methods; convenience functions - exceptions.py: Add XAPSAuditError exception class - __init__.py: Export XAPSInspector, XAPSResult, XAPSPolicy, audit helpers - test_xaps_audit.py: 40 unit tests covering all XAPS functionality Security checks performed before execution: 1. Signature integrity – valid Ed25519 signature from wallet's public key 2. Target validation – RTC prefix, correct length, hex body 3. Side-effect audit – memo size/chars, amount/fee bounds 4. Rate limiting – sliding-window per source address (default 5/min) 5. Custom policies – pluggable policy system for domain-specific checks
Review of PR #7999 — Float Reward Distribution Fix + XAPS Audit + Timer ModuleObservation 1: Integer reward distribution has an edge case with
|
|
Holding this — as written it does not conserve block emission. In Two problems compound it: (1) |
Issue #7896 Fix: Miner Reward Distribution Floating Point Precision Errors
Problem
The miner reward distribution calculation used floating point arithmetic which accumulated precision errors, causing:
Solution
Replaced floating point reward distribution with exact integer arithmetic:
Guarantees
Changes
rips/src/proof_of_antiquity.rs: Replaced floating point reward distribution with integer arithmeticrips/src/lib.rs: Added epoch timer module with overflow-safe arithmeticrips/src/timer.rs: New epoch timer module (365 lines)Tests Added