Skip to content

Commit

Permalink
[FIX] Audit Issues - Main (#149)
Browse files Browse the repository at this point in the history
* Update README.md (#136)

* [FIX] script redeploy testnet (#144)

* fix script redeploy testnet

* fix get_updated_l1_block

* solc version 0.8.20, blsKeyChecker issue

* digest hash add version field

* hardhat solidity version update

---------

Co-authored-by: cool-developer <51834436+cool-develope@users.noreply.github.com>
  • Loading branch information
ChainDev931105 and cool-develope authored Jul 29, 2024
1 parent aa29e68 commit 9d50439
Show file tree
Hide file tree
Showing 70 changed files with 199 additions and 181 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Lagrange Contracts
# Lagrange State Committee Contracts

## Prerequisites

Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IBLSKeyChecker.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
pragma solidity ^0.8.0;

interface IBLSKeyChecker {
struct BLSKeyWithProof {
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IEvidenceVerifier.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
pragma solidity ^0.8.0;

// Evidence is the data structure to store the slashing evidence.
struct Evidence {
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/ILagrangeCommittee.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
pragma solidity ^0.8.0;

import {IBLSKeyChecker} from "./IBLSKeyChecker.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/ILagrangeService.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
pragma solidity ^0.8.0;

import {ISignatureUtils} from "eigenlayer-contracts/src/contracts/interfaces/ISignatureUtils.sol";
import {IBLSKeyChecker} from "./IBLSKeyChecker.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/ISlashingAggregateVerifier.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
pragma solidity ^0.8.0;

interface ISlashingAggregateVerifier {
function verifyProof(uint256[2] memory a, uint256[2][2] memory b, uint256[2] memory c, uint256[5] memory input)
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/ISlashingSingleVerifier.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
pragma solidity ^0.8.0;

interface ISlashingSingleVerifier {
function verifyProof(uint256[2] memory a, uint256[2][2] memory b, uint256[2] memory c, uint256[47] memory input)
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IStakeManager.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
pragma solidity ^0.8.0;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IVoteWeigher.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
pragma solidity ^0.8.0;

interface IVoteWeigher {
struct TokenMultiplier {
Expand Down
10 changes: 6 additions & 4 deletions contracts/library/BLSKeyChecker.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

import {BN254} from "eigenlayer-middleware/libraries/BN254.sol";

Expand All @@ -11,11 +11,12 @@ abstract contract BLSKeyChecker is IBLSKeyChecker {
uint256 internal constant PAIRING_EQUALITY_CHECK_GAS = 120000;

bytes32 public constant DOMAIN_TYPEHASH =
keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");

bytes32 public constant BLS_KEY_WITH_PROOF_TYPEHASH =
keccak256("BLSKeyWithProof(address operator,bytes32 salt,uint256 expiry)");

/// @custom:storage-location erc7201:lagrange.blskeychecker.storage
struct SaltStorage {
mapping(address => mapping(bytes32 => bool)) operatorSalts;
}
Expand Down Expand Up @@ -74,7 +75,8 @@ abstract contract BLSKeyChecker is IBLSKeyChecker {
}

function domainSeparator() public view returns (bytes32) {
return
keccak256(abi.encode(DOMAIN_TYPEHASH, keccak256("Lagrange State Committee"), block.chainid, address(this)));
return keccak256(
abi.encode(DOMAIN_TYPEHASH, keccak256("Lagrange State Committee"), "1", block.chainid, address(this))
);
}
}
2 changes: 1 addition & 1 deletion contracts/library/EigenAdapter.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

import "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
import "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/library/StakeManager.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

import "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
import "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/library/slashing_aggregate/verifier_128.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//
//
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

library Pairing {
struct G1Point {
Expand Down
2 changes: 1 addition & 1 deletion contracts/library/slashing_aggregate/verifier_16.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//
//
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

library Pairing {
struct G1Point {
Expand Down
2 changes: 1 addition & 1 deletion contracts/library/slashing_aggregate/verifier_256.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//
//
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

library Pairing {
struct G1Point {
Expand Down
2 changes: 1 addition & 1 deletion contracts/library/slashing_aggregate/verifier_32.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//
//
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

library Pairing {
struct G1Point {
Expand Down
2 changes: 1 addition & 1 deletion contracts/library/slashing_aggregate/verifier_512.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//
//
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

library Pairing {
struct G1Point {
Expand Down
2 changes: 1 addition & 1 deletion contracts/library/slashing_aggregate/verifier_64.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//
//
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

library Pairing {
struct G1Point {
Expand Down
2 changes: 1 addition & 1 deletion contracts/library/slashing_single/verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//
//
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

library Pairing {
struct G1Point {
Expand Down
2 changes: 1 addition & 1 deletion contracts/mock/AVSDirectoryMock.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

import {IAVSDirectory, ISignatureUtils} from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol";
import {EIP1271SignatureUtils} from "eigenlayer-contracts/src/contracts/libraries/EIP1271SignatureUtils.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/mock/BLSKeyCheckerMock.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

import {BN254} from "eigenlayer-middleware/libraries/BN254.sol";

Expand Down
7 changes: 3 additions & 4 deletions contracts/mock/DMMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint-disable */
// forgefmt: disable-start

pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

import {IDelegationManager} from "eigenlayer-contracts/src/contracts/interfaces/IDelegationManager.sol";
import {IStrategy} from "eigenlayer-contracts/src/contracts/interfaces/IStrategy.sol";
Expand Down Expand Up @@ -156,9 +156,6 @@ contract DelegationManager is IDelegationManager {

function calculateWithdrawalRoot(Withdrawal memory /*withdrawal*/) external pure returns (bytes32) {}

function migrateQueuedWithdrawals(IStrategyManager.DeprecatedStruct_QueuedWithdrawal[] memory /*withdrawalsToQueue*/) external {}


function getOperatorShares(
address /*operator*/,
IStrategy[] memory /*strategies*/
Expand All @@ -169,4 +166,6 @@ contract DelegationManager is IDelegationManager {
function minWithdrawalDelayBlocks() external view returns (uint256) {}

function strategyWithdrawalDelayBlocks(IStrategy /*strategy*/) external view returns (uint256) {}

function beaconChainETHStrategy() external view returns (IStrategy) {}
}
2 changes: 1 addition & 1 deletion contracts/mock/ImportMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint-disable */
// forgefmt: disable-start

pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
Expand Down
12 changes: 3 additions & 9 deletions contracts/mock/SMMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint-disable */
// forgefmt: disable-start

pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

import {IStrategyManager} from "eigenlayer-contracts/src/contracts/interfaces/IStrategyManager.sol";
import {IStrategy} from "eigenlayer-contracts/src/contracts/interfaces/IStrategy.sol";
Expand Down Expand Up @@ -78,13 +78,7 @@ contract StrategyManager is IStrategyManager {
return address(0);
}

function migrateQueuedWithdrawal(DeprecatedStruct_QueuedWithdrawal calldata /*queuedWithdrawal*/) external pure returns (bool, bytes32) {
return (false, bytes32(0));
}

function calculateWithdrawalRoot(DeprecatedStruct_QueuedWithdrawal calldata /*queuedWithdrawal*/) external pure returns (bytes32) {
return bytes32(0);
}
function strategyIsWhitelistedForDeposit(IStrategy strategy) external view returns (bool) {}

function addShares(address /*staker*/, IERC20 /*token*/, IStrategy /*strategy*/, uint256 /*shares*/) external {}

Expand All @@ -93,5 +87,5 @@ contract StrategyManager is IStrategyManager {
bool[] calldata /*thirdPartyTransfersForbiddenValues*/
) external {}

function thirdPartyTransfersForbidden(IStrategy /*strategy*/) external view returns (bool){}
function thirdPartyTransfersForbidden(IStrategy /*strategy*/) external view returns (bool) {}
}
2 changes: 1 addition & 1 deletion contracts/mock/STMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint-disable */
// forgefmt: disable-start

pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

import {IStrategy} from "eigenlayer-contracts/src/contracts/interfaces/IStrategy.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/mock/SafeMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint-disable */
// forgefmt: disable-start

pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

import "@safe/contracts/Safe.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/mock/WETH9.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint-disable */
// forgefmt: disable-start

pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

import "@openzeppelin-upgrades/contracts/token/ERC20/ERC20Upgradeable.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/mock/arbitrum/IOutbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* eslint-disable */
// forgefmt: disable-start

pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

interface IOutbox {
function roots(bytes32) external view returns (bytes32); // maps root hashes => L2 block hash
Expand Down
2 changes: 1 addition & 1 deletion contracts/mock/arbitrum/Outbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* eslint-disable */
// forgefmt: disable-start

pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

import "./IOutbox.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/mock/mantle/BatchStorageMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint-disable */
// forgefmt: disable-start

pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

contract BatchStorageMock {
function getL2StoredBlockNumber() public view returns (uint256) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/mock/optimism/IL2OutputOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* eslint-disable */
// forgefmt: disable-start

pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

import {Types} from "./Types.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/mock/optimism/L2OutputOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint-disable */
// forgefmt: disable-start

pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/protocol/EvidenceVerifier.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

import "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
import "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
Expand Down
4 changes: 2 additions & 2 deletions contracts/protocol/LagrangeCommittee.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

import "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
import "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
Expand Down Expand Up @@ -430,9 +430,9 @@ contract LagrangeCommittee is BLSKeyChecker, Initializable, OwnableUpgradeable,
{
_validateBLSKeyWithProof(_operator, _blsKeyWithProof);

uint256 _orgLength = operatorsStatus[_operator].blsPubKeys.length;
delete operatorsStatus[_operator];
OperatorStatus storage _opStatus = operatorsStatus[_operator];
uint256 _orgLength = _opStatus.blsPubKeys.length;
_opStatus.signAddress = _signAddress;
uint256 _length = _blsKeyWithProof.blsG1PublicKeys.length;
for (uint256 i; i < _length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/protocol/LagrangeService.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

import "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
import "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/protocol/VoteWeigher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint-disable */
// forgefmt: disable-start

pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

import "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
import "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
Expand Down
4 changes: 2 additions & 2 deletions contracts/protocol/testnet/LagrangeCommitteeTestnet.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

import "../LagrangeCommittee.sol";

Expand Down Expand Up @@ -29,7 +29,7 @@ contract LagrangeCommitteeTestnet is LagrangeCommittee {

function _getUpdatedL1Block(uint32 _chainID, uint256 _epochNumber) internal view returns (uint256) {
uint256 _stored = committees[_chainID][_epochNumber].updatedBlock;
return (_stored >> 112) != 0 ? (_stored >> 112) : uint256(int256(_stored) + committeeParams[_chainID].l1Bias);
return (_stored >> 112) != 0 ? (_stored >> 112) : uint256(int256(_stored) - committeeParams[_chainID].l1Bias);
}

function _setUpdatedBlock(uint32 _chainID, uint256 _epochNumber, uint256 _l1BlockNumber) internal override {
Expand Down
2 changes: 1 addition & 1 deletion contracts/protocol/testnet/LagrangeServiceTestnet.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.12;
pragma solidity ^0.8.20;

import "../LagrangeService.sol";

Expand Down
2 changes: 2 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ libs = ["lib"]
fs_permissions = [{ access = "read-write", path = "./"}]
gas_reports = ["*"]

solc_version = "0.8.20"

# Enables or disables the optimizer
optimizer = true
# The number of optimizer runs
Expand Down
Loading

0 comments on commit 9d50439

Please sign in to comment.