0.0.6 • Published 5 months ago

@tokamak-zk-evm/synthesizer v0.0.6

Weekly downloads
-
License
MPL-2.0
Repository
github
Last release
5 months ago

Tokamak-zk-EVM/synthesizer

What is Synthesizer

You can convert your Ethereum transactions into zero-knowledge proofs (zkp) even if you don't know zkp.

Synthesizer is a compiler that takes an Ethereum transaction as input and returns a wire map (in the form of a permutation map). Combined with the library subcircuits in qap-compiler package, this wire map forms a zkp circuit specialized for the transaction. The transaction specific-circuit will be used as preprocessed input for Tokamak zk-SNARK.

For technical details, see Synthesizer Documentation.

Features

  • Preliminary work for zero-knowledge proof generation and verification
  • Seamless integration with Ethereum's EVM
  • Efficient witness calculation for zk-proofs
  • TypeScript/JavaScript friendly API for blockchain developers
  • Synthesizer is built on top of @ethereumJS/evm as a hardfork.

Version

  • In the current version, Synthesizer generates a circuit that verifies a transaction's signal processing from the inputs such as calldata and state information to the outputs such as storage and event logs.
  • In the next version, Synthesizer will generate a more general circuit that includes verification on the integrity of the input state information.

How to use Synthesizer

Prerequisite

  • Make sure you have the following installed on your system:

    • Node.js (v18 or later)
    • git (v2 or later)
    • tsx (v4 or later): Given Node.js installed, type
      npm install -g tsx
  • Make sure you have the Tokamak zk-EVM repository cloned on your system. For example,

    git clone https://github.com/tokamak-network/Tokamak-zk-EVM.git
    cd Tokamak-zk-EVM
  • Make sure you have installed Playground.

A. Package install

  1. Open a new terminal and go to the package directory.
  2. Install dependencies:
    npm install
    This package install includes some packages in EthereumJS-monorepo.

B. Start Synthesizer through Playground

  1. Run Playground
  2. In the Playground GUI, type a target transaction ID, which is the hash of the target transaction to run Synthesizer. You can get a transaction ID from etherscan.io.
  3. Click the button "Process".
  4. If the transaction contains logs, the GUI will display the outputs of your ZKP circuit, which are expected to be the same as the transaction logs. Verify that the displayed outputs match the transaction logs (we are aware that some transactions are not being processed correctly. We are working on a fix). image image

  5. Now you are ready to move on to the backend of Tokamak zk-EVM.

Supported EVM Operations

OpcodeNameDescriptionStatus
0STOPHalts execution
1ADDAddition operation
2MULMultiplication operation
3SUBSubtraction operation
4DIVInteger division operation
5SDIVSigned integer division operation (truncated)
6MODModulo remainder operation
7SMODSigned modulo remainder operation
8ADDMODModulo addition operation
9MULMODModulo multiplication operation
0aEXPExponential operation
0bSIGNEXTENDExtend length of two’s complement signed integer
10LTLess-than comparison
11GTGreater-than comparison
12SLTSigned less-than comparison
13SGTSigned greater-than comparison
14EQEquality comparison
15ISZEROIs-zero comparison
16ANDBitwise AND operation
17ORBitwise OR operation
18XORBitwise XOR operation
19NOTBitwise NOT operation
1aBYTERetrieve single byte from word
1bSHLLeft shift operation
1cSHRLogical right shift operation
1dSARArithmetic (signed) right shift operation
20KECCAK256Compute Keccak-256 hash⚠️
30ADDRESSGet address of currently executing account
31BALANCEGet balance of the given account
32ORIGINGet execution origination address
33CALLERGet caller address
34CALLVALUEGet deposited value by the instruction/transaction
35CALLDATALOADGet input data of current environment
36CALLDATASIZEGet size of input data in current environment
37CALLDATACOPYCopy input data in current environment to memory
38CODESIZEGet size of code running in current environment
39CODECOPYCopy code running in current environment to memory
3aGASPRICEGet price of gas in current environment
3bEXTCODESIZEGet size of an account’s code
3cEXTCODECOPYCopy an account’s code to memory
3dRETURNDATASIZEGet size of output data from the previous call
3eRETURNDATACOPYCopy output data from the previous call to memory
3fEXTCODEHASHGet hash of an account’s code
40BLOCKHASHGet the hash of one of the 256 most recent complete blocks
41COINBASEGet the block’s beneficiary address
42TIMESTAMPGet the block’s timestamp
43NUMBERGet the block’s number
44PREVRANDAOGet the block’s difficulty
45GASLIMITGet the block’s gas limit
46CHAINIDGet the chain ID
47SELFBALANCEGet balance of currently executing account
48BASEFEEGet the base fee
49BLOBHASHGet versioned hashes
4aBLOBBASEFEEReturns the value of the blob base-fee
50POPRemove item from stack
51MLOADLoad word from memory
52MSTORESave word to memory
53MSTORE8Save byte to memory
54SLOADLoad word from storage
55SSTORESave word to storage
56JUMPAlter the program counter
57JUMPIConditionally alter the program counter
58PCGet the value of the program counter
59MSIZEGet the size of active memory in bytes
5aGASGet the amount of available gas
5bJUMPDESTMark a valid destination for jumps
5cTLOADLoad word from transient storage
5dTSTORESave word to transient storage
5eMCOPYCopy memory areas
5fPUSH0Place value 0 on stack
60 - 7fPUSHxPlace x byte item on stack
80 - 8fDUPxDuplicate xst stack item
90 - 9fSWAPxExchange 1st and xnd stack items
a0 - a4LOGxAppend log record with x topics
f0CREATECreate a new account with associated code
f1CALLMessage-call into an account
f2CALLCODEMessage-call into this account with alternative code
f3RETURNHalt execution returning output data
f4DELEGATECALLStatic message-call into an account
f5CREATE2Create a new account with associated code at predictable
faSTATICCALLStatic message-call into an account
fdREVERTHalt execution reverting state changes
feINVALIDDesignated invalid instruction
ffSELFDESTRUCTHalt execution and delete account

Notes

  • This list is based on Cancun hardfork.
  • ❌: Will be supported in the future release
  • ⚠️: Implemented in a different way than the zkp circuit
  • Precompiled operations will be supported in the future.
  • Synthesizers and the resulting zkp circuits will support tracking of gas usage in the future.
  • Find details in Synthesizer Doc

Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Original contribution

  • JehyukJang: Algorithm design and development. Core functionality implementation.
  • SonYoungsung: Auxiliary functionality implementation. Code organization and optimization. Interface implementation.

License

MPL-2.0