Validate antiquity score inputs#4849
Conversation
saim256
left a comment
There was a problem hiding this comment.
Approved. This addresses the validation gaps from #4844/#4845 much more completely than the earlier partial patch.
What looks good:
validator.score.calculate_antiquity_score()now rejects impossible years, future years, booleans/non-integers, and negative/non-integer uptime before scoring.validate_hardware_claim()now rejects unknown hardware and impossible claimed years before model matching.- The sibling PoA scoring implementations in
consensus/poa.py,validator/setup_validator.py, andrips/python/rustchain/proof_of_antiquity.pyget matching guards, which closes the parity issue I flagged on #4846. - The new test file covers invalid release years, invalid uptime, valid scoring, unknown hardware rejection, impossible claimed-year rejection, and known hardware acceptance across the relevant implementations.
Validation I ran locally:
git diff --check origin/main...HEAD -- rips/rustchain-core/validator/score.py rips/rustchain-core/consensus/poa.py rips/rustchain-core/validator/setup_validator.py rips/python/rustchain/proof_of_antiquity.py tests/test_antiquity_score_validation.py-> passedpython -m py_compile rips\rustchain-core\validator\score.py rips\rustchain-core\consensus\poa.py rips\rustchain-core\validator\setup_validator.py rips\python\rustchain\proof_of_antiquity.py tests\test_antiquity_score_validation.py-> passedpython tools\bcos_spdx_check.py --base-ref origin/main-> OKpython -m pytest tests\test_antiquity_score_validation.py -q-> 47 passedpython -m ruff check ... --select E9,F821,F811-> still reportsrips\python\rustchain\proof_of_antiquity.py:482:26: F821 Undefined name CURRENT_YEAR; I checkedorigin/mainand this demo-block reference already exists, so I do not consider it introduced by this PR.
godd-ctrl
left a comment
There was a problem hiding this comment.
Approved current head 5e54ba0.
Validation performed:
- python -m pytest tests\test_antiquity_score_validation.py -q -> 47 passed
- python -m py_compile rips\rustchain-core\validator\score.py rips\rustchain-core\consensus\poa.py rips\rustchain-core\validator\setup_validator.py rips\python\rustchain\proof_of_antiquity.py tests\test_antiquity_score_validation.py -> passed
- git diff --check origin/main...HEAD -- changed files -> passed
- python tools\bcos_spdx_check.py --base-ref origin/main -> passed
- python -m ruff check ... -> unavailable in this environment: No module named ruff
This covers both invalid score inputs and unknown hardware rejection with focused regressions across the sibling PoA implementations.
508704820
left a comment
There was a problem hiding this comment.
Code Review: Validate Antiquity Score Inputs
Summary
Adds input validation to calculate_antiquity_score() in both Python SDK and core module. Validates release_year (integer, 1970-current_year, not bool) and uptime_days (integer, >=0, not bool).
What Works Well
- Bool guard: isinstance(x, bool) catches True/False which Python treats as 1/0
- Range check: release_year between MIN_RELEASE_YEAR (1970) and current_year
- Applied in both locations: Python SDK and core consensus module
- Clear error messages: Specific validation error for each failure mode
Issues Found
1. Low — MIN_RELEASE_YEAR=1970 may be too early
The first microprocessor (Intel 4004) was released in 1971. 1970 as minimum year means a pre-microprocessor era claim would pass validation. Consider 1971 or even 1980 as more realistic minimum.
2. Nit — No maximum uptime_days validation
uptime_days could be extremely large (e.g., 999999999). While log10(x+1) naturally diminishes large values, an absurdly large uptime could cause floating point precision issues. Consider adding:
if uptime_days > 365 * 50: # 50 years
raise ValueError("uptime_days exceeds realistic maximum")Verdict: Approve
Good input validation. The minimum year suggestion is minor.
508704820
left a comment
There was a problem hiding this comment.
Code Review — #4849
1. Comprehensive input validation
The _validate_antiquity_inputs function correctly checks:
- release_year is int (not bool, which is a subclass of int in Python)
- release_year in valid range [1970, current_year]
- uptime_days is int (not bool)
- uptime_days >= 0
2. Bool check is important
In Python, isinstance(True, int) returns True. Explicitly rejecting bools prevents 0/1 being passed as release_year via boolean coercion. Good catch.
3. MIN_RELEASE_YEAR = 1970
This is reasonable — no computer hardware predates 1970. However, vintage hardware from the 1970s-80s is rare. Consider logging a warning for extremely old dates (e.g., pre-1990) to catch potential data entry errors.
4. No upper bound on uptime_days
While uptime_days >= 0 is validated, there is no upper bound. A malicious miner could submit uptime_days=999999999 to inflate their antiquity score. The log10 formula dampens this, but extremely large values could still produce unreasonable scores.
5. Positive
- Dedicated validation function is clean and testable
- Bool rejection is a subtle but important fix
- Early validation before calculation prevents wasted computation
— Xeophon
dazer1234
left a comment
There was a problem hiding this comment.
Code review for RustChain bounty #73.
Summary: The input validation for release_year and uptime_days is useful and the tests cover several invalid numeric and type cases across the duplicate score implementations.
Findings:
- Medium: validate_hardware_claim now rejects all unknown hardware models. That is a larger policy change than input validation and could break onboarding for real hardware that is not yet in HARDWARE_DATABASE. If this is intentional, it should be called out in the PR and probably covered with migration/docs guidance; otherwise the patch should keep the warning/accept behavior and only validate the claimed year/type.
Verdict: Good validation work, but the unknown-hardware behavior change needs maintainer confirmation.
Reviewed with OpenAI Codex assistance.
Code Review: Validate antiquity score inputsSummaryThis PR adds input validation to Positive Observations ✅
Issues Found 🔍1. Duplicated validation code (MEDIUM)
Recommendation: Extract to a shared module (e.g., 2. Duplicated
|
jaxint
left a comment
There was a problem hiding this comment.
Great contribution! LGTM.
jaxint
left a comment
There was a problem hiding this comment.
Great contribution! LGTM.
Summary
Closes #4844
Closes #4845
Validation
python -m pytest tests\test_antiquity_score_validation.py -q-> 47 passedpython -m py_compile rips\rustchain-core\validator\score.py rips\rustchain-core\consensus\poa.py rips\rustchain-core\validator\setup_validator.py rips\python\rustchain\proof_of_antiquity.py tests\test_antiquity_score_validation.pygit diff --check -- rips\rustchain-core\validator\score.py rips\rustchain-core\consensus\poa.py rips\rustchain-core\validator\setup_validator.py rips\python\rustchain\proof_of_antiquity.py tests\test_antiquity_score_validation.pypython tools\bcos_spdx_check.py --base-ref origin/main-> OKpython -m ruff ...could not run locally:No module named ruffPayout
Wallet/miner ID:
SimoneMariaRomeo-codex-earner