Repository navigation
fix(#102): verify the attestor's owner against a pinned app id, not the borrower - #103
Conversation
…he borrower verify_claim rebuilt the digest's owner as the borrower's G… address, lowercased. A real attestor signs owner = the requesting Reclaim app (RECLAIM_APP_ID), so no real proof, AdSense or AdMob, could ever verify: the first real claim recovers to 0x9726…7896 under the old rebuild and to the attestor under the right one (#102). - DataKey::ClaimOwner, appended; set_claim_owner (admin, 0x + 40 hex, stored lowercase) and claim_owner(). verify_claim uses the pinned owner. Absent, it falls back to the borrower, which is what the rehearsal's test witness signs, so the dev contract and rehearsal.py keep working until it is pinned there. - The fixture is signed a second time with the app as owner. Tests: without a pin that claim is refused (the bug, kept as a test); pinned, it verifies; pinned, a borrower-owner claim is refused; the borrower binding is unchanged; malformed owners are refused; admin only. - docs/interface.md says what owner is and that it never bound the borrower.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The attestor signs owner = the app id the proof was requested with, and the contract now pins it. The relay and prove:adsense pass RECLAIM_APP_ID to the audit, so a proof with any other owner fails before the front end submits it, not as VerifierRejected on chain.
|
@Lexirieru, the rest of the team is now blocked on you. Everything below is built and checked; each item needs a review, a merge or a decision from you. Urgent: this PR (#102), by 2026-10-28No real proof, from AdSense or AdMob, can verify on the deployed contract until this lands (#102). The upgrade has a 24 h timelock and the deadline is 2026-10-30 (#90). So the timeline is:
If it is proposed later than the 28th, the demo uses the simulated fallback (option 3) for the advance itself. Waiting on you
Done on our side since your last word
A reply on #90 and a review of this PR today would unblock most of the table. |
Measured by CI with stellar-cli 28.1.0 on x86_64-unknown-linux-gnu. The contract changed, so the bytes did.
|
CI is green now. The Rust job had failed on the recorded wasm hash, because the contract changed. |
Lexirieru
left a comment
There was a problem hiding this comment.
Approved in approach, and this is the most important find on the project so far. One change I want folded into the combined upgrade, plus two smaller notes. Nothing here needs a new PR.
First, the finding itself. The bug was invisible to every test we had because rehearsal.py and make_claim_fixture.py both sign with owner = borrower, so the suite proved the contract agreed with itself. The 7/7 GREEN I reported to Axel on 2026-10-25 was that agreement, not agreement with the attestor. Same class as #76 — the part of our model that describes someone else's system was a guess until a real artifact arrived. It took a real proof to find, and you went and got one.
Verified rather than read
| Claim | How | Result |
|---|---|---|
cargo test --workspace --all-features on 367c491 |
ran it | 51 passed, plus 9 in reclaim-claim; all six new owner tests green |
is_eth_address |
read | length 42, 0x, 40 hex digits, either case — correct |
| The borrower binding is untouched | read | contextAddress is inside context, and identifier = keccak(provider \n parameters \n context). The owner is outside it |
Appending to DataKey is safe |
the committed snapshots | ledger keys are vec[symbol("Admin")], vec[symbol("ParamsTemplate")] … — encoded by name, not by index |
That last one is worth stating because your comment says "appended", as if position were what made it safe. It is stronger than that: variants are keyed by their symbol, so ClaimOwner could sit anywhere in the enum and no existing entry would move. Good to know the next time someone is nervous about touching that enum.
The one change: make the unpinned state refuse
Your fallback is not a security hole, and I checked rather than assumed. On production the verifier is Reclaim's real CA3EMXR6…H54DU5, whose witness is the production attestor, and that attestor sets owner to the requesting app. It will never sign a digest built from a lowercased G…. So unpinned production accepts nothing — it fails closed. On the dev contract the probe witness is published anyway, so there is no new exposure either.
What it is instead is a configuration cliff, with a test proving it is one:
fn without_a_pinned_owner_a_claim_signed_as_a_real_attestor_signs_is_refused() {
assert_eq!(verify_app_signed(&f), Err(Error::VerifierRejected));
}That test asserts that an unpinned contract refuses every real proof. After execute_upgrade and before set_claim_owner, production is in that state, and the symptom is a bare VerifierRejected — the exact opaque failure that cost us until a real proof existed to diagnose it. A fallback preserves #102's failure mode as the default state of the contract that matters.
It also reads against the house style everywhere else in this code: split_date refuses a window that is not YYYY-MM-DD rather than guessing, and pin_template.py refuses a window it was not given. Both chose a loud refusal over a plausible default, for this reason.
So take your own one-line offer: refuse when nothing is pinned. Since #94 is another code change on the same upgrade, it costs nothing extra now. Two asks with it:
- A new error code, not a reused one —
ClaimOwnerNotSet, next free number. Error codes are public ABI, so adding is safe and renumbering never is. - The rehearsal pins the borrower at setup. Your
the_borrower_binding_survives_the_pinned_owneralready shows a shared owner does not weaken the binding, so this costs one admin call inrehearsal.pyand nothing conceptual.
Two smaller notes
1. set_claim_owner returns ClaimMismatch (#11) for a malformed argument. #11 means "the rebuilt claim does not match what the attestor signed". Here it means "the admin passed something that is not an address". Someone reading #11 in a failed admin call will go looking at the template and the proof. Give it its own code alongside ClaimOwnerNotSet.
2. set_claim_owner calls bump(). That is the #76 trap: bump() extends the instance TTL to the network maximum, and the fee is rent over bytes × ledgers, not computation. #76's set_claim_template simulated fine and then wanted 21,370 XLM. The owner is only 42 bytes so the delta should be small, and the instance TTL was set to max on 2026-10-25, four days ago. But read the fee at simulation before sending it, and do not assume it is dust. The deployer holds 29,478 XLM, so it will not fail; it should still be looked at and recorded.
Deploy order on production, for the record
Production needs three admin calls, not one, because claim_template() on CCQFL2Q6…I2HS still returns null (#61):
execute_upgradeset_claim_owner 0x6415200c713135e77157e1536d488df4f2bb7d04set_claim_templatefrom a real proof (#61/#96)
Between 1 and 2 the contract is in the state your own test describes. Keep them in one sitting.
#81 is deployed as of today
execute_upgrade ran on both contracts this session — production 1220778c…, dev 17262af5…, both emitting UpgradeExecuted for 481e7f16…. I verified the release artifact hashes to exactly that, and the rehearsal is 7/7 GREEN on the upgraded wasm (tools/runs/2026-10-29T115559Z/). So this PR rebases onto a chain state where borrower authorisation is live, and propose_upgrade is free for #102 + #94.
Note on method: MCP Stellar Raven is disconnected in my session and needs re-authorisation, so the Stellar facts above come from the stellar-dev:smart-contracts skill and live reads against testnet, not from Raven. Flagging it because our working agreement names Raven for anything Stellar that gets written down.
|
@Lin1er the two changes I asked for are done, in #106, rather than sent back to you — two lines each and the clock matters. So this PR needs no edit from you; #106 is based on
Refusing turned out to be a stronger change than I argued for, and your fallback is why. You wrote that the fallback existed so the rehearsal keeps working, signing That is the fix for the class of bug #102 was, not just the instance. The harness could previously express a claim no attestor can produce, and that is the whole reason a green suite coexisted with a contract that could verify nothing real. Merge order: this one first, then #106 retargets itself to One more thing while you are in there: #106 found that |
Lexirieru
left a comment
There was a problem hiding this comment.
Approved. @Lin1er @Nabil-Aufa @AncungAulia — merging this now, and the two changes I asked for are already implemented in #106 on top of it, so nothing comes back to you here.
Everything in my earlier review stands, and I have since corroborated the Soroban facts in it with MCP Stellar Raven, which was disconnected when I wrote it. Two of them came back stronger than I stated:
"When replacing the WASM binary, existing storage is reinterpreted by the new code. Do not remove or rename existing storage keys. Do not change the type of values stored under existing keys. Adding new storage keys is safe. Soroban storage uses explicit string keys, so key naming is critical — unlike EVM sequential slots, there is no ordering dependency."
— OpenZeppelin,upgrade-stellar-contracts, Storage compatibility
That last clause independently confirms what I had only inferred from our own committed snapshots: DataKey variants are keyed by name, so a new one may sit anywhere in the enum. Nobody needs to be careful about where ClaimOwner went.
Merging without --delete-branch, so #106 retargets to main on its own instead of being auto-closed.
…wner A revenue source selects the template, and the template pins the host. So the caller's `source` argument cannot make a claim verify against the wrong API: an AdMob claim checked as AdSense is rebuilt into a request to adsense.googleapis.com, the identifier differs, and the signature recovers to nobody. Tested in both directions. The value order is NOT in the template. `rebuild_parameters` interleaves positionally, so the order is part of the source's shape and lives in `claim_values`. AdMob needs the reverse of AdSense's because the attestor sorts the parameter keys, putting `body` (which holds the window) before `url` (which holds the publisher id) — #93. Getting it wrong would surface as an unexplained ClaimMismatch, so three places check the same ordering without deriving it from each other: this contract, pin_template.py, and the relay. Micros truncate to cents, never round up. The figure's key is per source (`revenueUsd` / `revenueMicros`) and sits inside the signed context, because the two mistakes are not symmetric: dollars read as micros fail loudly, while micros read as dollars return the 100 USDC cap for any revenue at all, silently. Measured on the deployed contract, not reasoned about: quote("123450000") is 1000000000 stroops. The nullifier is tagged for AdMob only. One Google account's AdSense and AdMob publisher ids are the same `pub-` id (#93, on a real account), so untagged an AdMob proof would spend the AdSense nullifier for the same window. AdSense stays untagged because advances already on chain are keyed on those bytes — pinned against a literal derived independently in Python, so it is not the contract agreeing with itself. The source of an advance is `DataKey::AdvanceSource`, beside the `Advance` rather than a field in it: a required field would retype an existing stored value and every advance recorded before this upgrade would fail to decode. Those are debts. Also carries the two changes asked for on #103: an unpinned claim owner is refused with `ClaimOwnerNotSet` rather than falling back to the borrower, and `set_claim_owner` has its own `ClaimOwnerMalformed` instead of reusing `ClaimMismatch`. Refusing forced the test harness to adopt the real owner shape, which is the actual fix for the class of bug #102 was: a `G…` address cannot be pinned at all, so the pre-#102 form cannot be written here by accident any more. Every test now runs through an app-signed claim. make_claim_fixture.py gains the AdMob chain. Its identifier is byte-identical to the one be/src/admob/fixture.test.ts derives in TypeScript (#101) — a Python encoder and a TypeScript one agreeing on the canonical parameters, the context, and the keccak over them. 61 contract tests pass, plus 9 in reclaim-claim. fmt, clippy -D warnings, the wasm build, the no_std wasm check, make_claim_fixture --check and pin_template --self-test are all clean. The linux wasm row is PENDING for CI to measure. Refs #94, #102, #93. Base is #103. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QdNuoJ9e954ojofNVGUezW
…laim owner (#106) * feat(#94): AdMob as a second revenue source, and refuse an unpinned owner A revenue source selects the template, and the template pins the host. So the caller's `source` argument cannot make a claim verify against the wrong API: an AdMob claim checked as AdSense is rebuilt into a request to adsense.googleapis.com, the identifier differs, and the signature recovers to nobody. Tested in both directions. The value order is NOT in the template. `rebuild_parameters` interleaves positionally, so the order is part of the source's shape and lives in `claim_values`. AdMob needs the reverse of AdSense's because the attestor sorts the parameter keys, putting `body` (which holds the window) before `url` (which holds the publisher id) — #93. Getting it wrong would surface as an unexplained ClaimMismatch, so three places check the same ordering without deriving it from each other: this contract, pin_template.py, and the relay. Micros truncate to cents, never round up. The figure's key is per source (`revenueUsd` / `revenueMicros`) and sits inside the signed context, because the two mistakes are not symmetric: dollars read as micros fail loudly, while micros read as dollars return the 100 USDC cap for any revenue at all, silently. Measured on the deployed contract, not reasoned about: quote("123450000") is 1000000000 stroops. The nullifier is tagged for AdMob only. One Google account's AdSense and AdMob publisher ids are the same `pub-` id (#93, on a real account), so untagged an AdMob proof would spend the AdSense nullifier for the same window. AdSense stays untagged because advances already on chain are keyed on those bytes — pinned against a literal derived independently in Python, so it is not the contract agreeing with itself. The source of an advance is `DataKey::AdvanceSource`, beside the `Advance` rather than a field in it: a required field would retype an existing stored value and every advance recorded before this upgrade would fail to decode. Those are debts. Also carries the two changes asked for on #103: an unpinned claim owner is refused with `ClaimOwnerNotSet` rather than falling back to the borrower, and `set_claim_owner` has its own `ClaimOwnerMalformed` instead of reusing `ClaimMismatch`. Refusing forced the test harness to adopt the real owner shape, which is the actual fix for the class of bug #102 was: a `G…` address cannot be pinned at all, so the pre-#102 form cannot be written here by accident any more. Every test now runs through an app-signed claim. make_claim_fixture.py gains the AdMob chain. Its identifier is byte-identical to the one be/src/admob/fixture.test.ts derives in TypeScript (#101) — a Python encoder and a TypeScript one agreeing on the canonical parameters, the context, and the keccak over them. 61 contract tests pass, plus 9 in reclaim-claim. fmt, clippy -D warnings, the wasm build, the no_std wasm check, make_claim_fixture --check and pin_template --self-test are all clean. The linux wasm row is PENDING for CI to measure. Refs #94, #102, #93. Base is #103. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QdNuoJ9e954ojofNVGUezW * feat(#94): record the linux wasm hash CI measured Filled in from the measurement the runner printed for the PENDING row, rather than from a local build: wasm is byte-identical only within a host triple and toolchain, so the macOS hash is not the one CI checks. x86_64-unknown-linux-gnu 28.1.0 4c5b24de377fab73a55db715739f8b4d9f7e48e75484cad0c8f9df8f52b7a049 Every other step of that run passed, including "Test snapshots are committed", so the snapshots in the previous commit are complete and stable. Coverage was skipped because the job stopped at the PENDING row; this push is the first run that exercises it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QdNuoJ9e954ojofNVGUezW * docs(#94): say why unwrap_or on AdvanceSource is safe Verified against the official state-archival docs via MCP Stellar Raven: a persistent entry whose TTL lapses is archived, not deleted, and the host makes the caller restore it before the read. So an AdMob advance cannot quietly read back as AdSense once its TTL runs out. The line itself would be a silent debt-relabelling bug in temporary storage, and nothing in the code said why it is not one here. Same property the nullifier already rests on. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QdNuoJ9e954ojofNVGUezW * fix(#94): re-record the wasm hash, and why a doc comment moved it The previous row was measured before faf9540, which added a doc comment and nothing else. That changed the wasm. Proven rather than assumed, by building twice with nothing else different: with the doc comment on advance_source 0c5c70c9...acdd (aarch64-apple-darwin) with that one comment removed 57f3ebce...04b3 and `strings` finds the comment's text inside the wasm. soroban-sdk embeds the doc comments of #[contractimpl] functions in the contract-spec metadata section, so they are part of the deployed bytes. Two consequences, now in the wasm-hashes.txt header so the next person does not spend an afternoon on it: - A "docs only" commit is not docs-only for the artifact. It needs this row re-recorded, and on a released contract a new release and a new verification. - These comments are published on chain and readable by anyone. Good to have on purpose, surprising to discover by accident. Linux row from CI's own measurement on the rebased branch: x86_64-unknown-linux-gnu 28.1.0 f4fd10d646307bd4f204a26be3b64c35141587b9e12aca0f41b48c049d3a5a36 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QdNuoJ9e954ojofNVGUezW --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
The `aarch64-apple-darwin` row still held `2aefbf74...6ed25`, measured before #103 and #106. The row is reference only and nothing checks it — which is exactly why a stale value is worse than an absent one: it is still read, and it still gets trusted. Re-measured on main at 2ea1e15, the tree v0.5.0 is tagged from, with the same stellar-cli 27.0.0: 0c5c70c9...e1acdd. That is the value the header already records for "with a doc comment on advance_source", which is this tree. The CI-verified linux row is unchanged: `sc/` has not moved since #106 merged, so f4fd10d6...a5a36 is still current and still the hash CI rebuilds on every push. Neither hash is the one that goes on chain. That one comes from the release workflow's artifact, per docs/deployments.md. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QdNuoJ9e954ojofNVGUezW
Fixes #102. @Lexirieru, this is your contract, so it is a draft for your review, not a merge request. The deadline is 2026-10-30 (#90), and this is the one change every real proof depends on, so I wrote it for you to throw away or take.
The bug
verify_claimrebuilt the digest'sowneras the borrower'sG…, lowercased. A real attestor signsowner = the requesting Reclaim app(RECLAIM_APP_ID,0x6415…7d04). On the first real Forepay claim (#96), the old rebuild recovers to0x9726…7896; the right one recovers to the attestor0x2448…9072. So no real AdSense or AdMob proof could have verified.The fix
DataKey::ClaimOwner(appended),set_claim_owner(owner: Bytes)(admin only;0xand 40 hex digits; stored lowercased), andclaim_owner().verify_claimrebuilds the digest with the pinned owner. AClaimOwnerSetevent is published.CD25Q4TD…HQN4andtools/rehearsal.pykeep working with no change. No real attestor claim has that owner, so the fallback accepts nothing real. If you would rather refuse when nothing is pinned, it is a one-line change. The cost is re-signing the rehearsal with a pinned owner.request_advanceand the front end take the same arguments.contextAddress, inside the identifier. Thelib.rscomment that saidownercarried it was the root of the bug, and it is gone.Tests (
cargo test: 51 passed)The fixture is now signed twice by
tools/make_claim_fixture.py. The original signature is byte-identical, so every existing test is untouched. The new one is signed with the app as owner.without_a_pinned_owner_a_claim_signed_as_a_real_attestor_signs_is_refusedVerifierRejectedwith_the_app_pinned_as_owner_that_claim_verifieswith_the_app_pinned_a_claim_signed_for_the_borrower_is_refusedthe_borrower_binding_survives_the_pinned_ownerthe_owner_is_stored_lowercase_and_must_look_like_oneG…refusedonly_the_admin_can_pin_the_ownerrequire_authAlso run:
cargo clippy -D warningsandcargo fmt --checkare clean,stellar contract buildsucceeds,make_claim_fixture.py --checkandpin_template.py --self-testpass, andcheck_linkspasses ondocs/interface.md.Deploying it (yours to decide)
It goes through
propose_upgradeand the 24 h timelock, thenset_claim_owner 0x6415200c713135e77157e1536d488df4f2bb7d04on production. It can ride in one upgrade with #94. To make 2026-10-30, the proposal has to land by 2026-10-28. If #94 is not ready by then, this can go first on its own: AdSense alone would then work for a real account.Relay side (
2d8f6ad)The audit takes an
owner, and the relay andprove:adsensepassRECLAIM_APP_IDas that owner. A proof requested through any other app now fails the audit before the front end submits it, instead of failing on chain asVerifierRejected. BE: 101 of 101 tests pass, with two new ones; typecheck and lint are clean.