Skip to content

#4 Provider side of #6: the contract's context message, no date matches - #74

Merged
Lexirieru merged 1 commit into
mainfrom
feat/4-adsense-provider
Oct 20, 2026
Merged

Lexirieru merged 1 commit into
mainfrom
feat/4-adsense-provider

Conversation

@Lin1er

@Lin1er Lin1er commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

Refs #4, #6. This is the provider half of the proposal on #6. Of the three mismatches listed there, two can be fixed on the provider side, and this PR fixes both.

What changes

Before After
contextMessage forepay:adsense-trailing-revenue:v1 Forepay advance request, byte for byte claim::CONTEXT_MESSAGE
responseMatches / responseRedactions currency, startDate, endDate, total currency, total

Why it's safe to drop the date matches:

  • Google computes the total for the window named in the URL.
  • The URL is signed through parameters, so the window is already fixed.
  • The response's echo of the dates proved nothing beyond that.

What dropping them buys:

Drift guard. A new test reads sc/advance/src/claim.rs and checks that CONTEXT_MESSAGE matches, so the two can't silently drift apart again.

Still open on #6 (contract side, @Lexirieru)

AdSense only accepts dates as startDate.year=2026&startDate.month=7&startDate.day=1, unpadded. The contract therefore has to:

  • fill those six values in the URL, splitting window_start/window_end;
  • rebuild extractedParameters as {"revenueUsd":"<x>"}.

The details are on #6. #61 has to wait for that.

Verified

pnpm -C be test: 61 pass. Lint and tsc are clean.

The #17 relay (#73) picks this up unchanged, because it imports the provider.

…e matches

Two of the three mismatches on #6 are the provider's to fix:

- contextMessage is now "Forepay advance request", byte for byte the
  constant claim.rs rebuilds the context with. A test reads claim.rs and
  compares, so the two cannot drift again.
- The startDate/endDate regexes are gone from responseMatches and
  responseRedactions. Google computes the total for the window in the URL,
  and the URL is signed, so the echoed dates proved nothing more. Without
  them the matches are the same for every proof, and the contract's pinned
  template only has to fill in the URL's values. The attestor now sees two
  response fragments instead of four.

The URL still takes the dates as startDate.year/.month/.day: that is the
only form the AdSense API accepts. Matching it is the contract side of #6.
@vercel

vercel Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
forepay Skipped Skipped Oct 20, 2026 3:37am UTC

Lin1er added a commit that referenced this pull request Oct 20, 2026
Deployed from feat/17-proof-relay with #74 merged in. /config reports the
recorded addresses and relay: true; /ready answers. A smoke proof made on
the host was signed by the production attestor in 54 s and passes
verify_proof in simulation, with the one-byte flip refused as #5.

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

Approving, and merging — this is the other half of #76, which landed on main an hour ago in #79. The contract now rebuilds exactly what this provider produces.

Checked against the contract, not just read

  • CONTEXT_MESSAGE is "Forepay advance request", byte for byte claim::CONTEXT_MESSAGE. The test that reads claim.rs and compares is the right kind of test: this is a constant two languages have to agree on, and nothing else would have caught it drifting.
  • buildRevenueUrl produces exactly the bytes claim::split_date plus the eight-part template rebuild. I cross-checked all three producers — this file, tools/make_claim_fixture.py and tools/rehearsal.py — and they agree on the full query string including dateRange=CUSTOM and the trailing currencyCode=USD&reportingTimeZone=ACCOUNT_TIME_ZONE.
  • extractedParameters is {revenueUsd} alone, which audit.ts already enforced and the contract's rebuild_context now matches.

On dropping the date regexes

Worth writing down why this is safe, because "we stopped checking the dates in the response" is the kind of line that looks alarming in a review six weeks from now.

dateRegex worked. It could have stayed, with the contract rebuilding those too. You chose constant responseMatches instead, and that is the right trade:

  • the window is in the URL, which is signed through parameters and pinned in the contract;
  • Google computes the totals for the window in that URL, so the response's echo is derived from the thing already checked, not independent of it;
  • an attacker controls neither the URL nor Google's response, so the echo adds no check that can fail independently;
  • and keeping it would make responseMatches vary per proof, which means the template would have to interleave values into the matches as well — more values, more surface, for a check with no attack it closes.

Defence-in-depth you cannot state an attack against is just cost. Flagging the reasoning here so it reads as a decision rather than an omission.

One note

audit.ts now says "the same two fragments" — correct. Worth a line in docs/interface.md §2 eventually saying the matches are constant by design, since #61 depends on that property: it is the reason the pinned template only has to fill in the URL's values.

Nice catch on the whole thing, and thank you for not touching sc/ without asking — the split into #76 made the contract change reviewable on its own.

@Lexirieru
Lexirieru merged commit adc4c5d into main Oct 20, 2026
8 checks passed
@Lexirieru
Lexirieru deleted the feat/4-adsense-provider branch October 20, 2026 09:06
Lexirieru pushed a commit that referenced this pull request Oct 20, 2026
Deployed from feat/17-proof-relay with #74 merged in. /config reports the
recorded addresses and relay: true; /ready answers. A smoke proof made on
the host was signed by the production attestor in 54 s and passes
verify_proof in simulation, with the one-byte flip refused as #5.
Lexirieru pushed a commit that referenced this pull request Oct 20, 2026
…d claim (#73)

* feat(#17): proof relay, POST /proofs and GET /proofs/:id

The relay takes the borrower's G… and a Google access token with
adsense.readonly, proves the trailing AdSense revenue with zkFetch, and
returns request_advance's arguments. The G… goes into contextAddress before
the attestor signs, so the binding is inside the signed claim (#9).

Proving takes about ten minutes of CPU with snarkjs, so the request answers
202 with a job id and the front end polls. One proof runs at a time; one job
per borrower; a short queue. Jobs live in memory and the token only in the
running job's closure: never stored, logged or returned, and scrubbed from
errors.

The pre-flight checks (account, READY, response shape) move from the
prove:adsense CLI to adsense/account.ts and relay/prove.ts, so the CLI and
the relay run the same code. Failures carry a code that says whose move it
is: token, account, provider, prove, audit.

The browser flow and the API are in docs/api.md.

* docs(#17): the API and the relay, public at api-forepay.jameshub.fun

Deployed from feat/17-proof-relay with #74 merged in. /config reports the
recorded addresses and relay: true; /ready answers. A smoke proof made on
the host was signed by the production attestor in 54 s and passes
verify_proof in simulation, with the one-byte flip refused as #5.

* docs(#17): proving takes about a minute on the relay host, not ten

* feat(#17): relay errors carry a code: running, busy, unconfigured

The front end has to tell "your proof is still running" from "the relay is
full" from "the relay is not set up here", and the status alone cannot: 503
means two of them. Each refusal now says which in `code`.

409 deliberately does not return the running job's id. A borrower's address is
public, and the id is what reads their revenue, so the front end keeps the id
it was given with the 202 (review on #75).

* fix(#17): refuse an access token too short to be Google's

Scrubbing a one-character token out of a failure message cut that
character out of every word ("e[redacted]pired"), seen live on the relay.
Google's tokens run to hundreds of characters; under 16 is a 400.
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.

2 participants