Skip to content

fix(#16): read request_advance with #94's leading source, and tag AdMob's nullifier - #107

Merged
Lexirieru merged 1 commit into
mainfrom
fix/history-source
Oct 30, 2026
Merged

Lexirieru merged 1 commit into
mainfrom
fix/history-source

Conversation

@Lin1er

@Lin1er Lin1er commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Found while reviewing #106. This has to be deployed before #106's execute_upgrade, or with it.

The problem

#106 puts source: Source first in request_advance. The history routes (#16) read that call's arguments by position:

const [callBorrower, , pubId, windowStart, windowEnd] = call.args as string[];

After the upgrade, callBorrower would be the source (["AdSense"]). That never equals the wallet, so every advance taken after the upgrade, AdSense included, would silently disappear from /advances and /transactions. There would be no error and no 502, just an empty ledger on the Repayment screen. It is the same "argument order shifted" break @Nabil-Aufa found for the front end on #106, on the API side.

The fix

Checked

What How
A real funded call from the Horizon fixture, rewritten with ["AdSense"] first Reads deepEqual to the original, nullifier included
The same call with ["AdMob"] first Borrower and publisher read correctly; nullifier tagged, and different from AdSense's
AdMob nullifier for #106's fixture publisher and window b4e99442…3a58, equal to #106's own nullifier_for(AdMob, …), run on 648f864
AdSense nullifier for the same inputs 3140b7a0…a31a, the literal #106 pins in the_adsense_nullifier_bytes_did_not_change

BE lint and typecheck are clean, and 104/104 tests pass. docs/api.md documents source and the tagged nullifier.

Deploy

Merging this changes nothing on chain. The relay host picks it up through #100's rebase. Until the upgrade, every call is five arguments and reads exactly as today.

…ob's nullifier

#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.
@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 11:33pm UTC
forepay-vue5 Ready Ready Preview Oct 29, 2026 11:33pm UTC

@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. This is the catch of the week, @Lin1er — a break with no error, no 502 and no failing test, found by reading #106's argument order against code that nobody had changed. The Repayment screen would have gone quietly empty for every advance taken after the upgrade, AdSense included, and we would have blamed the contract.

Verified here, not read off CI

What Result
npx tsx --test "src/**/*.test.ts" in be/ 104 pass, 0 fail (5.8s)
npx eslint . clean, exit 0
npx tsc --noEmit clean, exit 0
nullifierFor(pub-1234567890123456, 2026-07-01, 2026-09-30, "AdMob") b4e99442…d93a58, derived independently in Python from docs/interface.md
The same inputs, AdSense 3140b7a0…4ba31a, the literal #106 pins

Both literals match a Python derivation I wrote from the spec, so your TypeScript, #106's Rust and that Python agree on the tagged nullifier. I also read #106's merged signature to check the positional skip: request_advance(env, source, borrower, revenue_usd, pub_id, window_start, window_end, …), so after stripping the source, [borrower, , pubId, windowStart, windowEnd] lands on exactly the right five. Both call sites — advanceCalls and ledgerTransactions — go through requestArgs, which is what makes this a fix rather than half a fix.

The Array.isArray(args[0]) discriminator is the right call. A unit variant arrives as ["AdMob"] and an address as a G… string; the two cannot collide, and it needs no flag, no config and no coordination with the upgrade.

One note, not blocking

source = args[0][0] === "AdMob" ? "AdMob" : "AdSense";

An unrecognized tag becomes AdSense. With Source holding exactly two variants that is correct today. But if a third source is ever added, this computes the untagged nullifier for it, readAdvance finds no record, the row is dropped by the record?.borrower === borrower filter, and it vanishes from /advances — the same silent disappearance this PR exists to fix, arriving by the same route. #106's source_tag gives every non-AdSense source a tag, so the asymmetry is in the contract's favour and only this line defaults the wrong way.

Worth one line, whenever Source next grows: treat an unknown tag as unknown and let it fail loudly, rather than calling it AdSense. Nothing to change now.

Merging, and why it is safe before the upgrade

Both shapes are read, so this is correct against the deployed v0.4.0 and against v0.5.0. Merging it now means the host can pick it up well before execute_upgrade, which is the window that matters.

@Lexirieru
Lexirieru merged commit 354d9e0 into main Oct 30, 2026
9 checks passed
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
Lexirieru pushed a commit that referenced this pull request Oct 30, 2026
…PI's source (#108)

* fix(#97): Advance details name AdMob for an AdMob advance, from the API's source

#107 adds `source` to every /advances row, read from the request_advance
call. The client keeps it, and reads a row without one (an API from before
#107) or with an unknown one as AdSense. "AdSense revenue, …" on Repayment
becomes "AdMob revenue, …" for an AdMob advance.

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

* fix(#97): keep the revenue window whole when the Advance details label wraps

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