Skip to content

Security

Where a payment is refused. And what we have not done.

Three separate checks stand between an agent and the money, and each refuses for its own reasons. Everything below names the file or the test behind it, so you can go and disagree with us.

Three keys

Three keys, and what each one cannot do.

Every action on a channel is signed by one of three keys. None of them can do another’s job, none of them can change what the agent signed, and the contract has no admin key that could. Dinara never holds your funds: the deposit sits in the contract, and only its rules move it.

  • The owner’s wallet

    Any EVM wallet you connect. It funds the channel, sets its terms and pays its fees in a stablecoin.

    Can

    • Open a channel and deposit into it
    • Add funds, raise the ceiling or extend the expiry
    • Bring expiry forward to five minutes from now, with requestClose
    • Reclaim everything if nobody settles within an hour of expiry

    Cannot

    • Lower a ceiling
    • Shorten an expiry, except by that five-minute notice
    • Settle or propose before expiry
    • Reclaim before the hour of grace has passed, or while a settlement is under dispute
  • The agent key

    A secp256k1 key the owner names when opening the channel. It signs EIP-712 states, not transactions, so it never holds money or pays a fee.

    Can

    • Sign a new running total for each charge
    • Propose a settlement before expiry, open for ten minutes to any state that owes a payee more

    Cannot

    • End its channel with a state that underpays: a payee’s voucher that owes it more raises the proposal
    • Get a state over the ceiling settled
    • Pay an address that is not one of the channel’s payees
    • Change the deposit, the ceiling or the payees
  • The operator

    An optional metering service the owner names when opening the channel.

    Can

    • Settle at once with a state the agent signed, when the owner or agent asks
    • Challenge a stale proposal with the newest state it holds

    Cannot

    • Change an amount
    • Sign a state of its own
    • Overtake a proposal under dispute
    • Touch the deposit any other way

Three refusals

Three places can refuse a payment, and none trusts the others.

The SDK refuses before the agent signs. The payee refuses before it serves. The contract refuses before money moves. Each runs its own checks, so a bug in one is not a hole in all three.

  1. The agent’s SDK

    A charge the channel would refuse is never signed.

    TempoMeterSession.charge checks each charge against the channel’s terms before it signs: a payee that is not on the list, a charge that would pass the ceiling or what the channel holds, an expired channel, or a token the channel does not hold. An x402 quote above the agent’s own maxPrice, or from a payee that does not trust the channel’s operator, is refused before that. It throws a MeterRefusal with the reason, and nothing exists to settle.

    In the repositorypackages/sdk/src/agent.tspackages/sdk/src/x402.ts

  2. The payee

    An API serves only against a voucher it has checked itself.

    verifyTempoX402Payment reads the voucher from x402’s PAYMENT-SIGNATURE and checks it on the payee’s own server, asking Dinara and no facilitator for anything. It recovers the agent’s EIP-712 signature locally and refuses a bad signature, a voucher for another chain, contract, channel or payee, a closed or expired channel, a state over the ceiling, a charge below the price, a channel holding another token, and anything older than, or owing less than, the newest voucher it already accepted. The amount is the agent’s signature, never the client’s copy of the quote.

    In the repositorypackages/sdk/src/payee.tspackages/sdk/src/x402.ts

  3. The contract

    Settlement pays what the agent signed, and nothing else.

    settle recovers the agent’s EIP-712 signature over the state itself, under a domain bound to Tempo’s chain id and the contract’s address. It fails with WrongSigner for any key but the agent’s, MalformedSignature for a signature that is not 65 bytes with a low s, CeilingExceeded for a state over the ceiling, LinesMismatch for a state without one line per payee, and SettlerNotAllowed for anyone but the operator. Everyone else proposes, and a proposal stays open to any state that owes a payee more.

    In the repositorycontracts/src/DinaraChannels.sol

No layer trusts the answer of the one before it. The contract checks the ceiling again although the SDK already did, because a payee can be handed a state that never went through the SDK.

The path of a paid call

Five steps between a call and a payment.

The API names a price and the agent signs for it. Three of the five steps can refuse on their own, and none of them takes the previous one’s word for anything. Refusing is not an error, which is why one of the two endings is amber and neither is red.

