Skip to content

Commit

Permalink
fix: witness some safety values in headers and add default result to ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
dndll committed Feb 15, 2024
1 parent bfd57bd commit 771e64b
Show file tree
Hide file tree
Showing 18 changed files with 407 additions and 85 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
[submodule "circuits/plonky2x/verifier/lib/foundry-devops"]
path = circuits/plonky2x/verifier/lib/foundry-devops
url = https://github.com/chainaccelorg/foundry-devops
[submodule "circuits/plonky2x/contract/lib/solidity-bytes-utils"]
path = circuits/plonky2x/contract/lib/solidity-bytes-utils
url = https://github.com/GNSPS/solidity-bytes-utils
20 changes: 9 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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" }
27 changes: 24 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.EXPORT_ALL_VARIABLES:
include .env
-include .env

TAG_PREFIX?=near
IMAGE_TAG?=0.0.1
Expand All @@ -26,7 +26,7 @@ build-verify-circuit:

SYNC_FUNCTION_ID=0x350c2939eb7ff2185612710a2b641b4b46faab68e1e2c57b6f15e0af0674f5e9
VERIFY_FUNCTION_ID=0x39fb2562b80725bb7538dd7d850126964e565a1a837d2d7f2a018e185b08fc0e
ETH_RPC=https://goerli.gateway.tenderly.co
ETH_RPC=https://rpc.goerli.eth.gateway.fm
NEAR_CHECKPOINT_HEADER_HASH=0x63b87190ffbaa36d7dab50f918fe36f70ab26910a0e9d797161e2356561598e3
CHAIN_ID=5
CD_CONTRACTS=cd ./circuits/plonky2x/contract
Expand All @@ -43,12 +43,33 @@ deploy: build-contracts
--verifier etherscan

initialise:
cd $(ETH_CONTRACTS_PATH) && forge script Initialise \
$(CD_CONTRACTS) && forge script Initialise \
--rpc-url $(ETH_RPC) \
--private-key $$ETH_PRIVATE_KEY \
--broadcast \
--verify \
--verifier etherscan
upgrade:
$(CD_CONTRACTS) && forge script Upgrade \
--rpc-url $(ETH_RPC) \
--private-key $$ETH_PRIVATE_KEY \
--broadcast \
--verify \
--verifier etherscan
verify:
$(CD_CONTRACTS) && forge script Verify \
--rpc-url $(ETH_RPC) \
--private-key $$ETH_PRIVATE_KEY \
--broadcast \
--verify \
--verifier etherscan


# verify-contract:
# cd circuits/plonky2x/contracts/ && forge verify-contract \
# --chain=5 \
# --watch \
# 0x438634f4dF74CdD6963c750c30E3e9bf9F029838 \
# src/NearX.sol:NearX
# TODO: upgrade

4 changes: 1 addition & 3 deletions bin/operator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
[package]
edition.workspace = true
license.workspace = true
name = "near-light-client-succint-operator"
name = "near-light-client-succinct-operator"
version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[[bin]]
name = "sync"
path = "src/main.rs"
Expand Down
3 changes: 2 additions & 1 deletion circuits/plonky2x/contract/foundry.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[profile.default]
fs_permissions = [ { access = "read", path = "./broadcast" } ]
libs = [ "lib" ]
optimizer = true
optimizer-runs = 1_000_000
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/contract/lib/solidity-bytes-utils
Submodule solidity-bytes-utils added at e0115c
39 changes: 39 additions & 0 deletions circuits/plonky2x/contract/script/Verify.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {Script} from "forge-std/Script.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {DevOpsTools} from "lib/foundry-devops/src/DevOpsTools.sol";
import {NearX, TransactionOrReceiptId} from "../src/NearX.sol";

contract Verify is Script {
function run() external {
address proxyAddress = DevOpsTools.get_most_recent_deployment(
"ERC1967Proxy",
block.chainid
);
TransactionOrReceiptId[] memory ids = new TransactionOrReceiptId[](2);

ids[0].isTransaction = true;
bytes32 txId = hex"2c53bcfe871da28decc45c3437f5864568d91af6d990dbc2662f11ce44c18d79";
ids[0].id = txId;
bytes
memory txAccount = hex"7a61766f64696c2e746573746e65742c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c";
ids[0].account = txAccount;

ids[1].isTransaction = false;
bytes32 rxId = hex"7ff581f8517ec58459099a5af2465d5232fdcdd7c4da9c3d42a887bf6bd5457e";
ids[1].id = rxId;
bytes
memory rxAccount = hex"70726963656f7261636c652e746573746e65742c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c";
ids[1].account = rxAccount;

vm.startBroadcast();

NearX lightClient = NearX(payable(proxyAddress));

lightClient.requestVerify(ids);

vm.stopBroadcast();
}
}
8 changes: 4 additions & 4 deletions circuits/plonky2x/contract/src/NearX.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Own
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {ISuccinctGateway} from "./interfaces/ISuccinctGateway.sol";
import {INearX, TransactionOrReceiptId, encodePackedIds, decodePackedIds} from "./interfaces/INearX.sol";
import {INearX, TransactionOrReceiptId, ProofVerificationResult, encodePackedIds, decodePackedIds, decodePackedResults} from "./interfaces/INearX.sol";

/// @notice The NearX contract is a light client for Near.
contract NearX is INearX, Initializable, OwnableUpgradeable, UUPSUpgradeable {
Expand Down Expand Up @@ -117,13 +117,13 @@ contract NearX is INearX, Initializable, OwnableUpgradeable, UUPSUpgradeable {
emit VerifyRequested(latestHeader, ids);
}

function handleVerify(bytes memory _output, bytes memory _context)
function handleVerify(bytes calldata _output, bytes memory _context)
external
{
if (msg.sender != gateway || !ISuccinctGateway(gateway).isCallback()) {
revert NotFromSuccinctGateway(msg.sender);
}
TransactionOrReceiptId[] memory ids = decodePackedIds(_output);
emit VerifyResult(ids);
ProofVerificationResult[] memory results = decodePackedResults(_output);
emit VerifyResult(results);
}
}
Loading

0 comments on commit 771e64b

Please sign in to comment.