百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

starlight

> 编程语言
开源

:zap: 固态 --> zApp 编译器 :zap:

200 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

:zap: 固态 --> zApp 编译器 :zap:

This code is not owned by EY and EY provides no warranty and disclaims any and all liability for use of this code. Users must conduct their own diligence with respect to use for their purposes and any and all usage is on an as-is basis and at your own risk.

starlight :stars:

Generate a zApp from a Solidity contract.


Introduction

zApps are zero-knowledge applications. They're like dApps (decentralised applications), but with privacy. zApps are tricky to write, but Solidity contracts are lovely to write. So why not try to write a zApp with Solidity?

starlight helps developers do just this...

  • Write a Solidity contract
  • Add a few new privacy decorators to the contract (to get a 'Zolidity' contract)
  • Run zappify
  • Get a fully working zApp in return

Solidity contract --> Zolidity contract --> zappify --> zApp

The main objective of this transpiler is to enable developers to quickly draft frameworks for zApps.

See here for the gitbook, and here for an enormously detailed explanation of how the transpiler works.


Warnings

This code is not owned by EY and EY provides no warranty and disclaims any and all liability for use of this code. Users must conduct their own diligence with respect to use for their purposes and any and all usage is on an as-is basis and at your own risk.

Note that this is an experimental prototype which is still under development. Not all Solidity syntax is currently supported. Here is guide to current functionality.

This code has not yet completed a security review and therefore we strongly recommend that you do not use it in production. We take no responsibility for any loss you may incur through the use of this code.

Due to its experimental nature, we strongly recommend that you do not use any zApps which are generated by this transpiler to transact items of material value.

Output zApps use the proof system Groth16 which is known to have vulnerabilities. Check if you can protect against them, or are protected by the zApps logic.

In the same way that Solidity does not protect against contract vulnerabilities, Starlight cannot protect against zApp vulnerabilities once they are written into the code. This compiler assumes knowledge of smart contract security.

Note on integer limits: Starlight compiles your Solidity contract into a zApp written in JavaScript. Unlike Solidity's uint256 (which supports integers up to 2^256-1), JavaScript's standard Number type can only safely represent integers up to 9,007,199,254,740,991 (2^53 – 1), known as Number.MAX_SAFE_INTEGER. This means that values above 2^53–1 are not fully supported in the JavaScript output, and large values will lose precision or behave unexpectedly. When designing your contracts, ensure that all values remain within the safe integer range for JavaScript.


  • starlight :stars:
    • Introduction
    • Warnings
    • Requirements
    • Quick User Guide
    • Install via npm
      • Troubleshooting
    • Install via clone
    • Run
      • CLI options
    • Troubleshooting
      • Installation
      • Compilation
    • Developer
      • Testing
        • full zapp
        • Private Swap Contract
          • Deposit Tokens
          • Initiate Swap
          • Complete Swap
          • Cancel Swap
        • Using secret states in the constructor
        • Deploy on public testnets
          • CLI options
        • circuit
      • Zokrates Worker
      • Contributing
    • License
    • Acknowledgements

Requirements

To run the zappify command:

  • Node.js v15 or higher (Known issues with v13 and v18).

To run the resulting zApp:

  • Node.js v15 or higher.
  • Docker (with 16GB RAM recommended)
  • Mac and Linux machines with at least 16GB of memory and 10GB of disk space are supported.

Quick User Guide

1. Creating a Zolidity (.zol) contract from a standard Solidity (.sol) contract

When writing zolidity contracts note that not all Solidity syntax is currently supported. Here is a guide to current functionality.

Zolidity decorators: secret, known, unknown, encrypt, sharedSecret and re-initialisable

In Starlight, each secret variable is assigned an owner. The owner holds a secret key that allows them to access the private value and update that variable. Secret variables are stored on-chain via commitments, and the original data (preimage) is kept locally by the owner.

Zolidity extends Solidity with the following decorators:

  • secret: Marks a variable or parameter as private, so its value is hidden from other users and only accessible to its owner.
  • known: Indicates that only the variable owner can modify the variable. By default all variables are known.
  • unknown: Allows any user to increment the variable, not just the owner.
  • encrypt: Use when creating a commitment for another user (e.g., with unknown). Ensures, via zk-proofs, that a correct encryption of the commitment pre-image is broadcast and can be decrypted by the owner so that the commitment can be used in the future.
  • sharedSecret: Marks a secret variable that is shared between two owners, for applications such as Swaps.
  • re-initialisable: Allows a secret variable to be re-initialised, if later in the contract it is burned.

Start with a standard Solidity contract, for example:

solidity
// SPDX-License-Identifier: CC0

