Repository navigation
Conversation
There was a problem hiding this comment.
1 optional suggestion (a nit or a note on pre-existing code) was found and not posted.
The latest push brings back an issue flagged in an earlier review; replied in that comment's thread.
Still open from earlier reviews (1):
- 🔴
src/request/session-topup.ts:321—Unsponsored session top-ups can now try to deposit the whole wallet balance, leaving nothing to pay the gas fee. Before…
If you have decided not to act on one of these findings, resolve its thread (a reply alone leaves it open) and the next review stops counting it. To review this commit again now, use Re-run on its "Claude Code Review" check.
There was a problem hiding this comment.
I reviewed the latest push and found no new bugs. The top-up fee room now comes from spendableAmount(capacity), which addresses my last comment. This change sizes payments and adds pre-sign funding checks in the request payment path, so a human should still look at it.
What was reviewed:
feeFundedTopUp/buildTopUpTransaction: unsponsored top-ups now keep the deposit plus fee within the balance and the key's limit, the floor stays at the shortfall, and the calls are rebuilt only when the amount changes.topUpAmount: anunknownallowance limits the top-up to the shortfall, and the cap refusal stays tied to the shortfall alone.charge.ts: the MACH route checks only the key allowance, so a short MACH balance still reachesmachRouteError. The dry-run reuse quote is now lowered to the read balance and key limit.
Extended reasoning...
The change touches the tempo request payment flow in src/request/ (session top-up sizing, the new funding.ts allowance and balance checks, charge pre-sign checks, and dry-run quoting), plus schema text, SKILL.md and tests. It changes how much money is deposited into payment channels and when payments are refused, though it does not touch auth or crypto. All four points from my earlier inline comments are handled in the current code. I deferred instead of approving because the change is large (about 800 lines) and sits on a money-moving path where sizing decisions benefit from a human look.
|
Informational: Charge funding preflight skips the balance check for single-split charges chargeSettlement treats any charge whose resolved calls number exactly two as a MACH route. A non-MACH charge offer with one split resolves to two TIP-20 transfers, so assertChargeFunding checks only the access key's allowance and skips the balance comparison. An underfunded split charge is therefore signed and sent instead of being refused before signing. Valid? React with 👍 / 👎. |
|
Informational · unverified: Session top-up quotes can understate the amount actually locked The new quotedDeposit path clamps a reused session's chunk using the locally stored key limit, but tryTopUpAndRetry sizes the actual transaction using the published key's live remaining allowance. These are different bounds even when nothing changes between quoting and paying. Full findingThe new quotedDeposit path clamps a reused session's chunk using the locally stored key limit, but tryTopUpAndRetry sizes the actual transaction using the published key's live remaining allowance. These are different bounds even when nothing changes between quoting and paying. If the owner has increased the published key's allowance without refreshing this installation's saved limits, the quote can be smaller than the actual deposit. For example, with a 1-token existing deposit, a 0.005-token shortfall, sufficient balance, a stored limit of 0.2, and live remaining allowance of 1, the exact source functions return a 0.2-token quote but a 1-token payment top-up. This was reproduced in an in-memory exact-source sizing probe. A sponsored transaction avoids any fee-related reduction of that example. The selected payment amount is encoded into the escrow topUp transaction. This contradicts the documented quote-then-approve workflow, which describes deposit as the amount the payment would lock, and can lock more funds than the user approved from the quote. The overall spending cap remains enforced; this is not a cap bypass or evidence that a merchant can redeem unsigned amounts. Production incidence and an end-to-end transaction were not established. Use the same live funding-capacity and unknown-allowance sizing policy for quotes and payments, preserving bounded dry-run RPC reads, and add coverage where stored and live limits differ. First reported at 45a2cb0; recheck at this head: still present. Valid? React with 👍 / 👎. |
| depositRaw: | ||
| required === 0n | ||
| ? 0n | ||
| : topUpAmount({ | ||
| cap: parseUnits(spendCap(options), 6), | ||
| deposit: reusable.deposit, | ||
| explicitCap: options.maxSpend !== undefined, | ||
| required, | ||
| suggestedDeposit: details.suggestedDeposit, | ||
| }), | ||
| signedCumulative, |
There was a problem hiding this comment.
Low: Dry-run session top-up quote ignores wallet balance and key limit clamp
On a reused session that needs a top-up, planSessionPayment sizes the dry-run deposit with topUpAmount but without the wallet's spendable amount, while the payment clamps the same chunk to the balance and the key's remaining limit. The quote's deposit therefore reports more than the payment locks, for example 1 instead of 0.3 USDC.e.
Full finding
On a reused session that needs a top-up, planSessionPayment sizes the dry-run deposit with topUpAmount but without the wallet's spendable amount, while the payment clamps the same chunk to the balance and the key's remaining limit. The quote's deposit therefore reports more than the payment locks, for example 1 instead of 0.3 USDC.e.
First reported at 8b7d1b3; recheck at this head: still present.
Valid? React with 👍 / 👎.
There was a problem hiding this comment.
I reviewed the latest push and found no new bugs. The issues I raised earlier look addressed in the code. This change moves real funds and shapes on-chain transactions, so a human look is still worthwhile.
What was reviewed:
topUpAmountandfeeFundedTopUpsizing. When the allowance is unknown, the top-up adds only the shortfall. Fee room now comes from the key-capped spendable amount, and the deposit never goes below the shortfall.- The MACH route in
resolveAccount, now detected by its token and swap addresses. Only the key allowance is checked on the route, androuteFundingErroris reported only for a route refusal. - Ruled out: an implicit MACH route with a short MACH balance going on-chain. The route deliberately leaves the balance check to the SDK's fallback, as designed.
Extended reasoning...
The PR changes how tempo request sizes session top-ups and checks payment funding. It adds src/request/funding.ts and touches session-topup.ts, session.ts, charge.ts and dry-run.ts, with new tests. None of it is auth code, but it decides how much is deposited and signed into on-chain transactions, including fee arithmetic (attodollars converted to 6-decimal fee units). Later commits addressed the earlier findings (fee room, the unknown-allowance cap, MACH error reporting). Two inline comments from another reviewer (at session.ts:305 and charge.ts:367) still have no resolution I can see. That and the funds-handling scope are why this defers instead of approving.
| export function topUpAmount(options: { | ||
| available?: bigint | undefined; | ||
| cap: bigint; | ||
| deposit: bigint; | ||
| explicitCap: boolean; | ||
| required: bigint; | ||
| suggestedDeposit?: bigint | undefined; | ||
| }) { | ||
| const headroom = options.cap > options.deposit ? options.cap - options.deposit : 0n; | ||
| const chunk = options.explicitCap ? headroom : options.deposit; | ||
| let amount = [options.required, options.suggestedDeposit ?? 0n, chunk].reduce((max, value) => | ||
| value > max ? value : max, | ||
| ); | ||
| if (amount > headroom) amount = headroom; | ||
| if (options.available !== undefined && amount > options.available) amount = options.available; | ||
| return amount > options.required ? amount : options.required; | ||
| } |
There was a problem hiding this comment.
Informational: Session top-up sizing can exceed the v2 channel's uint96 amount range
topUpAmount sizes the optional prefunding chunk from the explicit spending cap and the payer's spendable balance, never from the v2 channel precompile's uint96 amount. When both exceed 2^96-1 raw units, the top-up call cannot be encoded and the request fails, although the required shortfall alone would have encoded. First reported at 8b7d1b3; recheck at this head: still present.
Valid? React with 👍 / 👎.
| export async function readKeyAllowance( | ||
| identity: PaymentIdentity, | ||
| options: { chainId: number; rpc?: Rpc | undefined; token: string }, | ||
| ): Promise<KeyAllowance> { | ||
| if (!("key" in identity)) return { kind: "unlimited" }; | ||
| const client = createTempoPublicClient(options.chainId, options.rpc ?? {}); | ||
| const parameters = { account: identity.address, accessKey: identity.signerAddress }; | ||
| const metadata = await Actions.accessKey.getMetadata(client, parameters); | ||
| if (metadata.isRevoked) return { kind: "unusable" }; | ||
| if (metadata.address === zeroAddress) { | ||
| if (!identity.key.keyAuthorization) return { kind: "unusable" }; | ||
| const limit = storedAccessKeyLimit(identity.key, options.token); | ||
| return limit === null ? { kind: "unlimited" } : { kind: "limited", remaining: limit }; | ||
| } | ||
| if ( | ||
| metadata.address.toLowerCase() !== identity.signerAddress.toLowerCase() || | ||
| (metadata.expiry !== 0n && metadata.expiry <= BigInt(nowSeconds())) | ||
| ) | ||
| return { kind: "unusable" }; | ||
| if (metadata.spendPolicy === "unlimited") return { kind: "unlimited" }; | ||
| const { remaining } = await Actions.accessKey.getRemainingLimit(client, { | ||
| ...parameters, | ||
| token: options.token as Address, | ||
| }); | ||
| return { kind: "limited", remaining }; | ||
| } |
There was a problem hiding this comment.
Low: Funding preflight refuses payments from RPC reads on an unverified chain
readFundingCapacity and readKeyAllowance read key metadata, remaining limit and balance through the RPC override without checking which chain it serves. assertCanFund turns those answers into refusals for every charge and for a new session open, so an override on another chain yields a false key-revoked, insufficient-balance or limit diagnosis. First reported at 8b7d1b3; recheck at this head: still present.
Valid? React with 👍 / 👎.
…ge preflight without token decimals
Session top-ups added only the shortfall, so once a session's deposit was used up, every later call sent its own top-up transaction. Payments and channel transactions were also signed without checking the access key's remaining on-chain spending limit or the wallet balance, so a sponsored transaction the chain rejects (
SpendingLimitExceeded,InsufficientBalance) still landed as a failed transaction.Change
topUpAmount(src/request/session-topup.ts): a top-up adds the largest of the shortfall (or the server'srequiredTopUp), the server'ssuggestedDeposit, and a chunk of the spending cap: the whole headroom under an explicit--max-spend(matching how a new session's deposit already uses it), else the current deposit, so the deposit doubles. The chunk never lifts the deposit above the cap and never exceeds what the wallet can spend (balance within the key's remaining limit); it never drops below the shortfall. The cap refusal for a shortfall past the cap is unchanged.--dry-runquotes the same amount.src/request/funding.ts:readKeyAllowance(the logicpreferMachSessionalready used, now shared),readFundingCapacity, andassertCanFund, which refuses with the existingaccessKeyLimitError(E_LIMIT_EXCEEDED, namingtempo wallet keys update) when the key's remaining limit is below the amount, or with an insufficient-balance error, before anything is signed.assertCanFund. Charges run it fromresolveAccount, reading the amount from the TIP-20transfer/transferWithMemo/approvecalls the SDK resolves; a refused machine-token route still falls back to the direct transfer, and an explicit MACH charge reports the route's real cause. An allowance read that fails leaves the limit to the chain.preferMachSessionchecks only the shortfall for a reused session, since the top-up is lowered to what the wallet can spend.Effect
Per 1,000 calls to one service at a constant per-call price on a session opened with one call's deposit (the default without
suggestedDepositor--max-spend): before, about 999 top-up transactions; now about 10 (log2 of 1,000 under the default cap), or 1 under an explicit--max-spendthat covers the run. Transactions the chain would reject for the key's limit or the balance are no longer sent.Validation
test/request-funding.test.ts(top-up sizing, call decoding, refusals); new cases intest/request-mach-session.test.tsfor refusing an open and a top-up above the remaining limit or balance before signing, and for a headroom top-up; updated dry-run and receipt expectations.pnpm check:code,pnpm typecheck,pnpm test:types,pnpm changelog:validate,pnpm docs:checkpass.pnpm test: all pass except threetest/setup.test.tscases that fail identically onmainin this sandbox (its HTTP egress proxy).