Repository navigation
#4 Provider side of #6: the contract's context message, no date matches - #74
Conversation
…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.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Lexirieru
left a comment
There was a problem hiding this comment.
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_MESSAGEis"Forepay advance request", byte for byteclaim::CONTEXT_MESSAGE. The test that readsclaim.rsand 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.buildRevenueUrlproduces exactly the bytesclaim::split_dateplus the eight-part template rebuild. I cross-checked all three producers — this file,tools/make_claim_fixture.pyandtools/rehearsal.py— and they agree on the full query string includingdateRange=CUSTOMand the trailingcurrencyCode=USD&reportingTimeZone=ACCOUNT_TIME_ZONE.extractedParametersis{revenueUsd}alone, whichaudit.tsalready enforced and the contract'srebuild_contextnow 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
parametersand 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
responseMatchesvary 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.
…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.
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
contextMessageforepay:adsense-trailing-revenue:v1Forepay advance request, byte for byteclaim::CONTEXT_MESSAGEresponseMatches/responseRedactionsWhy it's safe to drop the date matches:
parameters, so the window is already fixed.What dropping them buys:
Drift guard. A new test reads
sc/advance/src/claim.rsand checks thatCONTEXT_MESSAGEmatches, 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:window_start/window_end;extractedParametersas{"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.