pragma solidity ^0.8.0;

contract Assign {
  uint256 private a;

  function assign(uint256 value) public {
    a = value;
  }
}

To convert your Solidity contract to a Zolidity contract, insert the secret keyword in front of the declaration of any state variable, local variable, or function parameter you want to keep private:

…

Example: Using the re-initisalisable decorator

In the contract below, the owner of tokenOwners[tokenId] is the address stored as its mapping value. When withdraw is called, the commitment is nullified and the new value is address(0), so no new commitment is created. This creates a problem if deposit is called again: how can a new owner provide a nullifier if the token was previously owned? The re-initialisable decorator solves this by allowing the variable to be re-initialised in deposit. Note that in the below contract the check require(tokenOwners[tokenId] == msg.sender, "You're not the owner of this token."); is essential to ensure that tokenOwners[tokenId] cannot be re-initialised maliciously in either transfer or withdraw. For a non re-initialisable secret variable this check would not be necessary because only the owner could modify it.

…

Save these decorated contracts with a .zol extension (for example, Assign.zol and CharityPot.zol). These files are now Zolidity contracts.


2. Using zappify to transpile Zolidity to a standalone zApp

Once you have your Zolidity (.zol) contract, run the following command to generate a standalone zApp:

zappify -i 

This will transpile your contract into an entire standalone zApp, outputting it to the ./zapps/ directory by default.


Install via npm

Starlight is now available on github's npm package repository! To install, you need to make sure that npm is looking in that registry, not the default npmjs:

npm config set @eyblockchain:registry https://npm.pkg.github.com `

Then you can import the zappify command like so:

import { zappify } from "@eyblockchain/starlight";

The only required input for zappify is the file path of the .zol file you'd like to compile, e.g. zappify('./contracts/myContract.zol'). You can optionally add a specific zApp name and the output directory:

zappify('./contracts/myContract.zol', 'myzApp', './test_zApps')

Then it works just as described in the below section Run.

Troubleshooting

Since we push the npm package to github's repository, you may need to specify the package location in your project's .npmrc file and authenticate to github. Try adding something like:

@eyblockchain:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=

...and re-run the install command, or manually add "@eyblockchain/starlight" to your package.json.

Install via clone

To install via github:

Clone the repo.

cd starlight

./bin/start (You might need to run chmod +x ./bin/start for permission to execute the newly created shell scripts)

This runs tsc and npm i -g ./ which will create a symlink to your node.js bin, allowing you to run the commands specified in the "bin": field of the package.json; namely the zappify command.

Run

zappify -i ./path/to/MyZolidityContract.zol

... converts a Zolidity contract into a zApp. By default, the zApp is output to a ./zapps/ folder.

CLI options

option abbr. description
--input -i Specify an input contract file with a .zol extension.
--output -o Specify an output directory for the zApp. By default, the zApp is output to a ./zapps/ folder.
--zapp-name -z Otherwise files get output to a folder with name matching that of the input file.
--log-level - Specify a Winston log level type.
--help -h CLI help.

Troubleshooting

Installation

If the zappify command isn't working, try the Install steps again. You might need to try npm i --force -g ./.

In very rare cases, you might need to navigate to your node.js innards and delete zappify from the bin and lib/node_modules. To find where your npm lib is, type npm and it will tell you the path.

E.g.:

~/.nvm/versions/node/v15.0.1/lib/node_modules/npm
                              ^
                              lib
                              ^
                              bin is also at this level

Compilation

If you find errors to do with 'knownness' or 'unknownness', try to mark incrementations. If you have any secret states which can be incremented by other users, mark those incrementations as unknown (since the value may be unknown to the caller).

solidity
// SPDX-License-Identifier: CC0

pragma solidity ^0.8.0;

contract Assign {

  secret uint256 private a; // ` in JSON format. Each variable should be named like the original parameter. For example, if you wanted to call `add` with the value 10, send:

{ value: 10 }

to `http://localhost:3000/add`. This would (privately) increase the value of secret state `a` by 10, and return the shield contract's transaction.

To access your secret data locally, you can look at all the commitments you have by sending a GET request to `http://localhost:3000/getAllCommitments`.

You can also filter these commitments by variable name. Using the example above, if you wanted to see all commitments you have representing the variable `a`, send:

{ "name": "a" }

as a GET request to `http://localhost:3000/getCommitmentsByVariableName`.

If the commitment database that stores commitment preimages is lost you can restore the DB (by decrypting the onchain encryptions of the preimages) by sending a POST request to `http://localhost:3000/backupDataRetriever`. You can also restore only the commitments with a specific variable name. For ex

Issues· 7 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言