Skip to content

Commit

Permalink
fix: update solhint
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Nov 4, 2024
1 parent 1a41d42 commit ace8335
Show file tree
Hide file tree
Showing 23 changed files with 316 additions and 304 deletions.
68 changes: 19 additions & 49 deletions l1-contracts/.solhint.json
Original file line number Diff line number Diff line change
@@ -1,69 +1,39 @@
{
"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-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"
}
}
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
2 changes: 1 addition & 1 deletion l1-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"scripts": {
"format": "forge fmt",
"lint": "solhint --config ./.solhint.json --fix \"src/**/*.sol\"",
"lint": "solhint --config ./.solhint.json \"src/**/*.sol\"",
"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
2 changes: 1 addition & 1 deletion l1-contracts/src/core/FeeJuicePortal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,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();
}
}
6 changes: 3 additions & 3 deletions l1-contracts/src/core/Leonidas.sol
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,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 +339,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 +403,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
48 changes: 31 additions & 17 deletions l1-contracts/src/core/ProofCommitmentEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,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 +34,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 +59,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 +78,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 +87,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 +141,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
34 changes: 17 additions & 17 deletions l1-contracts/src/core/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {

/**
* Sets the assumeProvenThroughBlockNumber. Only the contract deployer can set it.
* @param blockNumber - New value.
* @param _blockNumber - New value.
*/
function setAssumeProvenThroughBlockNumber(uint256 blockNumber)
function setAssumeProvenThroughBlockNumber(uint256 _blockNumber)
external
override(ITestRollup)
onlyOwner
{
fakeBlockNumberAsProven(blockNumber);
assumeProvenThroughBlockNumber = blockNumber;
_fakeBlockNumberAsProven(_blockNumber);
assumeProvenThroughBlockNumber = _blockNumber;
}

/**
Expand Down Expand Up @@ -298,7 +298,7 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {
emit L2ProofVerified(endBlockNumber, _args[6]);
}

function status(uint256 myHeaderBlockNumber)
function status(uint256 _myHeaderBlockNumber)
external
view
override(IRollup)
Expand All @@ -316,7 +316,7 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {
blocks[tips.provenBlockNumber].archive,
tips.pendingBlockNumber,
blocks[tips.pendingBlockNumber].archive,
archiveAt(myHeaderBlockNumber),
archiveAt(_myHeaderBlockNumber),
getEpochForBlock(tips.provenBlockNumber)
);
}
Expand Down Expand Up @@ -499,7 +499,7 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {

// Automatically flag the block as proven if we have cheated and set assumeProvenThroughBlockNumber.
if (blockNumber <= assumeProvenThroughBlockNumber) {
fakeBlockNumberAsProven(blockNumber);
_fakeBlockNumberAsProven(blockNumber);

bool isFeeCanonical = address(this) == FEE_JUICE_PORTAL.canonicalRollup();
bool isSysstiaCanonical = address(this) == SYSSTIA.canonicalRollup();
Expand All @@ -518,13 +518,13 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {
}
}

function quoteToDigest(EpochProofQuoteLib.EpochProofQuote memory quote)
function quoteToDigest(EpochProofQuoteLib.EpochProofQuote memory _quote)
public
view
override(IRollup)
returns (bytes32)
{
return _hashTypedDataV4(EpochProofQuoteLib.hash(quote));
return _hashTypedDataV4(EpochProofQuoteLib.hash(_quote));
}

/**
Expand Down Expand Up @@ -739,12 +739,12 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {
return tips.pendingBlockNumber;
}

function getEpochForBlock(uint256 blockNumber) public view override(IRollup) returns (Epoch) {
function getEpochForBlock(uint256 _blockNumber) public view override(IRollup) returns (Epoch) {
require(
blockNumber <= tips.pendingBlockNumber,
Errors.Rollup__InvalidBlockNumber(tips.pendingBlockNumber, blockNumber)
_blockNumber <= tips.pendingBlockNumber,
Errors.Rollup__InvalidBlockNumber(tips.pendingBlockNumber, _blockNumber)
);
return getEpochAt(getTimestampForSlot(blocks[blockNumber].slotNumber));
return getEpochAt(getTimestampForSlot(blocks[_blockNumber].slotNumber));
}

/**
Expand Down Expand Up @@ -968,13 +968,13 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {
}
}

function fakeBlockNumberAsProven(uint256 blockNumber) private {
if (blockNumber > tips.provenBlockNumber && blockNumber <= tips.pendingBlockNumber) {
tips.provenBlockNumber = blockNumber;
function _fakeBlockNumberAsProven(uint256 _blockNumber) private {
if (_blockNumber > tips.provenBlockNumber && _blockNumber <= tips.pendingBlockNumber) {
tips.provenBlockNumber = _blockNumber;

// If this results on a new epoch, create a fake claim for it
// Otherwise nextEpochToProve will report an old epoch
Epoch epoch = getEpochForBlock(blockNumber);
Epoch epoch = getEpochForBlock(_blockNumber);
if (Epoch.unwrap(epoch) == 0 || Epoch.unwrap(epoch) > Epoch.unwrap(proofClaim.epochToProve)) {
proofClaim = DataStructures.EpochProofClaim({
epochToProve: epoch,
Expand Down
3 changes: 3 additions & 0 deletions l1-contracts/src/core/interfaces/IFeeJuicePortal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ interface IFeeJuicePortal {
returns (bytes32, uint256);
function canonicalRollup() external view returns (address);

// solhint-disable-next-line func-name-mixedcase
function UNDERLYING() external view returns (IERC20);
// solhint-disable-next-line func-name-mixedcase
function L2_TOKEN_ADDRESS() external view returns (bytes32);
// solhint-disable-next-line func-name-mixedcase
function REGISTRY() external view returns (IRegistry);
}
Loading

0 comments on commit ace8335

Please sign in to comment.