Five stages in order, then two endings. The third, fourth and fifth stages can each refuse on their own, and no stage trusts the answer of the one before it.

  1. The call

    The agent calls an API through tempoPayingFetch, the way it would call fetch.

    Refuses nothing. Nothing has been asked for yet.

  2. The 402

    The API answers 402 Payment Required, with its price, address and token in x402’s PAYMENT-REQUIRED.

    Refuses nothing. It only names a price.

  3. The SDK

    The agent’s session checks the charge against the channel, signs a new running total with EIP-712 and retries with it in PAYMENT-SIGNATURE.

    Refuses an unknown payee, a charge over the ceiling, an expired channel. Nothing signed.

  4. The payee

    verifyTempoX402Payment checks the voucher on the API’s own server and keeps the newest one. Then the API serves, with PAYMENT-RESPONSE.

    Refuses a bad signature, an underpaid or a stale voucher, or one that lowers another payee’s line. Not served.

  5. The contract

    At the end, one settlement carries the newest signed state to the contract on Tempo.

    Refuses a wrong signer, a state over the ceiling, a line for anyone but the payees. No money moved.

Two endings

  • Paid

    $39.99 to three payees, in one transaction.

    The receipt records what each payee’s balance gained and what came back to the owner, so the figures written down are the figures that moved.

  • Refused

    Nothing signed, nothing owed.

    Each refusal carries its reason: a MeterRefusal from the SDK, a reason from verifyTempoX402Payment, or the contract’s own custom error. None of them leaves a payment half done.

A diagram of the path a paid call takes, not a screenshot. No check here trusts the answer of the one before it.

Enforced on chain

The rules the contract enforces.

Each rule is checked by the contract that holds the deposit, and each has a test that it holds and a test that breaking it is refused with its exact custom error. The names under each rule are Foundry tests in contracts/test.

The ceiling is funded
A ceiling is never more than the deposit the contract measured, so every metered dollar exists. Opening a channel with a ceiling above its deposit, or raising one above it later, fails with InvalidCeiling.test_refusesAZeroCeilingOrOneAboveTheDeposittest_neverRaisesTheCeilingAboveTheDeposit
Terms only widen
topUp adds funds, raises the ceiling or extends the expiry, and nothing else. A lower ceiling is CeilingLowered; an earlier expiry is ExpiryShortened. Ending early goes through requestClose, which leaves five minutes to settle.test_neverLowersACeilingOrShortensAnExpirytest_pullsTheExpiryInToTheCloseNotice
Only the agent’s signature counts
Every state is an EIP-712 signature the contract recovers itself. A state signed by any other key, or changed after signing, is WrongSigner; one signed for another channel is WrongChannel; and a signature that is not 65 bytes, low-s, with a v of 27 or 28 is MalformedSignature.test_refusesAStateSignedByAnyKeyButTheAgentstest_refusesAStateSignedForAnotherChanneltest_refusesTheMalleatedHighSFormOfAValidSignature
Never over the ceiling
A state whose total is above the ceiling is CeilingExceeded, even one the agent signed, and one above what the channel holds is InsufficientBalance.test_refusesAStateOverTheCeilingEvenOneTheAgentSignedtestFuzz_refusesEveryStateAboveTheCeiling
Only the channel’s payees
A state carries exactly one line per payee, in the order the owner named them, and its lines add up to its total. Anything else is LinesMismatch or TotalMismatch, so a settlement can pay nobody else.test_refusesAStateWithoutExactlyOneLinePerPayeetest_refusesAStateWhoseLinesDoNotAddUpToItsTotal
Only the operator settles at once
settle is the operator’s alone; anyone else is SettlerNotAllowed, the agent included, before or after expiry. Everyone else uses proposeSettlement: the agent or operator before expiry, anyone after, so a payee is never stuck behind a silent agent.test_letsNobodyButTheOperatorSettleAtOnceEvenAfterExpirytest_letsAnyoneProposeAfterExpirySoAPayeeIsNeverStuckBehindASilentAgent
A stale state cannot end a channel
A proposal stays open for ten minutes. Anyone holding an agent-signed state that owes some payee more raises that payee’s line with challengeSettlement; one that owes nobody more is StaleState, whatever sequence number the agent signed. Only when the window closes can anyone finalizeSettlement, and the owner cannot reclaim while it runs (DisputeInProgress).test_refusesAChallengeThatRaisesNoPayeesLineHoweverHighItsSeqtest_mergesTwoIncompatibleHistoriesToEachPayeesMaximumtest_neverReclaimsWhileASettlementIsUnderDispute
A merge never pays out more than there is
When the merged lines of a dispute owe more than the ceiling or the balance, finalizeSettlement scales every line down pro rata, rounding down, and refunds the rest to the owner.test_scalesAMergeThatOwesMoreThanTheCeilingDownProRataAndRefundsTheResttestFuzz_scalingIsProRataFlooredAndWithinTheCap
An hour of grace, then the owner
If nobody settles within an hour of expiry, reclaim returns everything to the owner. Before then it fails with GraceNotOver.test_returnsEverythingOnceTheGracePeriodHasPassedAndNotBefore
Measured, not claimed
Every payout and refund is measured from balances before and after it, and the receipt stores what each payee actually received, the refund, how many charges were metered and the head of their hash chain. A transfer that leaves the payee with less, or the contract with more, fails with TransferFailed.test_paysEachPayeeItsLineRefundsTheRestAndWritesAMeasuredReceipttest_recordsWhatEachPayeeAndTheOwnerReallyReceivedFromAFeeOnTransferTokentest_refusesAPayoutThatLeavesThePayeeWithLess
One channel never spends another’s money
One contract holds every deposit, and it accounts each channel’s share on its own. A settlement that would cost the contract more than its own channel holds, whatever the token does, fails with TransferFailed and moves nothing.test_numbersChannelsFromOneAndKeepsTheirMoneyAparttest_neverLetsATokenThatTakesMoreFromTheSenderSpendAnotherChannelsMoneyinvariant_holdsExactlyWhatEveryChannelHolds
No way back in
Every function that changes state is guarded, so a token or payee that calls back into the contract during a payout is refused with Reentrancy.test_refusesASecondSettlementFromInsideAPayouttest_refusesEveryOtherEntryPointWhileLocked
Exactly once
A channel ends in one receipt. A second settlement, or a settlement after a reclaim, fails with ChannelNotOpen.test_settlesExactlyOncetest_cannotSettleProposeOrReclaimAgainOnceReclaimed

