Skip to content

Commit

Permalink
Fix tact injection (#60)
Browse files Browse the repository at this point in the history
* force deploy

* fix tact injection

* func version fix
  • Loading branch information
shaharyakir authored Mar 12, 2024
1 parent ef0d74d commit 486f249
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/check-prerequisites.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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) => [
Expand Down
20 changes: 20 additions & 0 deletions src/fetch-compiler-versions.ts
Original file line number Diff line number Diff line change
@@ -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;
}
14 changes: 0 additions & 14 deletions src/fetch-func-versions.ts

This file was deleted.

5 changes: 2 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -207,7 +206,7 @@ app.get("/hc", (req, res) => {
},
);

await getFuncVersions();
await getSupportedVersions();

if (process.env.NODE_ENV === "production") checkPrerequisites();

Expand Down
9 changes: 8 additions & 1 deletion src/source-verifier/tact-source-verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Buffer>;
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 486f249

Please sign in to comment.