Skip to content

Commit

Permalink
wip: contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
dndll committed Feb 14, 2024
1 parent 5342629 commit 3a7eb48
Show file tree
Hide file tree
Showing 24 changed files with 384 additions and 223 deletions.
16 changes: 9 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ local.toml
*.db

# Compiler files
circuits/plonky2x/contracts/cache
circuits/plonky2x/contracts/out
circuits/plonky2x/contracts/lib
circuits/plonky2x/verifier/cache
circuits/plonky2x/verifier/out
circuits/plonky2x/verifier/lib
# Ignores development broadcast logs
!**broadcast
**broadcast/*/31337/
**broadcast/**/dry-run/
circuits/plonky2x/verifier/broadcast

wrapped/
build/

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

# Docs
docs/
Expand Down
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@
[submodule "vendor/succinctx"]
path = vendor/succinctx
url = git@github.com:succinctlabs/succinctx.git
[submodule "circuits/plonky2x/verifier/lib/openzeppelin-contracts-upgradeable"]
path = circuits/plonky2x/verifier/lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
[submodule "circuits/plonky2x/verifier/lib/openzeppelin-contracts"]
path = circuits/plonky2x/verifier/lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "circuits/plonky2x/verifier/lib/foundry-devops"]
path = circuits/plonky2x/verifier/lib/foundry-devops
url = https://github.com/chainaccelorg/foundry-devops
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ test-utils = { path = "crates/test-utils" }
curta = { git = "https://github.com/dndll/starkyx.git" }

[patch."https://github.com/succinctlabs/starkyx.git"]
#curta = { path = "./vendor/starkyx/curta" }
curta = { git = "https://github.com/dndll/starkyx.git" }
curta = { path = "./vendor/starkyx/curta" }
#curta = { git = "https://github.com/dndll/starkyx.git" }

[patch."https://github.com/succinctlabs/succinctx.git"]
#plonky2x = { path = "./vendor/succinctx/plonky2x/core" }
plonky2x = { git = "https://github.com/dndll/succinctx.git" }
plonky2x = { path = "./vendor/succinctx/plonky2x/core" }
#plonky2x = { git = "https://github.com/dndll/succinctx.git" }
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.EXPORT_ALL_VARIABLES:
include .env

TAG_PREFIX?=near
IMAGE_TAG?=0.0.1

Expand All @@ -20,3 +23,36 @@ build-verify-circuit:
RUST_LOG=debug ./build/verify build
.PHONY: build-verify-circuit


SYNC_FUNCTION_ID=0x350c2939eb7ff2185612710a2b641b4b46faab68e1e2c57b6f15e0af0674f5e9
VERIFY_FUNCTION_ID=0x39fb2562b80725bb7538dd7d850126964e565a1a837d2d7f2a018e185b08fc0e
ETH_RPC=https://goerli.gateway.tenderly.co
NEAR_CHECKPOINT_HEADER_HASH=0x63b87190ffbaa36d7dab50f918fe36f70ab26910a0e9d797161e2356561598e3
CHAIN_ID=5
ETH_CONTRACTS_PATH=./circuits/plonky2x/verifier

build-contracts:
cd $(ETH_CONTRACTS_PATH) && forge build

deploy-proxy: build-contracts
cd $(ETH_CONTRACTS_PATH) && forge script Deploy \
--rpc-url $(ETH_RPC) \
--private-key $$ETH_PRIVATE_KEY \
--broadcast \
--verify \
--verifier etherscan
initialise:
cd $(ETH_CONTRACTS_PATH) && forge script Initialise \
--rpc-url $(ETH_RPC) \
--private-key $$ETH_PRIVATE_KEY \
--broadcast \
--verify \
--verifier etherscan

verify:
cd circuits/plonky2x/contracts/ && forge verify-contract \
--chain=5 \
--watch \
--constructor-args $$(cast abi-encode "constructor(address)" "0x6e4f1e9eA315EBFd69d18C2DB974EEf6105FB803") \
0x438634f4dF74CdD6963c750c30E3e9bf9F029838 \
src/NearX.sol:NearX
2 changes: 2 additions & 0 deletions bin/operator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ cfg_if::cfg_if! {
}
}

// TODO: make this use a nicer API for use by the prover.
// TODO: perpetually sync, use queue etc
fn main() {
cfg_if::cfg_if! {
if #[cfg(feature = "sync")] {
Expand Down
6 changes: 0 additions & 6 deletions circuits/plonky2x/contracts/foundry.toml

This file was deleted.

28 changes: 0 additions & 28 deletions circuits/plonky2x/contracts/script/Deploy.s.sol

This file was deleted.

140 changes: 0 additions & 140 deletions circuits/plonky2x/contracts/src/NearX.sol

This file was deleted.

31 changes: 0 additions & 31 deletions circuits/plonky2x/contracts/src/interfaces/INearX.sol

This file was deleted.

1 change: 1 addition & 0 deletions circuits/plonky2x/src/circuits/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod sync;
pub mod verify;

// TODO: CIRCUIT SERIALISATION TESTS!!!
pub use sync::SyncCircuit;
pub use verify::VerifyCircuit;
7 changes: 2 additions & 5 deletions circuits/plonky2x/src/circuits/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@ use crate::{
},
};

pub type ProofMapReduceVariable<const B: usize> = ArrayVariable<ProofVerificationResultVariable, B>;

#[derive(CircuitVariable, Debug, Clone)]
pub struct ProofVerificationResultVariable {
pub id: CryptoHashVariable,
pub result: BoolVariable,
}

// TODO: improve the way we can lookup the transaction, ideally map
// TransactionOrReceiptId => Proof and map this way, now we are not limited by
// the data transformation
pub type ProofMapReduceVariable<const B: usize> = ArrayVariable<ProofVerificationResultVariable, B>;

#[derive(Debug, Clone)]
pub struct VerifyCircuit<const N: usize, const B: usize, const NETWORK: usize = 1>;

Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions circuits/plonky2x/verifier/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[profile.default]
fs_permissions = [ { access = "read", path = "./broadcast" } ]
libs = [ "lib" ]
out = "out"
remappings = [ "@openzeppelin/contracts=lib/openzeppelin-contracts/contracts", "@openzeppelin/contracts-upgradeable=lib/openzeppelin-contracts-upgradeable/contracts" ]
src = "src"
# See more config options https://github.com/foundry-rs/foundry/tree/master/config
1 change: 1 addition & 0 deletions circuits/plonky2x/verifier/lib/foundry-devops
Submodule foundry-devops added at 5415fa
1 change: 1 addition & 0 deletions circuits/plonky2x/verifier/lib/openzeppelin-contracts
Submodule openzeppelin-contracts added at 01ef44
28 changes: 28 additions & 0 deletions circuits/plonky2x/verifier/script/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;

import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {NearX} from "../src/NearX.sol";
import {Script} from "forge-std/Script.sol";

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

function run() external returns (address) {
address proxy = deployNearX();
return proxy;
}

function deployNearX() public returns (address) {
vm.startBroadcast();

NearX lightClient = new NearX();

ERC1967Proxy proxy = new ERC1967Proxy(address(lightClient), "");

lightClient.initialize();

vm.stopBroadcast();
return address(proxy);
}
}
Loading

0 comments on commit 3a7eb48

Please sign in to comment.