Skip to content

Commit

Permalink
feat(light-client): Restrict lightClientUpdate function
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimo99 committed Nov 4, 2024
1 parent 4dab5ca commit de98f82
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 16 deletions.
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
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}`);
});

0 comments on commit de98f82

Please sign in to comment.