The contract is deployed on Tempo mainnet at 0x98C00995Fb264305Dd1065Ed3E7B62aC7003B733 Open on Tempo’s explorer

Stated plainly

What is not true yet.

This is the half that usually gets left off. It is here at the same size as everything above it, because a page about what refuses a payment is not worth reading if it is quiet about what does not.

  • A payee has to answer within the window

    A stale proposal is only raised if someone holding a state that owes more challenges it within ten minutes. Dinara’s operator does so for the vouchers it has seen; a payee that keeps its vouchers to itself has to watch for proposals. Ten minutes suits a demo with small amounts; a deployment holding larger sums would use hours.

  • Payees trust the operator they accept

    The operator settles at once, without a window, with a state the agent signed. It cannot change an amount, but it could pick an older state, so a payee should only serve channels whose operator it trusts: the SDK’s verifyTempoPayment takes trustedOperators, the dinara requirement names them so an agent refuses before it signs, and the demo APIs accept only Dinara’s. A channel with no operator always settles through the window.

  • Payees must keep their newest voucher

    The newest voucher is all a payee needs to be paid, and nobody holds it on its behalf. The app keeps a log of the vouchers its demo APIs accept, but that log is a convenience for the screen, not a guarantee: a payee that loses its newest voucher can only settle for less.

  • Real money, so keep it small

    This deployment runs on Tempo mainnet and holds real USDC.e, USDC bridged to Tempo. Because nothing here has been audited, the app takes at most $100.00 per channel; the contract itself has no cap. Dinara never holds your funds: the deposit sits in the contract until a settlement or a reclaim pays it out. The app never makes a wallet for you here, so no key that holds real money is ever kept in your browser.

  • Nobody outside this project has reviewed it

    There has been no independent security review. The tests were written beside the code by the people who wrote the code, which is the arrangement least likely to find what the author did not think of. Read the contract as unaudited work, because that is what it is.

If a claim on this page is not backed by a file you can open or a test you can run, it should not be here. Report a security issue to the 71Labs team where you found this project.