From fd833f79f80d18e0031ee02af696cfad4c9a477d Mon Sep 17 00:00:00 2001 From: i582 <51853996+i582@users.noreply.github.com> Date: Mon, 13 Oct 2025 15:03:13 +0400 Subject: [PATCH 1/2] feat(instructions): add TVM 12 instructions --- package.json | 2 +- src/features/spec/gen/tvm-specification.json | 129 +++++++++++++++++++ yarn.lock | 24 +++- 3 files changed, 147 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 88c598ea..a73a9848 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "react-helmet-async": "^2.0.5", "react-icons": "^5.5.0", "react-markdown": "^10.1.0", - "ton-assembly": "0.2.4", + "ton-assembly": "0.5.0", "txtracer-core": "^0.3.1" }, "devDependencies": { diff --git a/src/features/spec/gen/tvm-specification.json b/src/features/spec/gen/tvm-specification.json index e108a1e1..c7762556 100644 --- a/src/features/spec/gen/tvm-specification.json +++ b/src/features/spec/gen/tvm-specification.json @@ -67960,6 +67960,135 @@ "line_number": 176, "function_name": "exec_get_var_in_msg_param" } + }, + "BTOS": { + "category": "cell", + "sub_category": "cell_deserialize", + "description": { + "short": "Converts a _Builder_ into a _Slice_.", + "long": "This instruction is equivalent to `ENDC`, `CTOS` without extra gas for intermediate Cell creation.", + "tags": [], + "operands": [], + "exit_codes": [], + "other_implementations": [ + { + "exact": true, + "instructions": ["ENDC", "CTOS"] + } + ], + "gas": [ + { + "value": 26, + "description": "Base gas consumption" + } + ] + }, + "layout": { + "min": 13586432, + "max": 13586688, + "checkLen": 16, + "skipLen": 16, + "args": { + "$": "simpleArgs", + "children": [] + }, + "exec": "exec_builder_to_slice", + "version": 12, + "kind": "simple", + "prefix": 53072, + "prefix_str": "CF50" + }, + "signature": { + "stack_string": "b:Builder -> s:Slice", + "inputs": { + "stack": [ + { + "type": "simple", + "name": "b", + "value_types": ["Builder"] + } + ] + }, + "outputs": { + "stack": [ + { + "type": "simple", + "name": "s", + "value_types": ["Slice"] + } + ] + } + }, + "implementation": { + "commit_hash": "4ebd7412c52248360464c2df5f434c8aaa3edfe1", + "file_path": "crypto/vm/cellops.cpp", + "line_number": 767, + "function_name": "exec_builder_to_slice" + } + }, + "HASHBU": { + "category": "crypto", + "sub_category": "crypto_common", + "description": { + "short": "", + "long": "Computes the hash of a _Builder_ `b` and returns it as a 256-bit unsigned integer `hash`. The result is the same as if an ordinary cell containing only data and references from `b` had been created and its hash computed by `HASHCU`.", + "tags": [], + "operands": [], + "other_implementations": [ + { + "exact": true, + "instructions": ["ENDC", "HASHCU"] + } + ], + "gas": [ + { + "value": 26, + "description": "Base gas consumption" + } + ] + }, + "layout": { + "min": 16324096, + "max": 16324352, + "checkLen": 16, + "skipLen": 16, + "args": { + "$": "simpleArgs", + "children": [] + }, + "exec": "exec_compute_hash", + "version": 12, + "kind": "simple", + "prefix": 63766, + "prefix_str": "F916" + }, + "signature": { + "stack_string": "b:Builder -> hash:Int", + "inputs": { + "stack": [ + { + "type": "simple", + "name": "b", + "value_types": ["Builder"] + } + ] + }, + "outputs": { + "stack": [ + { + "type": "simple", + "name": "hash", + "value_types": ["Int"] + } + ] + } + }, + "implementation": { + "commit_hash": "4ebd7412c52248360464c2df5f434c8aaa3edfe1", + "file_path": "crypto/vm/tonops.cpp", + "line_number": 612, + "function_name": "exec_compute_hash" + } } }, "fift_instructions": { diff --git a/yarn.lock b/yarn.lock index 42ddf975..67eebee0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11586,20 +11586,30 @@ __metadata: languageName: node linkType: hard -"ton-assembly@npm:0.2.4": - version: 0.2.4 - resolution: "ton-assembly@npm:0.2.4" +"ton-assembly@npm:0.5.0": + version: 0.5.0 + resolution: "ton-assembly@npm:0.5.0" dependencies: - "@ton/core": "npm:^0.60.1" "@tonstudio/parser-runtime": "npm:^0.0.1" cac: "npm:^6.7.14" + ton-source-map: "npm:^0.2.2" peerDependencies: - "@ton/core": ">=0.60.1" + "@ton/core": ">=0.61.0" + peerDependenciesMeta: + "@ton/core": + optional: false bin: tasm: dist/cli/assembler.js tdisasm: dist/cli/disassembler.js tfift: dist/cli/fift-compiler.js - checksum: 10c0/453042e3776ba9cf72dd1186643f5c79ce6c4dc88daadd56ee7eceeb68e0d20c1e70e7e2bab529288398eea2d2ddc41408e59e07d1bffe8699aaed09eab8badd + checksum: 10c0/f35e598c835c852eda6d71b6bf8a791b5015fda77f6ca3896902aac4057f11a62663d7f1dda9aa013c5420dabc818a33d028d20c4a058df16d5b2706bfddef21 + languageName: node + linkType: hard + +"ton-source-map@npm:^0.2.2": + version: 0.2.2 + resolution: "ton-source-map@npm:0.2.2" + checksum: 10c0/c1e0413983f589a1dfcbb53aa35d04f42244e88d75899eb4c04a3733ac37d2a915063dc91a726409b0239e4a039059d860e1069efb9c8faa6580d06c8b88f3a0 languageName: node linkType: hard @@ -11822,7 +11832,7 @@ __metadata: stylelint: "npm:^16.24.0" stylelint-config-css-modules: "npm:^4.5.1" stylelint-config-standard: "npm:^39.0.0" - ton-assembly: "npm:0.2.4" + ton-assembly: "npm:0.5.0" ts-node: "npm:^10.9.1" txtracer-core: "npm:^0.3.1" typescript: "npm:~5.8.3" From e66c46fe15fd6c676e08a885f03555259da3b2ed Mon Sep 17 00:00:00 2001 From: i582 <51853996+i582@users.noreply.github.com> Date: Mon, 13 Oct 2025 15:16:41 +0400 Subject: [PATCH 2/2] update --- src/features/godbolt/lib/func/compilation.ts | 13 ++++++++----- src/features/godbolt/lib/tolk/compilation.ts | 11 +++++++---- src/features/godbolt/lib/tolk/types.ts | 5 +++-- src/features/tasm/lib/executor.ts | 5 +++-- src/features/txTrace/hooks/useFuncLineStepper.ts | 3 ++- src/features/txTrace/lib/traceTx.ts | 5 ++--- .../GodboltPage/hooks/useSourceMapHighlight.ts | 3 ++- 7 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/features/godbolt/lib/func/compilation.ts b/src/features/godbolt/lib/func/compilation.ts index 3d457975..7685c4e3 100644 --- a/src/features/godbolt/lib/func/compilation.ts +++ b/src/features/godbolt/lib/func/compilation.ts @@ -1,5 +1,6 @@ import {Cell} from "@ton/core" import {runtime as i, text, trace} from "ton-assembly" +import type {InstructionInfo} from "ton-source-map" import {FUNC_STDLIB} from "@features/godbolt/lib/func/stdlib.ts" import {funcCompile} from "@features/godbolt/lib/func/func-wasm/func-compile.ts" @@ -10,7 +11,7 @@ export interface FuncCompilationResult { readonly code: string readonly assembly: string readonly sourceMap?: trace.FuncMapping - readonly mapping: Map + readonly mapping: Map } export class FuncCompilationError extends Error { @@ -51,12 +52,14 @@ export const compileFuncCode = async (code: string): Promise() + const debugSectionToInstructions = new Map() for (const instr of allInstructions) { - const arr = debugSectionToInstructions.get(instr.debugSection) ?? [] - arr.push(instr) - debugSectionToInstructions.set(instr.debugSection, arr) + for (const debugSection of instr.debugSections) { + const arr = debugSectionToInstructions.get(debugSection) ?? [] + arr.push(instr) + debugSectionToInstructions.set(debugSection, arr) + } } return { diff --git a/src/features/godbolt/lib/tolk/compilation.ts b/src/features/godbolt/lib/tolk/compilation.ts index 52d8e8a5..258bd105 100644 --- a/src/features/godbolt/lib/tolk/compilation.ts +++ b/src/features/godbolt/lib/tolk/compilation.ts @@ -1,5 +1,6 @@ import {Cell} from "@ton/core" import {runtime as i, text, trace} from "ton-assembly" +import type {InstructionInfo} from "ton-source-map" import {runTolkCompiler} from "@ton/tolk-js" @@ -27,12 +28,14 @@ export const compileTolkCode = async (code: string): Promise() + const debugSectionToInstructions = new Map() for (const instr of allInstructions) { - const arr = debugSectionToInstructions.get(instr.debugSection) ?? [] - arr.push(instr) - debugSectionToInstructions.set(instr.debugSection, arr) + for (const debugSection of instr.debugSections) { + const arr = debugSectionToInstructions.get(debugSection) ?? [] + arr.push(instr) + debugSectionToInstructions.set(debugSection, arr) + } } return { diff --git a/src/features/godbolt/lib/tolk/types.ts b/src/features/godbolt/lib/tolk/types.ts index 8029b442..96702b92 100644 --- a/src/features/godbolt/lib/tolk/types.ts +++ b/src/features/godbolt/lib/tolk/types.ts @@ -1,11 +1,12 @@ -import {runtime as i, trace} from "ton-assembly" +import {runtime as i} from "ton-assembly" +import type {InstructionInfo} from "ton-source-map" export interface TolkCompilationResult { readonly lang: "tolk" readonly instructions: i.Instr[] readonly code: string readonly assembly: string - readonly mapping: Map + readonly mapping: Map } export class TolkCompilationError extends Error { diff --git a/src/features/tasm/lib/executor.ts b/src/features/tasm/lib/executor.ts index d3c578ff..2dba769f 100644 --- a/src/features/tasm/lib/executor.ts +++ b/src/features/tasm/lib/executor.ts @@ -3,7 +3,8 @@ import type {Address, Contract, ContractProvider, Sender, StateInit, TupleReader import {Cell, contractAddress, toNano, TupleBuilder} from "@ton/core" import {GetMethodError, type SandboxContract, type TreasuryContract} from "@ton/sandbox" import {Blockchain} from "@ton/sandbox" -import {createMappingInfo, type MappingInfo} from "ton-assembly/dist/trace/mapping" +import {createMappingInfo} from "ton-assembly/dist/trace/mapping" +import type {AssemblyMapping} from "ton-source-map" import type {StackElement} from "ton-assembly/dist/trace" import {type ExitCode, findExitCode} from "@features/txTrace/lib/traceTx.ts" @@ -112,7 +113,7 @@ export interface AssemblyExecutionResult { readonly vmLogs: string readonly instructions: i.Instr[] readonly code: string - readonly mappingInfo: MappingInfo | null + readonly mappingInfo: AssemblyMapping | null readonly exitCode: ExitCode | undefined readonly traceInfo: trace.TraceInfo | undefined } diff --git a/src/features/txTrace/hooks/useFuncLineStepper.ts b/src/features/txTrace/hooks/useFuncLineStepper.ts index 76b94cf2..f2f2834b 100644 --- a/src/features/txTrace/hooks/useFuncLineStepper.ts +++ b/src/features/txTrace/hooks/useFuncLineStepper.ts @@ -1,10 +1,11 @@ import {useCallback, useEffect, useMemo, useState} from "react" import {trace} from "ton-assembly" +import type {InstructionInfo} from "ton-source-map" import type {UseTraceStepperReturn} from "./useTraceStepper" export interface CompilationResult { - readonly mapping?: Map + readonly mapping?: Map readonly assembly?: string readonly funcSourceMap?: trace.FuncMapping } diff --git a/src/features/txTrace/lib/traceTx.ts b/src/features/txTrace/lib/traceTx.ts index 500f065b..16659e8b 100644 --- a/src/features/txTrace/lib/traceTx.ts +++ b/src/features/txTrace/lib/traceTx.ts @@ -3,8 +3,6 @@ import type {TraceResult} from "txtracer-core/dist/types" import {compileCellWithMapping, decompileCell} from "ton-assembly/dist/runtime/instr" import { createMappingInfo, - type InstructionInfo, - type MappingInfo, } from "ton-assembly/dist/trace/mapping" import {type Step, type TraceInfo} from "ton-assembly/dist/trace" import {createTraceInfoPerTransaction, findInstructionInfo} from "ton-assembly/dist/trace/trace" @@ -29,6 +27,7 @@ import { TxNotFoundError, TxTraceError, } from "./errors" +import type {AssemblyMapping, InstructionInfo} from "ton-source-map" export type ExitCode = { readonly num: number @@ -135,7 +134,7 @@ export function findException(reversedEntries: l.VmLine[]) { return mapped.find(it => it !== undefined) } -export function findExitCode(vmLogs: string, mappingInfo: MappingInfo) { +export function findExitCode(vmLogs: string, mappingInfo: AssemblyMapping) { const res = l.parse(vmLogs) const reversedEntries = [...res].reverse() const description = findException(reversedEntries) diff --git a/src/pages/GodboltPage/hooks/useSourceMapHighlight.ts b/src/pages/GodboltPage/hooks/useSourceMapHighlight.ts index 001724f6..8a702453 100644 --- a/src/pages/GodboltPage/hooks/useSourceMapHighlight.ts +++ b/src/pages/GodboltPage/hooks/useSourceMapHighlight.ts @@ -4,6 +4,7 @@ import type * as monaco from "monaco-editor" import {trace} from "ton-assembly" import type {HighlightGroup, HighlightRange} from "@shared/ui/CodeEditor" +import type {InstructionInfo} from "ton-source-map" export interface UseSourceMapHighlightReturn { readonly funcHighlightGroups: readonly HighlightGroup[] @@ -78,7 +79,7 @@ const COLORS = [ export function useSourceMapHighlight( sourceMap: trace.FuncMapping | undefined, - debugSectionToInstructions?: Map, + debugSectionToInstructions?: Map, funcEditorRef?: React.RefObject, asmEditorRef?: React.RefObject, originalAsmCode?: string,