crypto-aio 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +151 -1
- package/README.md +32 -12
- package/dist/adapters/evm/builder.js +64 -4
- package/dist/adapters/evm/builder.js.map +1 -1
- package/dist/adapters/evm/decode.js +6 -1
- package/dist/adapters/evm/decode.js.map +1 -1
- package/dist/adapters/evm/ethers-client.js +4 -0
- package/dist/adapters/evm/ethers-client.js.map +1 -1
- package/dist/adapters/evm/fees.d.ts +24 -0
- package/dist/adapters/evm/fees.js +47 -4
- package/dist/adapters/evm/fees.js.map +1 -1
- package/dist/adapters/evm/index.d.ts +1 -1
- package/dist/adapters/evm/index.js +2 -1
- package/dist/adapters/evm/index.js.map +1 -1
- package/dist/adapters/evm/network.d.ts +5 -0
- package/dist/adapters/evm/network.js +21 -2
- package/dist/adapters/evm/network.js.map +1 -1
- package/dist/adapters/evm/plugin.d.ts +5 -6
- package/dist/adapters/evm/plugin.js +50 -2
- package/dist/adapters/evm/plugin.js.map +1 -1
- package/dist/adapters/evm/proofs.js +17 -5
- package/dist/adapters/evm/proofs.js.map +1 -1
- package/dist/adapters/evm/reader.d.ts +18 -0
- package/dist/adapters/evm/reader.js +34 -0
- package/dist/adapters/evm/reader.js.map +1 -1
- package/dist/adapters/evm/tokens.d.ts +3 -0
- package/dist/adapters/evm/tokens.js.map +1 -1
- package/dist/adapters/evm/types.d.ts +10 -0
- package/dist/adapters/evm/types.js.map +1 -1
- package/dist/adapters/evm/web3-client.d.ts +6 -3
- package/dist/adapters/evm/web3-client.js +19 -2
- package/dist/adapters/evm/web3-client.js.map +1 -1
- package/dist/adapters/solana/builder.js +29 -18
- package/dist/adapters/solana/builder.js.map +1 -1
- package/dist/adapters/solana/fees.d.ts +12 -3
- package/dist/adapters/solana/fees.js +13 -4
- package/dist/adapters/solana/fees.js.map +1 -1
- package/dist/adapters/solana/message.d.ts +15 -0
- package/dist/adapters/solana/message.js +120 -0
- package/dist/adapters/solana/message.js.map +1 -0
- package/dist/adapters/solana/plugin.js +4 -1
- package/dist/adapters/solana/plugin.js.map +1 -1
- package/dist/adapters/solana/types.d.ts +8 -5
- package/dist/adapters/solana/types.js.map +1 -1
- package/dist/adapters/solana/web3.js +10 -32
- package/dist/adapters/solana/web3.js.map +1 -1
- package/dist/adapters/ton/proofs.js +18 -76
- package/dist/adapters/ton/proofs.js.map +1 -1
- package/dist/adapters/ton/reader.d.ts +45 -4
- package/dist/adapters/ton/reader.js +200 -5
- package/dist/adapters/ton/reader.js.map +1 -1
- package/dist/adapters/ton/trace.d.ts +26 -0
- package/dist/adapters/ton/trace.js +35 -9
- package/dist/adapters/ton/trace.js.map +1 -1
- package/dist/adapters/tron/abi.d.ts +2 -0
- package/dist/adapters/tron/abi.js +2 -0
- package/dist/adapters/tron/abi.js.map +1 -1
- package/dist/adapters/tron/builder.js +20 -4
- package/dist/adapters/tron/builder.js.map +1 -1
- package/dist/adapters/tron/decode.d.ts +2 -0
- package/dist/adapters/tron/decode.js +1 -1
- package/dist/adapters/tron/decode.js.map +1 -1
- package/dist/adapters/tron/proofs.js +1 -0
- package/dist/adapters/tron/proofs.js.map +1 -1
- package/dist/adapters/tron/reader.d.ts +10 -0
- package/dist/adapters/tron/reader.js +17 -0
- package/dist/adapters/tron/reader.js.map +1 -1
- package/dist/adapters/tron/tokens.d.ts +2 -0
- package/dist/adapters/tron/tokens.js.map +1 -1
- package/dist/adapters/utxo/builder.js +1 -1
- package/dist/adapters/utxo/builder.js.map +1 -1
- package/dist/adapters/utxo/chains.js +2 -1
- package/dist/adapters/utxo/chains.js.map +1 -1
- package/dist/adapters/utxo/context.d.ts +6 -0
- package/dist/adapters/utxo/context.js +8 -1
- package/dist/adapters/utxo/context.js.map +1 -1
- package/dist/adapters/utxo/decode.d.ts +8 -0
- package/dist/adapters/utxo/decode.js +36 -0
- package/dist/adapters/utxo/decode.js.map +1 -1
- package/dist/adapters/utxo/driver.js +5 -0
- package/dist/adapters/utxo/driver.js.map +1 -1
- package/dist/adapters/utxo/esplora.d.ts +23 -2
- package/dist/adapters/utxo/esplora.js +49 -2
- package/dist/adapters/utxo/esplora.js.map +1 -1
- package/dist/adapters/utxo/proofs.d.ts +15 -6
- package/dist/adapters/utxo/proofs.js +185 -47
- package/dist/adapters/utxo/proofs.js.map +1 -1
- package/dist/adapters/utxo/rawblock.d.ts +46 -0
- package/dist/adapters/utxo/rawblock.js +159 -0
- package/dist/adapters/utxo/rawblock.js.map +1 -0
- package/dist/adapters/utxo/rawtx.d.ts +14 -0
- package/dist/adapters/utxo/rawtx.js +44 -14
- package/dist/adapters/utxo/rawtx.js.map +1 -1
- package/dist/core/blockchain/handle.d.ts +6 -27
- package/dist/core/blockchain/handle.js +112 -112
- package/dist/core/blockchain/handle.js.map +1 -1
- package/dist/core/config/types.d.ts +15 -0
- package/dist/core/config/types.js.map +1 -1
- package/dist/core/container/container.d.ts +1 -8
- package/dist/core/container/container.js +42 -8
- package/dist/core/container/container.js.map +1 -1
- package/dist/core/driver/types.d.ts +34 -1
- package/dist/core/driver/types.js.map +1 -1
- package/dist/core/errors/codes.d.ts +10 -0
- package/dist/core/errors/codes.js +4 -0
- package/dist/core/errors/codes.js.map +1 -1
- package/dist/core/lifecycle/engine-rules.d.ts +3 -4
- package/dist/core/lifecycle/engine-rules.js +16 -6
- package/dist/core/lifecycle/engine-rules.js.map +1 -1
- package/dist/core/lifecycle/engine.d.ts +2 -0
- package/dist/core/lifecycle/engine.js +19 -1
- package/dist/core/lifecycle/engine.js.map +1 -1
- package/dist/core/lifecycle/evaluate.js +9 -4
- package/dist/core/lifecycle/evaluate.js.map +1 -1
- package/dist/core/lifecycle/monitor.js +16 -6
- package/dist/core/lifecycle/monitor.js.map +1 -1
- package/dist/core/lifecycle/reconcile.d.ts +1 -1
- package/dist/core/lifecycle/reconcile.js +1 -1
- package/dist/core/lifecycle/reconcile.js.map +1 -1
- package/dist/core/lifecycle/workers.d.ts +9 -3
- package/dist/core/lifecycle/workers.js +32 -14
- package/dist/core/lifecycle/workers.js.map +1 -1
- package/dist/core/model/ids.d.ts +1 -0
- package/dist/core/model/ids.js +1 -0
- package/dist/core/model/ids.js.map +1 -1
- package/dist/core/model/ordering.d.ts +8 -0
- package/dist/core/model/ordering.js.map +1 -1
- package/dist/core/model/transaction.d.ts +7 -0
- package/dist/core/model/transaction.js.map +1 -1
- package/dist/core/observe/scanner.js +3 -0
- package/dist/core/observe/scanner.js.map +1 -1
- package/dist/core/signing/wallet.js +8 -0
- package/dist/core/signing/wallet.js.map +1 -1
- package/dist/core/store/format.d.ts +20 -0
- package/dist/core/store/format.js +86 -0
- package/dist/core/store/format.js.map +1 -0
- package/dist/core/store/memory.js +2 -2
- package/dist/core/store/memory.js.map +1 -1
- package/dist/core/store/types.d.ts +15 -3
- package/dist/core/store/types.js +2 -0
- package/dist/core/store/types.js.map +1 -1
- package/dist/core/transport/http-transport.js +21 -13
- package/dist/core/transport/http-transport.js.map +1 -1
- package/dist/core/transport/types.d.ts +16 -1
- package/dist/core/transport/types.js.map +1 -1
- package/dist/core/util/json.d.ts +7 -1
- package/dist/core/util/json.js +13 -4
- package/dist/core/util/json.js.map +1 -1
- package/dist/core/util/names.d.ts +6 -0
- package/dist/core/util/names.js +10 -0
- package/dist/core/util/names.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/testing/contracts/operations.js +20 -1
- package/dist/testing/contracts/operations.js.map +1 -1
- package/dist/testing/env.d.ts +5 -0
- package/dist/testing/env.js +1 -1
- package/dist/testing/env.js.map +1 -1
- package/dist/testing/faulty-store.d.ts +2 -0
- package/dist/testing/faulty-store.js +5 -0
- package/dist/testing/faulty-store.js.map +1 -1
- package/package.json +17 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proofs.js","sourceRoot":"","sources":["../../../src/adapters/ton/proofs.ts"],"names":[],"mappings":";;;AAwHA,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AE,gBAAgB,CAAC;gBAChD,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC1C,EACD,UAAI,CACL,CAAC;YACF,MAAM,KAAK,GAAG,EAAE,CAAC;YACjB,MAAM,IAAI,GAAG,IAAA,iBAAQ,GAAE,CAAC;YACxB,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;gBACnC,KAAK,CAAC,IAAI,CAAC,MAAM,IAAA,0BAAiB,EAAC,GAAG,EAAE,EAAE,EAAE,UAAI,EAAE,IAAI,CAAC,CAAC,CAAC;YAC3D,CAAC;YACD,OAAO;gBACL,KAAK;gBACL,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACnE,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Proofs and address history. Every proof attests a fact at its own height, with a\n * monotone predicate or at a fixed block, and no endpoint proposes a height. The one\n * exception is the unanchored head: one endpoint's masterchain head, trailed by\n * `finalitySkewBlocks` and attested by a quorum read of that block, retried at the\n * transport's own lag tolerance. Every lookup is bound to what it asked for: a header\n * names the block asked, the shard tops cover the basechain, a state and a get-method\n * name the block asked and the state read there.\n *\n * \"Not included\" rests only on authenticated chain data, never on an indexer's records: a\n * lying or lagging indexer can miss a message that ran, and a `rebuild` on its word would\n * pay twice. The proof reads, at an attested block where the message is expired, the\n * account's own chain of transactions, as the liteserver serves their cells, each hashed\n * here and linked by its `prev_trans` fields back from the attested state's last\n * transaction. A wallet can be reset (deleted, or destroyed to uninitialized, then\n * re-deployed from its public `StateInit` with seqno 0), so an activation, a destruction\n * or a chain start inside what the proof must see decides nothing, unless the chain\n * itself shows our transaction. Anything not yet decidable throws a retryable\n * `PROVIDER_UNAVAILABLE`, and an answer the chain could not have produced a retryable\n * `PROVIDER_INCONSISTENT`; both decide nothing.\n */\nimport { Cell, loadTransaction, type Message, type Transaction } from '@ton/core';\nimport type { AddressHistorySource, ProofSource } from '../../core/driver/types';\nimport {\n ProviderError,\n ValidationError,\n isCryptoAioError,\n} from '../../core/errors/error';\nimport type { OrderingData } from '../../core/model/ordering';\nimport {\n MASTERCHAIN_SHARD,\n MONITOR,\n PROOF,\n READ,\n boundRunResultOf,\n runResultOf,\n sameBlock,\n type AccountState,\n type BlockHeader,\n type BlockId,\n type BoundRunResult,\n type RawTransaction,\n type RunResult,\n type TransactionId,\n type V3Transaction,\n} from './api';\nimport { OP } from './messages';\nimport {\n CHAIN_MEMO,\n MEMO_TX_LENGTH,\n confirmLegs,\n decodeWithJettons,\n findOwnAttempt,\n keep,\n pageMemo,\n provenRequest,\n publicKeyAt,\n traceBlock,\n type TonContext,\n} from './reader';\nimport {\n CHAIN_TIME_TOLERANCE,\n MAX_VALID_FOR_SECONDS,\n recordedValidFrom,\n} from './network';\nimport { attemptVerdict, consumesSeqno, isOwnAttempt } from './trace';\nimport { externalHashOf, requestIsOwn } from './wallets';\n\n/** How far back the consumer of a seqno is searched: pages of `CONSUMER_PAGE` transactions. */\nexport const CONSUMER_PAGES = 8;\nconst CONSUMER_PAGE = 64;\n\n/** How far the chain is walked: pages of `WALK_PAGE` transactions. */\nexport const WALK_PAGES = 16;\nconst WALK_PAGE = 32;\n/** How far an anchored indexer history is read: pages of `HISTORY_PAGE` transactions. */\nconst HISTORY_PAGES = 8;\nconst HISTORY_PAGE = 64;\n\n/** toncenter v3 refuses a page of more rows (\"limit is not allowed: 1001 > 1000\", live). */\nconst HISTORY_PAGE_MAX = 1000;\n/** A logical time is a u64; a history cursor is one, in decimal. */\nconst MAX_LT = (1n << 64n) - 1n;\nconst MAX_LT_DIGITS = 20;\n/** A wallet seqno is a u32: any other number is no seqno. */\nconst MAX_WALLET_SEQNO = 0xffff_ffffn;\n/** The shard id space of a workchain: 2^64 ids, which its shards partition. */\nconst SHARD_SPACE = 1n << 64n;\n\nconst undecided = (reason: string) =>\n new ProviderError('PROVIDER_UNAVAILABLE', reason, { retryable: true });\n\nconst inconsistent = (reason: string) =>\n new ProviderError('PROVIDER_INCONSISTENT', reason, { retryable: true });\n\n/**\n * The masterchain block `seqno`, attested by the proof quorum (ids, hashes, time, global\n * id), and bound to the block asked: an answer about another block or network decides\n * nothing.\n */\nasync function masterchainBlock(ctx: TonContext, seqno: number): Promise<BlockHeader> {\n const header = await ctx.api.masterchainHeader(seqno, PROOF);\n const { id } = header;\n if (\n id.workchain !== -1 ||\n id.shard !== MASTERCHAIN_SHARD ||\n id.seqno !== seqno ||\n header.globalId !== ctx.config.globalId\n ) {\n throw inconsistent('the endpoints answered another block than the one asked');\n }\n return header;\n}\n\n/**\n * The one unanchored head: one endpoint's head, trailed by the network's skew and\n * attested by the quorum; when a healthy peer trails further, retried at the transport's\n * lag tolerance, the furthest a proof endpoint may trail. Never a false head, only a\n * later one.\n */\nexport async function attestedHead(ctx: TonContext): Promise<BlockHeader> {\n const head = await ctx.api.masterchainHead(MONITOR);\n const skew = ctx.config.finalitySkewBlocks;\n const lag = ctx.api.lagTolerance;\n let last: unknown;\n for (const trail of lag > skew ? [skew, lag] : [skew]) {\n try {\n return await masterchainBlock(ctx, Math.max(1, head - trail));\n } catch (error) {\n if (!isCryptoAioError(error) || !error.retryable) throw error;\n last = error;\n }\n }\n throw last;\n}\n\n/**\n * Whether the basechain shards among `tops` partition its whole id space: a shard id is its\n * prefix, then a 1 bit, then zeros, so it covers `id ± lowest set bit` (unsigned). A set that\n * leaves a shard out would hide that shard's time.\n */\nfunction coversBasechain(tops: readonly BlockId[]): boolean {\n const ranges: (readonly [bigint, bigint])[] = [];\n for (const top of tops) {\n if (top.workchain !== 0) continue;\n const id = BigInt.asUintN(64, BigInt(top.shard));\n const half = id & -id;\n if (half === 0n) return false;\n ranges.push([id - half, id + half]);\n }\n ranges.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));\n let next = 0n;\n for (const [start, end] of ranges) {\n if (start !== next) return false;\n next = end;\n }\n return next === SHARD_SPACE;\n}\n\n/**\n * The earliest chain time our message can have run at. The build recorded it\n * (`TonSeqnoOrdering.validFrom`); less the builder's chain-time tolerance, it covers an\n * endpoint whose time ran ahead of the chain within that tolerance, whatever the\n * network's `validForSeconds` is now (a window from today's setting could start after an\n * earlier run, and a reset wallet's history would then prove \"not included\" falsely).\n * Without a well-formed record (an attempt built before it, or bytes this driver did not\n * assemble), the widest lifetime any network allows before `validUntil`, less the\n * tolerance.\n * Known gap: an endpoint and the local clock both more than the tolerance ahead of the\n * chain start the window too late; the host's clock must stay in sync.\n */\nfunction windowStartOf(slot: { readonly validUntil: number }): number {\n const recorded = recordedValidFrom(slot);\n return (recorded ?? slot.validUntil - MAX_VALID_FOR_SECONDS) - CHAIN_TIME_TOLERANCE;\n}\n\n/** A lifetime is a positive chain time; the reservation's placeholder 0 is none. */\nconst hasLifetime = (validUntil: number): boolean =>\n Number.isSafeInteger(validUntil) && validUntil > 0;\n\n/**\n * No block after `header` can include a message valid until `validUntil`: the\n * masterchain block and every shard top it commits are at least that old, every later block\n * of a shard is younger than its top (the collator's `now` rises), and a wallet rejects a\n * message once `valid_until <= now()`. The shard tops are asked for the attested block's\n * seqno; toncenter's answer names no block (live), so only the proof quorum binds the list\n * to it, and it must cover the basechain. Each top's header is read under the quorum\n * and bound to the id the list gives. A lifetime that is no time decides nothing.\n */\nexport async function expiredAt(\n ctx: TonContext,\n header: BlockHeader,\n validUntil: number,\n): Promise<boolean> {\n if (!hasLifetime(validUntil)) throw undecided('a TON attempt needs its lifetime');\n if (validUntil > header.genUtime) return false;\n const tops = await ctx.api.shards(header.id.seqno, PROOF);\n if (!coversBasechain(tops)) {\n throw inconsistent('the shard tops do not cover the basechain');\n }\n for (const top of tops) {\n const shard = await ctx.api.blockHeader(top, PROOF);\n if (!sameBlock(shard.id, top) || shard.globalId !== ctx.config.globalId) {\n throw inconsistent('the endpoints answered another shard block than the one asked');\n }\n if (validUntil > shard.genUtime) return false;\n }\n return true;\n}\n\n/** The seqno a `seqno` get-method answers; undefined when it answers none. */\nfunction seqnoIn(result: RunResult): bigint | undefined {\n const first = result.stack[0];\n return result.exitCode === 0 &&\n first?.type === 'num' &&\n first.value >= 0n &&\n first.value <= MAX_WALLET_SEQNO\n ? first.value\n : undefined;\n}\n\n/**\n * The account state at the attested block `head`, bound to it: the block the\n * answer names is `head`, its workchain, shard, seqno and hashes.\n */\nasync function stateAt(\n ctx: TonContext,\n wallet: string,\n head: BlockHeader,\n): Promise<AccountState> {\n const state = await ctx.api.account(wallet, PROOF, head.id.seqno);\n if (!sameBlock(state.block, head.id)) {\n throw inconsistent('the endpoints answered the state at another block');\n }\n return state;\n}\n\n/**\n * The wallet's seqno in the attested `state`: the get-method's answer must name the\n * attested block and the state's last transaction, so it is the state whose status was\n * read, never an endpoint's latest one. The quorum key is the seqno and that binding, as\n * parsed values, so formatting never splits the quorum; it never throws.\n */\nasync function seqnoAt(\n ctx: TonContext,\n wallet: string,\n head: BlockHeader,\n state: AccountState,\n): Promise<bigint | undefined> {\n const bound = (result: BoundRunResult): boolean =>\n sameBlock(result.block, head.id) &&\n result.lastTransaction.lt === state.lastLt &&\n result.lastTransaction.hash === state.lastHash;\n const key = (body: unknown): unknown => {\n try {\n const result = boundRunResultOf(body);\n return { seqno: seqnoIn(result)?.toString() ?? null, bound: bound(result) };\n } catch {\n return 'malformed';\n }\n };\n const result = await ctx.api.runGetMethodAt(\n wallet,\n 'seqno',\n [],\n { ...PROOF, quorumKey: key },\n head.id.seqno,\n );\n if (!bound(result)) {\n throw inconsistent('the seqno was read at another state than the attested one');\n }\n return seqnoIn(result);\n}\n\n/** An Attempt id (a 32-byte hash in hex, either case) in lower case; undefined otherwise. */\nconst attemptId = (id: string): string | undefined =>\n /^[0-9a-fA-F]{64}$/.test(id) ? id.toLowerCase() : undefined;\n\n/**\n * A positive-path hint only: the wallet transaction the indexer lists as the consumer of\n * `seqno`, searched newest-first below the wallet's last transaction at the attested\n * block `head`, on the indexer's pages as served. Only a proven request counts\n * (`provenRequest`), and one whose request had expired by its transaction's time\n * contradicts the chain. The caller takes it only when it is our own; it is never the\n * basis of \"not included\". `undefined` when none is indexed.\n */\nasync function consumerOf(\n ctx: TonContext,\n from: string,\n seqno: bigint,\n head: BlockHeader,\n state: AccountState,\n): Promise<V3Transaction | undefined> {\n const keyAtHead = publicKeyAt(ctx, from, PROOF, head.id, state);\n const key = () => keyAtHead();\n let endLt = state.lastLt;\n for (let page = 0; page < CONSUMER_PAGES; page++) {\n const { transactions, next } = await ctx.api.accountTransactionsPage(\n from,\n { limit: CONSUMER_PAGE, endLt },\n PROOF,\n );\n for (const tx of transactions) {\n const request = await provenRequest(ctx, tx, from, key);\n if (!request) continue;\n const claimed = BigInt(request.seqno);\n if (claimed > seqno) continue;\n if (claimed < seqno) return undefined;\n if (request.validUntil <= tx.now) {\n throw inconsistent('the seqno consumer ran after its request expired');\n }\n return tx;\n }\n if (next === undefined) return undefined;\n endLt = next;\n }\n ctx.log.warn('the seqno consumer is beyond the search window', {\n code: 'SEQNO_CONSUMER_NOT_FOUND',\n });\n return undefined;\n}\n\n// ---- the account's own chain --------------------------------------------------------------\n\nconst hex256 = (value: bigint): string => value.toString(16).padStart(64, '0');\n\n/**\n * A transaction the liteserver served, authenticated: its cell (capped by the API before\n * this decodes it) hashes to the id expected, and it is the account's own at the lt\n * expected. Anything else is not the chain's.\n */\nconst notTheChains = () =>\n inconsistent(\"the liteserver answered a transaction that is not the chain's\");\n\nfunction authenticated(\n row: RawTransaction,\n expected: TransactionId,\n account: bigint,\n): Transaction {\n if (row.lt !== expected.lt || row.hash !== expected.hash) throw notTheChains();\n let cell: Cell;\n let tx: Transaction;\n try {\n const cells = Cell.fromBoc(Buffer.from(row.boc, 'base64'));\n if (cells.length !== 1) throw notTheChains();\n cell = cells[0] as Cell;\n tx = loadTransaction(cell.beginParse());\n } catch {\n throw notTheChains();\n }\n if (\n cell.hash().toString('hex') !== expected.hash ||\n tx.lt !== expected.lt ||\n tx.address !== account\n ) {\n throw notTheChains();\n }\n return tx;\n}\n\n/** The most transactions one walk visits, fetched or kept: `WALK_PAGES` full pages. */\nconst WALK_LIMIT = WALK_PAGES * WALK_PAGE;\n\n/**\n * The account's chain from `from` back, one authenticated transaction at a time, each naming\n * the next by its `prev_trans_lt`/`prev_trans_hash`; `visit` returns true to stop. Ends at\n * the chain's start (`prev_trans_lt` 0: the account's first transaction, or its first since\n * a deletion, transaction.cpp `init_new`), or after `WALK_LIMIT` transactions or\n * `WALK_PAGES` pages. The replay guard walks before every resend, so a transaction\n * authenticated once is kept by its id (`chainTxs`), and a walk fetches only the part of\n * the chain it has not seen; a kept one is bound to the account as a fetched one is.\n */\nasync function walkChain(\n ctx: TonContext,\n wallet: string,\n from: TransactionId,\n visit: (tx: Transaction, hash: string) => Promise<boolean>,\n): Promise<'stopped' | 'start' | 'exhausted'> {\n const account = BigInt(`0x${wallet.slice(wallet.indexOf(':') + 1)}`);\n let expected = from;\n let page: RawTransaction[] = [];\n let fetched = 0;\n for (let visited = 0; visited < WALK_LIMIT; visited++) {\n const key = `${expected.lt}:${expected.hash}`;\n const row = page.shift();\n let tx = ctx.chainTxs.get(key);\n if (tx !== undefined) {\n if (tx.address !== account) throw notTheChains();\n // The page fetched earlier no longer follows the walk: drop it.\n if (row !== undefined && (row.lt !== expected.lt || row.hash !== expected.hash)) {\n page = [];\n }\n } else {\n let next = row;\n if (next === undefined) {\n if (fetched === WALK_PAGES) return 'exhausted';\n fetched += 1;\n page = await ctx.api.rawTransactions(wallet, expected, WALK_PAGE, PROOF);\n next = page.shift();\n if (next === undefined) {\n throw undecided('the liteserver does not hold the transaction asked');\n }\n }\n tx = authenticated(next, expected, account);\n // Only a wallet-sized transaction is kept (a lying endpoint's is not): the memo\n // stays bounded.\n if (next.boc.length <= MEMO_TX_LENGTH) keep(ctx.chainTxs, key, tx, CHAIN_MEMO);\n }\n if (await visit(tx, expected.hash)) return 'stopped';\n if (tx.prevTransactionLt === 0n) return 'start';\n expected = { lt: tx.prevTransactionLt, hash: hex256(tx.prevTransactionHash) };\n }\n return 'exhausted';\n}\n\nconst CODE: ReadonlySet<string> = new Set(['active', 'frozen']);\nconst NO_CODE: ReadonlySet<string> = new Set(['uninitialized', 'non-existing']);\n\n/** What a transaction did, as the chain records it. */\nfunction phasesOf(tx: Transaction) {\n const d = tx.description;\n const compute = 'computePhase' in d ? d.computePhase : undefined;\n const vm = compute?.type === 'vm' ? compute : undefined;\n return {\n /** The wallet's code ran: the chain runs it only when code exists or a StateInit\n * activates the account (transaction.cpp). */\n ran: vm !== undefined,\n /** A request ran to the end, so a seqno moved (the action phase keeps it). */\n consumed:\n d.type === 'generic' && vm?.success === true && d.actionPhase?.success === true,\n /** The account had code before or after. */\n lived: CODE.has(tx.oldStatus) || CODE.has(tx.endStatus),\n /** A re-deploy from no code: the seqno starts again (transaction.cpp activation). */\n activation: NO_CODE.has(tx.oldStatus) && tx.endStatus === 'active',\n /** The code went (+32 destroy, storage deletion): the seqno goes with it. */\n destruction:\n (CODE.has(tx.oldStatus) && NO_CODE.has(tx.endStatus)) ||\n ('destroyed' in d && d.destroyed),\n };\n}\n\n/**\n * The seqno a request the wallet ran claims, read from its signed header alone (so a\n * v4r2 plugin request or a W5 extended-action request counts too): an external request, or\n * a W5 `internal_signed` one, signed by the wallet's key for this very wallet\n * (`requestIsOwn`: a v5r1 wallet runs a forged relayed body and ignores it).\n */\nasync function claimedSeqno(\n ctx: TonContext,\n wallet: string,\n message: Message | null | undefined,\n key: () => Promise<Uint8Array | undefined>,\n): Promise<bigint | undefined> {\n if (!message) return undefined;\n const { body } = message;\n const op = body.bits.length >= 32 ? body.beginParse().preloadUint(32) : undefined;\n const w5 = op === OP.w5SignedExternal || op === OP.w5SignedInternal;\n if (\n message.info.type === 'internal'\n ? op !== OP.w5SignedInternal\n : message.info.type !== 'external-in'\n ) {\n return undefined;\n }\n let seqno: number;\n try {\n const s = body.beginParse();\n // W5: op, wallet id, valid_until, seqno; v4r2: signature, subwallet id, valid_until, seqno.\n s.skip(w5 ? 32 + 32 + 32 : 512 + 32 + 32);\n seqno = s.loadUint(32);\n } catch {\n return undefined;\n }\n const publicKey = await key();\n return publicKey && requestIsOwn(wallet, body, publicKey, ctx.config.globalId)\n ? BigInt(seqno)\n : undefined;\n}\n\ntype Absence = { readonly ours: string } | { readonly absent: true };\n\ninterface ChainQuestion {\n readonly wallet: string;\n readonly id: string;\n readonly slot: { readonly seqno: bigint; readonly validUntil: number };\n readonly head: BlockHeader;\n readonly state: AccountState;\n readonly active: boolean;\n /** The seqno at `head` (0 for an uninitialized wallet). */\n readonly seqno: bigint;\n}\n\nconst resetSuspected = (ctx: TonContext) => {\n ctx.log.warn('the wallet may have been reset since our message', {\n code: 'WALLET_RESET_SUSPECTED',\n });\n return undecided('the wallet may have been reset since our message');\n};\n\nconst walkExhausted = (ctx: TonContext) => {\n ctx.log.warn('the wallet history is beyond the proof window', {\n code: 'TX_CHAIN_WALK_EXHAUSTED',\n });\n return undecided('the wallet history is beyond the proof window');\n};\n\n/**\n * The wallet's code never ran in the history the indexer holds\n * below lt `below` (an earlier incarnation, before a chain start), or in all of it when\n * `below` is undefined (no chain now: never created, or deleted with its last transaction),\n * read under the proof quorum once the indexer has indexed masterchain block `reached`: no\n * compute phase that ran, and no status with code. Our message runs only in the wallet's\n * code, so an incarnation whose code never ran cannot hold it, whether the wallet is active\n * or uninitialized now (a deposit that bounced before the wallet existed is no reset).\n * A row where the code ran, a row without its statuses, or a history past the window\n * decides nothing.\n */\nasync function codeNeverRan(\n ctx: TonContext,\n wallet: string,\n reached: number,\n below?: bigint,\n): Promise<void> {\n if (!(await ctx.api.indexerReached(reached, PROOF))) {\n throw undecided('the indexer has not reached the attested block yet');\n }\n let endLt = below === undefined ? undefined : below - 1n;\n for (let page = 0; page < HISTORY_PAGES; page++) {\n const { transactions, next } = await ctx.api.accountTransactionsPage(\n wallet,\n { limit: HISTORY_PAGE, ...(endLt !== undefined ? { endLt } : {}) },\n PROOF,\n );\n for (const tx of transactions) {\n const { origStatus, endStatus } = tx;\n if (\n !tx.compute.skipped ||\n origStatus === undefined ||\n endStatus === undefined ||\n origStatus === 'active' ||\n origStatus === 'frozen' ||\n endStatus === 'active' ||\n endStatus === 'frozen'\n ) {\n throw resetSuspected(ctx);\n }\n }\n if (next === undefined) return;\n endLt = next;\n }\n throw walkExhausted(ctx);\n}\n\n/**\n * At an attested block where the message is expired, whether our message\n * consumed its seqno, from the account's own chain alone, walked back from the attested\n * state's last transaction:\n * - our message (its TEP-467 hash computed here) run to the end: ours, proven by the caller;\n * - otherwise \"absent\" only when the chain shows no reset: the walk reaches the earliest\n * time our message could have run (`windowStart`, from the attempt's own record) with,\n * when our seqno is consumed at `head`, its consumer found (another request, by its\n * signed header); or it reaches the chain's start inside that window, and the anchored\n * indexer history shows that the code never ran before it.\n * An activation, a destruction, or a consumer of a lower seqno first is a reset: from then\n * on the wallet must never have run, as far as the chain goes back into the window; a walk\n * past its cap decides nothing. An uninitialized wallet must never have run in the\n * window (our message cannot have run before it), nor, without a chain, at all.\n */\nasync function fromTheChain(ctx: TonContext, q: ChainQuestion): Promise<Absence> {\n const needConsumer = q.active && q.seqno > q.slot.seqno;\n if (q.state.lastLt === 0n) {\n // No chain at `head`: never created, or deleted with its last transaction.\n if (q.active) throw inconsistent('an active account without a transaction');\n await codeNeverRan(ctx, q.wallet, q.head.id.seqno);\n return { absent: true };\n }\n const windowStart = windowStartOf(q.slot);\n const key = publicKeyAt(ctx, q.wallet, PROOF, q.head.id, q.state);\n let codeless = !q.active;\n let consumerFound = false;\n let reset = false;\n let ours: string | undefined;\n let first = q.state.lastLt;\n const end = await walkChain(\n ctx,\n q.wallet,\n { lt: q.state.lastLt, hash: q.state.lastHash },\n async (tx, hash) => {\n first = tx.lt;\n const t = phasesOf(tx);\n const inbound = tx.inMessage;\n if (ourRun(tx, t, q.wallet, q.id)) {\n ours = hash;\n return true;\n }\n if (tx.now < windowStart && (!needConsumer || consumerFound)) return true;\n if (codeless) {\n if (t.ran || t.lived || t.destruction) reset = true;\n return false;\n }\n if (t.destruction) reset = true;\n if (needConsumer && !consumerFound && t.consumed) {\n const claimed = await claimedSeqno(ctx, q.wallet, inbound, key);\n if (claimed === q.slot.seqno) consumerFound = true;\n else if (claimed !== undefined && claimed < q.slot.seqno) reset = true;\n }\n if (t.activation) {\n if (needConsumer && !consumerFound) reset = true;\n codeless = true;\n }\n return false;\n },\n );\n if (ours !== undefined) return { ours };\n if (end === 'exhausted') throw walkExhausted(ctx);\n if (reset || (needConsumer && !consumerFound)) throw resetSuspected(ctx);\n if (end === 'start') await codeNeverRan(ctx, q.wallet, q.head.id.seqno, first);\n return { absent: true };\n}\n\n/**\n * Whether `tx` is our message run to the end: its inbound external message's TEP-467 hash,\n * computed here from the authenticated body, is `id`, and it consumed its seqno.\n */\nfunction ourRun(\n tx: Transaction,\n t: ReturnType<typeof phasesOf>,\n wallet: string,\n id: string,\n): boolean {\n const inbound = tx.inMessage;\n return (\n t.consumed &&\n inbound?.info.type === 'external-in' &&\n externalHashOf(wallet, inbound.body) === id\n );\n}\n\n// ---- the replay guard ---------------------------------------------------------------------\n\n/**\n * Stored bytes about to be sent again: the wallet they go to (raw), their TEP-467 hash, and\n * the seqno and lifetime their signed header carries. `validFrom` is the build's recorded\n * chain time when this driver assembled them; otherwise the widest lifetime applies.\n */\nexport interface StoredMessage {\n readonly wallet: string;\n readonly id: string;\n readonly seqno: bigint;\n readonly validUntil: number;\n readonly validFrom?: number;\n}\n\n/**\n * The monotone predicate \"my seqno is above `seqno`\" at the endpoints' own states, under the\n * proof quorum; its key is the verdict itself and never throws.\n */\nasync function seqnoAbove(\n ctx: TonContext,\n wallet: string,\n seqno: bigint,\n): Promise<boolean> {\n const above = (result: RunResult): boolean => {\n const value = seqnoIn(result);\n return value !== undefined && value > seqno;\n };\n const key = (body: unknown): unknown => {\n try {\n return above(runResultOf(body));\n } catch {\n return 'malformed';\n }\n };\n return above(\n await ctx.api.runGetMethod(wallet, 'seqno', [], { ...PROOF, quorumKey: key }),\n );\n}\n\n/**\n * Whether stored bytes may go out again. A wallet reset (a deletion, then a deposit,\n * or a re-deploy from the public `StateInit` back to our seqno) makes a message that already\n * ran and paid runnable again while it is valid, so every send of stored bytes asks first:\n * - `send`: the wallet's seqno is already above ours under the proof quorum, so the message\n * cannot run (no walk); or the chain shows it cannot have run: the walk reaches the\n * earliest time it could have run (`windowStartOf`, from the recorded build time, else\n * the widest lifetime) with no reset, or a chain start whose earlier history shows the\n * code never ran (a wallet funded a minute ago is sent to);\n * - `ours`: the chain holds our message run to the end: it must never be sent again.\n * The walk starts from the freshest state an endpoint serves (the attested head trails it\n * by 10 to 150 blocks, and a reset in that trail is exactly the danger), and must lead\n * down to the attested state's last transaction, so a lying fresh endpoint can hide only\n * what the attested walk could not see either. Anything else, including a deletion or a\n * new chain since the attested head, an activation or a destruction in the window, a walk\n * past its cap, an indexer behind the fresh block or a failed read, throws a retryable\n * error: the guard never sends while it cannot decide, and the proof decides.\n * Known gap: once a wallet is reset (which takes software that shares its key), anyone\n * can replay our message from the chain's public record; no client can stop that, and the\n * guard covers only this library's own sends.\n */\nexport async function replayVerdict(\n ctx: TonContext,\n message: StoredMessage,\n): Promise<'send' | 'ours'> {\n const { wallet, id } = message;\n // A seqno past ours needs no walk. A failed read is only \"not known\".\n const past = await seqnoAbove(ctx, wallet, message.seqno).catch(() => false);\n if (past) return 'send';\n const windowStart = windowStartOf(message);\n const head = await attestedHead(ctx);\n const attested = await stateAt(ctx, wallet, head);\n const fresh = await ctx.api.account(wallet, MONITOR);\n // An endpoint behind the attested head adds nothing; one past it must agree with it.\n const top = fresh.blockSeqno > head.id.seqno ? fresh : attested;\n if (top === fresh) {\n if (\n fresh.lastLt === attested.lastLt\n ? fresh.lastHash !== attested.lastHash\n : fresh.lastLt < attested.lastLt && fresh.lastLt !== 0n\n ) {\n throw inconsistent('the freshest state does not follow the attested one');\n }\n }\n if (top.status === 'frozen')\n throw undecided('the wallet state does not show its seqno');\n // The account was deleted since the attested head: our message may have run just before.\n if (top.lastLt === 0n && attested.lastLt !== 0n) throw resetSuspected(ctx);\n if (top.lastLt === 0n) {\n // No chain now, nor at the attested head: never created, or deleted long ago.\n await codeNeverRan(ctx, wallet, top.blockSeqno);\n return 'send';\n }\n // The fresh part of the chain must lead to the attested state's last transaction.\n const link = top !== attested && attested.lastLt !== 0n ? attested : undefined;\n let linked = link === undefined || link.lastLt === top.lastLt;\n let codeless = top.status !== 'active';\n let reset = false;\n let ours = false;\n let first = top.lastLt;\n const end = await walkChain(\n ctx,\n wallet,\n { lt: top.lastLt, hash: top.lastHash },\n async (tx, hash) => {\n first = tx.lt;\n if (!linked && link !== undefined) {\n if (tx.lt < link.lastLt || (tx.lt === link.lastLt && hash !== link.lastHash)) {\n throw inconsistent('the freshest state does not follow the attested one');\n }\n linked = tx.lt === link.lastLt;\n }\n const t = phasesOf(tx);\n if (ourRun(tx, t, wallet, id)) {\n ours = true;\n return true;\n }\n if (linked && tx.now < windowStart) return true;\n if (codeless) {\n if (t.ran || t.lived || t.destruction) reset = true;\n return false;\n }\n if (t.destruction) reset = true;\n if (t.activation) codeless = true;\n return false;\n },\n );\n if (ours) return 'ours';\n if (end === 'exhausted') throw walkExhausted(ctx);\n // Not linked at the chain's start: a new chain since the attested head, so a deletion.\n if (reset || !linked) throw resetSuspected(ctx);\n if (end === 'start') await codeNeverRan(ctx, wallet, top.blockSeqno, first);\n return 'send';\n}\n\ntype Included = Extract<\n Awaited<ReturnType<ProofSource['includedFinal']>>,\n { included: true }\n>;\n\n/**\n * Our indexed transaction that consumed its seqno, proven: a complete trace, whose last\n * block the endpoints attest they hold, and the verdict, its jetton wallets confirmed at\n * that block under the proof quorum.\n */\nasync function proveIncluded(\n ctx: TonContext,\n tx: V3Transaction,\n from: string,\n): Promise<Included> {\n const trace = await ctx.api.trace(tx.hash, PROOF);\n if (!trace || !trace.complete) throw undecided('the message trace is not complete yet');\n const last = traceBlock(tx, trace);\n if (!(await ctx.api.reachedMasterchain(last, PROOF))) {\n throw undecided('the endpoints have not reached the trace yet');\n }\n const verdict = await confirmLegs(ctx, attemptVerdict(tx, trace), from, PROOF, last);\n if (verdict.kind === 'pending')\n throw undecided('the message trace is not complete yet');\n const header = await masterchainBlock(ctx, tx.mcSeqno);\n return {\n included: true,\n success: verdict.kind === 'success',\n blockHeight: BigInt(tx.mcSeqno),\n blockHash: header.id.rootHash,\n txHash: tx.hash,\n ...(verdict.kind === 'failed' ? { reason: verdict.reason } : {}),\n };\n}\n\n/**\n * Our transaction the chain itself holds (`hash`), proven through the indexer's record of\n * that very transaction, which must be our message and have consumed its seqno.\n */\nasync function proveOurs(\n ctx: TonContext,\n hash: string,\n wallet: string,\n id: string,\n): Promise<Included> {\n const record = await ctx.api.transaction(hash, PROOF);\n if (!record) throw undecided('our transaction is not indexed yet');\n if (!isOwnAttempt(record, wallet, id) || !consumesSeqno(record)) {\n throw inconsistent(\"the indexer's record is not the chain's transaction\");\n }\n return proveIncluded(ctx, record, wallet);\n}\n\nconst seqnoOrdering = (ordering: OrderingData) =>\n ordering.kind === 'seqno' ? ordering : undefined;\n\nexport function createTonProofs(ctx: TonContext): ProofSource {\n const { api } = ctx;\n const walletOf = (from: string) => ctx.codec.normalize(from).canonical;\n return {\n async finalizedHead() {\n const header = await attestedHead(ctx);\n return {\n height: BigInt(header.id.seqno),\n hash: header.id.rootHash,\n timestamp: header.genUtime,\n };\n },\n\n async includedFinal(ref, ordering, from) {\n const wallet = walletOf(from);\n // Only our own wallet transaction, its hash computed here from the bound body. A\n // run that did not consume its seqno (a failed action phase) moved nothing and may\n // run again until the message expires: only the seqno decides it.\n const own = await findOwnAttempt(ctx, ref, wallet, PROOF);\n if (own && consumesSeqno(own)) return proveIncluded(ctx, own, wallet);\n const id = attemptId(ref.id);\n if (id === undefined) throw undecided('a TON attempt needs its message hash');\n const slot = seqnoOrdering(ordering);\n if (!slot) throw undecided('a TON attempt needs its seqno ordering');\n if (!hasLifetime(slot.validUntil))\n throw undecided('a TON attempt needs its lifetime');\n // Not proven under our hash: decide only from state at an attested block.\n const head = await attestedHead(ctx);\n const state = await stateAt(ctx, wallet, head);\n const active = state.status === 'active';\n // A frozen wallet, or an uninitialized one past seqno 0, shows no seqno (never 0).\n if (!active && (state.status === 'frozen' || slot.seqno !== 0n)) {\n throw undecided('the wallet state does not show its seqno');\n }\n const seqno = active ? await seqnoAt(ctx, wallet, head, state) : 0n;\n if (seqno === undefined)\n throw undecided('the wallet state does not show its seqno');\n if (seqno > slot.seqno) {\n // The indexer's consumer search: a hint that finds ours, never a \"no\", nor a veto\n // either; a hint that cannot be used (a record the chain could not produce, a\n // failed read) is logged, and the authenticated path decides.\n let hint: V3Transaction | undefined;\n try {\n hint = await consumerOf(ctx, wallet, slot.seqno, head, state);\n } catch (error) {\n if (!isCryptoAioError(error) || !error.retryable) throw error;\n ctx.log.warn('the indexer gave no usable seqno consumer', {\n code: 'SEQNO_CONSUMER_HINT_UNUSABLE',\n });\n }\n if (hint && isOwnAttempt(hint, wallet, id))\n return proveIncluded(ctx, hint, wallet);\n }\n // Never \"not included\" while the message may still run: a reset of the wallet could\n // bring its seqno back to ours.\n if (!(await expiredAt(ctx, head, slot.validUntil))) {\n throw undecided('the message may still be included');\n }\n const chain = await fromTheChain(ctx, {\n wallet,\n id,\n slot,\n head,\n state,\n active,\n seqno,\n });\n if ('ours' in chain) return proveOurs(ctx, chain.ours, wallet, id);\n return { included: false };\n },\n\n async slotConsumed(ordering, from, level) {\n const slot = seqnoOrdering(ordering);\n if (!slot) return false;\n // Masterchain state is final once it exists, so TON gives no separate `latest`\n // evidence: our own landed-but-unindexed message is never observed as `replaced`.\n if (level === 'latest') return false;\n // \"My seqno at the final state is above n\", a monotone predicate.\n return seqnoAbove(ctx, walletOf(from), slot.seqno);\n },\n\n async expired(ordering) {\n const slot = seqnoOrdering(ordering);\n if (!slot) return false;\n return expiredAt(ctx, await attestedHead(ctx), slot.validUntil);\n },\n\n async blockHash(height) {\n // Every masterchain block is final once it exists: both levels read the same.\n if (height < 0n || height > BigInt(await api.masterchainHead(MONITOR))) return null;\n return (await masterchainBlock(ctx, Number(height))).id.rootHash;\n },\n };\n}\n\n/** A history cursor: the next page's `end_lt`, a u64 in decimal, capped before use. */\nfunction cursorLt(cursor: string | undefined): bigint | undefined {\n if (cursor === undefined) return undefined;\n if (\n cursor.length === 0 ||\n cursor.length > MAX_LT_DIGITS ||\n !/^\\d+$/.test(cursor) ||\n BigInt(cursor) > MAX_LT\n ) {\n throw new ValidationError('INVALID_INTENT', 'not a TON history cursor');\n }\n return BigInt(cursor);\n}\n\n/**\n * An address's transactions from the indexer, newest first, decoded with jettons only for\n * verified jetton wallets. The cursor is the next page's `end_lt`, taken from the page as\n * the indexer served it, so rows not final yet never end the history early; a page\n * is at most what toncenter serves.\n */\nexport function createTonHistory(ctx: TonContext): AddressHistorySource {\n return {\n async list(address, options) {\n const endLt = cursorLt(options.cursor);\n const account = ctx.codec.normalize(address).canonical;\n const page = await ctx.api.accountTransactionsPage(\n account,\n {\n limit: Math.min(options.limit, HISTORY_PAGE_MAX),\n ...(endLt !== undefined ? { endLt } : {}),\n },\n READ,\n );\n const items = [];\n const memo = pageMemo();\n for (const tx of page.transactions) {\n items.push(await decodeWithJettons(ctx, tx, READ, memo));\n }\n return {\n items,\n ...(page.next !== undefined ? { next: page.next.toString() } : {}),\n };\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"proofs.js","sourceRoot":"","sources":["../../../src/adapters/ton/proofs.ts"],"names":[],"mappings":";;;AA+HA,oCAcC;AAuDD,8BAmBC;AAsbD,sCAwEC;AAmED,0CA6FC;AAsBD,4CAwBC;AA34BD,mDAIiC;AAEjC,+BAgBe;AACf,yCAAgC;AAChC,qCAkBkB;AAClB,uCAImB;AACnB,mCAAsE;AACtE,uCAAyC;AAEzC,+FAA+F;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AC;YACjB,MAAM,IAAI,GAAG,IAAA,iBAAQ,GAAE,CAAC;YACxB,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;gBACnC,KAAK,CAAC,IAAI,CAAC,MAAM,IAAA,0BAAiB,EAAC,GAAG,EAAE,EAAE,EAAE,UAAI,EAAE,IAAI,CAAC,CAAC,CAAC;YAC3D,CAAC;YACD,OAAO;gBACL,KAAK;gBACL,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACnE,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Proofs and address history. Every proof attests a fact at its own height, with a\n * monotone predicate or at a fixed block, and no endpoint proposes a height. The one\n * exception is the unanchored head: one endpoint's masterchain head, trailed by\n * `finalitySkewBlocks` and attested by a quorum read of that block, retried at the\n * transport's own lag tolerance. Every lookup is bound to what it asked for: a header\n * names the block asked, the shard tops cover the basechain, a state and a get-method\n * name the block asked and the state read there.\n *\n * \"Not included\" rests only on authenticated chain data, never on an indexer's records: a\n * lying or lagging indexer can miss a message that ran, and a `rebuild` on its word would\n * pay twice. The proof reads, at an attested block where the message is expired, the\n * account's own chain of transactions, as the liteserver serves their cells, each hashed\n * here and linked by its `prev_trans` fields back from the attested state's last\n * transaction. A wallet can be reset (deleted, or destroyed to uninitialized, then\n * re-deployed from its public `StateInit` with seqno 0), so an activation, a destruction\n * or a chain start inside what the proof must see decides nothing, unless the chain\n * itself shows our transaction. A bounce rests on the same liteserver cells\n * (`confirmBounce`), never on the indexer's trace alone, since `failed` invites a second\n * payment too. Anything not yet decidable throws a retryable `PROVIDER_UNAVAILABLE`, and an answer the\n * chain could not have produced a retryable `PROVIDER_INCONSISTENT`; both decide nothing.\n */\nimport type { Message, Transaction } from '@ton/core';\nimport type { AddressHistorySource, ProofSource } from '../../core/driver/types';\nimport {\n ProviderError,\n ValidationError,\n isCryptoAioError,\n} from '../../core/errors/error';\nimport type { OrderingData } from '../../core/model/ordering';\nimport {\n MASTERCHAIN_SHARD,\n MONITOR,\n PROOF,\n READ,\n boundRunResultOf,\n runResultOf,\n sameBlock,\n type AccountState,\n type BlockHeader,\n type BlockId,\n type BoundRunResult,\n type RawTransaction,\n type RunResult,\n type TransactionId,\n type V3Transaction,\n} from './api';\nimport { OP } from './messages';\nimport {\n CHAIN_MEMO,\n MEMO_TX_LENGTH,\n accountId,\n authenticated,\n chainRan,\n confirmBounce,\n confirmLegs,\n decodeWithJettons,\n findOwnAttempt,\n keep,\n notTheChains,\n ourRun,\n pageMemo,\n provenRequest,\n publicKeyAt,\n traceBlock,\n type TonContext,\n} from './reader';\nimport {\n CHAIN_TIME_TOLERANCE,\n MAX_VALID_FOR_SECONDS,\n recordedValidFrom,\n} from './network';\nimport { attemptVerdict, consumesSeqno, isOwnAttempt } from './trace';\nimport { requestIsOwn } from './wallets';\n\n/** How far back the consumer of a seqno is searched: pages of `CONSUMER_PAGE` transactions. */\nexport const CONSUMER_PAGES = 8;\nconst CONSUMER_PAGE = 64;\n\n/** How far the chain is walked: pages of `WALK_PAGE` transactions. */\nexport const WALK_PAGES = 16;\nconst WALK_PAGE = 32;\n/** How far an anchored indexer history is read: pages of `HISTORY_PAGE` transactions. */\nconst HISTORY_PAGES = 8;\nconst HISTORY_PAGE = 64;\n\n/** toncenter v3 refuses a page of more rows (\"limit is not allowed: 1001 > 1000\", live). */\nconst HISTORY_PAGE_MAX = 1000;\n/** A logical time is a u64; a history cursor is one, in decimal. */\nconst MAX_LT = (1n << 64n) - 1n;\nconst MAX_LT_DIGITS = 20;\n/** A wallet seqno is a u32: any other number is no seqno. */\nconst MAX_WALLET_SEQNO = 0xffff_ffffn;\n/** The shard id space of a workchain: 2^64 ids, which its shards partition. */\nconst SHARD_SPACE = 1n << 64n;\n\nconst undecided = (reason: string) =>\n new ProviderError('PROVIDER_UNAVAILABLE', reason, { retryable: true });\n\nconst inconsistent = (reason: string) =>\n new ProviderError('PROVIDER_INCONSISTENT', reason, { retryable: true });\n\n/**\n * The masterchain block `seqno`, attested by the proof quorum (ids, hashes, time, global\n * id), and bound to the block asked: an answer about another block or network decides\n * nothing.\n */\nasync function masterchainBlock(ctx: TonContext, seqno: number): Promise<BlockHeader> {\n const header = await ctx.api.masterchainHeader(seqno, PROOF);\n const { id } = header;\n if (\n id.workchain !== -1 ||\n id.shard !== MASTERCHAIN_SHARD ||\n id.seqno !== seqno ||\n header.globalId !== ctx.config.globalId\n ) {\n throw inconsistent('the endpoints answered another block than the one asked');\n }\n return header;\n}\n\n/**\n * The one unanchored head: one endpoint's head, trailed by the network's skew and\n * attested by the quorum; when a healthy peer trails further, retried at the transport's\n * lag tolerance, the furthest a proof endpoint may trail. Never a false head, only a\n * later one.\n */\nexport async function attestedHead(ctx: TonContext): Promise<BlockHeader> {\n const head = await ctx.api.masterchainHead(MONITOR);\n const skew = ctx.config.finalitySkewBlocks;\n const lag = ctx.api.lagTolerance;\n let last: unknown;\n for (const trail of lag > skew ? [skew, lag] : [skew]) {\n try {\n return await masterchainBlock(ctx, Math.max(1, head - trail));\n } catch (error) {\n if (!isCryptoAioError(error) || !error.retryable) throw error;\n last = error;\n }\n }\n throw last;\n}\n\n/**\n * Whether the basechain shards among `tops` partition its whole id space: a shard id is its\n * prefix, then a 1 bit, then zeros, so it covers `id ± lowest set bit` (unsigned). A set that\n * leaves a shard out would hide that shard's time.\n */\nfunction coversBasechain(tops: readonly BlockId[]): boolean {\n const ranges: (readonly [bigint, bigint])[] = [];\n for (const top of tops) {\n if (top.workchain !== 0) continue;\n const id = BigInt.asUintN(64, BigInt(top.shard));\n const half = id & -id;\n if (half === 0n) return false;\n ranges.push([id - half, id + half]);\n }\n ranges.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));\n let next = 0n;\n for (const [start, end] of ranges) {\n if (start !== next) return false;\n next = end;\n }\n return next === SHARD_SPACE;\n}\n\n/**\n * The earliest chain time our message can have run at. The build recorded it\n * (`TonSeqnoOrdering.validFrom`); less the builder's chain-time tolerance, it covers an\n * endpoint whose time ran ahead of the chain within that tolerance, whatever the\n * network's `validForSeconds` is now (a window from today's setting could start after an\n * earlier run, and a reset wallet's history would then prove \"not included\" falsely).\n * Without a well-formed record (an attempt built before it, or bytes this driver did not\n * assemble), the widest lifetime any network allows before `validUntil`, less the\n * tolerance.\n * Known gap: an endpoint and the local clock both more than the tolerance ahead of the\n * chain start the window too late; the host's clock must stay in sync.\n */\nfunction windowStartOf(slot: { readonly validUntil: number }): number {\n const recorded = recordedValidFrom(slot);\n return (recorded ?? slot.validUntil - MAX_VALID_FOR_SECONDS) - CHAIN_TIME_TOLERANCE;\n}\n\n/** A lifetime is a positive chain time; the reservation's placeholder 0 is none. */\nconst hasLifetime = (validUntil: number): boolean =>\n Number.isSafeInteger(validUntil) && validUntil > 0;\n\n/**\n * No block after `header` can include a message valid until `validUntil`: the\n * masterchain block and every shard top it commits are at least that old, every later block\n * of a shard is younger than its top (the collator's `now` rises), and a wallet rejects a\n * message once `valid_until <= now()`. The shard tops are asked for the attested block's\n * seqno; toncenter's answer names no block (live), so only the proof quorum binds the list\n * to it, and it must cover the basechain. Each top's header is read under the quorum\n * and bound to the id the list gives. A lifetime that is no time decides nothing.\n */\nexport async function expiredAt(\n ctx: TonContext,\n header: BlockHeader,\n validUntil: number,\n): Promise<boolean> {\n if (!hasLifetime(validUntil)) throw undecided('a TON attempt needs its lifetime');\n if (validUntil > header.genUtime) return false;\n const tops = await ctx.api.shards(header.id.seqno, PROOF);\n if (!coversBasechain(tops)) {\n throw inconsistent('the shard tops do not cover the basechain');\n }\n for (const top of tops) {\n const shard = await ctx.api.blockHeader(top, PROOF);\n if (!sameBlock(shard.id, top) || shard.globalId !== ctx.config.globalId) {\n throw inconsistent('the endpoints answered another shard block than the one asked');\n }\n if (validUntil > shard.genUtime) return false;\n }\n return true;\n}\n\n/** The seqno a `seqno` get-method answers; undefined when it answers none. */\nfunction seqnoIn(result: RunResult): bigint | undefined {\n const first = result.stack[0];\n return result.exitCode === 0 &&\n first?.type === 'num' &&\n first.value >= 0n &&\n first.value <= MAX_WALLET_SEQNO\n ? first.value\n : undefined;\n}\n\n/**\n * The account state at the attested block `head`, bound to it: the block the\n * answer names is `head`, its workchain, shard, seqno and hashes.\n */\nasync function stateAt(\n ctx: TonContext,\n wallet: string,\n head: BlockHeader,\n): Promise<AccountState> {\n const state = await ctx.api.account(wallet, PROOF, head.id.seqno);\n if (!sameBlock(state.block, head.id)) {\n throw inconsistent('the endpoints answered the state at another block');\n }\n return state;\n}\n\n/**\n * The wallet's seqno in the attested `state`: the get-method's answer must name the\n * attested block and the state's last transaction, so it is the state whose status was\n * read, never an endpoint's latest one. The quorum key is the seqno and that binding, as\n * parsed values, so formatting never splits the quorum; it never throws.\n */\nasync function seqnoAt(\n ctx: TonContext,\n wallet: string,\n head: BlockHeader,\n state: AccountState,\n): Promise<bigint | undefined> {\n const bound = (result: BoundRunResult): boolean =>\n sameBlock(result.block, head.id) &&\n result.lastTransaction.lt === state.lastLt &&\n result.lastTransaction.hash === state.lastHash;\n const key = (body: unknown): unknown => {\n try {\n const result = boundRunResultOf(body);\n return { seqno: seqnoIn(result)?.toString() ?? null, bound: bound(result) };\n } catch {\n return 'malformed';\n }\n };\n const result = await ctx.api.runGetMethodAt(\n wallet,\n 'seqno',\n [],\n { ...PROOF, quorumKey: key },\n head.id.seqno,\n );\n if (!bound(result)) {\n throw inconsistent('the seqno was read at another state than the attested one');\n }\n return seqnoIn(result);\n}\n\n/** An Attempt id (a 32-byte hash in hex, either case) in lower case; undefined otherwise. */\nconst attemptId = (id: string): string | undefined =>\n /^[0-9a-fA-F]{64}$/.test(id) ? id.toLowerCase() : undefined;\n\n/**\n * A positive-path hint only: the wallet transaction the indexer lists as the consumer of\n * `seqno`, searched newest-first below the wallet's last transaction at the attested\n * block `head`, on the indexer's pages as served. Only a proven request counts\n * (`provenRequest`), and one whose request had expired by its transaction's time\n * contradicts the chain. The caller takes it only when it is our own; it is never the\n * basis of \"not included\". `undefined` when none is indexed.\n */\nasync function consumerOf(\n ctx: TonContext,\n from: string,\n seqno: bigint,\n head: BlockHeader,\n state: AccountState,\n): Promise<V3Transaction | undefined> {\n const keyAtHead = publicKeyAt(ctx, from, PROOF, head.id, state);\n const key = () => keyAtHead();\n let endLt = state.lastLt;\n for (let page = 0; page < CONSUMER_PAGES; page++) {\n const { transactions, next } = await ctx.api.accountTransactionsPage(\n from,\n { limit: CONSUMER_PAGE, endLt },\n PROOF,\n );\n for (const tx of transactions) {\n const request = await provenRequest(ctx, tx, from, key);\n if (!request) continue;\n const claimed = BigInt(request.seqno);\n if (claimed > seqno) continue;\n if (claimed < seqno) return undefined;\n if (request.validUntil <= tx.now) {\n throw inconsistent('the seqno consumer ran after its request expired');\n }\n return tx;\n }\n if (next === undefined) return undefined;\n endLt = next;\n }\n ctx.log.warn('the seqno consumer is beyond the search window', {\n code: 'SEQNO_CONSUMER_NOT_FOUND',\n });\n return undefined;\n}\n\n// ---- the account's own chain --------------------------------------------------------------\n\nconst hex256 = (value: bigint): string => value.toString(16).padStart(64, '0');\n\n/** The most transactions one walk visits, fetched or kept: `WALK_PAGES` full pages. */\nconst WALK_LIMIT = WALK_PAGES * WALK_PAGE;\n\n/**\n * The account's chain from `from` back, one authenticated transaction at a time, each naming\n * the next by its `prev_trans_lt`/`prev_trans_hash`; `visit` returns true to stop. Ends at\n * the chain's start (`prev_trans_lt` 0: the account's first transaction, or its first since\n * a deletion, transaction.cpp `init_new`), or after `WALK_LIMIT` transactions or\n * `WALK_PAGES` pages. The replay guard walks before every resend, so a transaction\n * authenticated once is kept by its id (`chainTxs`), and a walk fetches only the part of\n * the chain it has not seen; a kept one is bound to the account as a fetched one is.\n */\nasync function walkChain(\n ctx: TonContext,\n wallet: string,\n from: TransactionId,\n visit: (tx: Transaction, hash: string) => Promise<boolean>,\n): Promise<'stopped' | 'start' | 'exhausted'> {\n const account = accountId(wallet);\n let expected = from;\n let page: RawTransaction[] = [];\n let fetched = 0;\n for (let visited = 0; visited < WALK_LIMIT; visited++) {\n const key = `${expected.lt}:${expected.hash}`;\n const row = page.shift();\n let tx = ctx.chainTxs.get(key);\n if (tx !== undefined) {\n if (tx.address !== account) throw notTheChains();\n // The page fetched earlier no longer follows the walk: drop it.\n if (row !== undefined && (row.lt !== expected.lt || row.hash !== expected.hash)) {\n page = [];\n }\n } else {\n let next = row;\n if (next === undefined) {\n if (fetched === WALK_PAGES) return 'exhausted';\n fetched += 1;\n page = await ctx.api.rawTransactions(wallet, expected, WALK_PAGE, PROOF);\n next = page.shift();\n if (next === undefined) {\n throw undecided('the liteserver does not hold the transaction asked');\n }\n }\n tx = authenticated(next, expected, account);\n // Only a wallet-sized transaction is kept (a lying endpoint's is not): the memo\n // stays bounded.\n if (next.boc.length <= MEMO_TX_LENGTH) keep(ctx.chainTxs, key, tx, CHAIN_MEMO);\n }\n if (await visit(tx, expected.hash)) return 'stopped';\n if (tx.prevTransactionLt === 0n) return 'start';\n expected = { lt: tx.prevTransactionLt, hash: hex256(tx.prevTransactionHash) };\n }\n return 'exhausted';\n}\n\nconst CODE: ReadonlySet<string> = new Set(['active', 'frozen']);\nconst NO_CODE: ReadonlySet<string> = new Set(['uninitialized', 'non-existing']);\n\n/** What a transaction did, as the chain records it. */\nfunction phasesOf(tx: Transaction) {\n const d = tx.description;\n const compute = 'computePhase' in d ? d.computePhase : undefined;\n const vm = compute?.type === 'vm' ? compute : undefined;\n return {\n /** The wallet's code ran: the chain runs it only when code exists or a StateInit\n * activates the account (transaction.cpp). */\n ran: vm !== undefined,\n /** A request ran to the end, so a seqno moved (the action phase keeps it). */\n consumed: chainRan(tx),\n /** The account had code before or after. */\n lived: CODE.has(tx.oldStatus) || CODE.has(tx.endStatus),\n /** A re-deploy from no code: the seqno starts again (transaction.cpp activation). */\n activation: NO_CODE.has(tx.oldStatus) && tx.endStatus === 'active',\n /** The code went (+32 destroy, storage deletion): the seqno goes with it. */\n destruction:\n (CODE.has(tx.oldStatus) && NO_CODE.has(tx.endStatus)) ||\n ('destroyed' in d && d.destroyed),\n };\n}\n\n/**\n * The seqno a request the wallet ran claims, read from its signed header alone (so a\n * v4r2 plugin request or a W5 extended-action request counts too): an external request, or\n * a W5 `internal_signed` one, signed by the wallet's key for this very wallet\n * (`requestIsOwn`: a v5r1 wallet runs a forged relayed body and ignores it).\n */\nasync function claimedSeqno(\n ctx: TonContext,\n wallet: string,\n message: Message | null | undefined,\n key: () => Promise<Uint8Array | undefined>,\n): Promise<bigint | undefined> {\n if (!message) return undefined;\n const { body } = message;\n const op = body.bits.length >= 32 ? body.beginParse().preloadUint(32) : undefined;\n const w5 = op === OP.w5SignedExternal || op === OP.w5SignedInternal;\n if (\n message.info.type === 'internal'\n ? op !== OP.w5SignedInternal\n : message.info.type !== 'external-in'\n ) {\n return undefined;\n }\n let seqno: number;\n try {\n const s = body.beginParse();\n // W5: op, wallet id, valid_until, seqno; v4r2: signature, subwallet id, valid_until, seqno.\n s.skip(w5 ? 32 + 32 + 32 : 512 + 32 + 32);\n seqno = s.loadUint(32);\n } catch {\n return undefined;\n }\n const publicKey = await key();\n return publicKey && requestIsOwn(wallet, body, publicKey, ctx.config.globalId)\n ? BigInt(seqno)\n : undefined;\n}\n\ntype Absence = { readonly ours: string } | { readonly absent: true };\n\ninterface ChainQuestion {\n readonly wallet: string;\n readonly id: string;\n readonly slot: { readonly seqno: bigint; readonly validUntil: number };\n readonly head: BlockHeader;\n readonly state: AccountState;\n readonly active: boolean;\n /** The seqno at `head` (0 for an uninitialized wallet). */\n readonly seqno: bigint;\n}\n\nconst resetSuspected = (ctx: TonContext) => {\n ctx.log.warn('the wallet may have been reset since our message', {\n code: 'WALLET_RESET_SUSPECTED',\n });\n return undecided('the wallet may have been reset since our message');\n};\n\nconst walkExhausted = (ctx: TonContext) => {\n ctx.log.warn('the wallet history is beyond the proof window', {\n code: 'TX_CHAIN_WALK_EXHAUSTED',\n });\n return undecided('the wallet history is beyond the proof window');\n};\n\n/**\n * The wallet's code never ran in the history the indexer holds\n * below lt `below` (an earlier incarnation, before a chain start), or in all of it when\n * `below` is undefined (no chain now: never created, or deleted with its last transaction),\n * read under the proof quorum once the indexer has indexed masterchain block `reached`: no\n * compute phase that ran, and no status with code. Our message runs only in the wallet's\n * code, so an incarnation whose code never ran cannot hold it, whether the wallet is active\n * or uninitialized now (a deposit that bounced before the wallet existed is no reset).\n * A row where the code ran, a row without its statuses, or a history past the window\n * decides nothing.\n */\nasync function codeNeverRan(\n ctx: TonContext,\n wallet: string,\n reached: number,\n below?: bigint,\n): Promise<void> {\n if (!(await ctx.api.indexerReached(reached, PROOF))) {\n throw undecided('the indexer has not reached the attested block yet');\n }\n let endLt = below === undefined ? undefined : below - 1n;\n for (let page = 0; page < HISTORY_PAGES; page++) {\n const { transactions, next } = await ctx.api.accountTransactionsPage(\n wallet,\n { limit: HISTORY_PAGE, ...(endLt !== undefined ? { endLt } : {}) },\n PROOF,\n );\n for (const tx of transactions) {\n const { origStatus, endStatus } = tx;\n if (\n !tx.compute.skipped ||\n origStatus === undefined ||\n endStatus === undefined ||\n origStatus === 'active' ||\n origStatus === 'frozen' ||\n endStatus === 'active' ||\n endStatus === 'frozen'\n ) {\n throw resetSuspected(ctx);\n }\n }\n if (next === undefined) return;\n endLt = next;\n }\n throw walkExhausted(ctx);\n}\n\n/**\n * At an attested block where the message is expired, whether our message\n * consumed its seqno, from the account's own chain alone, walked back from the attested\n * state's last transaction:\n * - our message (its TEP-467 hash computed here) run to the end: ours, proven by the caller;\n * - otherwise \"absent\" only when the chain shows no reset: the walk reaches the earliest\n * time our message could have run (`windowStart`, from the attempt's own record) with,\n * when our seqno is consumed at `head`, its consumer found (another request, by its\n * signed header); or it reaches the chain's start inside that window, and the anchored\n * indexer history shows that the code never ran before it.\n * An activation, a destruction, or a consumer of a lower seqno first is a reset: from then\n * on the wallet must never have run, as far as the chain goes back into the window; a walk\n * past its cap decides nothing. An uninitialized wallet must never have run in the\n * window (our message cannot have run before it), nor, without a chain, at all.\n */\nasync function fromTheChain(ctx: TonContext, q: ChainQuestion): Promise<Absence> {\n const needConsumer = q.active && q.seqno > q.slot.seqno;\n if (q.state.lastLt === 0n) {\n // No chain at `head`: never created, or deleted with its last transaction.\n if (q.active) throw inconsistent('an active account without a transaction');\n await codeNeverRan(ctx, q.wallet, q.head.id.seqno);\n return { absent: true };\n }\n const windowStart = windowStartOf(q.slot);\n const key = publicKeyAt(ctx, q.wallet, PROOF, q.head.id, q.state);\n let codeless = !q.active;\n let consumerFound = false;\n let reset = false;\n let ours: string | undefined;\n let first = q.state.lastLt;\n const end = await walkChain(\n ctx,\n q.wallet,\n { lt: q.state.lastLt, hash: q.state.lastHash },\n async (tx, hash) => {\n first = tx.lt;\n const t = phasesOf(tx);\n const inbound = tx.inMessage;\n if (ourRun(tx, q.wallet, q.id)) {\n ours = hash;\n return true;\n }\n if (tx.now < windowStart && (!needConsumer || consumerFound)) return true;\n if (codeless) {\n if (t.ran || t.lived || t.destruction) reset = true;\n return false;\n }\n if (t.destruction) reset = true;\n if (needConsumer && !consumerFound && t.consumed) {\n const claimed = await claimedSeqno(ctx, q.wallet, inbound, key);\n if (claimed === q.slot.seqno) consumerFound = true;\n else if (claimed !== undefined && claimed < q.slot.seqno) reset = true;\n }\n if (t.activation) {\n if (needConsumer && !consumerFound) reset = true;\n codeless = true;\n }\n return false;\n },\n );\n if (ours !== undefined) return { ours };\n if (end === 'exhausted') throw walkExhausted(ctx);\n if (reset || (needConsumer && !consumerFound)) throw resetSuspected(ctx);\n if (end === 'start') await codeNeverRan(ctx, q.wallet, q.head.id.seqno, first);\n return { absent: true };\n}\n\n// ---- the replay guard ---------------------------------------------------------------------\n\n/**\n * Stored bytes about to be sent again: the wallet they go to (raw), their TEP-467 hash, and\n * the seqno and lifetime their signed header carries. `validFrom` is the build's recorded\n * chain time when this driver assembled them; otherwise the widest lifetime applies.\n */\nexport interface StoredMessage {\n readonly wallet: string;\n readonly id: string;\n readonly seqno: bigint;\n readonly validUntil: number;\n readonly validFrom?: number;\n}\n\n/**\n * The monotone predicate \"my seqno is above `seqno`\" at the endpoints' own states, under the\n * proof quorum; its key is the verdict itself and never throws.\n */\nasync function seqnoAbove(\n ctx: TonContext,\n wallet: string,\n seqno: bigint,\n): Promise<boolean> {\n const above = (result: RunResult): boolean => {\n const value = seqnoIn(result);\n return value !== undefined && value > seqno;\n };\n const key = (body: unknown): unknown => {\n try {\n return above(runResultOf(body));\n } catch {\n return 'malformed';\n }\n };\n return above(\n await ctx.api.runGetMethod(wallet, 'seqno', [], { ...PROOF, quorumKey: key }),\n );\n}\n\n/**\n * Whether stored bytes may go out again. A wallet reset (a deletion, then a deposit,\n * or a re-deploy from the public `StateInit` back to our seqno) makes a message that already\n * ran and paid runnable again while it is valid, so every send of stored bytes asks first:\n * - `send`: the wallet's seqno is already above ours under the proof quorum, so the message\n * cannot run (no walk); or the chain shows it cannot have run: the walk reaches the\n * earliest time it could have run (`windowStartOf`, from the recorded build time, else\n * the widest lifetime) with no reset, or a chain start whose earlier history shows the\n * code never ran (a wallet funded a minute ago is sent to);\n * - `ours`: the chain holds our message run to the end: it must never be sent again.\n * The walk starts from the freshest state an endpoint serves (the attested head trails it\n * by 10 to 150 blocks, and a reset in that trail is exactly the danger), and must lead\n * down to the attested state's last transaction, so a lying fresh endpoint can hide only\n * what the attested walk could not see either. Anything else, including a deletion or a\n * new chain since the attested head, an activation or a destruction in the window, a walk\n * past its cap, an indexer behind the fresh block or a failed read, throws a retryable\n * error: the guard never sends while it cannot decide, and the proof decides.\n * Known gap: once a wallet is reset (which takes software that shares its key), anyone\n * can replay our message from the chain's public record; no client can stop that, and the\n * guard covers only this library's own sends.\n */\nexport async function replayVerdict(\n ctx: TonContext,\n message: StoredMessage,\n): Promise<'send' | 'ours'> {\n const { wallet, id } = message;\n // A seqno past ours needs no walk. A failed read is only \"not known\".\n const past = await seqnoAbove(ctx, wallet, message.seqno).catch(() => false);\n if (past) return 'send';\n const windowStart = windowStartOf(message);\n const head = await attestedHead(ctx);\n const attested = await stateAt(ctx, wallet, head);\n const fresh = await ctx.api.account(wallet, MONITOR);\n // An endpoint behind the attested head adds nothing; one past it must agree with it.\n const top = fresh.blockSeqno > head.id.seqno ? fresh : attested;\n if (top === fresh) {\n if (\n fresh.lastLt === attested.lastLt\n ? fresh.lastHash !== attested.lastHash\n : fresh.lastLt < attested.lastLt && fresh.lastLt !== 0n\n ) {\n throw inconsistent('the freshest state does not follow the attested one');\n }\n }\n if (top.status === 'frozen')\n throw undecided('the wallet state does not show its seqno');\n // The account was deleted since the attested head: our message may have run just before.\n if (top.lastLt === 0n && attested.lastLt !== 0n) throw resetSuspected(ctx);\n if (top.lastLt === 0n) {\n // No chain now, nor at the attested head: never created, or deleted long ago.\n await codeNeverRan(ctx, wallet, top.blockSeqno);\n return 'send';\n }\n // The fresh part of the chain must lead to the attested state's last transaction.\n const link = top !== attested && attested.lastLt !== 0n ? attested : undefined;\n let linked = link === undefined || link.lastLt === top.lastLt;\n let codeless = top.status !== 'active';\n let reset = false;\n let ours = false;\n let first = top.lastLt;\n const end = await walkChain(\n ctx,\n wallet,\n { lt: top.lastLt, hash: top.lastHash },\n async (tx, hash) => {\n first = tx.lt;\n if (!linked && link !== undefined) {\n if (tx.lt < link.lastLt || (tx.lt === link.lastLt && hash !== link.lastHash)) {\n throw inconsistent('the freshest state does not follow the attested one');\n }\n linked = tx.lt === link.lastLt;\n }\n const t = phasesOf(tx);\n if (ourRun(tx, wallet, id)) {\n ours = true;\n return true;\n }\n if (linked && tx.now < windowStart) return true;\n if (codeless) {\n if (t.ran || t.lived || t.destruction) reset = true;\n return false;\n }\n if (t.destruction) reset = true;\n if (t.activation) codeless = true;\n return false;\n },\n );\n if (ours) return 'ours';\n if (end === 'exhausted') throw walkExhausted(ctx);\n // Not linked at the chain's start: a new chain since the attested head, so a deletion.\n if (reset || !linked) throw resetSuspected(ctx);\n if (end === 'start') await codeNeverRan(ctx, wallet, top.blockSeqno, first);\n return 'send';\n}\n\ntype Included = Extract<\n Awaited<ReturnType<ProofSource['includedFinal']>>,\n { included: true }\n>;\n\n/**\n * Our indexed transaction that consumed its seqno (the Attempt `id`), proven: a complete\n * trace, whose last block the endpoints attest they hold, and the verdict, its jetton\n * wallets confirmed at that block and a bounce read from the chain itself, both under the\n * proof quorum.\n */\nasync function proveIncluded(\n ctx: TonContext,\n tx: V3Transaction,\n from: string,\n id: string,\n): Promise<Included> {\n const trace = await ctx.api.trace(tx.hash, PROOF);\n if (!trace || !trace.complete) throw undecided('the message trace is not complete yet');\n const last = traceBlock(tx, trace);\n if (!(await ctx.api.reachedMasterchain(last, PROOF))) {\n throw undecided('the endpoints have not reached the trace yet');\n }\n const verdict = await confirmBounce(\n ctx,\n await confirmLegs(ctx, attemptVerdict(tx, trace), from, PROOF, last),\n from,\n id,\n PROOF,\n );\n if (verdict.kind === 'pending')\n throw undecided('the message trace is not complete yet');\n const header = await masterchainBlock(ctx, tx.mcSeqno);\n return {\n included: true,\n success: verdict.kind === 'success',\n blockHeight: BigInt(tx.mcSeqno),\n blockHash: header.id.rootHash,\n txHash: tx.hash,\n ...(verdict.kind === 'failed' ? { reason: verdict.reason } : {}),\n ...(verdict.kind === 'failed' && verdict.failure ? { failure: verdict.failure } : {}),\n };\n}\n\n/**\n * Our transaction the chain itself holds (`hash`), proven through the indexer's record of\n * that very transaction, which must be our message and have consumed its seqno.\n */\nasync function proveOurs(\n ctx: TonContext,\n hash: string,\n wallet: string,\n id: string,\n): Promise<Included> {\n const record = await ctx.api.transaction(hash, PROOF);\n if (!record) throw undecided('our transaction is not indexed yet');\n if (!isOwnAttempt(record, wallet, id) || !consumesSeqno(record)) {\n throw inconsistent(\"the indexer's record is not the chain's transaction\");\n }\n return proveIncluded(ctx, record, wallet, id);\n}\n\nconst seqnoOrdering = (ordering: OrderingData) =>\n ordering.kind === 'seqno' ? ordering : undefined;\n\nexport function createTonProofs(ctx: TonContext): ProofSource {\n const { api } = ctx;\n const walletOf = (from: string) => ctx.codec.normalize(from).canonical;\n return {\n async finalizedHead() {\n const header = await attestedHead(ctx);\n return {\n height: BigInt(header.id.seqno),\n hash: header.id.rootHash,\n timestamp: header.genUtime,\n };\n },\n\n async includedFinal(ref, ordering, from) {\n const wallet = walletOf(from);\n // Only our own wallet transaction, its hash computed here from the bound body. A\n // run that did not consume its seqno (a failed action phase) moved nothing and may\n // run again until the message expires: only the seqno decides it.\n const id = attemptId(ref.id);\n if (id === undefined) throw undecided('a TON attempt needs its message hash');\n const own = await findOwnAttempt(ctx, ref, wallet, PROOF);\n if (own && consumesSeqno(own)) return proveIncluded(ctx, own, wallet, id);\n const slot = seqnoOrdering(ordering);\n if (!slot) throw undecided('a TON attempt needs its seqno ordering');\n if (!hasLifetime(slot.validUntil))\n throw undecided('a TON attempt needs its lifetime');\n // Not proven under our hash: decide only from state at an attested block.\n const head = await attestedHead(ctx);\n const state = await stateAt(ctx, wallet, head);\n const active = state.status === 'active';\n // A frozen wallet, or an uninitialized one past seqno 0, shows no seqno (never 0).\n if (!active && (state.status === 'frozen' || slot.seqno !== 0n)) {\n throw undecided('the wallet state does not show its seqno');\n }\n const seqno = active ? await seqnoAt(ctx, wallet, head, state) : 0n;\n if (seqno === undefined)\n throw undecided('the wallet state does not show its seqno');\n if (seqno > slot.seqno) {\n // The indexer's consumer search: a hint that finds ours, never a \"no\", nor a veto\n // either; a hint that cannot be used (a record the chain could not produce, a\n // failed read) is logged, and the authenticated path decides.\n let hint: V3Transaction | undefined;\n try {\n hint = await consumerOf(ctx, wallet, slot.seqno, head, state);\n } catch (error) {\n if (!isCryptoAioError(error) || !error.retryable) throw error;\n ctx.log.warn('the indexer gave no usable seqno consumer', {\n code: 'SEQNO_CONSUMER_HINT_UNUSABLE',\n });\n }\n if (hint && isOwnAttempt(hint, wallet, id))\n return proveIncluded(ctx, hint, wallet, id);\n }\n // Never \"not included\" while the message may still run: a reset of the wallet could\n // bring its seqno back to ours.\n if (!(await expiredAt(ctx, head, slot.validUntil))) {\n throw undecided('the message may still be included');\n }\n const chain = await fromTheChain(ctx, {\n wallet,\n id,\n slot,\n head,\n state,\n active,\n seqno,\n });\n if ('ours' in chain) return proveOurs(ctx, chain.ours, wallet, id);\n return { included: false };\n },\n\n async slotConsumed(ordering, from, level) {\n const slot = seqnoOrdering(ordering);\n if (!slot) return false;\n // Masterchain state is final once it exists, so TON gives no separate `latest`\n // evidence: our own landed-but-unindexed message is never observed as `replaced`.\n if (level === 'latest') return false;\n // \"My seqno at the final state is above n\", a monotone predicate.\n return seqnoAbove(ctx, walletOf(from), slot.seqno);\n },\n\n async expired(ordering) {\n const slot = seqnoOrdering(ordering);\n if (!slot) return false;\n return expiredAt(ctx, await attestedHead(ctx), slot.validUntil);\n },\n\n async blockHash(height) {\n // Every masterchain block is final once it exists: both levels read the same.\n if (height < 0n || height > BigInt(await api.masterchainHead(MONITOR))) return null;\n return (await masterchainBlock(ctx, Number(height))).id.rootHash;\n },\n };\n}\n\n/** A history cursor: the next page's `end_lt`, a u64 in decimal, capped before use. */\nfunction cursorLt(cursor: string | undefined): bigint | undefined {\n if (cursor === undefined) return undefined;\n if (\n cursor.length === 0 ||\n cursor.length > MAX_LT_DIGITS ||\n !/^\\d+$/.test(cursor) ||\n BigInt(cursor) > MAX_LT\n ) {\n throw new ValidationError('INVALID_INTENT', 'not a TON history cursor');\n }\n return BigInt(cursor);\n}\n\n/**\n * An address's transactions from the indexer, newest first, decoded with jettons only for\n * verified jetton wallets. The cursor is the next page's `end_lt`, taken from the page as\n * the indexer served it, so rows not final yet never end the history early; a page\n * is at most what toncenter serves.\n */\nexport function createTonHistory(ctx: TonContext): AddressHistorySource {\n return {\n async list(address, options) {\n const endLt = cursorLt(options.cursor);\n const account = ctx.codec.normalize(address).canonical;\n const page = await ctx.api.accountTransactionsPage(\n account,\n {\n limit: Math.min(options.limit, HISTORY_PAGE_MAX),\n ...(endLt !== undefined ? { endLt } : {}),\n },\n READ,\n );\n const items = [];\n const memo = pageMemo();\n for (const tx of page.transactions) {\n items.push(await decodeWithJettons(ctx, tx, READ, memo));\n }\n return {\n items,\n ...(page.next !== undefined ? { next: page.next.toString() } : {}),\n };\n },\n };\n}\n"]}
|
|
@@ -6,12 +6,13 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { type Transaction } from '@ton/core';
|
|
8
8
|
import type { AddressCodec, ChainReader, DriverBlock, SequenceSource } from '../../core/driver/types';
|
|
9
|
+
import { ProviderError } from '../../core/errors/error';
|
|
9
10
|
import type { Logger } from '../../core/events/logger';
|
|
10
11
|
import type { AssetRef } from '../../core/model/asset';
|
|
11
12
|
import type { ChainInfo, NetworkInfo } from '../../core/model/chain';
|
|
12
13
|
import type { AttemptRef } from '../../core/model/transaction';
|
|
13
14
|
import type { Clock } from '../../core/util/clock';
|
|
14
|
-
import { type AccountState, type BlockHeader, type BlockId, type TonApi, type V3Trace, type V3Transaction } from './api';
|
|
15
|
+
import { type AccountState, type BlockHeader, type BlockId, type RawTransaction, type TonApi, type TransactionId, type V3Trace, type V3Transaction } from './api';
|
|
15
16
|
import { type VerifiedJettonWallet } from './decode';
|
|
16
17
|
import { type WalletRequest } from './messages';
|
|
17
18
|
import type { TonNetworkConfig } from './network';
|
|
@@ -37,9 +38,10 @@ export interface TonContext {
|
|
|
37
38
|
/** jetton wallet → its owner and master, verified under the quorum. */
|
|
38
39
|
readonly verified: Map<string, VerifiedJettonWallet>;
|
|
39
40
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
41
|
+
* Transactions authenticated under the proof quorum (the chain walk's wallet
|
|
42
|
+
* transactions, a bounce's deliveries), by `lt:hash`. A transaction is immutable and its
|
|
43
|
+
* cell hashes to its id, so a kept one is as good as one fetched again; each walk fetches
|
|
44
|
+
* only what it has not seen (bounded, `CHAIN_MEMO`).
|
|
43
45
|
*/
|
|
44
46
|
readonly chainTxs: Map<string, Transaction>;
|
|
45
47
|
/**
|
|
@@ -153,6 +155,45 @@ export declare function findOwnAttempt(ctx: TonContext, ref: AttemptRef, from: s
|
|
|
153
155
|
export declare function confirmLegs(ctx: TonContext, verdict: Verdict, from: string, tags: TonCallTags, block: number): Promise<Verdict>;
|
|
154
156
|
/** The newest masterchain block of a trace: every leg's wallet has run by then. */
|
|
155
157
|
export declare function traceBlock(root: V3Transaction, trace: V3Trace | null): number;
|
|
158
|
+
/** A raw address's account id, as a transaction cell names it. */
|
|
159
|
+
export declare const accountId: (raw: string) => bigint;
|
|
160
|
+
export declare const notTheChains: () => ProviderError;
|
|
161
|
+
/**
|
|
162
|
+
* A transaction the liteserver served, authenticated: its cell (capped by the API before
|
|
163
|
+
* this decodes it) hashes to the id expected, and it is the account's own at the lt
|
|
164
|
+
* expected. Anything else is not the chain's.
|
|
165
|
+
*/
|
|
166
|
+
export declare function authenticated(row: RawTransaction, expected: TransactionId, account: bigint): Transaction;
|
|
167
|
+
/**
|
|
168
|
+
* Whether the chain's `tx` ran its inbound message to the end: its compute and action
|
|
169
|
+
* phases both succeeded, so its state and its outgoing messages stand (a failed phase
|
|
170
|
+
* drops both, transaction.cpp).
|
|
171
|
+
*/
|
|
172
|
+
export declare function chainRan(tx: Transaction): boolean;
|
|
173
|
+
/**
|
|
174
|
+
* Whether the chain's `tx` is our message run to the end: its inbound external message's
|
|
175
|
+
* TEP-467 hash, computed here from the authenticated body, is `id`, and it consumed its
|
|
176
|
+
* seqno.
|
|
177
|
+
*/
|
|
178
|
+
export declare function ourRun(tx: Transaction, wallet: string, id: string): boolean;
|
|
179
|
+
/**
|
|
180
|
+
* A bounce verdict (`transfer bounced`, `jetton transfer bounced`), authenticated from the
|
|
181
|
+
* chain itself: a lone lying indexer could report one for a transfer that landed, and a
|
|
182
|
+
* `failed` invites a second payment. The indexer only names the transactions
|
|
183
|
+
* (`BounceEvidence`); the liteserver serves each under `tags` (the proof quorum on the
|
|
184
|
+
* proof path), hashed here (`chainTransaction`). The verdict stands only when the chain
|
|
185
|
+
* shows all of it: our wallet transaction is our Attempt run to the end; each delivery
|
|
186
|
+
* received a message the one before it sent, by the message's cell hash, so no other
|
|
187
|
+
* delivery (another transfer's bounce at the same recipient) stands in for ours, and the
|
|
188
|
+
* message past our jetton wallet carries our jettons onward; and the last one sent the
|
|
189
|
+
* value back, ran nothing, or moved no jettons. A delivery the liteserver does not hold
|
|
190
|
+
* yet decides nothing (a retryable `PROVIDER_UNAVAILABLE`), nor do endpoints that disagree
|
|
191
|
+
* on one (the quorum's `PROVIDER_INCONSISTENT`); a chain that shows otherwise is a
|
|
192
|
+
* retryable `PROVIDER_INCONSISTENT` (logged `BOUNCE_UNPROVEN`), never `success` either: a
|
|
193
|
+
* real bounce may only lack its evidence yet, and the indexer's word decides neither way.
|
|
194
|
+
* Any other verdict passes unchanged.
|
|
195
|
+
*/
|
|
196
|
+
export declare function confirmBounce(ctx: TonContext, verdict: Verdict, from: string, id: string, tags: TonCallTags): Promise<Verdict>;
|
|
156
197
|
/**
|
|
157
198
|
* What one history page reads once and uses for every transaction on it:
|
|
158
199
|
* each masterchain block's header, and each jetton wallet's facts, read at the block of the
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pageMemo = exports.NO_STATE_EXIT = exports.ASSEMBLED_MEMO = exports.MEMO_TX_LENGTH = exports.CHAIN_MEMO = void 0;
|
|
3
|
+
exports.pageMemo = exports.notTheChains = exports.accountId = exports.NO_STATE_EXIT = exports.ASSEMBLED_MEMO = exports.MEMO_TX_LENGTH = exports.CHAIN_MEMO = void 0;
|
|
4
4
|
exports.keep = keep;
|
|
5
5
|
exports.createTonContext = createTonContext;
|
|
6
6
|
exports.jettonWalletAddress = jettonWalletAddress;
|
|
@@ -12,6 +12,10 @@ exports.toDriverBlock = toDriverBlock;
|
|
|
12
12
|
exports.findOwnAttempt = findOwnAttempt;
|
|
13
13
|
exports.confirmLegs = confirmLegs;
|
|
14
14
|
exports.traceBlock = traceBlock;
|
|
15
|
+
exports.authenticated = authenticated;
|
|
16
|
+
exports.chainRan = chainRan;
|
|
17
|
+
exports.ourRun = ourRun;
|
|
18
|
+
exports.confirmBounce = confirmBounce;
|
|
15
19
|
exports.decodeWithJettons = decodeWithJettons;
|
|
16
20
|
exports.createTonReader = createTonReader;
|
|
17
21
|
exports.walletSeqno = walletSeqno;
|
|
@@ -501,7 +505,12 @@ async function confirmLegs(ctx, verdict, from, tags, block) {
|
|
|
501
505
|
if (recipient.kind === 'foreign' ||
|
|
502
506
|
recipient.wallet.owner !== leg.recipient ||
|
|
503
507
|
recipient.wallet.master !== sender.wallet.master) {
|
|
504
|
-
|
|
508
|
+
// The jettons left the wallet, to a wallet the master does not name.
|
|
509
|
+
return Object.freeze({
|
|
510
|
+
kind: 'failed',
|
|
511
|
+
reason: trace_1.REASONS.jettonUnverified,
|
|
512
|
+
failure: 'unevidenced',
|
|
513
|
+
});
|
|
505
514
|
}
|
|
506
515
|
}
|
|
507
516
|
return verdict;
|
|
@@ -510,6 +519,186 @@ async function confirmLegs(ctx, verdict, from, tags, block) {
|
|
|
510
519
|
function traceBlock(root, trace) {
|
|
511
520
|
return Math.max(root.mcSeqno, ...(trace?.transactions ?? []).map((tx) => tx.mcSeqno));
|
|
512
521
|
}
|
|
522
|
+
// ---- the chain's own transactions ---------------------------------------------------------
|
|
523
|
+
/** A raw address's account id, as a transaction cell names it. */
|
|
524
|
+
const accountId = (raw) => BigInt(`0x${raw.slice(raw.indexOf(':') + 1)}`);
|
|
525
|
+
exports.accountId = accountId;
|
|
526
|
+
const notTheChains = () => new error_1.ProviderError('PROVIDER_INCONSISTENT', "the liteserver answered a transaction that is not the chain's", { retryable: true });
|
|
527
|
+
exports.notTheChains = notTheChains;
|
|
528
|
+
/**
|
|
529
|
+
* A transaction the liteserver served, authenticated: its cell (capped by the API before
|
|
530
|
+
* this decodes it) hashes to the id expected, and it is the account's own at the lt
|
|
531
|
+
* expected. Anything else is not the chain's.
|
|
532
|
+
*/
|
|
533
|
+
function authenticated(row, expected, account) {
|
|
534
|
+
if (row.lt !== expected.lt || row.hash !== expected.hash)
|
|
535
|
+
throw (0, exports.notTheChains)();
|
|
536
|
+
let cell;
|
|
537
|
+
let tx;
|
|
538
|
+
try {
|
|
539
|
+
const cells = core_1.Cell.fromBoc(Buffer.from(row.boc, 'base64'));
|
|
540
|
+
if (cells.length !== 1)
|
|
541
|
+
throw (0, exports.notTheChains)();
|
|
542
|
+
cell = cells[0];
|
|
543
|
+
tx = (0, core_1.loadTransaction)(cell.beginParse());
|
|
544
|
+
}
|
|
545
|
+
catch {
|
|
546
|
+
throw (0, exports.notTheChains)();
|
|
547
|
+
}
|
|
548
|
+
if (cell.hash().toString('hex') !== expected.hash ||
|
|
549
|
+
tx.lt !== expected.lt ||
|
|
550
|
+
tx.address !== account) {
|
|
551
|
+
throw (0, exports.notTheChains)();
|
|
552
|
+
}
|
|
553
|
+
return tx;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Whether the chain's `tx` ran its inbound message to the end: its compute and action
|
|
557
|
+
* phases both succeeded, so its state and its outgoing messages stand (a failed phase
|
|
558
|
+
* drops both, transaction.cpp).
|
|
559
|
+
*/
|
|
560
|
+
function chainRan(tx) {
|
|
561
|
+
const d = tx.description;
|
|
562
|
+
return (d.type === 'generic' &&
|
|
563
|
+
d.computePhase.type === 'vm' &&
|
|
564
|
+
d.computePhase.success &&
|
|
565
|
+
d.actionPhase?.success === true);
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Whether the chain's `tx` is our message run to the end: its inbound external message's
|
|
569
|
+
* TEP-467 hash, computed here from the authenticated body, is `id`, and it consumed its
|
|
570
|
+
* seqno.
|
|
571
|
+
*/
|
|
572
|
+
function ourRun(tx, wallet, id) {
|
|
573
|
+
const inbound = tx.inMessage;
|
|
574
|
+
return (chainRan(tx) &&
|
|
575
|
+
inbound?.info.type === 'external-in' &&
|
|
576
|
+
(0, wallets_1.externalHashOf)(wallet, inbound.body) === id);
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* The transaction `id` names, as the liteserver serves it under `tags` (v2, by its lt and
|
|
580
|
+
* hash), authenticated. One read under the proof quorum is kept with the chain walk's
|
|
581
|
+
* (`chainTxs`), and a kept one is as good as one fetched again; one read under any other
|
|
582
|
+
* tags is used once.
|
|
583
|
+
*/
|
|
584
|
+
async function chainTransaction(ctx, id, tags) {
|
|
585
|
+
const key = `${id.lt}:${id.hash}`;
|
|
586
|
+
const account = (0, exports.accountId)(id.account);
|
|
587
|
+
const kept = ctx.chainTxs.get(key);
|
|
588
|
+
if (kept !== undefined) {
|
|
589
|
+
if (kept.address !== account)
|
|
590
|
+
throw (0, exports.notTheChains)();
|
|
591
|
+
return kept;
|
|
592
|
+
}
|
|
593
|
+
const [row] = await ctx.api.rawTransactions(id.account, id, 1, tags);
|
|
594
|
+
if (row === undefined)
|
|
595
|
+
throw notYet('the liteserver does not hold the transaction asked');
|
|
596
|
+
const tx = authenticated(row, id, account);
|
|
597
|
+
if (tags.quorum !== undefined && row.boc.length <= exports.MEMO_TX_LENGTH) {
|
|
598
|
+
keep(ctx.chainTxs, key, tx, exports.CHAIN_MEMO);
|
|
599
|
+
}
|
|
600
|
+
return tx;
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* An `out_msgs` value (block.tlb `HashmapE 15 ^(Message Any)`): the message's own cell,
|
|
604
|
+
* read as `loadTransaction` reads it, so every transaction it loaded reads here too.
|
|
605
|
+
*/
|
|
606
|
+
const MESSAGE_CELL = {
|
|
607
|
+
serialize: core_1.Dictionary.Values.Cell().serialize,
|
|
608
|
+
parse: (slice) => slice.loadRef(),
|
|
609
|
+
};
|
|
610
|
+
/**
|
|
611
|
+
* The cells of the messages the chain's `tx` received and sent, as its own cell holds
|
|
612
|
+
* them: a message's hash is its cell's, the same in the transaction that sent it and the
|
|
613
|
+
* one that received it.
|
|
614
|
+
*/
|
|
615
|
+
function messageCells(tx) {
|
|
616
|
+
const slice = tx.raw.refs[0].beginParse();
|
|
617
|
+
const inbound = slice.loadBit() ? slice.loadRef() : undefined;
|
|
618
|
+
const outbound = slice.loadDict(core_1.Dictionary.Keys.Uint(15), MESSAGE_CELL).values();
|
|
619
|
+
return { inbound, outbound };
|
|
620
|
+
}
|
|
621
|
+
const hashOf = (cell) => cell?.hash().toString('hex');
|
|
622
|
+
/** The jettons an `internal_transfer` in `message` carries from `from`; else undefined. */
|
|
623
|
+
function jettonsFrom(message, from) {
|
|
624
|
+
const { info, body } = (0, core_1.loadMessage)(message.beginParse());
|
|
625
|
+
const transfer = info.type === 'internal' ? (0, messages_1.decodeJettonInternalTransfer)(body) : null;
|
|
626
|
+
return transfer?.from === from ? transfer.amount : undefined;
|
|
627
|
+
}
|
|
628
|
+
/** Whether the chain's last delivery `tx` did what the verdict says (`end`). */
|
|
629
|
+
function endedAs(tx, end, from) {
|
|
630
|
+
if (end === 'bounced') {
|
|
631
|
+
// The bounce phase sent the value back; `nofunds` and `negfunds` left it there.
|
|
632
|
+
const d = tx.description;
|
|
633
|
+
return d.type === 'generic' && d.bouncePhase?.type === 'ok';
|
|
634
|
+
}
|
|
635
|
+
if (end === 'unran')
|
|
636
|
+
return !chainRan(tx);
|
|
637
|
+
// It ran, and every `internal_transfer` it sent for us moved nothing.
|
|
638
|
+
const amounts = messageCells(tx).outbound.map((m) => jettonsFrom(m, from));
|
|
639
|
+
return (chainRan(tx) &&
|
|
640
|
+
amounts.some((amount) => amount === 0n) &&
|
|
641
|
+
!amounts.some((amount) => amount !== undefined && amount > 0n));
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* A bounce verdict (`transfer bounced`, `jetton transfer bounced`), authenticated from the
|
|
645
|
+
* chain itself: a lone lying indexer could report one for a transfer that landed, and a
|
|
646
|
+
* `failed` invites a second payment. The indexer only names the transactions
|
|
647
|
+
* (`BounceEvidence`); the liteserver serves each under `tags` (the proof quorum on the
|
|
648
|
+
* proof path), hashed here (`chainTransaction`). The verdict stands only when the chain
|
|
649
|
+
* shows all of it: our wallet transaction is our Attempt run to the end; each delivery
|
|
650
|
+
* received a message the one before it sent, by the message's cell hash, so no other
|
|
651
|
+
* delivery (another transfer's bounce at the same recipient) stands in for ours, and the
|
|
652
|
+
* message past our jetton wallet carries our jettons onward; and the last one sent the
|
|
653
|
+
* value back, ran nothing, or moved no jettons. A delivery the liteserver does not hold
|
|
654
|
+
* yet decides nothing (a retryable `PROVIDER_UNAVAILABLE`), nor do endpoints that disagree
|
|
655
|
+
* on one (the quorum's `PROVIDER_INCONSISTENT`); a chain that shows otherwise is a
|
|
656
|
+
* retryable `PROVIDER_INCONSISTENT` (logged `BOUNCE_UNPROVEN`), never `success` either: a
|
|
657
|
+
* real bounce may only lack its evidence yet, and the indexer's word decides neither way.
|
|
658
|
+
* Any other verdict passes unchanged.
|
|
659
|
+
*/
|
|
660
|
+
async function confirmBounce(ctx, verdict, from, id, tags) {
|
|
661
|
+
if (verdict.kind !== 'failed')
|
|
662
|
+
return verdict;
|
|
663
|
+
const evidence = verdict.bounce;
|
|
664
|
+
if (evidence === undefined &&
|
|
665
|
+
verdict.reason !== trace_1.REASONS.bounced &&
|
|
666
|
+
verdict.reason !== trace_1.REASONS.jettonBounced) {
|
|
667
|
+
return verdict;
|
|
668
|
+
}
|
|
669
|
+
const unproven = () => {
|
|
670
|
+
ctx.log.warn('the chain does not show the bounce the indexer reports', {
|
|
671
|
+
code: 'BOUNCE_UNPROVEN',
|
|
672
|
+
});
|
|
673
|
+
return new error_1.ProviderError('PROVIDER_INCONSISTENT', 'the chain does not show the bounce the indexer reports', { retryable: true });
|
|
674
|
+
};
|
|
675
|
+
// Only a Gram bounce rests on a bounce phase, the value sent back; a jetton one rests on
|
|
676
|
+
// a jetton wallet that ran nothing or moved nothing.
|
|
677
|
+
if (evidence === undefined ||
|
|
678
|
+
evidence.path.length === 0 ||
|
|
679
|
+
(evidence.end === 'bounced') !== (verdict.reason === trace_1.REASONS.bounced)) {
|
|
680
|
+
throw unproven();
|
|
681
|
+
}
|
|
682
|
+
const ours = await chainTransaction(ctx, { ...evidence.root, account: from }, tags);
|
|
683
|
+
if (!ourRun(ours, from, id))
|
|
684
|
+
throw unproven();
|
|
685
|
+
let sent = messageCells(ours).outbound;
|
|
686
|
+
for (const [index, step] of evidence.path.entries()) {
|
|
687
|
+
const message = sent.find((cell) => hashOf(cell) === step.message);
|
|
688
|
+
if (!message || (index > 0 && !((jettonsFrom(message, from) ?? 0n) > 0n))) {
|
|
689
|
+
throw unproven();
|
|
690
|
+
}
|
|
691
|
+
const tx = await chainTransaction(ctx, step, tags);
|
|
692
|
+
const cells = messageCells(tx);
|
|
693
|
+
const last = index === evidence.path.length - 1;
|
|
694
|
+
if (hashOf(cells.inbound) !== step.message ||
|
|
695
|
+
(last ? !endedAs(tx, evidence.end, from) : !chainRan(tx))) {
|
|
696
|
+
throw unproven();
|
|
697
|
+
}
|
|
698
|
+
sent = cells.outbound;
|
|
699
|
+
}
|
|
700
|
+
return verdict;
|
|
701
|
+
}
|
|
513
702
|
const pageMemo = () => ({
|
|
514
703
|
headers: new Map(),
|
|
515
704
|
jettonWallets: new Map(),
|
|
@@ -602,14 +791,20 @@ function createTonReader(ctx) {
|
|
|
602
791
|
// Anyone's transaction: its execution status as the chain reports it.
|
|
603
792
|
if (wallet === undefined)
|
|
604
793
|
return { ...seen, success: (0, decode_1.executed)(tx) };
|
|
605
|
-
// Our own Attempt: the verdict path.
|
|
794
|
+
// Our own Attempt, found under its id: the verdict path. A bounce, as a jetton leg,
|
|
795
|
+
// stands only once the chain shows it.
|
|
606
796
|
const trace = await api.trace(tx.hash, api_1.MONITOR);
|
|
607
|
-
const verdict = await confirmLegs(ctx, (0, trace_1.attemptVerdict)(tx, trace), wallet, api_1.MONITOR, traceBlock(tx, trace));
|
|
797
|
+
const verdict = await confirmBounce(ctx, await confirmLegs(ctx, (0, trace_1.attemptVerdict)(tx, trace), wallet, api_1.MONITOR, traceBlock(tx, trace)), wallet, hashId(ref.id), api_1.MONITOR);
|
|
608
798
|
if (verdict.kind === 'pending')
|
|
609
799
|
return seen;
|
|
610
800
|
return verdict.kind === 'success'
|
|
611
801
|
? { ...seen, success: true }
|
|
612
|
-
: {
|
|
802
|
+
: {
|
|
803
|
+
...seen,
|
|
804
|
+
success: false,
|
|
805
|
+
reason: verdict.reason,
|
|
806
|
+
...(verdict.failure ? { failure: verdict.failure } : {}),
|
|
807
|
+
};
|
|
613
808
|
},
|
|
614
809
|
getTokenMetadata: async (ref) => jettonMetadata(ctx, jettonMaster(ctx, ref)),
|
|
615
810
|
normalizeTokenRef: (ref) => ({
|