Skip to content

fix(#76): rebuild the claim in the encoding AdSense actually produces - #79

Merged
Lexirieru merged 2 commits into
mainfrom
fix/6-claim-date-encoding
Oct 20, 2026
Merged

Lexirieru merged 2 commits into
mainfrom
fix/6-claim-date-encoding

Conversation

@Lexirieru

Copy link
Copy Markdown
Collaborator

Closes #76. Unblocks #61, #17 and the on-chain half of #5.

Found by @Lin1er on #6 while building the provider. He was right, and I verified it against Google's reference before changing anything rather than taking the report on trust.

The fact

startDate and endDate on accounts.reports.generate are object (Date) — and Date is {year, month, day} as integers. The REST transport flattens that into startDate.year=2026&startDate.month=7&startDate.day=1. Unpadded, because they are integers: 7, never 07.

There is no string form of a date in that API. So ?startDate=2026-07-01 — what docs/interface.md froze and what is pinned on the dev contract right now — describes a request Google cannot serve, and every real AdSense proof would have been refused, with a bare ClaimMismatch and nothing to say which byte was wrong.

Two changes, both inside the rebuild

The template takes seven values instead of three: pub_id, sy, sm, sd, ey, em, ed, so eight parts. claim::split_date converts YYYY-MM-DD on the way in — ten bytes of fixed-width parsing, every byte checked, no JSON, no allocation beyond the three outputs.

extractedParameters is {"revenueUsd":"<x>"} alone. A responseMatches regex captures one contiguous substring, and AdSense echoes the window back as "startDate":{"year":2026,"month":7,"day":1} — "2026-07-01" does not appear anywhere in the response, so it cannot be captured from one.

What did not change, and this is the part worth checking

The interface. request_advance(…, window_start: "YYYY-MM-DD", window_end, …) is byte-identical, and the nullifier is still sha256 over those two strings plus pub_id. Nothing about what is being borrowed against moved. This is a re-encoding on the way into the template.

The strength of the currency and window checks. Both left extractedParameters; neither left the signature:

Was asserted by Now asserted by
extractedParameters.currency the "currencyCode": "USD" response match
extractedParameters.startDate / .endDate the URL — Google computes the totals for the window in the URL

Both of those live in parameters, which this contract pins and rebuilds. If anything, the window is held more tightly now: it is in the thing Google computed from, not in an echo of it.

set_claim_template refuses a four-part template outright

Accepting the old shape and failing per-proof later would bury the cause under the least readable error in this pipeline. Better to refuse the template.

This means the dev contract's currently pinned template has to be re-pinned after the upgrade. I will do that and re-run the rehearsal; details below.

The fixture was the real failure

tools/fixtures/forepay-claim.json was a hand-pasted blob. Nobody could re-derive it, so when the encoding changed there was no mechanism by which anyone would notice it had gone stale — the digest tests would just keep passing against bytes that no longer described anything.

It now comes from tools/make_claim_fixture.py, and CI runs that script with --check. The signing key is a published test constant, the same one tools/rehearsal.py uses; the real attestor vector is still real-reclaim-proof.json and is untouched.

Tests

43 pass, fmt and clippy -D warnings clean. Four new:

  • a_date_becomes_three_unpadded_numbers — 7, not 07. A padded month produces a URL Google never sent.
  • a_window_that_is_not_yyyy_mm_dd_is_refused_rather_than_guessed — eight malformed inputs.
  • the_context_carries_only_the_figure — pinned byte for byte, because a context with the old keys still compiles, still hashes, and is simply never what an attestor signed. No type catches that.
  • the_template_the_contract_used_to_accept_is_refused_now.

Cross-checked that tools/rehearsal.py, tools/make_claim_fixture.py and be/src/adsense/request.ts (#74) all produce the same URL bytes.

After this merges

  1. Tag v0.3.0 → release artifact, attested to StellarExpert.
  2. Upload, propose_upgrade on both contracts, 24h timelock, execute_upgrade.
  3. Re-pin the dev contract's template with the eight new parts, then re-run the rehearsal end to end.
  4. Production stays TemplateNotSet until Pin the AdSense claim template on the deployed advance contract #61, which still waits on FEASIBILITY GATE: one real AdSense revenue proof verified on testnet #5 — and on Find an approved (READY) AdSense account for the gate and the demo #77, which nobody has picked up.

@Lin1er — once this is deployed, hand me the real template parts and provider_hash from the first proof and #61 is one admin call. The eight parts you will need to supply are the literal segments around those seven values, in the order above.

🤖 Generated with Claude Code

The frozen interface described a request the AdSense API cannot serve, so
every real proof would have been refused with a bare ClaimMismatch and no
indication of which byte was wrong. Found by @Lin1er on #6 while building
the provider. Verified against Google's own reference before changing
anything: `startDate` and `endDate` on accounts.reports.generate are
`object (Date)` — {year, month, day} as integers — which the REST transport
flattens into startDate.year=2026&startDate.month=7&startDate.day=1.
Unpadded: 7, never 07. There is no string date form to use instead.

Two changes, both inside the rebuild:

The template now has eight parts and takes seven values — pub_id, then each
date as year, month and day. `claim::split_date` converts YYYY-MM-DD on the
way in: ten bytes of fixed-width parsing, every byte checked, no JSON. The
interface is untouched. `request_advance` still takes YYYY-MM-DD and the
nullifier is still computed over those strings, so nothing about what is
being borrowed against has moved.

`extractedParameters` is now {"revenueUsd": "<x>"} alone. A responseMatches
regex captures one contiguous substring and AdSense echoes the window back
as {"year":2026,"month":7,"day":1}, so "2026-07-01" cannot be extracted from
any response. The currency and the window did not leave the signature, they
moved to where the provider actually puts them: the "currencyCode": "USD"
match and the URL, both inside the pinned `parameters`.

set_claim_template now refuses a four-part template outright. Accepting one
and failing per-proof later would hide the cause behind the hardest error in
this pipeline to read.

The fixture had to be regenerated, and it was a hand-pasted blob nobody could
re-derive — which is why nothing caught that it had gone stale. It now comes
from tools/make_claim_fixture.py, and CI runs that script with --check so the
two cannot drift apart again.

Four new tests: a date becomes three unpadded numbers (7, not 07); a window
that is not exactly dddd-dd-dd is refused rather than guessed; the rebuilt
context is pinned byte for byte, because a context with the old keys still
compiles and still hashes and is simply never what an attestor signed; and
the template the contract used to accept is refused now.

43 tests pass, fmt and clippy clean.

Refs #76, #6, #61, #17, #5

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 20, 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 20, 2026 8:42am UTC

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

Contract: rebuild the AdSense claim in the encoding the AdSense API actually produces

1 participant