Skip to content

fix(beacon): require claimed bounty completion#7361

Merged
Scottcjn merged 1 commit into
Scottcjn:mainfrom
yyswhsccc:yys/beacon-bounty-complete-claimed-agent
Jun 14, 2026
Merged

fix(beacon): require claimed bounty completion#7361
Scottcjn merged 1 commit into
Scottcjn:mainfrom
yyswhsccc:yys/beacon-bounty-complete-claimed-agent

Conversation

@yyswhsccc

@yyswhsccc yyswhsccc commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • require Beacon bounty completion to start from state=claimed
  • if claimant_agent is recorded, only that agent can receive completion credit
  • keep legacy claimed rows with a null claimant completable by the admin-provided agent_id
  • guard the completion UPDATE with state/claimant predicates before reputation credit is written

Impact

Before this change, /api/bounties/<id>/complete could complete an open bounty without a claim, or complete a bounty claimed by Alice while crediting Bob. Since the endpoint also increments beacon_reputation, stale or malformed admin automation could misattribute bounty completion credit.

BCOS

BCOS-L2: this touches Beacon bounty / reward workflow state and reputation credit attribution.

Safety

  • Does not change payout amounts or reward amounts
  • Does not change wallet balances, production wallets, manual crediting, or admin keys
  • Does not create user-callable payout endpoints
  • Keeps legacy claimed rows with null claimant_agent completable

Validation

  • Failing-before-fix PoC: open bounty completion returned 200 and credited reputation
  • Failing-before-fix PoC: claimed bounty with claimant_agent=bcn_alice_test accepted completion for bcn_bob_test
  • uv run --no-project --with pytest --with flask --with cryptography python -B -m pytest -q tests/test_beacon_atlas_behavior.py -> 28 passed
  • uv run --no-project --with pytest --with flask --with cryptography python -B -m pytest -q tests/test_beacon_atlas_behavior.py::TestBeaconAtlasAPIBehavior::test_bounty_completion_updates_reputation tests/test_beacon_atlas_behavior.py::TestBeaconAtlasAPIBehavior::test_bounty_completion_requires_claimed_state tests/test_beacon_atlas_behavior.py::TestBeaconAtlasAPIBehavior::test_bounty_completion_must_match_recorded_claimant -> 3 passed
  • PATH=/usr/bin:/bin bash scripts/check_fetchall.sh -> passed, legacy baseline count 179
  • python -m py_compile node/beacon_api.py tests/test_beacon_atlas_behavior.py -> passed
  • git diff --check -> passed

Closes #7360

wallet: RTC47bc28896a1a4bf240d1fd780f4559b242bcd945

@github-actions github-actions Bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) node Node server related tests Test suite changes size/M PR: 51-200 lines labels Jun 11, 2026

@jicekeji jicekeji left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bounty #1009 Code Review: PR #7361

Reviewed head 9945053c against origin/main 0017aa3a.

Assessment

APPROVED — focused Beacon bounty completion attribution hardening.

Findings

  • Diff scope is narrow: 3 files, +96/-7, with the only production change in node/beacon_api.py; the fetchall baseline update is line-number drift from the Beacon API edit.
  • The pre-fix behavior is a real workflow/accounting risk: /api/bounties/<id>/complete could complete an open bounty without a prior claim, or complete a bounty claimed by one agent while crediting another agent. Since the route also increments beacon_reputation, this could misattribute completion credit.
  • The fix adds explicit state validation (state must be claimed), claimant validation when claimant_agent is present, and an UPDATE predicate that rechecks state=claimed plus claimant match before reputation credit is written. That gives both clear API errors and a race guard.
  • Legacy claimed rows with null claimant_agent remain completable by the admin-provided agent ID, matching the stated compatibility boundary.
  • The new tests cover open -> complete rejection and mismatched claimant rejection, then assert no state/reputation mutation occurred.

Safety checks

  • git diff --name-status origin/main...HEAD -> 2 modified code/test files plus baseline line update; no schema changes or deletions.
  • git diff --check origin/main...HEAD -> clean.
  • git merge-tree --write-tree origin/main HEAD -> clean tree ea7fe219ff5ea72c60dbc6409bf6c177de20c3ba.
  • No changes to reward amounts, payout amounts, wallet balances, manual crediting, admin keys, or user-callable payout endpoints.

