项目进展 AZTEC目前已经在 ethereum mainnet 上线PoC ,应用于 DAI 与 AZTEC Token 的转换,即从 DAI 的明文 ERC20 到密文 AZTEC note 的转换。
目前 AZTEC 也可以实现独立密文 Token 的发布和使用,完全基于密文的 Join Split 交易证明。
目前如果是 2 个输入note,2 个输出note,保密交易的情况下,在 ethereum 的 gas 消耗大概是 900,000gas。如果 EIP1108 上线了的话,gas 消耗大约在 200,000 — 300,000gas 之间。
示例项目 step by step 发布至 Ganache 1.下载,git clone https://github.com/AztecProtocol/aztec-ganache-starter-kit.git
2.安装,cd aztec-ganache-starter-kit && yarn install
3.复制 account 环境,cp RENAME_ME.env .env
4.通过 **package.json **的 script,配合.env 中的 account 配置,启动 Ganache,yarn start
5.通过 **package.json **的 script,按照 truffle-config.js 中的内容,配合migrations中的发布文件,编译合约并发布至 Ganache,yarn migrate
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 ➜ aztec-ganache-starter-kit git:(master) ✗ yarn migrate yarn run v1.16.0 $ truffle compile --all && truffle migrate --reset Compiling your contracts... =========================== > Compiling ./contracts/AceContracts.sol > Compiling ./contracts/Migrations.sol > Compiling ./contracts/TestERC20.sol > Compiling @aztec/protocol/contracts/ACE/ACE.sol > Compiling @aztec/protocol/contracts/ACE/NoteRegistry.sol > Compiling @aztec/protocol/contracts/ACE/validators/adjustSupply/AdjustSupply.sol > Compiling @aztec/protocol/contracts/ACE/validators/adjustSupply/AdjustSupplyABIEncoder.sol > Compiling @aztec/protocol/contracts/ACE/validators/bilateralSwap/BilateralSwap.sol > Compiling @aztec/protocol/contracts/ACE/validators/bilateralSwap/BilateralSwapABIEncoder.sol > Compiling @aztec/protocol/contracts/ACE/validators/dividendComputation/DividendComputation.sol > Compiling @aztec/protocol/contracts/ACE/validators/dividendComputation/DividendComputationABIEncoder.sol > Compiling @aztec/protocol/contracts/ACE/validators/joinSplit/JoinSplit.sol > Compiling @aztec/protocol/contracts/ACE/validators/joinSplit/JoinSplitABIEncoder.sol > Compiling @aztec/protocol/contracts/ACE/validators/privateRange/PrivateRange.sol > Compiling @aztec/protocol/contracts/ACE/validators/privateRange/PrivateRangeABIEncoder.sol > Compiling @aztec/protocol/contracts/ERC1724/ZkAsset.sol > Compiling @aztec/protocol/contracts/ERC1724/ZkAssetMintable.sol > Compiling @aztec/protocol/contracts/ERC1724/ZkAssetOwnable.sol > Compiling @aztec/protocol/contracts/ERC20/ERC20Mintable.sol > Compiling @aztec/protocol/contracts/interfaces/AdjustSupplyInterface.sol > Compiling @aztec/protocol/contracts/interfaces/DividendComputationInterface.sol > Compiling @aztec/protocol/contracts/interfaces/IAZTEC.sol > Compiling @aztec/protocol/contracts/interfaces/IZkAsset.sol > Compiling @aztec/protocol/contracts/interfaces/JoinSplitInterface.sol > Compiling @aztec/protocol/contracts/interfaces/PrivateRangeInterface.sol > Compiling @aztec/protocol/contracts/libs/LibEIP712.sol > Compiling @aztec/protocol/contracts/libs/NoteUtils.sol > Compiling @aztec/protocol/contracts/libs/ProofUtils.sol > Compiling @aztec/protocol/contracts/libs/SafeMath8.sol > Compiling openzeppelin-solidity/contracts/math/SafeMath.sol > Compiling openzeppelin-solidity/contracts/ownership/Ownable.sol > Compiling openzeppelin-solidity/contracts/token/ERC20/ERC20.sol > Compiling openzeppelin-solidity/contracts/token/ERC20/IERC20.sol > Artifacts written to /home/user/Documents/Aztec/aztec-ganache-starter-kit/build/contracts > Compiled successfully using: - solc: 0.5.4+commit.9549d8ff.Emscripten.clang Compiling your contracts... =========================== > Everything is up to date, there is nothing to compile. Starting migrations... ====================== > Network name: 'development' > Network id: 1564378609369 > Block gas limit : 0x6691b7 1_initial_migration.js ====================== Deploying 'Migrations' ---------------------- > transaction hash : 0x6d94779d277c1f3f02ae8bf1e86ca9c62866f308ccd0834347233d2522ac2306 > Blocks: 0 Seconds: 0 > contract address: 0x31bA6208D85a545C75186c51d0F36B1498Fd70bB > block number: 1 > block timestamp: 1564379036 > account: 0x909E433c507A398a5405677B5b2767a3f523F73b > balance: 999.99580786 > gas used: 209607 > gas price: 20 gwei > value sent: 0 ETH > total cost: 0.00419214 ETH > Saving migration to chain. > Saving artifacts ------------------------------------- > Total cost: 0.00419214 ETH 2_ace.js ======== Deploying 'ACE' --------------- > transaction hash : 0x249b155829f8a7c069009129d008751e8c6547d39e54b961cb07d80beec13c29 > Blocks: 0 Seconds: 0 > contract address: 0x7BeDb6777e6fFe535Fc444217A80edf349DB8623 > block number: 3 > block timestamp: 1564379036 > account: 0x909E433c507A398a5405677B5b2767a3f523F73b > balance: 999.9273801 > gas used: 3379461 > gas price: 20 gwei > value sent: 0 ETH > total cost: 0.06758922 ETH Deploying 'AdjustSupply' ------------------------ > transaction hash : 0xc8c52025eb50204fee60bc65cdb7b7abc09345abff8264e0f88b3f4ec80c54f5 > Blocks: 0 Seconds: 0 > contract address: 0x817888dC24398DEE4A53AB6b247b58C3B22F862c > block number: 4 > block timestamp: 1564379037 > account: 0x909E433c507A398a5405677B5b2767a3f523F73b > balance: 999.9142172 > gas used: 658145 > gas price: 20 gwei > value sent: 0 ETH > total cost: 0.0131629 ETH Deploying 'BilateralSwap' ------------------------- > transaction hash : 0xebc929146741026593580155d9d19844c96f65877eb48faa6e43bad2da812db5 > Blocks: 0 Seconds: 0 > contract address: 0xcD53E73dADB6eaD307892C0aBe0bfE5B2f8f570F > block number: 5 > block timestamp: 1564379037 > account: 0x909E433c507A398a5405677B5b2767a3f523F73b > balance: 999.9055876 > gas used: 431480 > gas price: 20 gwei > value sent: 0 ETH > total cost: 0.0086296 ETH Deploying 'JoinSplit' --------------------- > transaction hash : 0x1fa8ac853d1f6c9306418c07e50f85e3fee1a759ccbe79fa5b035fac0083b00c > Blocks: 0 Seconds: 0 > contract address: 0x77c76635fdBE43afECa6A12cE8588010Ea6f2E02 > block number: 6 > block timestamp: 1564379037 > account: 0x909E433c507A398a5405677B5b2767a3f523F73b > balance: 999.8929998 > gas used: 629390 > gas price: 20 gwei > value sent: 0 ETH > total cost: 0.0125878 ETH Deploying 'PrivateRange' ------------------------ > transaction hash : 0x5820bd16d8f9b725f2dcfe965dd7d8dd20e80a763ef1a8e7c2a98c35040d05b0 > Blocks: 0 Seconds: 0 > contract address: 0xe052a2Ab6b49af87265e7d4b245B0AbFE470865b > block number: 7 > block timestamp: 1564379037 > account: 0x909E433c507A398a5405677B5b2767a3f523F73b > balance: 999.88160816 > gas used: 569582 > gas price: 20 gwei > value sent: 0 ETH > total cost: 0.01139164 ETH Deploying 'DividendComputation' ------------------------------- > transaction hash : 0x6154f1716037db818d98ce0293c6370b84fca6977863ce90a5f736451dca4c68 > Blocks: 0 Seconds: 0 > contract address: 0x36cBFA4f87a3771E92D51F41fa0E32d5Ca65f340 > block number: 8 > block timestamp: 1564379038 > account: 0x909E433c507A398a5405677B5b2767a3f523F73b > balance: 999.86990106 > gas used: 585355 > gas price: 20 gwei > value sent: 0 ETH > total cost: 0.0117071 ETH > Saving migration to chain. > Saving artifacts ------------------------------------- > Total cost: 0.12506826 ETH 3_ZkAsset.js ============ Deploying 'TestERC20' --------------------- > transaction hash : 0x166f81eec89ffc816f12dbcb05a581194125df3ab191fc8025c425cd641509e2 > Blocks: 0 Seconds: 0 > contract address: 0x1fE2f08A5D69e6A886B349bd8c26407C0e3Ef89d > block number: 16 > block timestamp: 1564379039 > account: 0x909E433c507A398a5405677B5b2767a3f523F73b > balance: 999.84888398 > gas used: 629044 > gas price: 20 gwei > value sent: 0 ETH > total cost: 0.01258088 ETH Deploying 'ZkAsset' ------------------- > transaction hash : 0xba9cbfe6a1c5de0126ff7152f12b0b72812c652ad63daa6604bcefd186180a96 > Blocks: 0 Seconds: 0 > contract address: 0x8B02C67c7175a48e1aBA3067b5F5eEA29a051ECd > block number: 17 > block timestamp: 1564379039 > account: 0x909E433c507A398a5405677B5b2767a3f523F73b > balance: 999.81309922 > gas used: 1789238 > gas price: 20 gwei > value sent: 0 ETH > total cost: 0.03578476 ETH Deploying 'ZkAssetMintable' --------------------------- > transaction hash : 0xd8d3c7e33af3e7ec5dfdb8e3a0ee5d3928b884011d87035443ab229f5c7a4502 > Blocks: 0 Seconds: 0 > contract address: 0x2E63304e1F9f6AD963540A05D3f385426957A2C7 > block number: 18 > block timestamp: 1564379040 > account: 0x909E433c507A398a5405677B5b2767a3f523F73b > balance: 999.76265604 > gas used: 2522159 > gas price: 20 gwei > value sent: 0 ETH > total cost: 0.05044318 ETH > Saving migration to chain. > Saving artifacts ------------------------------------- > Total cost: 0.09880882 ETH Summary ======= > Total deployments: 10 > Final cost: 0.22806922 ETH Done in 41.03s.
第一步 1_initial_migration.js
第二步 2_ace.js。发布 ACE,setCommonReferenceString
方法建立零知识系统的配置文档
await aceContract.setCommonReferenceString(constants.CRS);
通过 ACE 的setProof(proofId, address)
方法来设定各个执行证明的合约地址。proofId 为 proof 的类别,从@aztec/dev-utils
里面取得定义。address为发布的合约地址
1 2 3 4 5 await aceContract.setProof(MINT_PROOF, AdjustSupply.address); await aceContract.setProof(BILATERAL_SWAP_PROOF, BilateralSwap.address); await aceContract.setProof(DIVIDEND_PROOF, DividendComputation.address); await aceContract.setProof(JOIN_SPLIT_PROOF, JoinSplit.address); await aceContract.setProof(PRIVATE_RANGE_PROOF, PrivateRange.address);
第三步 3_ZkAsset.js。发布零知识资产(ZkAsset)
1 2 3 4 5 6 7 8 9 await deployer.deploy( ZkAsset, aceContract.address, TestERC20.address, 1 , false , true );
此处共计 5 个参数:
1.aceAddress — ACE 的合约地址;
2.linkedTokenAddress — 零知识资产所代表的公开的 ERC20 Token 的合约地址,如不代表特定 Token 则可设定为 address(0);
3.scalingFactor — 是表示与代表的 ERC20 Token 的转换比例,此处为 1:1 转换;
4.canAdjustSupply — owner 是否可以修改 note 的 totalSupply;
5.canConvert — 是否可以将保密 note 转换回到公开的 ERC20 Token
测试 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ➜ aztec-ganache-starter-kit git:(master) ✗ truffle test Using network 'development'. Compiling your contracts... =========================== \> Everything is up to date, there is nothing to compile. Contract: PrivateVenmo Bob wants to deposit 100 Bob succesffully deposited 190 Bob takes a taxi, Sally is the driver The fare comes to 25 Bob paid sally 25 for the taxi and gets 75 back ✓ Bob should be able to deposit 100 then pay sally 25 by splitting notes he owns (5861ms) 1 passing (6s)
测试程序位于test
文件夹内。