Skip to content

contracts: no fee-on-transfer mock, so the received-delta accounting is untested on every path #1521

Closed

Description

@thiras

Found by the multi-agent review of #1518. Pre-existing — confirmed with git log -S"received < minDeposit", which shows the predecessor check arrived in #777 with no fixture, and topUp on main already carried the identical untested received == 0.

The gap

contracts/test/ has no fee-on-transfer or rebasing token mock. contracts/test/mocks/ holds only MintableUSDC, MockCapacityBond, MockEd25519Verifier, MockFeeRouter, MockSlashJudgeEvidence, and PaymentChannelTest uses a plain OZ MockUSDC. So four guard sites are unreachable by the suite:

  • openChannel pre-transfer deposit == 0 (covered — test_openChannel_revertsOnZeroDeposit)
  • openChannel post-transfer received == 0 — untested, and // slither-disable-next-line incorrect-equality means static analysis won't comment either
  • topUp pre-transfer additionalDeposit == 0
  • topUp post-transfer received == 0 — untested

The more valuable assertion this unlocks

Not the reverts — the delta accounting. openChannel credits ch.deposit = received, deliberately, so a fee-on-transfer proxy cannot over-state a channel. Nothing tests that the credited value is received rather than the requested deposit. That is the case that would silently lose money.

And there is a live inconsistency on the Rust side: crates/client-pull/src/buyer_channel.rs records the requested deposit in the local channel row rather than opened.deposit (the decoded ChannelOpened value, which is the contract's received). A one-word fix. Today it is unreachable — USDC is immutable at deployment and Arbitrum USDC is not fee-on-transfer — but it means the buyer's local watermark could over-state the on-chain deposit, its vouchers exceed it, and _advanceClaimWatermark reverts at withdraw/settleChannel: the seller has delivered bytes it can never claim.

Note on what #1518 narrowed

Before #1515, a proxy shaving a 10 USDC deposit to 0.4 USDC reverted DepositBelowMinimum(400000, 1000000) and rolled the transfer back. Now only a shave to exactly zero reverts; a partial shave opens a channel at the shaved value. #1518's commit message and CHANGELOG are accurate about this ("cannot shave a deposit to nothing"), and it matches topUp's long-standing behaviour, so it is defensible — but it is a narrowing, and it is currently undocumented as an intentional decision rather than an unexercised path.

Proposal

A ~15-line FeeOnTransferUSDC (an ERC20 whose _update burns a fixed bps) covering:

  • both post-transfer ZeroAmount reverts, at 100% fee
  • getChannel(id).deposit == received (not deposit) at a partial fee, on both openChannel and topUp — the assertion that actually matters
  • a decision, pinned by a test either way, on whether a partial shave should revert (received != deposit, or a bps tolerance) or be accepted as it is today

Temper the priority: the USDC address is immutable at deployment and the deployed token is not fee-on-transfer, so this is defensive depth for a token that will never be configured. It is cheap, though, and it converts three "we think this is fine" comments into assertions.

Activity

  1. added
    kind:test
    area:contracts
    on Jul 29, 2026
  2. self-assigned this
    on Jul 30, 2026
  3. added 4 commits that reference this issue on Jul 30, 2026
    bb73634
    1084585
    d002f93
    b1a5962
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:contractskind:test

Type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions