Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mission31 zk #119

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Compiler files
cache/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/

# Docs
docs/

# Dotenv file
.env

.vscode/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "missions/new/31/contracts/lib/openzeppelin-contracts"]
path = missions/new/31/contracts/lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
34 changes: 34 additions & 0 deletions missions/new/31/contracts/.github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: test

on: workflow_dispatch

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run Forge build
run: |
forge --version
forge build --sizes
id: build

- name: Run Forge tests
run: |
forge test -vvv
id: test
9 changes: 9 additions & 0 deletions missions/new/31/contracts/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[profile.default]
src = "src"
out = "out"
libs = ["lib"]

[rpc_endpoints]
shardeum = "${SHARDEUM_URL}"

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
1 change: 1 addition & 0 deletions missions/new/31/contracts/lib/openzeppelin-contracts
Submodule openzeppelin-contracts added at e50c24
22 changes: 22 additions & 0 deletions missions/new/31/contracts/script/Upgrade.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/Script.sol";
import "../src/UpgradableContract.sol";
import "openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import "openzeppelin-contracts/contracts/proxy/transparent/ProxyAdmin.sol";

contract UpgradeScript is Script {
function setUp() public {}

function run() public {
// uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast();

UpgradableContract upgrade = new UpgradableContract();
ProxyAdmin admin = new ProxyAdmin();
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(address(upgrade), address(admin), "");

vm.stopBroadcast();
}
}
23 changes: 23 additions & 0 deletions missions/new/31/contracts/src/TestUpgrade.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "openzeppelin-contracts/contracts/access/Ownable.sol";
import "openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Upgrade.sol";

contract TestUpgrade is ERC1967Upgrade {
uint256 public importantVariable;
uint256 public upgradeVariable;

function changeImportantVariable(uint256 newValue) external {
importantVariable = newValue;
}

function changeUpgradeVariable(uint256 newValue) external {
upgradeVariable = newValue;
}

function upgradeContract(address newImplementation) external {
require(msg.sender == _getAdmin(), "Not deployer");
_upgradeTo(newImplementation);
}
}
18 changes: 18 additions & 0 deletions missions/new/31/contracts/src/UpgradableContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "openzeppelin-contracts/contracts/access/Ownable.sol";
import "openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Upgrade.sol";

contract UpgradableContract is ERC1967Upgrade {
uint256 public importantVariable;

function changeImportantVariable(uint256 newValue) external {
importantVariable = newValue;
}

function upgradeContract(address newImplementation) external {
require(msg.sender == _getAdmin(), "Not deployer");
_upgradeTo(newImplementation);
}
}
53 changes: 53 additions & 0 deletions missions/new/31/contracts/test/Upgrade.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;

import "forge-std/Test.sol";
import "forge-std/console2.sol";
import "../src/UpgradableContract.sol";
import "../src/TestUpgrade.sol";
import "openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import "openzeppelin-contracts/contracts/proxy/transparent/ProxyAdmin.sol";

