diff --git a/solidity/README.md b/solidity/README.md index cb6b4fc..7b23d7b 100644 --- a/solidity/README.md +++ b/solidity/README.md @@ -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. diff --git a/solidity/contracts/factory.sol b/solidity/contracts/factory.sol index 706b442..10d72bb 100644 --- a/solidity/contracts/factory.sol +++ b/solidity/contracts/factory.sol @@ -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); diff --git a/solidity/contracts/lib/interfaces/zeto_fungible.sol b/solidity/contracts/lib/interfaces/zeto_fungible.sol deleted file mode 100644 index 98b507f..0000000 --- a/solidity/contracts/lib/interfaces/zeto_fungible.sol +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright © 2024 Kaleido, Inc. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -pragma solidity ^0.8.20; - -import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; - -interface IZetoFungible { - function setERC20(IERC20 _erc20) external; -} diff --git a/solidity/contracts/lib/zeto_fungible.sol b/solidity/contracts/lib/zeto_fungible.sol index 6d151ee..2b59285 100644 --- a/solidity/contracts/lib/zeto_fungible.sol +++ b/solidity/contracts/lib/zeto_fungible.sol @@ -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 diff --git a/solidity/hardhat.config.ts b/solidity/hardhat.config.ts index cc6ed24..81e7bd1 100644 --- a/solidity/hardhat.config.ts +++ b/solidity/hardhat.config.ts @@ -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", @@ -26,13 +35,7 @@ const config: HardhatUserConfig = { networks: { besu: { url: "http://localhost:8545", - accounts: [ - "7bc522e9ba27f118ad4157771bec290f59ffffe45ee66bb81f137043150bd001", - "7bc522e9ba27f118ad4157771bec290f59ffffe45ee66bb81f137043150bd002", - "7bc522e9ba27f118ad4157771bec290f59ffffe45ee66bb81f137043150bd003", - "7bc522e9ba27f118ad4157771bec290f59ffffe45ee66bb81f137043150bd004", - "7bc522e9ba27f118ad4157771bec290f59ffffe45ee66bb81f137043150bd005", - ], + accounts: keys, gasPrice: 0, } } diff --git a/solidity/test/lib/deploy.ts b/solidity/test/lib/deploy.ts index daff6dc..26a2ff6 100644 --- a/solidity/test/lib/deploy.ts +++ b/solidity/test/lib/deploy.ts @@ -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);