From 486f2492243d3a1f3c6a4b26053c1716eee0a150 Mon Sep 17 00:00:00 2001 From: Shahar Yakir Date: Tue, 12 Mar 2024 17:14:24 +0000 Subject: [PATCH] Fix tact injection (#60) * force deploy * fix tact injection * func version fix --- src/check-prerequisites.ts | 4 ++-- src/fetch-compiler-versions.ts | 20 ++++++++++++++++++++ src/fetch-func-versions.ts | 14 -------------- src/server.ts | 5 ++--- src/source-verifier/tact-source-verifier.ts | 9 ++++++++- 5 files changed, 32 insertions(+), 20 deletions(-) create mode 100644 src/fetch-compiler-versions.ts delete mode 100644 src/fetch-func-versions.ts diff --git a/src/check-prerequisites.ts b/src/check-prerequisites.ts index 6640d51..ea61f0c 100644 --- a/src/check-prerequisites.ts +++ b/src/check-prerequisites.ts @@ -1,7 +1,7 @@ import fs from "fs"; import path from "path"; import { binaryPath } from "./binaries"; -import { getFuncVersions } from "./fetch-func-versions"; +import { getSupportedVersions } from "./fetch-compiler-versions"; export async function checkPrerequisites() { const missingEnvVars = [ "VERIFIER_ID", @@ -19,7 +19,7 @@ export async function checkPrerequisites() { if (missingEnvVars) throw new Error("Missing env vars: " + missingEnvVars); - const funcVersions = await getFuncVersions(); + const { funcVersions } = await getSupportedVersions(); const missingFiles = funcVersions! .map((versionDir: string) => [ diff --git a/src/fetch-compiler-versions.ts b/src/fetch-compiler-versions.ts new file mode 100644 index 0000000..8e57408 --- /dev/null +++ b/src/fetch-compiler-versions.ts @@ -0,0 +1,20 @@ +import axios from "axios"; +let versions: { + funcVersions: string[]; + tactVersions: string[]; +} | null = null; + +export async function getSupportedVersions() { + if (!versions) { + const { data } = await axios.get( + "https://raw.githubusercontent.com/ton-community/contract-verifier-config/main/config.json", + { responseType: "json" }, + ); + versions = { + funcVersions: data.funcVersions, + tactVersions: data.tactVersions, + }; + } + + return versions; +} diff --git a/src/fetch-func-versions.ts b/src/fetch-func-versions.ts deleted file mode 100644 index 5dad7e7..0000000 --- a/src/fetch-func-versions.ts +++ /dev/null @@ -1,14 +0,0 @@ -import axios from "axios"; -let funcVersions: string[] | null = null; - -export async function getFuncVersions() { - if (!funcVersions) { - const { data } = await axios.get( - "https://raw.githubusercontent.com/ton-community/contract-verifier-config/main/config.json", - { responseType: "json" }, - ); - funcVersions = data.funcVersions; - } - - return funcVersions; -} diff --git a/src/server.ts b/src/server.ts index 5b94250..fe5c127 100644 --- a/src/server.ts +++ b/src/server.ts @@ -21,8 +21,7 @@ import { TactSourceVerifier, FileSystem } from "./source-verifier/tact-source-ve import { TonReaderClientImpl } from "./ton-reader-client"; import { getLatestVerified } from "./latest-known-contracts"; import { DeployController } from "./deploy-controller"; -import axios from "axios"; -import { getFuncVersions } from "./fetch-func-versions"; +import { getSupportedVersions } from "./fetch-compiler-versions"; const app = express(); app.use(idMiddleware()); @@ -207,7 +206,7 @@ app.get("/hc", (req, res) => { }, ); - await getFuncVersions(); + await getSupportedVersions(); if (process.env.NODE_ENV === "production") checkPrerequisites(); diff --git a/src/source-verifier/tact-source-verifier.ts b/src/source-verifier/tact-source-verifier.ts index 1f52017..796b0d8 100644 --- a/src/source-verifier/tact-source-verifier.ts +++ b/src/source-verifier/tact-source-verifier.ts @@ -4,6 +4,7 @@ import { PackageFileFormat } from "tact-1.1.5"; import type { verify as VerifyFunction } from "tact-1.1.5"; import path from "path"; import { timeoutPromise } from "../utils"; +import { getSupportedVersions } from "../fetch-compiler-versions"; export type FileSystem = { readFile: (path: string) => Promise; @@ -34,6 +35,12 @@ export class TactSourceVerifier implements SourceVerifier { const output: string[] = []; + const { tactVersions } = await getSupportedVersions(); + + if (!tactVersions.includes(pkgParsed.compiler.version)) { + throw new Error("Unsupported tact version: " + pkgParsed.compiler.version); + } + const verify: typeof VerifyFunction = await import(`tact-${pkgParsed.compiler.version}`) .then((m) => m.verify) .catch((e) => { @@ -67,7 +74,7 @@ export class TactSourceVerifier implements SourceVerifier { const sources = await Promise.all( Object.entries(v.files) - .filter(([filename]) => !filename.match(/\.(fif|boc|ts|md|pkg)/)) + .filter(([filename]) => filename.match(/\.(abi|tact|pkg)$/) && !filename.match(/\.\./)) .map(async ([filename, contentB64]) => { const writePath = path.join(payload.tmpDir, filename); let content = Buffer.from(contentB64, "base64").toString("utf-8");