Skip to content

Commit

Permalink
Addressing review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Zhang <[email protected]>
  • Loading branch information
jimthematrix committed Aug 21, 2024
1 parent 516267b commit d7c4ffe
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 35 deletions.
18 changes: 18 additions & 0 deletions solidity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ This project contains sample implementations of privacy preserving tokens for bo

The Hardhat test cases make use of the `zeto-js` library, which must be built first. Refer to the steps in [the library's README](/zkp/js/README.md#build) to build the proving keys, and verification keys. Make sure you can successfully run the unit tests for the zeto-js library, before returning back here to continue with the hardhat tests for the Solidity implementation.

# Deploy Zeto Token Contracts

Zeto token contracts are all upgradeable contracts. They can be deployed with one of the two hardhat scripts:

- [deploy_upgradeable](/solidity/scripts/deploy_upgradeable.ts): Deploys the target contract, designated by the `ZETO_NAME` environment variable, as a [UUPSUpgradeable contract](https://docs.openzeppelin.com/contracts/4.x/api/proxy#transparent-vs-uups).

```console
export ZETO_NAME=Zeto_AnonEncNullifier
npx hardhat run scripts/deploy_upgradeable.js
```

- [deploy_cloneable](/solidity/scripts/deploy_cloneable.ts): Deploys the target contract, designated by the `ZETO_NAME` environment variable, as a [cloneable contract](https://blog.openzeppelin.com/workshop-recap-cheap-contract-deployment-through-clones).

```console
export ZETO_NAME=Zeto_AnonEncNullifier
npx hardhat run scripts/deploy_cloneable.js
```

# Run The Hardhat Tests

Once the above pre-reqs are complete, you can proceed to run the hardhat tests in this project.
Expand Down
4 changes: 0 additions & 4 deletions solidity/contracts/factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@
// limitations under the License.
pragma solidity ^0.8.20;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {IZetoFungible} from "./lib/interfaces/zeto_fungible.sol";
import {IZetoFungibleInitializable} from "./lib/interfaces/zeto_fungible_initializable.sol";
import {IZetoNonFungibleInitializable} from "./lib/interfaces/zeto_nf_initializable.sol";
import {SampleERC20} from "./erc20.sol";

contract ZetoTokenFactory {
event ZetoTokenDeployed(address indexed zetoToken);
Expand Down
22 changes: 0 additions & 22 deletions solidity/contracts/lib/interfaces/zeto_fungible.sol

This file was deleted.

3 changes: 1 addition & 2 deletions solidity/contracts/lib/zeto_fungible.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ pragma solidity ^0.8.20;
import {Groth16Verifier_CheckHashesValue} from "./verifier_check_hashes_value.sol";
import {Groth16Verifier_CheckNullifierValue} from "./verifier_check_nullifier_value.sol";
import {Commonlib} from "./common.sol";
import {IZetoFungible} from "./interfaces/zeto_fungible.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

/// @title A sample implementation of a base Zeto fungible token contract
/// @author Kaleido, Inc.
/// @dev Defines the verifier library for checking UTXOs against a claimed value.
abstract contract ZetoFungible is IZetoFungible, OwnableUpgradeable {
abstract contract ZetoFungible is OwnableUpgradeable {
// depositVerifier library for checking UTXOs against a claimed value.
// this can be used in the optional deposit calls to verify that
// the UTXOs match the deposited value
Expand Down
17 changes: 10 additions & 7 deletions solidity/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import "@openzeppelin/hardhat-upgrades";
import crypto from "crypto";

const keys = [
crypto.randomBytes(32).toString("hex"),
crypto.randomBytes(32).toString("hex"),
crypto.randomBytes(32).toString("hex"),
crypto.randomBytes(32).toString("hex"),
crypto.randomBytes(32).toString("hex"),
];

const config: HardhatUserConfig = {
solidity: "0.8.20",
Expand All @@ -26,13 +35,7 @@ const config: HardhatUserConfig = {
networks: {
besu: {
url: "http://localhost:8545",
accounts: [
"7bc522e9ba27f118ad4157771bec290f59ffffe45ee66bb81f137043150bd001",
"7bc522e9ba27f118ad4157771bec290f59ffffe45ee66bb81f137043150bd002",
"7bc522e9ba27f118ad4157771bec290f59ffffe45ee66bb81f137043150bd003",
"7bc522e9ba27f118ad4157771bec290f59ffffe45ee66bb81f137043150bd004",
"7bc522e9ba27f118ad4157771bec290f59ffffe45ee66bb81f137043150bd005",
],
accounts: keys,
gasPrice: 0,
}
}
Expand Down
2 changes: 2 additions & 0 deletions solidity/test/lib/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ export async function deployZeto(tokenName: string) {
}

if (process.env.USE_FACTORY !== 'true') {
console.log('Deploying as upgradeable contracts');
// setup via the deployment scripts
const deployFunc = isFungible ? deployFungibleUpgradeable : deployNonFungibleUpgradeable;
const result = await deployFunc(tokenName);
({ deployer, zeto, erc20 } = result as any);
} else {
console.log('Deploying as cloneable contracts using "ZetoTokenFactory"');
let args, zetoImpl;
const deployFunc = isFungible ? deployFungibleCloneable : deployNonFungibleCloneable;
const result = await deployFunc(tokenName);
Expand Down

0 comments on commit d7c4ffe

Please sign in to comment.