Validation

  • uv run --no-project --with pytest --with flask --with cryptography python -B -m pytest -q tests/test_beacon_atlas_behavior.py -> 28 passed in 0.30s.
  • uv run --no-project --with pytest --with flask --with cryptography python -B -m pytest -q tests/test_beacon_atlas_behavior.py::TestBeaconAtlasAPIBehavior::test_bounty_completion_updates_reputation tests/test_beacon_atlas_behavior.py::TestBeaconAtlasAPIBehavior::test_bounty_completion_requires_claimed_state tests/test_beacon_atlas_behavior.py::TestBeaconAtlasAPIBehavior::test_bounty_completion_must_match_recorded_claimant -> 3 passed in 0.24s.
  • python -m py_compile node/beacon_api.py tests/test_beacon_atlas_behavior.py -> passed.
  • GitHub reports all maintained checks successful on this head, and the PR is MERGEABLE.

Wallet for any accepted review bounty: RTC439f1e1bbb78a0b539c7e2e8e38cdf821c65b40a

@jaxint jaxint left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent contribution! Changes are well-organized. Consider integration tests.

@BossChaos BossChaos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI Fix PR — Stabilizes baseline checks and test coverage. Clean merge state or well-documented stacking strategy.

✅ Bounty claim: Code Review Bounty #73 | Wallet: RTC6d1f27d28961279f1034d9561c2403697eb55602

@yyswhsccc

Copy link
Copy Markdown
Contributor Author

@Scottcjn Could you take a look when convenient? This PR is ready for maintainer review; the PR body has the focused change summary, review tier where applicable, and validation.

I'll keep follow-up comments sparse unless you request changes or CI points to a real issue.

@jaxint

jaxint commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Great PR! 🎉

Thanks for contributing to RustChain!

RTC Reward Address: AhqbFaPBPLMMiaLDzA9WhQcyvv4hMxiteLhPk3NhG1iG

Looking forward to more contributions! 🚀

@jaxint

jaxint commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Great work on this PR!

I've reviewed the changes and they look solid. The implementation follows best practices and the code is well-structured.

Wallet Address for Bounty: AhqbFaPBPLMMiaLDzA9WhQcyvv4hMxiteLhPk3NhG1iG

Keep up the excellent contributions to the RustChain ecosystem!

@jaxint

jaxint commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Code Review

Reviewed the code changes. Implementation looks solid!

Wallet for RTC: AhqbFaPBPLMMiaLDzA9WhQcyvv4hMxiteLhPk3NhG1iG

@Scottcjn

Copy link
Copy Markdown
Owner

Thanks for the contribution — and for caring about RustChain's security. Closing under our SECURITY.md deployment-scope policy: a security fix earns a merge + RTC bounty only when it fixes a real, reachable defect on a deployed surface (the production node, live nginx, or the live explorer/dashboards served from rustchain.org).

This change is generalized/defensive hardening of a path that isn't wired into production — or it duplicates an already-merged fix, or defends an input that can't actually occur. We reviewed it adversarially (diff + prod-surface trace) before deciding, so this isn't a drive-by close.

If you can show a concrete, reachable exploit on a deployed endpoint (request + observed effect), reopen with that repro and we'll re-evaluate and pay if it lands. No hard feelings — keep them coming. — Sophia / Elyan Labs

@Scottcjn Scottcjn closed this Jun 14, 2026
@Scottcjn Scottcjn reopened this Jun 14, 2026
@Scottcjn Scottcjn merged commit f5b03bf into Scottcjn:main Jun 14, 2026
19 of 20 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

RTC Reward

This merged PR earned 5 RTC — sent to RTC47bc28896a1a4bf240d1fd780f4559b242bcd945.

RustChain Bounty Program

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) node Node server related size/M PR: 51-200 lines tests Test suite changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Beacon bounty completion can skip claim state or credit the wrong claimant

5 participants