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

feat(light-client): Update contract to trusted setup #389

Open
wants to merge 3 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
pragma solidity 0.8.20;

interface ILightClient {
struct LightClientUpdate {
Expand Down Expand Up @@ -32,5 +32,5 @@ interface ILightClient {

function lightClientUpdate(
LightClientUpdate calldata update
) external payable;
) external;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
pragma solidity 0.8.20;

import '../../utils/LightClientUpdateVerifier.sol';
import '../../interfaces/ILightClient.sol';
import '@openzeppelin/contracts/access/Ownable.sol';

uint256 constant BUFER_SIZE = 32;

contract BeaconLightClient is LightClientUpdateVerifier, ILightClient {
contract BeaconLightClient is Ownable, LightClientUpdateVerifier, ILightClient {
error ProofVerificationFailed();
error InvalidAccessControll();

bytes32[BUFER_SIZE] public optimisticHeaders;

uint256[BUFER_SIZE] public optimisticSlots;
Expand All @@ -19,13 +23,15 @@ contract BeaconLightClient is LightClientUpdateVerifier, ILightClient {

bytes32 domain;

address adapterAddress;

constructor(
bytes32 _optimisticHeaderRoot,
uint256 _optimisticHeaderSlot,
bytes32 _finalizedHeaderRoot,
bytes32 _executionStateRoot,
bytes32 _domain
) {
) Ownable(msg.sender) {
currentIndex = 0;

optimisticHeaders[currentIndex] = _optimisticHeaderRoot;
Expand All @@ -51,13 +57,17 @@ contract BeaconLightClient is LightClientUpdateVerifier, ILightClient {
return executionStateRoots[currentIndex];
}

// TODO: fix name to lightClientUpdate
function lightClientUpdate(LightClientUpdate calldata update)
external
payable
{
require(
verifyUpdate(
function changeAdapterAddress(address _adapterAddress) external onlyOwner {
adapterAddress = _adapterAddress;
}

function lightClientUpdate(LightClientUpdate calldata update) external {
if (msg.sender != adapterAddress && msg.sender != owner()) {
revert InvalidAccessControll();
}

if (
!verifyUpdate(
update.a,
update.b,
update.c,
Expand All @@ -67,9 +77,10 @@ contract BeaconLightClient is LightClientUpdateVerifier, ILightClient {
update.finalizedHeaderRoot,
update.finalizedExecutionStateRoot,
domain
),
'!proof'
);
)
) {
revert ProofVerificationFailed();
}

currentIndex = (currentIndex + 1) % BUFER_SIZE;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
pragma solidity 0.8.20;

import './Verifier.sol';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ contract Groth16Verifier {
uint256 constant gammax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781;
uint256 constant gammay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531;
uint256 constant gammay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930;
uint256 constant deltax1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634;
uint256 constant deltax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781;
uint256 constant deltay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531;
uint256 constant deltay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930;
uint256 constant deltax1 = 2343236923834963358037492110423434801285275176030641534786585479610777991492;
uint256 constant deltax2 = 7354734418275536777818704753730665460248350105717340249623478132690757632061;
uint256 constant deltay1 = 14156031723817663434631995261455976608108837842676842217057543351737739467454;
uint256 constant deltay2 = 20646074624478348418892142743169842075310032726102859617297640617605155938039;


uint256 constant IC0x = 15885245864077738868080438953982725331851392259561989715709451737775650751499;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ for key in ${keys}; do

# Use jq to extract pi_a, pi_b, pi_c, and public
extracted_proof=$(echo "${json_data}" | jq '.proof | {pi_a, pi_b, pi_c}')
extracted_public=$(echo "${json_data}" | jq '.public')
extracted_public=$(echo "${json_data}" | jq '.proof.public')

# Extract update data from proofInput
nextHeaderHash_bin=$(echo "${json_data}" | jq -r '.proofInput.nextHeaderHash // empty | map(.) | join("")')
Expand Down
41 changes: 41 additions & 0 deletions beacon-light-client/solidity/tasks/change-adapter-address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { task } from 'hardhat/config';
import { getGenericLogger } from '@dendreth/utils/ts-utils/logger';
import Web3 from 'web3';
import { publishTransaction } from '@dendreth/relay/implementations/publish_evm_transaction';

const logger = getGenericLogger();

task('change-adapter-address', 'Verify')
.addParam('lightClient', 'The address of the BeaconLightClient contract')
.addParam('adapter', 'The address of the adapter contract')
.addParam(
'transactionSpeed',
'The speed you want the transactions to be included in a block',
'avg',
undefined,
true,
)
.setAction(async (args, { network, ethers }) => {
const [publisher] = await ethers.getSigners();

logger.info(`Changing adapter with address ${publisher.address}`);

const lightClientContract = await ethers.getContractAt(
'BeaconLightClient',
args.lightClient,
publisher,
);

const web3 = new Web3((network.config as any).url);

await publishTransaction(
lightClientContract,
'changeAdapterAddress',
[args.adapter],
web3,
args.transactionSpeed,
true,
);

logger.info(`Adapter changed to ${args.adapter}`);
});
1 change: 1 addition & 0 deletions beacon-light-client/solidity/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ import './start-publishing';
import './remove-repeat-job';
import './deploy-balance-verifier';
import './balance-verifier-publisher';
import './change-adapter-address';
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getFilesInDir, Proof } from './utils';
import { convertProofToSolidityCalldata } from '@dendreth/utils/ts-utils/zk-utils';
import { getGenericLogger } from '@dendreth/utils/ts-utils/logger';

import INITIAL_UPDATE from '../../../vendor/eth2-light-client-updates/mainnet/deneb-update-284/update_9265121_9273312.json';
import INITIAL_UPDATE from '../../../vendor/eth2-light-client-updates/mainnet/trusted-setup/update_6069888_6078433.json';

const logger = getGenericLogger();

Expand All @@ -26,7 +26,7 @@ describe('BeaconLightClientReadyProofs', async function () {
'vendor',
'eth2-light-client-updates',
'mainnet',
'deneb-update-284',
'trusted-setup',
);

proofs = getFilesInDir(dir, 'proof*.json').map(p =>
Expand All @@ -43,9 +43,9 @@ describe('BeaconLightClientReadyProofs', async function () {
});

beforeEach(async function () {
const FORK_VERSION = '0x04000000';
const FORK_VERSION = '0x90000073';
const genesis_validators_root =
'0x4b363db94e286120d76eb905340fdd4e54bfe9f06bf33ff6cf5ad27f511bfe95';
'0xd8ea171f3c94aea21ebc42a1ed61052acf3f9209c00e4efbaaddac09ed9b8078';
const DOMAIN_SYNC_COMMITTEE = '0x07000000';

let result = sha256(
Expand Down
2 changes: 1 addition & 1 deletion process-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ processes:
gnosis:
description: Start generating proofs for the contract on ${LC_GNOSIS} and update it with them
log_location: ./logs/gnosis.log
command: yarn hardhat start-publishing --light-client ${LC_GNOSIS} --network gnosis --follow-network ${FOLLOW_NETWORK_GNOSIS} --slots-jump ${SLOTS_JUMP} --prometheus-port 3014
command: yarn hardhat start-publishing --light-client ${LC_GNOSIS} --network gnosis --follow-network ${FOLLOW_NETWORK_GNOSIS} --slots-jump ${SLOTS_JUMP} --hashi ${GNOSIS_HASHI} --prometheus-port 3014
working_dir: ./beacon-light-client/solidity
depends_on:
proverserver:
Expand Down
7 changes: 1 addition & 6 deletions relay/process-compose-scripts/download-zk-and-dat-files.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

ZKEY_B3SUM_SUM='7bd1baf6e4aa1bb97933df06f68b26f8aa034e6743ff52c4dd7f6097d6e7d104'
ZKEY_B3SUM_SUM='e5cb635fd494414d599fb22fc132f8ff9ecbc811d7cfc2557b1d8af55165fdad'
DAT_B3SUM_SUM='c94eb86af7c0451a4277a7bdfc90232a9db75c192d6852ad18baa9a46e1e52e5'

source "${GIT_ROOT}/.env"
Expand Down Expand Up @@ -99,8 +99,3 @@ if [ -z "${SLOTS_JUMP}" ]; then
echo "Error: SLOTS_JUMP environment variable is not set. Exiting..."
exit 1
fi

if [[ "${PRATTER}" != "TRUE" && "${MAINNET}" != "TRUE" ]]; then
echo "Neither PRATTER nor MAINNET is set or true."
exit 1
fi
4 changes: 3 additions & 1 deletion relay/utils/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ export async function addUpdate(
}
}

const finalizedSlot = (await beaconApi.getFinalizedBlockHeader(optimisticSlot)).slot;

const nextSlot = await getNextSlot(
optimisticSlot,
finalizedSlot,
slotsJump,
headSlot,
beaconApi,
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@
}],
"files": ["vendor/eth2-light-client-updates/mainnet/bootstrap.json",
"vendor/eth2-light-client-updates/mainnet/updates/00290.json",
"vendor/eth2-light-client-updates/mainnet/deneb-update-284/update_9265121_9273312.json"],
"vendor/eth2-light-client-updates/mainnet/trusted-setup/update_6069888_6078433.json"],
"include": ["**/*.ts", "**/*.json"]
}
2 changes: 1 addition & 1 deletion vendor/eth2-light-client-updates
Submodule eth2-light-client-updates updated 60 files
+26 −0 mainnet/trusted-setup/proof_6069888_6078433.json
+26 −0 mainnet/trusted-setup/proof_6078433_6086624.json
+26 −0 mainnet/trusted-setup/proof_6086624_6094817.json
+26 −0 mainnet/trusted-setup/proof_6094817_6103008.json
+26 −0 mainnet/trusted-setup/proof_6103008_6111200.json
+26 −0 mainnet/trusted-setup/proof_6111200_6119392.json
+26 −0 mainnet/trusted-setup/proof_6119392_6127585.json
+26 −0 mainnet/trusted-setup/proof_6127585_6135776.json
+26 −0 mainnet/trusted-setup/proof_6135776_6143969.json
+26 −0 mainnet/trusted-setup/proof_6143969_6152161.json
+26 −0 mainnet/trusted-setup/proof_6152161_6160352.json
+26 −0 mainnet/trusted-setup/proof_6160352_6168544.json
+26 −0 mainnet/trusted-setup/proof_6168544_6176736.json
+26 −0 mainnet/trusted-setup/proof_6176736_6184928.json
+26 −0 mainnet/trusted-setup/proof_6184928_6193120.json
+26 −0 mainnet/trusted-setup/proof_6193120_6200672.json
+26 −0 mainnet/trusted-setup/proof_6200672_6200704.json
+26 −0 mainnet/trusted-setup/proof_6200704_6200736.json
+26 −0 mainnet/trusted-setup/proof_6200736_6200768.json
+26 −0 mainnet/trusted-setup/proof_6200768_6200800.json
+4 −0 mainnet/trusted-setup/public_6069888_6078433.json
+4 −0 mainnet/trusted-setup/public_6078433_6086624.json
+4 −0 mainnet/trusted-setup/public_6086624_6094817.json
+4 −0 mainnet/trusted-setup/public_6094817_6103008.json
+4 −0 mainnet/trusted-setup/public_6103008_6111200.json
+4 −0 mainnet/trusted-setup/public_6111200_6119392.json
+4 −0 mainnet/trusted-setup/public_6119392_6127585.json
+4 −0 mainnet/trusted-setup/public_6127585_6135776.json
+4 −0 mainnet/trusted-setup/public_6135776_6143969.json
+4 −0 mainnet/trusted-setup/public_6143969_6152161.json
+4 −0 mainnet/trusted-setup/public_6152161_6160352.json
+4 −0 mainnet/trusted-setup/public_6160352_6168544.json
+4 −0 mainnet/trusted-setup/public_6168544_6176736.json
+4 −0 mainnet/trusted-setup/public_6176736_6184928.json
+4 −0 mainnet/trusted-setup/public_6184928_6193120.json
+4 −0 mainnet/trusted-setup/public_6193120_6200672.json
+4 −0 mainnet/trusted-setup/public_6200672_6200704.json
+4 −0 mainnet/trusted-setup/public_6200704_6200736.json
+4 −0 mainnet/trusted-setup/public_6200736_6200768.json
+4 −0 mainnet/trusted-setup/public_6200768_6200800.json
+6 −0 mainnet/trusted-setup/update_6069888_6078433.json
+6 −0 mainnet/trusted-setup/update_6078433_6086624.json
+6 −0 mainnet/trusted-setup/update_6086624_6094817.json
+6 −0 mainnet/trusted-setup/update_6094817_6103008.json
+6 −0 mainnet/trusted-setup/update_6103008_6111200.json
+6 −0 mainnet/trusted-setup/update_6111200_6119392.json
+6 −0 mainnet/trusted-setup/update_6119392_6127585.json
+6 −0 mainnet/trusted-setup/update_6127585_6135776.json
+6 −0 mainnet/trusted-setup/update_6135776_6143969.json
+6 −0 mainnet/trusted-setup/update_6143969_6152161.json
+6 −0 mainnet/trusted-setup/update_6152161_6160352.json
+6 −0 mainnet/trusted-setup/update_6160352_6168544.json
+6 −0 mainnet/trusted-setup/update_6168544_6176736.json
+6 −0 mainnet/trusted-setup/update_6176736_6184928.json
+6 −0 mainnet/trusted-setup/update_6184928_6193120.json
+6 −0 mainnet/trusted-setup/update_6193120_6200672.json
+6 −0 mainnet/trusted-setup/update_6200672_6200704.json
+6 −0 mainnet/trusted-setup/update_6200704_6200736.json
+6 −0 mainnet/trusted-setup/update_6200736_6200768.json
+6 −0 mainnet/trusted-setup/update_6200768_6200800.json
Loading