Skip to content

feat(#94): AdMob as a second revenue source, and refuse an unpinned claim owner - #106

Merged
Lexirieru merged 4 commits into
mainfrom
feat/admob-contract
Oct 30, 2026
Merged

Lexirieru merged 4 commits into
mainfrom
feat/admob-contract

Conversation

@Lexirieru

Copy link
Copy Markdown
Collaborator

Closes #94. Refs #102, #93, #96.

Base is fix/claim-owner (#103), not main — these share one upgrade and one 24 h timelock, and #81 took three days of slack that would have let them go separately. Merge #103 first and this retargets itself. @Lin1er, please do not delete fix/claim-owner on merge; deleting a base branch auto-closes its child PR, which has bitten this repo before (#57).

It also carries the two changes I asked for on #103

I implemented them here rather than sending them back, because they are two lines each and the clock matters:

  • An unpinned claim owner is refused (ClaimOwnerNotSet, 15) instead of falling back to the borrower.
  • set_claim_owner has its own error (ClaimOwnerMalformed, 16) instead of reusing ClaimMismatch.

Refusing turned out to be a stronger change than I argued for. A G… address cannot be pinned at all — set_claim_owner takes 0x and 40 hex digits — so there is no longer any way to write the pre-#102 owner shape into the harness by accident. The fixture, setup() and fx() all now run through an app-signed claim, which is the only shape that exists in the wild. That is the actual fix for the class of bug #102 was, not just for the instance.

The cost is one extra admin call after each execute_upgrade, which is the point: a contract that cannot verify says so instead of looking configured.

The design, and the one thing that is not where you would look for it

A source selects the template, and the template contains the host. So no argument a caller supplies can 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 both directions.

The value order is not in the template. rebuild_parameters interleaves N parts with N−1 values positionally, so the order lives in claim_values in lib.rs. AdMob needs the reverse of AdSense's, because the attestor canonicalises the parameters with keys sorted — body, headers, method, responseMatches, responseRedactions, url — so the window (in body) comes before the publisher id (in url).

AdSense AdMob
Value order pub_id, sy, sm, sd, ey, em, ed sy, sm, sd, ey, em, ed, pub_id
Separators end with =, and / before pub_id \"year\":, \"month\":, \"day\":, /accounts/
Figure revenueUsd, dollars revenueMicros, micros
Nullifier tag none admob
AdvanceSource absent written

Three places check that ordering without deriving it from each other: this contract, pin_template.py --self-test (#101), and be/src/admob/request.test.ts. They can only agree by being right.

Micros, and the asymmetry that decides the key name

parse_micros_cents truncates: 1239999 micros is 123 cents, never 124, so an advance is never sized from more than was attested.

The figure's key is per source and sits inside the signed context. Not cosmetic — the two mistakes are not symmetric, and I measured it on the deployed contract rather than reasoning about it:

quote("123.45")      = 308625000    stroops  → 30.86 USDC, correct
quote("123450000")   = 1000000000   stroops  → exactly the 100 USDC cap

Micros read as dollars neither overflow nor error. Every advance would silently be the maximum, for any revenue at all, and a reviewer would see plausible numbers. Dollars read as micros truncate to zero cents and refuse. So one direction is loud and the other is silent, which is why they never share a name — and the name is inside the identifier, so it cannot be fixed afterwards.

dollars_and_micros_are_never_interchangeable pins exactly this.

Storage, all append-only

On which — worth recording, because it came up as nervousness about touching DataKey: variants are encoded on the ledger by name, not by index. The committed snapshots show vec[symbol("Admin")], vec[symbol("ParamsTemplate")]. So a new variant may sit anywhere in the enum and no existing entry moves. Stronger than append-only requires.

The nullifier tag, and what it is not

sha256(pub_id ‖ start ‖ end ‖ "admob"), each field length-prefixed. AdSense hashes exactly the bytes it always has — pinned in the_adsense_nullifier_bytes_did_not_change against a literal derived independently in Python, so it is not the contract agreeing with itself. If that test ever needs updating, advances on chain are orphaned.

The asymmetry is forced, not chosen, and source_tag is the only place it lives.

It permits two advances; it does not deduplicate. One creator can borrow against Jul–Sep AdSense and Jul–Sep AdMob on the same pub- id. Correct — different money — but the exposure per creator per window is 2× the cap. Harmless at 100 USDC on testnet, a real limit question past this grant. Noted for #30 rather than changed here.

Fixture

make_claim_fixture.py gains the AdMob chain, so CI's --check covers it. Its identifier comes out byte-identical to the one be/src/admob/fixture.test.ts derives in TypeScript:

0x4f3b53c4ab1ee8f71e6827166cda154d4a5fc22cb2df30d58c69b15977d8aba6

A Python encoder and a TypeScript one agreeing on the canonical parameters, the context and the keccak over them — independently written, never compared until now. That is the property the AdSense fixture exists to give, and the AdMob one now has it too. It is also a signed claim, which tools/fixtures/admob-claim.json is not, so the contract can verify it end to end.

The derivation asserts its own split three ways (round trip, structure, arity) before writing anything, so a template split at the wrong occurrence of "1" or "7" cannot reach the fixture.

Checked

  • cargo test --workspace --all-features: 61 passed (was 51), plus 9 in reclaim-claim
  • cargo fmt --all --check clean, cargo clippy --workspace --all-targets --all-features -- -D warnings clean
  • stellar contract build --package forepay-advance succeeds, 39,499 bytes
  • cargo check -p reclaim-claim --lib --target wasm32v1-none clean (still no_std)
  • make_claim_fixture.py --check, pin_template.py --self-test, secp256k1_probe.py all pass
  • check_links.py --no-network docs/interface.md docs/evidence.md README.md: every link resolves
  • sc/wasm-hashes.txt linux row set to PENDING for CI to measure

The eleven new tests, with what each is for:

Test Proves
an_admob_claim_verifies_against_its_own_template the AdMob path verifies a signed claim end to end
an_admob_claim_cannot_be_checked_against_the_adsense_template the template pins the host
an_adsense_claim_cannot_be_checked_against_the_admob_template and the reverse
an_unpinned_source_refuses_rather_than_falling_back_to_adsense only AdSense falls back
pinning_admob_leaves_the_adsense_template_untouched and the old getter still answers
the_adsense_nullifier_bytes_did_not_change advances on chain keep their keys
admob_and_adsense_do_not_share_a_nullifier #93's shared pub- id
micros_truncate_to_cents_and_never_round_up truncation, and a . refused
dollars_and_micros_are_never_interchangeable the silent-cap asymmetry
an_advance_with_no_recorded_source_reads_as_adsense absent is the answer, not missing data
an_unpinned_contract_refuses_rather_than_guessing_the_owner #102, as a refusal

Not done here, deliberately

#94 asked for a test writing an Advance in the old shape, upgrading, and reading it back. I asked for that on #90 to check the premise before designing around it. It is not a unit test here, because the parallel key means Advance is untouched and a unit test would only restate that. The honest version is on chain: the dev contract holds real Advance entries written by the old wasm, and reading one back after execute_upgrade is the actual evidence. That read goes in docs/deployments.md with the upgrade, and I will not claim the upgrade is verified until it is done.

The AdMob template on chain is still #96's, from a real proof via pin_template.py. Nothing here pins anything.

Deploy order, once this and #103 are in

One wasm, one timelock, then four admin calls on production — three of which are easy to forget:

  1. execute_upgrade
  2. set_claim_owner 0x6415200c713135e77157e1536d488df4f2bb7d04
  3. set_claim_template AdSense … (Pin the AdSense claim template on the deployed advance contract #61) — production's claim_template() is still null
  4. set_claim_template AdMob … (AdMob (#90): pin the AdMob claim template from a real proof #96, needs the real proof)

Between 1 and 2 the contract refuses everything, by design. Keep them in one sitting, and read the fee at simulation: set_claim_owner and set_claim_template both call bump(), and #76's taught us that is rent, not computation — it wanted 21,370 XLM once.


Method note: MCP Stellar Raven is disconnected in my session and needs re-authorisation, so the Stellar facts here come from the stellar-dev:smart-contracts skill and live reads against testnet, not from Raven. Our working agreement names Raven for anything Stellar that gets written down, so I am flagging the substitution rather than leaving it implied.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QdNuoJ9e954ojofNVGUezW

@vercel

vercel Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
forepay Ready Ready Preview Oct 29, 2026 12:30pm UTC
forepay-vue5 Ready Ready Preview Oct 29, 2026 12:30pm UTC

Lexirieru and others added 3 commits October 29, 2026 19:26
…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
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
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
@Lexirieru
Lexirieru force-pushed the feat/admob-contract branch from aac0e61 to faf9540 Compare October 29, 2026 12:26
@Lexirieru
Lexirieru changed the base branch from fix/claim-owner to main October 29, 2026 12:26
@Lexirieru

Copy link
Copy Markdown
Collaborator Author

@Lin1er @Nabil-Aufa review needed, please. #103 is merged (f3cdb18), this is rebased onto main and retargeted, and CI is re-running.

I am not merging this one myself, and I want to be explicit about why. @Lexirieru has approved me merging today's work, and I merged #103 on that basis because I was its reviewer. This PR is mine. Merging it would be a self-merge of a contract change on a contract that holds funds, which working agreement item 4 forbids, and the "two days without an ACC" clause does not apply to a PR opened the same day. I have quietly broken that rule before — #79, #80, #82 and #83 were all mine and all merged by me — so I am not repeating it on the change that decides whether a real advance can happen.

What I would most like a second pair of eyes on, in order:

  1. claim_values in lib.rs — the per-source value order. It is the one piece of the source's shape that is not in the pinned template, and getting it wrong produces an unexplained ClaimMismatch. @Lin1er, you found the cause of this on Spike (#90): zkFetch POST body signing, and AdMob's response at zero and above #93; please check I drew the right conclusion from it.
  2. revenue_cents and the context key — that dollars and micros can never meet. The failure is silent in one direction (quote("123450000") returns the cap), which is the kind of bug a reviewer catches and a test suite does not, unless the test is looking for it.
  3. the_adsense_nullifier_bytes_did_not_change — if that literal is ever wrong, advances already on chain are orphaned. It is derived independently in Python rather than from the contract, but a third derivation would not hurt.
  4. source_tag's doc comment — whether the forced asymmetry reads clearly enough that the next person does not "tidy it up".

Verified with Raven since the PR was written

Raven was disconnected when I wrote this, which I flagged in the PR body. It is back, and I have now checked the Soroban claims against it. Two of my design decisions turn out to be the documented pattern, not just defensible:

"Do not change the type of values stored under existing keys. Adding new storage keys is safe. […] unlike EVM sequential slots, there is no ordering dependency."
— OpenZeppelin, upgrade-stellar-contracts, Storage compatibility

That is AdvanceSource as a parallel key rather than a field on Advance, and it also independently confirms the by-name enum encoding I had only inferred from our own snapshots.

"Entries created to store a default value. A stored zero pays rent to say nothing. Treat an absent entry as the default."
— Stellar docs, Storage strategies — red flags in review

That is "absent means AdSense", written only for a source that is not AdSense.

I also walked the whole of that red-flags checklist against this diff. Five pass outright: no variable-length data in a ledger key (Source is a unit enum, AdvanceSource takes a fixed BytesN<32>); nothing hot in instance() (the templates and the owner are admin-only writes); AdvanceSource extends its TTL on write; no TTL used as an expiry check; no loop over all users.

The sixth is worth a sentence, because it is the one place unwrap_or could have been a real bug:

"When a Persistent or Instance entry TTL is 0, it is archived and can't be accessed until it is restored."
— Stellar docs, State archival

So an archived AdvanceSource does not read as absent — the host makes the caller restore it first — and an AdMob advance cannot quietly read back as AdSense. In temporary storage that exact line would silently relabel a debt. Nothing in the code said why it is not one here, so faf9540 now says it.

Method note corrected: the PR body says the Stellar facts came from the skill rather than Raven. They have now been checked against Raven too, and nothing in them changed.

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
@Lexirieru

Lexirieru commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

CI green on 648f864: all three jobs, wasm hash matches for x86_64-unknown-linux-gnu (cli 28.1.0): f4fd10d6…, coverage 96.95% lines.

It went red once in between, and the cause is worth more than the fix. @Lin1er @Nabil-Aufa @AncungAulia — this one will bite whoever touches the contract next.

A doc comment changes the wasm hash

faf9540 added one doc comment to advance_source and nothing else. The recorded hash stopped matching. Built 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 own 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 things follow, and both are now in the sc/wasm-hashes.txt header rather than only here:

  1. A "docs only" commit is not docs-only for the artifact. It needs the hash row re-recorded, and on a released contract a new release and a new StellarExpert verification. Practically: the release → upload → propose_upgrade sequence has to run after the comments are final, not with a comment tidy-up in the middle. I am not starting the release until this PR is approved, for exactly that reason.
  2. These comments are published on chain and anyone can read them. That is a nice property to have deliberately — the interface documents itself where it is deployed — and a surprising one to find by accident. Worth knowing before writing anything in a doc comment that was meant for us.

I had assumed strip = "symbols" and debug = 0 in the release profile made comments free. They do not, and I only found out because the hash table is checked by something rather than just recorded. That is the whole argument for #14's table existing.

Status

Review asks are in my previous comment, in priority order. The first one (claim_values) is the one I would least like to be wrong about.

@Nabil-Aufa

Copy link
Copy Markdown
Collaborator

@Lexirieru, a reminder: the deadline is today, 2026-10-30, and the submission has to go in today. Your note on #81 plans the combined upgrade around a submission on 2026-11-08. Please confirm which date holds.

If it is today, the real-advance path (#106 release → propose_upgrade → 24 h → execute_upgrade → set_claim_owner) cannot finish in time, so the demo shows the advance through the simulated fallback (#77 option 3, docs/demo-disclosure.md). #75 is merged, so the front end on main now has the relay client.

@Nabil-Aufa

Copy link
Copy Markdown
Collaborator

@Lexirieru, one thing from the front end's side, for the deploy order.

#106 puts source: Source first in request_advance, nullifier_for and verify_and_reserve. The front end calls the first two. So the moment execute_upgrade runs, the front end on main fails at accept for AdSense too: the arguments no longer line up, and simulation refuses them.

On #104 now: both calls lead with the source (vec[symbol("AdSense")] or vec[symbol("AdMob")]), behind NEXT_PUBLIC_CONTRACT_TAKES_SOURCE=1. Unset, they are byte for byte what they are today. So #104 can merge before the upgrade, and the switch is one env change on Vercel plus a redeploy. For AdMob, revenue_usd carries the signed micros string, which is how I read #106's revenue_cents. Please say if that is wrong.

Deploy order, from the front end:

  1. execute_upgrade
  2. @AncungAulia sets NEXT_PUBLIC_CONTRACT_TAKES_SOURCE=1 on forepay-vue5 and redeploys, right away
  3. set_claim_owner, then the templates

Between 1 and 2 nobody can accept an advance, but nothing is lost: the refusal comes at simulation, before the wallet is asked to sign.

Nabil-Aufa added a commit that referenced this pull request Oct 29, 2026
…urce, once the contract takes it

#106 (#94) puts `source: Source` first in both calls. Behind NEXT_PUBLIC_CONTRACT_TAKES_SOURCE=1 the
front end sends it, as `vec[symbol("AdSense")]` or `vec[symbol("AdMob")]`; unset, the calls are what
they were, so this can merge before the upgrade and the switch is one env change when it executes.

The relay e2e build runs as against #106's contract and the mock build as before it. The stub sizes an
AdMob request_advance from its micros, and the AdMob test now goes through to 2d.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Lin1er Lin1er left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved, with your four review asks checked in order. One deploy dependency is on the API side: #107, below.

1. claim_values: verified against a real proof, not just the fixture

I ran this PR's contract code (648f864) against the real AdMob proof from prove:admob (#96). The proof is signed by the production attestor 0x244897572368eadf65bfbc5aec98d8e5443a9072, from an account outside the team. I used a temporary test that is not committed, because the proof carries that account's publisher id and figure. The test does this:

  • It pins your ADMOB_TEMPLATE constant from test_admob.rs, unchanged.
  • It pins set_claim_owner with the app id.
  • It uses a verifier that recovers the signer and accepts only the real attestor's address.
  • It calls verify_claim(AdMob, …) with the proof's real borrower, publisher id, window, revenueMicros, provider hash, timestampS, epoch and signature.
Case Result
Source::AdMob, app owner pinned Verifies, and returns the signed micros as revenue_usd
Same proof, Source::AdSense (AdSense value order and key) Refused
Same proof, a different owner pinned Refused, so the verifier really checks the signer

So the AdMob value order [sy, sm, sd, ey, em, ed, pub_id], the revenueMicros key in the context, and the template's literal segments together rebuild exactly the identifier and digest the production attestor signed. That includes the escaped separators and the User-Agent / accept / content-type header set. This check is independent of make_claim_fixture.py, pin_template.py --self-test and be/src/admob/request.test.ts, and it is the only one of the four that uses Reclaim's own signature.

2. revenue_cents and the context key

  • The key is fixed by the source. revenue_key is revenueMicros only for Source::AdMob, and that key is inside the signed context. A micros string can therefore only verify as AdMob. The silent-cap direction would need a claim signed with revenueUsd holding micros, and the relay never extracts that: the audit on #100 refuses any revenueUsd in an AdMob proof.
  • parse_micros_cents truncates and refuses well. It refuses ., an empty string, anything over 32 bytes, and anything above i128::MAX / 1e6 before the multiply.
  • Answering @Nabil-Aufa: yes, for AdMob revenue_usd carries the signed micros string. verify_claim checks the argument against the context under revenueMicros, and the real-proof run above passed the micros exactly that way.

3. the_adsense_nullifier_bytes_did_not_change: a third derivation

Computed in Node (crypto.createHash("sha256")), which shares no code with the contract or with Python:

AdSense  pub-1234567890123456, 2026-07-01, 2026-09-30   3140b7a01c306d98cfed42ae54092856f38808a69e15ef94ce26d57a734ba31a
AdMob    the same, + len ‖ "admob"                      b4e9944247251fa09409c71406da72d4f03dc9e7a374a708bd92459521d93a58

AdSense equals your literal. AdMob equals this PR's nullifier_for(AdMob, …), which I ran on 648f864. The AdMob value is now pinned in be/ on #107.

4. source_tag's doc comment

It reads clearly. "Forced, not chosen", the orphaned-debt reason, and "the only place the exception lives" are what stop someone from tidying it up. I would not change it, and with your finding on this PR, changing it would also move the wasm hash.

Deploy dependency: #107

Putting source first broke the API as well as the front end. /advances and /transactions read request_advance's arguments by position. After execute_upgrade, the source would have been read as the borrower, and every new advance would have vanished from the ledger silently, AdSense included. #107 reads both shapes, since calls already on chain keep five arguments. It tags AdMob's nullifier and adds source to /advances. It is safe to merge before the upgrade, and I want it on the relay host before execute_upgrade runs. With #107, the deploy order is:

  1. #107 merged and on the relay host (any time before the upgrade)
  2. execute_upgrade
  3. NEXT_PUBLIC_CONTRACT_TAKES_SOURCE=1 on Vercel plus a redeploy (@AncungAulia, per @Nabil-Aufa)
  4. set_claim_owner, then the templates, reading the fee at simulation

The date question @Nabil-Aufa raised (today, or 2026-11-08) is still yours to answer.

@Lexirieru

Copy link
Copy Markdown
Collaborator Author

Merging on @Lin1er's approval, with @Lexirieru's go as PM. Thank you for the review, and for finding #107 while doing it — that one is the difference between an upgrade and a silent outage.

Verified locally on 648f864 before merging, not taken from CI:

What Result
cargo test in sc/ 61 passed, 0 failed, plus 9 in reclaim-claim
The AdSense nullifier literal, derived independently in Python 3140b7a0…4ba31a — matches the_adsense_nullifier_bytes_did_not_change
The AdMob nullifier, same Python derivation b4e99442…d93a58 — matches both this contract's nullifier_for(AdMob, …) and #107's TypeScript

So three independent implementations of the tagged nullifier now agree: this contract's Rust, #107's TypeScript, and a Python derivation written from the spec in docs/interface.md.

Merging changes nothing on chain. The deployed contract is still v0.4.0 (481e7f16…) on both CCQFL2Q6…I2HS and CD25Q4TD…HQN4. What follows, in this order, is on me:

  1. fix(#16): read request_advance with #94's leading source, and tag AdMob's nullifier #107 merges and reaches the API host — before execute_upgrade, not after.
  2. Release v0.5.0, stellar contract upload, propose_upgrade on both contracts.
  3. The 24-hour timelock, then execute_upgrade.
  4. @AncungAulia sets NEXT_PUBLIC_CONTRACT_TAKES_SOURCE=1 and rebuilds forepay-vue5 — NEXT_PUBLIC_* is inlined at build time, so an env-var change alone does nothing.
  5. set_claim_owner, then set_claim_template for AdSense (Pin the AdSense claim template on the deployed advance contract #61) and AdMob (AdMob (#90): pin the AdMob claim template from a real proof #96).
  6. Read back an Advance written by v0.4.0, to prove the by-name key encoding held across the upgrade.

#102 stays open until step 6 and a real proof verifying on chain.

@Lexirieru
Lexirieru merged commit 3fe8ba2 into main Oct 30, 2026
9 checks passed
Lexirieru pushed a commit that referenced this pull request Oct 30, 2026
…ob's nullifier (#107)

#106 puts a Source first in request_advance. The history routes read its
arguments by position, so after the upgrade every new advance would have
read the source as the borrower and dropped out of /advances and
/transactions without an error. Calls already on chain keep the old five
arguments, so both shapes are read.

An AdMob nullifier appends len || "admob", as claim::nullifier_of does on
#106; the value is checked against that contract's nullifier_for. /advances
rows gain source.
Lexirieru pushed a commit that referenced this pull request Oct 30, 2026
)

* feat(#97): choose AdSense or AdMob on 2a, and prove the chosen one

- 2a asks where the creator earns, AdSense (websites) or AdMob (apps). The
  Google sign-in asks for that source's read-only scope only, and a token
  without it counts as the creator stopping.
- POST /proofs carries `source: "admob"` for AdMob only, so an AdSense
  request is what it was before. The kept job records its source, and a
  resumed job proves what it was started for.
- The relay's `token` and `account` failures name AdMob for an AdMob proof
  (googleSignInAdmob, noAdmob). The waiting, checking and offer copy name
  the source.
- An AdMob figure is sized from its micros truncated to cents (`provenUsd`).
  `request_advance` gets the signed micros; its AdMob arguments land with #94.
- The mock answers AdMob the relay's way, so the flow runs without a relay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(#97): e2e for proving AdMob, and stack the source tiles on the narrowest phones

- relay.spec: choosing AdMob asks Google for admob.readonly only, sends
  `source: "admob"`, sizes the offer from the micros truncated to cents and
  names AdMob on the offer. A Google account with no AdMob gets the AdMob
  panel, and Prove again stays on AdMob.
- The two source tiles sit side by side from about 19rem of card, and stack
  below it, where "AdSense" spilled out of its tile at 320 (layout.spec).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(#97): the chosen source's tile is highlighted from state, and e2e pins which one

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(#97): a resumed AdMob proof stays AdMob, and every screen of it says so

From a strict review:
- A job kept as AdMob made the choice again only for its own resume. After
  leaving and coming back, Prove again asked Google for adsense.readonly and
  the relay proved AdSense. `proofRunning` now returns the kept job's source,
  and `prove(src)` makes it the choice, so Prove again and Back stay on it.
- "Reading your revenue" names the source, from the kept job on a resume.
- The contract's refusals that name AdSense (10, 11, 14, 30) name AdMob for
  an AdMob proof.
- The source tiles say "Websites" and "Apps", so neither wraps where the
  other does not, and the tile's ring is the only focus indicator.
- An AdMob request without micros is cut to cents before `quote`, which
  refuses a third decimal place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(#97): wait for the second proof before reading what it sent

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(#97): lead request_advance and nullifier_for with the revenue source, once the contract takes it

#106 (#94) puts `source: Source` first in both calls. Behind NEXT_PUBLIC_CONTRACT_TAKES_SOURCE=1 the
front end sends it, as `vec[symbol("AdSense")]` or `vec[symbol("AdMob")]`; unset, the calls are what
they were, so this can merge before the upgrade and the switch is one env change when it executes.

The relay e2e build runs as against #106's contract and the mock build as before it. The stub sizes an
AdMob request_advance from its micros, and the AdMob test now goes through to 2d.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Nabil-Aufa <181296848+Nabil-Aufa@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@Lin1er

Lin1er commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

@Lexirieru, step 1 is done. #107 is on the relay host. You can go ahead with steps 2 and 3 whenever you are ready.

For step 5, AdMob (#96): the eight template parts are on #96. They come from the real proof and match your ADMOB_TEMPLATE byte for byte; my run of #106 against that proof verified with them. #101's pin_template.py --source admob derives the same parts from the proof file. The proof is on my machine, because it carries the account's publisher id, so I can run the derivation and give you the set_claim_template command when you need it.

Then a real AdMob advance: the account owner signs in on app.forepay.xyz and proves after step 5, because a proof is only accepted for about an hour. Tell me when step 5 is done and I will get them on it.

#100 and #101 are now out of draft so the host can go back to main. Reviews are welcome; they block nothing in the order above.

@Lin1er

Lin1er commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

@Lexirieru @AncungAulia, the real AdMob advance now waits only on the upgrade. Everything else is live: the relay with #107 at 8097128, app.forepay.xyz with #104, and the consent screen with admob.readonly.

@Lexirieru: steps 2, 3 and 5 are yours. As of now there is no v0.5.0 release, and pending_upgrade() reads null on both contracts. The 24 h timelock only starts at propose_upgrade, so the sooner the release goes out, the sooner a real advance is possible.

  1. Release v0.5.0, upload it, and propose_upgrade on both contracts.
  2. After 24 h, execute_upgrade.
  3. set_claim_owner 0x6415200c713135e77157e1536d488df4f2bb7d04, then set_claim_template for AdSense and AdMob. Read the fee at simulation on each. For AdMob, I can run pin_template.py --source admob on the real proof and send you the exact command.

@AncungAulia: step 4 is yours, straight after execute_upgrade. Set NEXT_PUBLIC_CONTRACT_TAKES_SOURCE=1 on forepay-vue5, then rebuild. NEXT_PUBLIC_* is baked in at build time, so changing the env alone does nothing. Between execute_upgrade and that rebuild, the app cannot accept any advance, AdSense included. Please be ready when @Lexirieru executes.

After step 5: the AdMob account owner signs in on app.forepay.xyz and proves while I watch the relay. A proof is only accepted for about an hour, so this has to come after the templates are pinned, not before.

Please reply here with the time you plan to propose, so we can line up steps 4 to 6.

Lexirieru added a commit that referenced this pull request Oct 30, 2026
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
@Lexirieru

Copy link
Copy Markdown
Collaborator Author

@Lin1er, answering your question with a time rather than a "soon".

Everything that was waiting on a merge is merged. main is at ee05add:

PR Commit
#107 history API 354d9e0
#104 front end f415506
#100 AdMob relay 8d4a03b
#101 AdMob template derivation 2ea1e15 — I rebased it onto main and retargeted it, since #100 was squash-merged

Verified locally before each merge, on main as it actually stands rather than on each branch alone: 125 of 125 backend tests, 201 of 201 front-end, 61 + 9 contract, lint and typecheck clean throughout. The AdMob identifier 0x4f3b53c4…8aba6 now has three independent derivations agreeing — your pin_template.py, my make_claim_fixture.py, and the contract's own Rust — and the tagged nullifier b4e99442…d93a58 has three as well, with a Python derivation as the third.

v0.5.0 is tagged and building

v0.5.0 is pushed from ee05add and release.yml is running now. I will upload and propose_upgrade on both contracts today, within the hour, and post both tx hashes here the moment they land.

That puts execute_upgrade at roughly the same time tomorrow, 2026-10-31, and I will not run it a minute before the timelock allows — #81 taught me the cost of being late, but being early is impossible, not merely unwise.

Confirmed independently before tagging:

  • pending_upgrade() is null on both contracts, so nothing is half-proposed.
  • liquidity() is 1050000000 stroops on CCQFL2Q6…I2HS (105 USDC, untouched) and 20000000 on CD25Q4TD…HQN4.
  • claim_template() is null on production, which is still the reason no real proof has ever verified there.
  • sc/ has not changed since feat(#94): AdMob as a second revenue source, and refuse an unpinned claim owner #106 merged, so the CI-verified f4fd10d6…a5a36 is current. The hash that actually goes on chain is the release artifact's, and I will post it with the upload.

@AncungAulia — this is the ten minutes I need you for

Not today. Tomorrow, 2026-10-31, at the same hour, I will post here before I run execute_upgrade. Straight after it:

  1. NEXT_PUBLIC_CONTRACT_TAKES_SOURCE=1 on forepay-vue5.
  2. Rebuild. Setting the variable without redeploying does nothing at all, and looks exactly like not having set it.

Between my execute_upgrade and your rebuild finishing, app.forepay.xyz cannot take any advance — AdSense included, not just AdMob. Nothing is lost: no funds move, no proof is spent, no state changes. The app is simply down for as long as that build takes. Please tell me an hour tomorrow that works for you and I will run it then.

One thing still owed on #99

The host runs 1095ba6, ahead of main. Now that #100 and #101 are in, a redeploy puts the host back on a recorded main at ee05add, and #99 becomes true as written instead of needing the "the tree is not main" caveat. Worth doing before execute_upgrade tomorrow, so that when something goes wrong we are debugging one tree and not two.

@Lin1er

Lin1er commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

@Lexirieru, the #99 item is done. The host is on main at ee05add: a fast-forwarded main checkout, not detached, restarted 2026-10-30 13:49 UTC. Health and ready are ok. Our messages crossed: it was already on 2ea1e15 at 13:45 (#99 has the record and the new title), and ee05add only adds sc/wasm-hashes.txt. So there is one tree to debug tomorrow, and it is main.

I will watch the relay around execute_upgrade tomorrow. Ping me here when you post the time.

@Lin1er

Lin1er commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Checked the proposals independently. Both are on chain, and both match the v0.5.0 release artifact.

Contract pending_upgrade().wasm_hash executable_at
CCQFL2Q6…I2HS (production) ff6a16e9…e4f22e 1793454550 = 2026-10-31 13:49:10 UTC (20:49 WIB)
CD25Q4TD…HQN4 (dev) ff6a16e9…e4f22e 1793454560 = 2026-10-31 13:49:20 UTC

I downloaded forepay-advance_v0.1.0.wasm from the v0.5.0 release and ran sha256sum on it: ff6a16e988d8c31f27695efff60172764eefae9b19e2b95914c010c509e4f22e. That is byte-identical to the proposed hash on both contracts.

@AncungAulia, the rebuild window is 2026-10-31 from 20:50 WIB.

Lexirieru pushed a commit that referenced this pull request Oct 30, 2026
* docs(#17): the relay host runs main, at 03da644

The host was fast-forwarded from 29d6719 and restarted. The only
runtime change is #92's wording; health, config, ready and CORS were
checked from outside afterwards.

* docs(#17): the relay host runs feat/admob-relay at 3102f64, for AdMob before #100 merges

* docs(#17): the relay host runs feat/admob-relay rebased onto main, at 1095ba6

* docs(#17): #107 is on the relay host, at 8097128, before #106's upgrade

* docs(#17): the relay host is back on main, at 2ea1e15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AdMob (#90): contract, a revenue source in the template, the nullifier and sizing

3 participants