Repository navigation
Closed
Labels
out-of-sowNot an Instawards deliverableNot an Instawards deliverableready-to-devUnblocked: development can start on the issue's branchUnblocked: development can start on the issue's branch
Description
Owner: @Lexirieru · Branch: feat/admob-contract · Parent: #90 · Was blocked by: #93, done 2026-10-26 (both parts) · Start: now on the branch, pending @Lexirieru's go on #90 for merging before 2026-10-30 (otherwise after 2026-11-08) · Label: out-of-sow · Also after: #81 deployed
Let the advance contract verify an AdMob claim beside an AdSense one, without moving anything already stored.
What
enum Source { AdSense, AdMob }.- New keys
ParamsTemplateFor(Source)andProviderHashFor(Source). - The existing
ParamsTemplateandProviderHashkeys are read asAdSense.DataKeystays append-only.
- New keys
set_claim_templatetakessource.verify_claim,verify_and_reserveandrequest_advancetakesourceand rebuild from that source's template.- The template pins the host, so an AdMob claim can never be checked against the AdSense template.
- AdMob's template layout.
- Spike (#90): zkFetch POST body signing, and AdMob's response at zero and above #93 showed the window inside the signed
bodyas an escaped JSON string (\"year\":2026), with unpadded integers. bodysorts beforeurl, so the six date values come beforepub_id.- The value order per source is fixed in code, not taken from the caller.
- Spike (#90): zkFetch POST body signing, and AdMob's response at zero and above #93 showed the window inside the signed
- Micros to cents.
- AdMob's
ESTIMATED_EARNINGSismicrosValue("123450000"= $123.45). - Add a micros parser that truncates to cents and never rounds up.
sizingstays one function over cents.
- AdMob's
- The nullifier is tagged for AdMob only.
- AdSense nullifiers keep their current bytes, because advances already on chain are keyed on them.
- Put the exception in one
source_tagfunction, with the reason in its doc comment (wording on Proposal: AdMob as a second revenue source, beside AdSense (needs a decision) #90).
- The source of an advance is stored as a parallel key, not as a field.
DataKey::AdvanceSource(BytesN<32>) -> Source, written at disbursement. Absent means AdSense.- Not a new field on
Advance: old entries would fail to decode. - Prove that premise first with a test: write an
Advancein the old shape, upgrade, read it back.
- Upgrade through
propose_upgradeand the 24-hour timelock. Evidence goes indocs/deployments.md.
Done when
- The tests cover an AdMob claim verified end to end on a template from a real AdMob proof (Proposal: AdMob as a second revenue source, beside AdSense (needs a decision) #90 item 4).
- Cross-source refusals are tested both ways.
- AdSense nullifier bytes are unchanged (pinned by a test).
- Micros truncation and the old-
Advancedecode are both tested. - The upgrade is executed on testnet and recorded.
Working agreement
- One issue, one owner. 2. Branch per issue, named above, not the GitHub-suggested one. 3. MCP Stellar Raven for any Stellar/Soroban fact that gets written down. 4. Merge through PR review by Axel (PM); no self-merge. If an ACC has not arrived within two days on something already verified, merge and say so in the PR. 5. Deploys need evidence: contract address or tx hash on stellar.expert, recorded in
docs/deployments.md. 6. Secrets live in.env, gitignored,chmod 600: never printed, never committed, never pasted into an issue or PR. Only publicG…andC…addresses appear anywhere. 7. Issues, commits and PRs in English.
Metadata
Metadata
Assignees
Labels
out-of-sowNot an Instawards deliverableNot an Instawards deliverableready-to-devUnblocked: development can start on the issue's branchUnblocked: development can start on the issue's branch
Activity
Lexirieru commentedon Oct 25, 2026
A design consequence of #93 that is not written down anywhere yet, and that a template-per-source does not cover on its own.
@Lin1er already spotted the cause in #93:
What follows from it is bigger than the template. The order of the seven values is hardcoded in the contract, at
sc/advance/src/lib.rs:570:rebuild_parametersinterleaves N parts with N−1 values positionally. For AdSense that order is right:pub_idsits in the URL path, the dates in the query string after it. For AdMob the window is insidebody, which sorts beforeurl, so the order is reversed — the six date numbers come first andpub_idlast. A template alone cannot express that, because the template is only the literal segments; the order lives in this line.Proven, not inferred
I built an AdMob-shaped canonical
parametersusing the key order the attestor itself produced in #93 (body, headers, method, responseMatches, responseRedactions, url) and rantools/pin_template.py's own derivation against it:Two things fall out:
pub_idis at offset 386 and the dates at offset 65, so a left-to-right search for the dates afterpub_idfinds nothing. Good: it fails loudly rather than producing a wrong template. That refusal is tools(#61): derive the claim template from a real proof, and prove it three ways #83's structure check doing its job on a shape it was never written for.check()is wrong for AdMob. Part 0 ends\"year\":, not/. All six separators end with:, not=. The last one ends/accounts/. Those assertions are the check that actually catches a split at the wrong occurrence of"1"or"7"(tools(#61): derive the claim template from a real proof, and prove it three ways #83), so they cannot just be dropped for AdMob — they have to be restated for a JSON body.Caveat on my own evidence: this is a synthetic
parametersstring, not a real AdMob proof. What it establishes is the ordering and the separator shape, which follow from alphabetical key sorting and from JSON escaping and do not depend on the exact bytes. The real parts still have to come from a real proof (#96).What I propose for this issue
Add the value order to the per-source branch, beside the template — not as new storage, since it is derivable from the source:
Seven lines, no storage change, and it keeps the property that makes this design safe: the template fixes the host, so a claim made against
admob.googleapis.comcan never be checked against the AdSense template.And a test that would have caught it: pin the AdMob template, then verify a claim whose
parameterswere built in the AdSense order and assertClaimMismatch. Without it, the failure mode is the one #83's docstring calls the hardest in this pipeline to read — an unexplained mismatch with nothing pointing at the cause.This also means #96 is not "the same tool with a different value layout", which is what I wrote on #90.
values_for()needs a per-source order andcheck()needs per-source structure rules. Noted there.Still blocked by #93 and still after 2026-11-08 — nothing changes about the schedule. This is only so it is not rediscovered at the point where it costs a timelock cycle.
Lin1er commentedon Oct 25, 2026
Agreed on both: the per-source
matchfor the value order, and the test that pins the AdMob template and expectsClaimMismatchfor a claim built in the AdSense order. I had noticedbodysorting beforeurl, but not that the order lives inlib.rs:570, outside the template. That is exactly what would have shown up as an unexplained mismatch after a timelock cycle.The relay side (#95) does not change: the relay sends the
reportSpecbody as built, and the attestor canonicalises it. I will add one relay test that builds the AdMobparametersfrom a fixed window and asserts the value order[sy, sm, sd, ey, em, ed, pub_id]againstsplit_parts. That way the relay,pin_template.pyand the contract each check the order on their own.Lin1er commentedon Oct 26, 2026
@Lexirieru one input for the contract from #100, the relay side of #95:
be/src/admob/request.test.tsasserts that in the canonical parameters the six date numbers come before/accounts/pub-…, which is your[sy, sm, sd, ey, em, ed, pub_id].revenueMicros, notrevenueUsd. Sorebuild_contextalso needs the key per source: one more arm in the samematch. A separate name means a micros string can never be read as dollars by anything that sees the claim. If you would rather keep one key, tell me before AdMob (#90): pin the AdMob claim template from a real proof #96 derives the template, because the name is inside the signed context.docs(#81): borrower authorisation executed, three days late
Lexirieru commentedon Oct 29, 2026
@Lin1er
revenueMicrosas its own key. Yes, keep them separate — and the reason is stronger than readability, so I checked it against the live contract before answering.If a micros figure were ever read as dollars, here is what
quote()onCCQFL2Q6…I2HSactually does today:$123.45 expressed as
123450000micros, read as dollars, does not overflow and does not error. It returns the maximum advance, silently, becausecap_stroopsis 1,000,000,000 and sizing truncates into it. Every AdMob advance would be exactly 100 USDC no matter what the creator earned, and nothing in the pipeline would say a word. A reviewer would see plausible numbers.The reverse mistake — dollars read as micros — gives
123.45micros, truncates to 0 cents, and fails loudly asAdvanceTooSmall. So the two directions are not symmetric: one is a loud refusal, the other is a silent maximum. A shared key would leave the silent one one typo away, in the one place a typo cannot be fixed afterwards, because the key name is inside the signed context and therefore inside the identifier.So: one more arm in the same
match, as you suggested.Go ahead on #96/#101 with
revenueMicros.Two more things from your #100 note
The relay-side order test is the right shape. Three independent checks of the same ordering —
be/src/admob/request.test.ts,pin_template.py --self-test, and the contract test — is what I would have asked for. They can only agree by being right, because none of them derives the order from the others.tools/fixtures/admob-claim.jsonunblocks me. I was expecting to need the real proof fromprove:admobbefore I could write #94's contract tests. With a signed AdMob-shaped fixture whose identifier recomputes, I can build and test the whole per-source path now, and #96 only has to swap in the real parts afterwards. That is the same thingmake_claim_fixture.pydid for #76, and it is why that fixture was worth generating rather than pasting.Where #94 stands
Starting it now, on top of #103 rather than on
main, because they share one upgrade and one timelock — #81 is deployed as of today (1220778c…and17262af5…, rehearsal 7/7 GREEN), sopropose_upgradeis free.That upgrade will also carry the two changes I asked for on #103: refusing when no claim owner is pinned, rather than falling back to the borrower, and its own error code instead of reusing
ClaimMismatch.feat(#94): record the linux wasm hash CI measured
Lexirieru commentedon Oct 29, 2026
Built: #106, on
feat/admob-contract, based on #103 because they share one upgrade and one timelock.61 contract tests pass, up from 51. fmt, clippy
-D warnings, the wasm build, theno_stdwasm check,make_claim_fixture.py --checkandpin_template.py --self-testare all clean, and CI's "Test snapshots are committed" passes.Everything this issue listed is in, with three things worth pulling out of the PR:
1. @Lin1er, your AdMob identifier and mine agree byte for byte.
make_claim_fixture.pynow derives the AdMob chain in Python;be/src/admob/fixture.test.tsderives it in TypeScript (#101). Two encoders, written separately, never compared until today, agreeing on the canonical parameters, the context and the keccak over them. That is the property the AdSense fixture exists to give and the AdMob one now has it too — and unliketools/fixtures/admob-claim.json, mine is signed, so the contract verifies it end to end rather than just matching a string.2. The micros/dollars asymmetry is worse than "confusing", and it is measured. Already on this issue, now pinned by
dollars_and_micros_are_never_interchangeable:quote("123450000")is exactly1000000000stroops. Not an overflow, not an error — the cap, for any revenue at all.3. The item I did not turn into a unit test, and why. This issue asks for "write an
Advancein the old shape, upgrade, read it back" — my own ask on #90. With the parallel key,Advanceis untouched, so a unit test would only restate that. The honest version is on chain: the dev contract holds realAdvanceentries written by the old wasm, and reading one back afterexecute_upgradeis the evidence. It goes indocs/deployments.mdwith the upgrade, and I will not call the upgrade verified until that read is done.Deploy order, which is four admin calls and not one
Production needs all of these in one sitting, because between 1 and 2 the contract refuses everything by design:
execute_upgradeset_claim_owner 0x6415200c713135e77157e1536d488df4f2bb7d04set_claim_template AdSense …— production'sclaim_template()is stillnull(Pin the AdSense claim template on the deployed advance contract #61)set_claim_template AdMob …— needs the real proof (AdMob (#90): pin the AdMob claim template from a real proof #96)Read the fee at simulation on 2 and 3. Both call
bump(), and #76 taught us that is rent rather than computation: it wanted 21,370 XLM once.Blocked on #103 merging. Nothing here pins a template on chain — that is #96's, from a real proof.
docs(#94): say why unwrap_or on AdvanceSource is safe
feat(#94): AdMob as a second revenue source, and refuse an unpinned o…
feat(#94): record the linux wasm hash CI measured
5 remaining items
feat(#96): pin_template.py derives an AdMob template, with its own or…
feat(#94): AdMob as a second revenue source, and refuse an unpinned c…
fix(#16): read request_advance with #94's leading source, and tag AdM…
feat(#97): choose AdSense or AdMob on 2a, and prove the chosen one (#104
feat(#95): an AdMob provider beside AdSense, selected by source on PO…
feat(#96): pin_template.py derives an AdMob template, with its own or…
feat(#95): an AdMob provider beside AdSense, selected by source on PO…
feat(#96): pin_template.py derives an AdMob template, with its own or…
feat(#96): pin_template.py derives an AdMob template, with its own or…
docs(#94): re-measure the macOS reference hash for the v0.5.0 tree
docs(#102,#94): v0.5.0 uploaded and proposed on both contracts
fix(#102): pin_template --command names the source set_claim_template…
docs(#102,#94): v0.5.0 executed, claim owner and AdMob template pinned
docs(#102,#94,#5): the first real advance, and a correction