Skip to content
Merged
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
72 changes: 22 additions & 50 deletions l1-contracts/.solhint.json
Original file line number Diff line number Diff line change
@@ -1,69 +1,41 @@
{
"extends": "solhint:recommended",
"rules": {
"compiler-version": [
"error",
">=0.8.27"
],
"one-contract-per-file": "off",
"no-inline-assembly": "off",
"func-visibility": [
"error",
{
"ignoreConstructors": true
}
],
"no-empty-blocks": "off",
"no-unused-vars": [
"error"
],
"state-visibility": [
"error"
],
"not-rely-on-time": "off",
"gas-custom-errors": "off",
"custom-errors": "off",
"interface-starts-with-i": "error",
"immutable-vars-naming": [
"warn",
"error",
{
"immutablesAsConstants": true
}
],
"var-name-mixedcase": [
"compiler-version": [
"error",
{
"treatImmutableVarAsConstant": true
}
">=0.8.27"
],
"custom-error-name-camelcase": [
"func-visibility": [
"error",
{
"allowPrefix": true
"ignoreConstructors": true
}
],
"private-func-leading-underscore": [
"error"
],
"private-vars-no-leading-underscore": [
"error"
],
"func-param-name-leading-underscore": [
"error"
],
"interface-starts-with-i": "warn",
"func-param-name-mixedcase": [
"error"
],
"strict-override": [
"error"
],
"strict-import": [
"error"
],
"ordering": [
"error"
],
"comprehensive-interface": [
"error"
],
"custom-error-over-require": "off",
"no-unused-import": "error"
"no-unused-vars": "error",
"state-visibility": "error",
"var-name-mixedcase": "error",
"private-func-leading-underscore": "error",
"private-vars-no-leading-underscore": "error",
"func-param-name-leading-underscore": "error",
"func-param-name-mixedcase": "error",
"strict-override": "error",
"ordering": "error",
"comprehensive-interface": "error",
"no-unused-import": "error",
"imports-order": "error",
"check-send-result": "error"
}
}
6 changes: 4 additions & 2 deletions l1-contracts/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ RUN rm -rf terraform scripts
#RUN git init
RUN forge clean && forge fmt --check && forge build && forge test --no-match-contract UniswapPortalTest

RUN npm install --global solhint
RUN solhint --config ./.solhint.json --fix "src/**/*.sol"
# Install husky and solhint, using our own fork of solhint with a few extra rules.
RUN npm install --global husky
RUN npm install --global LHerskind/solhint#master
RUN solhint --config ./.solhint.json "src/**/*.sol"

# RUN git add . && yarn slither && yarn slither-has-diff
RUN forge build
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ src:

lint:
FROM +src
RUN solhint --config ./.solhint.json --fix "src/**/*.sol"
RUN solhint --config ./.solhint.json "src/**/*.sol"
RUN forge clean && forge fmt --check

build:
Expand Down
3 changes: 2 additions & 1 deletion l1-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
},
"scripts": {
"format": "forge fmt",
"lint": "solhint --config ./.solhint.json --fix \"src/**/*.sol\"",
"lint": "solhint --config ./.solhint.json \"src/**/*.sol\"",
"lint:fix": "solhint --config ./.solhint.json --fix --noPrompt \"src/**/*.sol\"; forge fmt",
"slither": "forge clean && forge build --build-info --skip '*/test/**' --force && slither . --checklist --ignore-compile --show-ignored-findings --config-file ./slither.config.json | tee slither_output.md",
"slither-has-diff": "./slither_has_diff.sh"
}
Expand Down
11 changes: 5 additions & 6 deletions l1-contracts/src/core/FeeJuicePortal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
// Copyright 2024 Aztec Labs.
pragma solidity >=0.8.27;

import {IERC20} from "@oz/token/ERC20/IERC20.sol";
import {IFeeJuicePortal} from "@aztec/core/interfaces/IFeeJuicePortal.sol";
import {IInbox} from "@aztec/core/interfaces/messagebridge/IInbox.sol";
import {IRegistry} from "@aztec/governance/interfaces/IRegistry.sol";
import {IRollup} from "@aztec/core/interfaces/IRollup.sol";

import {IInbox} from "@aztec/core/interfaces/messagebridge/IInbox.sol";
import {Constants} from "@aztec/core/libraries/ConstantsGen.sol";
import {Hash} from "@aztec/core/libraries/crypto/Hash.sol";
import {DataStructures} from "@aztec/core/libraries/DataStructures.sol";
import {Errors} from "@aztec/core/libraries/Errors.sol";
import {Hash} from "@aztec/core/libraries/crypto/Hash.sol";
import {IRegistry} from "@aztec/governance/interfaces/IRegistry.sol";
import {IERC20} from "@oz/token/ERC20/IERC20.sol";
import {SafeERC20} from "@oz/token/ERC20/utils/SafeERC20.sol";

contract FeeJuicePortal is IFeeJuicePortal {
Expand Down Expand Up @@ -104,7 +103,7 @@ contract FeeJuicePortal is IFeeJuicePortal {
emit FeesDistributed(_to, _amount);
}

function canonicalRollup() public view returns (address) {
function canonicalRollup() public view override(IFeeJuicePortal) returns (address) {
return REGISTRY.getRollup();
}
}
17 changes: 7 additions & 10 deletions l1-contracts/src/core/Leonidas.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
pragma solidity >=0.8.27;

import {ILeonidas} from "@aztec/core/interfaces/ILeonidas.sol";

import {Constants} from "@aztec/core/libraries/ConstantsGen.sol";
import {DataStructures} from "@aztec/core/libraries/DataStructures.sol";
import {Errors} from "@aztec/core/libraries/Errors.sol";
import {SampleLib} from "@aztec/core/libraries/crypto/SampleLib.sol";
import {SignatureLib} from "@aztec/core/libraries/crypto/SignatureLib.sol";
import {DataStructures} from "@aztec/core/libraries/DataStructures.sol";
import {Errors} from "@aztec/core/libraries/Errors.sol";
import {Timestamp, Slot, Epoch, SlotLib, EpochLib} from "@aztec/core/libraries/TimeMath.sol";
import {Ownable} from "@oz/access/Ownable.sol";
import {MessageHashUtils} from "@oz/utils/cryptography/MessageHashUtils.sol";
import {EnumerableSet} from "@oz/utils/structs/EnumerableSet.sol";

import {Ownable} from "@oz/access/Ownable.sol";

import {Timestamp, Slot, Epoch, SlotLib, EpochLib} from "@aztec/core/libraries/TimeMath.sol";

/**
* @title Leonidas
* @author Anaxandridas II
Expand Down Expand Up @@ -139,7 +136,7 @@ contract Leonidas is Ownable, ILeonidas {
* @return The validator set for the current epoch
*/
function getCurrentEpochCommittee() external view override(ILeonidas) returns (address[] memory) {
return getCommitteeAt(Timestamp.wrap(block.timestamp));
return _getCommitteeAt(Timestamp.wrap(block.timestamp));
}

/**
Expand Down Expand Up @@ -339,7 +336,7 @@ contract Leonidas is Ownable, ILeonidas {
validatorSet.add(_validator);
}

function getCommitteeAt(Timestamp _ts) internal view returns (address[] memory) {
function _getCommitteeAt(Timestamp _ts) internal view returns (address[] memory) {
Epoch epochNumber = getEpochAt(_ts);
EpochData storage epoch = epochs[epochNumber];

Expand Down Expand Up @@ -403,7 +400,7 @@ contract Leonidas is Ownable, ILeonidas {
return;
}

address[] memory committee = getCommitteeAt(ts);
address[] memory committee = _getCommitteeAt(ts);

uint256 needed = committee.length * 2 / 3 + 1;
require(
Expand Down
55 changes: 34 additions & 21 deletions l1-contracts/src/core/ProofCommitmentEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
// Copyright 2024 Aztec Labs.
pragma solidity >=0.8.27;

import {SafeERC20} from "@oz/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@oz/token/ERC20/IERC20.sol";

import {IProofCommitmentEscrow} from "@aztec/core/interfaces/IProofCommitmentEscrow.sol";
import {Errors} from "@aztec/core/libraries/Errors.sol";
import {Constants} from "@aztec/core/libraries/ConstantsGen.sol";
import {Errors} from "@aztec/core/libraries/Errors.sol";
import {Timestamp} from "@aztec/core/libraries/TimeMath.sol";
import {IERC20} from "@oz/token/ERC20/IERC20.sol";
import {SafeERC20} from "@oz/token/ERC20/utils/SafeERC20.sol";

contract ProofCommitmentEscrow is IProofCommitmentEscrow {
using SafeERC20 for IERC20;
Expand All @@ -18,12 +17,14 @@ contract ProofCommitmentEscrow is IProofCommitmentEscrow {
Timestamp executableAt;
}

address public immutable ROLLUP;
uint256 public constant WITHDRAW_DELAY =
Constants.ETHEREUM_SLOT_DURATION * Constants.AZTEC_EPOCH_DURATION * 3;

address public immutable ROLLUP;
IERC20 public immutable TOKEN;

mapping(address => uint256) public deposits;
mapping(address => WithdrawRequest) public withdrawRequests;
IERC20 public immutable token;

modifier onlyRollup() {
require(msg.sender == ROLLUP, Errors.ProofCommitmentEscrow__NotOwner(msg.sender));
Expand All @@ -32,18 +33,18 @@ contract ProofCommitmentEscrow is IProofCommitmentEscrow {

constructor(IERC20 _token, address _rollup) {
ROLLUP = _rollup;
token = _token;
TOKEN = _token;
}

/**
* @notice Deposit tokens into the escrow
* @notice Deposit TOKENs into the escrow
*
* @dev The caller must have approved the token transfer
* @dev The caller must have approved the TOKEN transfer
*
* @param _amount The amount of tokens to deposit
* @param _amount The amount of TOKENs to deposit
*/
function deposit(uint256 _amount) external override {
token.safeTransferFrom(msg.sender, address(this), _amount);
function deposit(uint256 _amount) external override(IProofCommitmentEscrow) {
TOKEN.safeTransferFrom(msg.sender, address(this), _amount);

deposits[msg.sender] += _amount;

Expand All @@ -57,9 +58,9 @@ contract ProofCommitmentEscrow is IProofCommitmentEscrow {
* The withdrawal request will be executable after a delay
* Subsequent calls to this function will overwrite the previous request
*
* @param _amount - The amount of tokens to withdraw
* @param _amount - The amount of TOKENs to withdraw
*/
function startWithdraw(uint256 _amount) external override {
function startWithdraw(uint256 _amount) external override(IProofCommitmentEscrow) {
require(
deposits[msg.sender] >= _amount,
Errors.ProofCommitmentEscrow__InsufficientBalance(deposits[msg.sender], _amount)
Expand All @@ -76,7 +77,7 @@ contract ProofCommitmentEscrow is IProofCommitmentEscrow {
/**
* @notice Execute a mature withdrawal request
*/
function executeWithdraw() external override {
function executeWithdraw() external override(IProofCommitmentEscrow) {
WithdrawRequest memory request = withdrawRequests[msg.sender];
require(
request.executableAt <= Timestamp.wrap(block.timestamp),
Expand All @@ -85,35 +86,47 @@ contract ProofCommitmentEscrow is IProofCommitmentEscrow {

delete withdrawRequests[msg.sender];
deposits[msg.sender] -= request.amount;
token.safeTransfer(msg.sender, request.amount);
TOKEN.safeTransfer(msg.sender, request.amount);

emit ExecuteWithdraw(msg.sender, request.amount);
}

/**
* @notice Stake an amount of previously deposited tokens
* @notice Stake an amount of previously deposited TOKENs
*
* @dev Only callable by the owner
* The prover must have sufficient balance
* The prover's balance will be reduced by the bond amount
*/
function stakeBond(address _prover, uint256 _amount) external override onlyRollup {
function stakeBond(address _prover, uint256 _amount)
external
override(IProofCommitmentEscrow)
onlyRollup
{
deposits[_prover] -= _amount;

emit StakeBond(_prover, _amount);
}

/**
* @notice Unstake the bonded tokens, returning them to the prover
* @notice Unstake the bonded TOKENs, returning them to the prover
*
* @dev Only callable by the owner
*/
function unstakeBond(address _prover, uint256 _amount) external override onlyRollup {
function unstakeBond(address _prover, uint256 _amount)
external
override(IProofCommitmentEscrow)
onlyRollup
{
deposits[_prover] += _amount;

emit UnstakeBond(_prover, _amount);
}

function token() external view override(IProofCommitmentEscrow) returns (IERC20) {
return TOKEN;
}

/**
* @notice Get the minimum balance of a prover at a given timestamp.
*
Expand All @@ -127,7 +140,7 @@ contract ProofCommitmentEscrow is IProofCommitmentEscrow {
function minBalanceAtTime(Timestamp _timestamp, address _prover)
external
view
override
override(IProofCommitmentEscrow)
returns (uint256)
{
// If the timestamp is beyond the WITHDRAW_DELAY, the minimum possible balance is 0;
Expand Down
Loading