/eigen-secret

Confidential Transaction with Collaborative Traceability, zk-zkRollup

Primary LanguageTypeScript

Eigen Secret

Eigen Secret is a zk-zkRollup providing confidential transaction and selective exposure for users with low gas cost.

Building on Private State Model and zkSnark.

The circuits is written by Circom 2, proved by eigen zkit.

Installation

cp .env.sample .env
## configure .env

npm install
npm run build

Test

npm run test

# optional, which is used to generate the zkey
cd circuits && ./run.sh main_update_state

Task

  1. Start hardhat node
npx hardhat node
  1. Start server in a new terminal
npm run server
  1. Launch another terminal, and run the CI, which includes create-account, deposit, send, and withdraw
npm run deploy --network dev # npx run deploy:dev
npx hardhat ci --network dev

More tasks

Common arguments:

--alias: account id, namely user's alias
--password: password for encrypting the signing key
--contract-file: the contract address, default value is $PWD/.contract.json

The network dev is hardhat node, which is used to debug locally. And the hermez is Polygon zkEVMand .

  1. deploy contracts
npm run deploy:dev

# expose token address in env
export TOKEN=0x0165878A594ca255338adfa4d48449f69242Eb8F
  1. create account, make sure that the server is on.
npx hardhat create-account --alias Alice --index 0 --network dev
 // accountKey:  eig:b82a1b55d3d2becbbb25e75286c4eaa87ba380b46e4dc3f197d3826d5fe69618

can use npx hardhat get-account to get the current account information.

  1. setup rollup coordinator
npx hardhat setup-rollup --network dev

set the current account as the coordinator of Rollup contract

  1. register token
npx hardhat register-token --token $TOKEN --network dev
  1. deposit asset to L2
npx hardhat deposit --alias Alice --index 0 --value 10 --asset-id 2 --network dev
  1. create another account and deposit
npx hardhat create-account --alias Bob --index 1 --network dev

npx hardhat send-l1 --alias Alice --asset-id 2 --receiver 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 --value 100 --network dev

npx hardhat deposit --alias Bob --index 1 --value 10 --asset-id 2 --network dev
  1. send asset to L2
npx hardhat get-account --alias Bob

npx hardhat send --alias Bob --value 5 --index 1 --asset-id 2 --receiver eig:099425cfd131bf4fc0b5f0cf484615c14485d42b3107301dfdeb58814dbfad86 --receiver-alias Alice --network dev
// using Alice's accountKey as the receiver.
  1. get L2 balance
npx hardhat get-balance --alias Bob --index 1 --asset-id 2 --network dev
  1. withdraw
npx hardhat withdraw --alias Bob --index 1 --value 4 --asset-id 2 --network dev
  1. migrate account
npx hardhat migrate-account --alias Alice --index 0 --network dev
  1. update account
npx hardhat update-account --alias Alice --index 0 --network dev

Gas Reporter

npx hardhat test

ETH Price: 1899.33 usd/eth

GasPrice: 20Gwei

Contract Method gas consumption

Contract Method Min Max Avg usd(avg)
Rollup approveToken - - 63083 2.40
Rollup deposit - - 226016 8.59
Rollup processDeposits - - 2086729 79.27
Rollup registerToken - - 49443 1.88
Rollup update 333467 350963 339443 12.89
Rollup withdraw - - 983815 37.37
TestToken approve 46223 46235 46229 1.76
TestToken transfer 26678 51378 50142 1.90
TokenRegistry setRollupNC - - 46053 1.75

Contract deployment gas consumption

Deployments Min Max Avg usd(avg)
PoseidonFacade - - 354579 13.47
Rollup - - 4390248 166.77
SMT 358301 358313 358307 13.61
SpongePoseidon - - 271682 10.32
TestToken - - 735448 27.94
TokenRegistry - - 310495 11.79

SDK

The SDK tutorial is generated by typedoc.

Licence

Not determined, any suggestions are welcome.