o1js icon indicating copy to clipboard operation
o1js copied to clipboard

Add SmartContract.setVerificationKeyUnsafe(vk: VerificationKey)

Open dfstio opened this issue 4 months ago • 0 comments

When building the SmartContract deploy transaction without calling compile(), o1js refuses to build, asking for the verification key to be present. In frontend, it does not make sense to compile the SmartContract if the proving is being made on backend. The workaround now is to directly set the _verificationKey variable using pre-calculated verification keys for different networks:

import { verificationKeys } from "./vk";

const adminContractVerificationKey = verificationKeys[chain]?.admin;
const tokenContractVerificationKey = verificationKeys[chain]?.token;

FungibleTokenAdmin._verificationKey = {
      hash: Field(adminContractVerificationKey.hash),
      data: adminContractVerificationKey.data,
    };
FungibleToken._verificationKey = {
      hash: Field(tokenContractVerificationKey.hash),
      data: tokenContractVerificationKey.data,
    };

The variable _verificationKey is an internal one and can be changed in future o1js versions.

Proposal:

Add SmartContract.setVerificationKeyUnsafe(vk: VerificationKey) to set verification key of the SmartContract without compiling it.

dfstio avatar Sep 30 '24 08:09 dfstio