contract UpgradeTest is Test {
address public upgrade;
address public upgrade2;
address public proxy;
ProxyAdmin public admin;

function setUp() public {
upgrade = address(new UpgradableContract());
upgrade2 = address(new TestUpgrade());
admin = new ProxyAdmin();
proxy = address(new TransparentUpgradeableProxy(upgrade, address(admin), ""));
}

function testUserTxn() public {
(bool s, ) = proxy.call(abi.encodeWithSignature("changeImportantVariable(uint256)", 123));
require(s);
( , bytes memory data) = proxy.call(abi.encodeWithSignature("importantVariable()"));
assertEq(data, abi.encode(123));
}

function testUpgrade() public {
admin.upgrade(ITransparentUpgradeableProxy(proxy), upgrade2);

(bool s, ) = proxy.call(abi.encodeWithSignature("changeUpgradeVariable(uint256)", 321));
require(s);
( , bytes memory data) = proxy.call(abi.encodeWithSignature("upgradeVariable()"));

vm.prank(address(vm.addr(1)));
(s, ) = proxy.call(abi.encodeWithSignature("changeImportantVariable(uint256)", 123));
require(s);

( , bytes memory data2) = proxy.call(abi.encodeWithSignature("importantVariable()"));
console2.logBytes(data2);

assertEq(data, abi.encode(321));
}

function testUnauthorizedUpgrade() public {
admin.upgrade(ITransparentUpgradeableProxy(proxy), upgrade2);
(bool s, ) = proxy.call(abi.encodeWithSignature("upgradeContract(address)", upgrade2));
assertFalse(s);
}
}
2 changes: 2 additions & 0 deletions missions/new/31/frontend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Infura
NEXT_PUBLIC_INFURA_ID=
7 changes: 7 additions & 0 deletions missions/new/31/frontend/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": ["next", "next/core-web-vitals"],
"rules": {
// Other rules
"@next/next/no-img-element": "off"
}
}
34 changes: 34 additions & 0 deletions missions/new/31/frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel
21 changes: 21 additions & 0 deletions missions/new/31/frontend/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 arisac.eth

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
79 changes: 79 additions & 0 deletions missions/new/31/frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# dApp Starter Boilerplate

A dApp starter kit template to quick start a dapp project with Next.js + Tailwind CSS + Ethers + wagmi + RainbowKit.

Other tools/components included: Headless UI, Heroicons, Autoprefixer, Sass, PostCSS, ESLint, Prettier.

Live preview for this repo: https://dapp-starter.aris.ac

## Getting Started

```bash
# Install Dependencies
yarn

# Run the development server
yarn dev
```

### ENV

```bash
# Copy ENV File
cp .env.example .env.local
```

### Configs

- `src/appConfig.ts`: app name, title, SEO etc.
- `src/pages/_app.tsx`: chains, providers, wallet connectors

### Scripts

**Next.js**

```bash
# Build
yarn build

# Start server with build files
yarn start
```

**Prettier**

```bash
# Use Prettier to do Format Check for files under ./src
yarn fc

# Use Prettier to do Format Fix for files under ./src
yarn ff
```

**Contract Types**

```bash
# Generate contract types from src/contracts/*.json
yarn compile-contract-types
```

### Deployment

The easiest way to deploy your Next.js app is to use [Vercel](https://vercel.com/), by the creators of Next.js.

Check out the [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.

## More

Learn about components of this kit is using:

- [Next.js](https://nextjs.org/) - React Framework by Vercel
- [Tailwind CSS](https://tailwindcss.com/) - Utility-first CSS Framework
- [Ethers.js](https://github.com/ethers-io/ethers.js/) - Compact library for interacting with Ethereum.
- [wagmi](https://wagmi.sh/) - React Hooks for Ethereum
- [RainbowKit](https://rainbowkit.com/) - React library for wallet connections with dApp.
- [Headless UI](https://headlessui.dev/) - Unstyled, fully accessible UI components

## License

This app is open-source and licensed under the MIT license. For more details, check the [License file](LICENSE).
5 changes: 5 additions & 0 deletions missions/new/31/frontend/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
20 changes: 20 additions & 0 deletions missions/new/31/frontend/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
reactStrictMode: true

/* AssetPrefix
--------------------------------------------------------------------------------
AssetPrefix is used to determine where the "app" folder is located.
Use "/" to have it at the root.
Use "./" to have it at the root of the current directory.
Learn more at https://nextjs.org/docs/api-reference/next.config.js/cdn-support-with-asset-prefix
*/
// assetPrefix: './',

/* exportTrailingSlash
--------------------------------------------------------------------------------
exportTrailingSlash is used to determine whether to export a trailing slash
on the generated URL.
Learn more at https://nextjs.org/docs/api-reference/next.config.js/export-trailing-slash
*/
// exportTrailingSlash: true,
}
Loading