From ace8335345fa2dd4374e408ee3f60054adaa583d Mon Sep 17 00:00:00 2001 From: LHerskind Date: Thu, 24 Oct 2024 13:15:28 +0000 Subject: [PATCH 1/3] fix: update solhint --- l1-contracts/.solhint.json | 68 ++----- l1-contracts/Dockerfile | 6 +- l1-contracts/Earthfile | 2 +- l1-contracts/package.json | 2 +- l1-contracts/src/core/FeeJuicePortal.sol | 2 +- l1-contracts/src/core/Leonidas.sol | 6 +- .../src/core/ProofCommitmentEscrow.sol | 48 +++-- l1-contracts/src/core/Rollup.sol | 34 ++-- .../src/core/interfaces/IFeeJuicePortal.sol | 3 + l1-contracts/src/core/interfaces/IRollup.sol | 10 +- .../src/core/libraries/EpochProofQuoteLib.sol | 12 +- l1-contracts/src/core/libraries/TimeMath.sol | 170 +++++++++--------- .../src/core/libraries/crypto/FrontierLib.sol | 38 ++-- .../src/core/libraries/crypto/SampleLib.sol | 28 +-- l1-contracts/src/governance/Apella.sol | 44 +++-- l1-contracts/src/governance/Sysstia.sol | 4 +- .../src/governance/interfaces/IApella.sol | 8 + .../governance/libraries/ConfigurationLib.sol | 32 ++-- .../src/governance/libraries/Errors.sol | 4 +- .../src/governance/libraries/ProposalLib.sol | 36 ++-- .../src/governance/libraries/UserLib.sol | 44 ++--- l1-contracts/src/mock/MockFeeJuicePortal.sol | 8 +- l1-contracts/src/mock/TestERC20.sol | 11 +- 23 files changed, 316 insertions(+), 304 deletions(-) diff --git a/l1-contracts/.solhint.json b/l1-contracts/.solhint.json index 3c14ae3cf16..e2eb8eb9628 100644 --- a/l1-contracts/.solhint.json +++ b/l1-contracts/.solhint.json @@ -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" } } \ No newline at end of file diff --git a/l1-contracts/Dockerfile b/l1-contracts/Dockerfile index 6aafd98bc95..46a94e854a3 100644 --- a/l1-contracts/Dockerfile +++ b/l1-contracts/Dockerfile @@ -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 diff --git a/l1-contracts/Earthfile b/l1-contracts/Earthfile index 011d4b98215..144caa09c90 100644 --- a/l1-contracts/Earthfile +++ b/l1-contracts/Earthfile @@ -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: diff --git a/l1-contracts/package.json b/l1-contracts/package.json index 263d57c74d5..f01146a0382 100644 --- a/l1-contracts/package.json +++ b/l1-contracts/package.json @@ -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" } diff --git a/l1-contracts/src/core/FeeJuicePortal.sol b/l1-contracts/src/core/FeeJuicePortal.sol index 59aad41c5e5..285e1fdbb86 100644 --- a/l1-contracts/src/core/FeeJuicePortal.sol +++ b/l1-contracts/src/core/FeeJuicePortal.sol @@ -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(); } } diff --git a/l1-contracts/src/core/Leonidas.sol b/l1-contracts/src/core/Leonidas.sol index 55b86818bc5..05b42325253 100644 --- a/l1-contracts/src/core/Leonidas.sol +++ b/l1-contracts/src/core/Leonidas.sol @@ -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)); } /** @@ -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]; @@ -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( diff --git a/l1-contracts/src/core/ProofCommitmentEscrow.sol b/l1-contracts/src/core/ProofCommitmentEscrow.sol index c6cc900d81d..dc7aff1f314 100644 --- a/l1-contracts/src/core/ProofCommitmentEscrow.sol +++ b/l1-contracts/src/core/ProofCommitmentEscrow.sol @@ -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)); @@ -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; @@ -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) @@ -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), @@ -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. * @@ -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; diff --git a/l1-contracts/src/core/Rollup.sol b/l1-contracts/src/core/Rollup.sol index 9a627d5d690..10749015dea 100644 --- a/l1-contracts/src/core/Rollup.sol +++ b/l1-contracts/src/core/Rollup.sol @@ -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; } /** @@ -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) @@ -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) ); } @@ -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(); @@ -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)); } /** @@ -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)); } /** @@ -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, diff --git a/l1-contracts/src/core/interfaces/IFeeJuicePortal.sol b/l1-contracts/src/core/interfaces/IFeeJuicePortal.sol index 19de1638ac5..884430cb201 100644 --- a/l1-contracts/src/core/interfaces/IFeeJuicePortal.sol +++ b/l1-contracts/src/core/interfaces/IFeeJuicePortal.sol @@ -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); } diff --git a/l1-contracts/src/core/interfaces/IRollup.sol b/l1-contracts/src/core/interfaces/IRollup.sol index c3141e0fc40..292c89722c4 100644 --- a/l1-contracts/src/core/interfaces/IRollup.sol +++ b/l1-contracts/src/core/interfaces/IRollup.sol @@ -15,7 +15,7 @@ interface ITestRollup { function setEpochVerifier(address _verifier) external; function setVkTreeRoot(bytes32 _vkTreeRoot) external; function setProtocolContractTreeRoot(bytes32 _protocolContractTreeRoot) external; - function setAssumeProvenThroughBlockNumber(uint256 blockNumber) external; + function setAssumeProvenThroughBlockNumber(uint256 _blockNumber) external; } interface IRollup { @@ -81,7 +81,9 @@ interface IRollup { // solhint-disable-next-line func-name-mixedcase function L1_BLOCK_AT_GENESIS() external view returns (uint256); - function status(uint256 myHeaderBlockNumber) + function canPrune() external view returns (bool); + + function status(uint256 _myHeaderBlockNumber) external view returns ( @@ -93,7 +95,7 @@ interface IRollup { Epoch provenEpochNumber ); - function quoteToDigest(EpochProofQuoteLib.EpochProofQuote memory quote) + function quoteToDigest(EpochProofQuoteLib.EpochProofQuote memory _quote) external view returns (bytes32); @@ -105,11 +107,11 @@ interface IRollup { function getPendingBlockNumber() external view returns (uint256); function getEpochToProve() external view returns (Epoch); function getClaimableEpoch() external view returns (Epoch); - function getEpochForBlock(uint256 blockNumber) external view returns (Epoch); function validateEpochProofRightClaimAtTime( Timestamp _ts, EpochProofQuoteLib.SignedEpochProofQuote calldata _quote ) external view; + function getEpochForBlock(uint256 _blockNumber) external view returns (Epoch); function getEpochProofPublicInputs( uint256 _epochSize, bytes32[7] calldata _args, diff --git a/l1-contracts/src/core/libraries/EpochProofQuoteLib.sol b/l1-contracts/src/core/libraries/EpochProofQuoteLib.sol index 1aba031a64d..4f270d2204d 100644 --- a/l1-contracts/src/core/libraries/EpochProofQuoteLib.sol +++ b/l1-contracts/src/core/libraries/EpochProofQuoteLib.sol @@ -36,15 +36,15 @@ library EpochProofQuoteLib { "EpochProofQuote(uint256 epochToProve,uint256 validUntilSlot,uint256 bondAmount,address prover,uint32 basisPointFee)" ); - function hash(EpochProofQuote memory quote) internal pure returns (bytes32) { + function hash(EpochProofQuote memory _quote) internal pure returns (bytes32) { return keccak256( abi.encode( EPOCH_PROOF_QUOTE_TYPEHASH, - quote.epochToProve, - quote.validUntilSlot, - quote.bondAmount, - quote.prover, - quote.basisPointFee + _quote.epochToProve, + _quote.validUntilSlot, + _quote.bondAmount, + _quote.prover, + _quote.basisPointFee ) ); } diff --git a/l1-contracts/src/core/libraries/TimeMath.sol b/l1-contracts/src/core/libraries/TimeMath.sol index f017be21411..a2f0469773f 100644 --- a/l1-contracts/src/core/libraries/TimeMath.sol +++ b/l1-contracts/src/core/libraries/TimeMath.sol @@ -11,170 +11,170 @@ type Slot is uint256; type Epoch is uint256; library SlotLib { - function toTimestamp(Slot a) internal pure returns (Timestamp) { - return Timestamp.wrap(Slot.unwrap(a) * Constants.AZTEC_SLOT_DURATION); + function toTimestamp(Slot _a) internal pure returns (Timestamp) { + return Timestamp.wrap(Slot.unwrap(_a) * Constants.AZTEC_SLOT_DURATION); } - function fromTimestamp(Timestamp a) internal pure returns (Slot) { - return Slot.wrap(Timestamp.unwrap(a) / Constants.AZTEC_SLOT_DURATION); + function fromTimestamp(Timestamp _a) internal pure returns (Slot) { + return Slot.wrap(Timestamp.unwrap(_a) / Constants.AZTEC_SLOT_DURATION); } - function positionInEpoch(Slot a) internal pure returns (uint256) { - return Slot.unwrap(a) % Constants.AZTEC_EPOCH_DURATION; + function positionInEpoch(Slot _a) internal pure returns (uint256) { + return Slot.unwrap(_a) % Constants.AZTEC_EPOCH_DURATION; } - function unwrap(Slot a) internal pure returns (uint256) { - return Slot.unwrap(a); + function unwrap(Slot _a) internal pure returns (uint256) { + return Slot.unwrap(_a); } } library EpochLib { - function toSlots(Epoch a) internal pure returns (Slot) { - return Slot.wrap(Epoch.unwrap(a) * Constants.AZTEC_EPOCH_DURATION); + function toSlots(Epoch _a) internal pure returns (Slot) { + return Slot.wrap(Epoch.unwrap(_a) * Constants.AZTEC_EPOCH_DURATION); } - function toTimestamp(Epoch a) internal pure returns (Timestamp) { - return SlotLib.toTimestamp(toSlots(a)); + function toTimestamp(Epoch _a) internal pure returns (Timestamp) { + return SlotLib.toTimestamp(toSlots(_a)); } - function fromTimestamp(Timestamp a) internal pure returns (Epoch) { + function fromTimestamp(Timestamp _a) internal pure returns (Epoch) { return Epoch.wrap( - Timestamp.unwrap(a) / (Constants.AZTEC_EPOCH_DURATION * Constants.AZTEC_SLOT_DURATION) + Timestamp.unwrap(_a) / (Constants.AZTEC_EPOCH_DURATION * Constants.AZTEC_SLOT_DURATION) ); } - function unwrap(Epoch a) internal pure returns (uint256) { - return Epoch.unwrap(a); + function unwrap(Epoch _a) internal pure returns (uint256) { + return Epoch.unwrap(_a); } } using SlotLib for Slot; using EpochLib for Epoch; -function addTimestamp(Timestamp a, Timestamp b) pure returns (Timestamp) { - return Timestamp.wrap(Timestamp.unwrap(a) + Timestamp.unwrap(b)); +function _addTimestamp(Timestamp _a, Timestamp _b) pure returns (Timestamp) { + return Timestamp.wrap(Timestamp.unwrap(_a) + Timestamp.unwrap(_b)); } -function subTimestamp(Timestamp a, Timestamp b) pure returns (Timestamp) { - return Timestamp.wrap(Timestamp.unwrap(a) - Timestamp.unwrap(b)); +function _subTimestamp(Timestamp _a, Timestamp _b) pure returns (Timestamp) { + return Timestamp.wrap(Timestamp.unwrap(_a) - Timestamp.unwrap(_b)); } -function ltTimestamp(Timestamp a, Timestamp b) pure returns (bool) { - return Timestamp.unwrap(a) < Timestamp.unwrap(b); +function _ltTimestamp(Timestamp _a, Timestamp _b) pure returns (bool) { + return Timestamp.unwrap(_a) < Timestamp.unwrap(_b); } -function lteTimestamp(Timestamp a, Timestamp b) pure returns (bool) { - return Timestamp.unwrap(a) <= Timestamp.unwrap(b); +function _lteTimestamp(Timestamp _a, Timestamp _b) pure returns (bool) { + return Timestamp.unwrap(_a) <= Timestamp.unwrap(_b); } -function gtTimestamp(Timestamp a, Timestamp b) pure returns (bool) { - return Timestamp.unwrap(a) > Timestamp.unwrap(b); +function _gtTimestamp(Timestamp _a, Timestamp _b) pure returns (bool) { + return Timestamp.unwrap(_a) > Timestamp.unwrap(_b); } -function gteTimestamp(Timestamp a, Timestamp b) pure returns (bool) { - return Timestamp.unwrap(a) >= Timestamp.unwrap(b); +function _gteTimestamp(Timestamp _a, Timestamp _b) pure returns (bool) { + return Timestamp.unwrap(_a) >= Timestamp.unwrap(_b); } -function neqTimestamp(Timestamp a, Timestamp b) pure returns (bool) { - return Timestamp.unwrap(a) != Timestamp.unwrap(b); +function _neqTimestamp(Timestamp _a, Timestamp _b) pure returns (bool) { + return Timestamp.unwrap(_a) != Timestamp.unwrap(_b); } -function eqTimestamp(Timestamp a, Timestamp b) pure returns (bool) { - return Timestamp.unwrap(a) == Timestamp.unwrap(b); +function _eqTimestamp(Timestamp _a, Timestamp _b) pure returns (bool) { + return Timestamp.unwrap(_a) == Timestamp.unwrap(_b); } // Slot -function addSlot(Slot a, Slot b) pure returns (Slot) { - return Slot.wrap(Slot.unwrap(a) + Slot.unwrap(b)); +function _addSlot(Slot _a, Slot _b) pure returns (Slot) { + return Slot.wrap(Slot.unwrap(_a) + Slot.unwrap(_b)); } -function eqSlot(Slot a, Slot b) pure returns (bool) { - return Slot.unwrap(a) == Slot.unwrap(b); +function _eqSlot(Slot _a, Slot _b) pure returns (bool) { + return Slot.unwrap(_a) == Slot.unwrap(_b); } -function neqSlot(Slot a, Slot b) pure returns (bool) { - return Slot.unwrap(a) != Slot.unwrap(b); +function _neqSlot(Slot _a, Slot _b) pure returns (bool) { + return Slot.unwrap(_a) != Slot.unwrap(_b); } -function ltSlot(Slot a, Slot b) pure returns (bool) { - return Slot.unwrap(a) < Slot.unwrap(b); +function _ltSlot(Slot _a, Slot _b) pure returns (bool) { + return Slot.unwrap(_a) < Slot.unwrap(_b); } -function lteSlot(Slot a, Slot b) pure returns (bool) { - return Slot.unwrap(a) <= Slot.unwrap(b); +function _lteSlot(Slot _a, Slot _b) pure returns (bool) { + return Slot.unwrap(_a) <= Slot.unwrap(_b); } -function gtSlot(Slot a, Slot b) pure returns (bool) { - return Slot.unwrap(a) > Slot.unwrap(b); +function _gtSlot(Slot _a, Slot _b) pure returns (bool) { + return Slot.unwrap(_a) > Slot.unwrap(_b); } -function gteSlot(Slot a, Slot b) pure returns (bool) { - return Slot.unwrap(a) >= Slot.unwrap(b); +function _gteSlot(Slot _a, Slot _b) pure returns (bool) { + return Slot.unwrap(_a) >= Slot.unwrap(_b); } // Epoch -function eqEpoch(Epoch a, Epoch b) pure returns (bool) { - return Epoch.unwrap(a) == Epoch.unwrap(b); +function _eqEpoch(Epoch _a, Epoch _b) pure returns (bool) { + return Epoch.unwrap(_a) == Epoch.unwrap(_b); } -function neqEpoch(Epoch a, Epoch b) pure returns (bool) { - return Epoch.unwrap(a) != Epoch.unwrap(b); +function _neqEpoch(Epoch _a, Epoch _b) pure returns (bool) { + return Epoch.unwrap(_a) != Epoch.unwrap(_b); } -function subEpoch(Epoch a, Epoch b) pure returns (Epoch) { - return Epoch.wrap(Epoch.unwrap(a) - Epoch.unwrap(b)); +function _subEpoch(Epoch _a, Epoch _b) pure returns (Epoch) { + return Epoch.wrap(Epoch.unwrap(_a) - Epoch.unwrap(_b)); } -function addEpoch(Epoch a, Epoch b) pure returns (Epoch) { - return Epoch.wrap(Epoch.unwrap(a) + Epoch.unwrap(b)); +function _addEpoch(Epoch _a, Epoch _b) pure returns (Epoch) { + return Epoch.wrap(Epoch.unwrap(_a) + Epoch.unwrap(_b)); } -function gteEpoch(Epoch a, Epoch b) pure returns (bool) { - return Epoch.unwrap(a) >= Epoch.unwrap(b); +function _gteEpoch(Epoch _a, Epoch _b) pure returns (bool) { + return Epoch.unwrap(_a) >= Epoch.unwrap(_b); } -function gtEpoch(Epoch a, Epoch b) pure returns (bool) { - return Epoch.unwrap(a) > Epoch.unwrap(b); +function _gtEpoch(Epoch _a, Epoch _b) pure returns (bool) { + return Epoch.unwrap(_a) > Epoch.unwrap(_b); } -function lteEpoch(Epoch a, Epoch b) pure returns (bool) { - return Epoch.unwrap(a) <= Epoch.unwrap(b); +function _lteEpoch(Epoch _a, Epoch _b) pure returns (bool) { + return Epoch.unwrap(_a) <= Epoch.unwrap(_b); } -function ltEpoch(Epoch a, Epoch b) pure returns (bool) { - return Epoch.unwrap(a) < Epoch.unwrap(b); +function _ltEpoch(Epoch _a, Epoch _b) pure returns (bool) { + return Epoch.unwrap(_a) < Epoch.unwrap(_b); } using { - addTimestamp as +, - subTimestamp as -, - ltTimestamp as <, - gtTimestamp as >, - lteTimestamp as <=, - gteTimestamp as >=, - neqTimestamp as !=, - eqTimestamp as == + _addTimestamp as +, + _subTimestamp as -, + _ltTimestamp as <, + _gtTimestamp as >, + _lteTimestamp as <=, + _gteTimestamp as >=, + _neqTimestamp as !=, + _eqTimestamp as == } for Timestamp global; using { - addEpoch as +, - subEpoch as -, - eqEpoch as ==, - neqEpoch as !=, - gteEpoch as >=, - gtEpoch as >, - lteEpoch as <=, - ltEpoch as < + _addEpoch as +, + _subEpoch as -, + _eqEpoch as ==, + _neqEpoch as !=, + _gteEpoch as >=, + _gtEpoch as >, + _lteEpoch as <=, + _ltEpoch as < } for Epoch global; using { - eqSlot as ==, - neqSlot as !=, - gteSlot as >=, - gtSlot as >, - lteSlot as <=, - ltSlot as <, - addSlot as + + _eqSlot as ==, + _neqSlot as !=, + _gteSlot as >=, + _gtSlot as >, + _lteSlot as <=, + _ltSlot as <, + _addSlot as + } for Slot global; diff --git a/l1-contracts/src/core/libraries/crypto/FrontierLib.sol b/l1-contracts/src/core/libraries/crypto/FrontierLib.sol index 6b9e7aef132..e907ec74b5d 100644 --- a/l1-contracts/src/core/libraries/crypto/FrontierLib.sol +++ b/l1-contracts/src/core/libraries/crypto/FrontierLib.sol @@ -19,57 +19,57 @@ library FrontierLib { mapping(uint256 => bytes32) frontier; } - function initialize(Forest storage self, uint256 _height) internal { - self.zeros[0] = bytes32(0); + function initialize(Forest storage _self, uint256 _height) internal { + _self.zeros[0] = bytes32(0); for (uint256 i = 1; i <= _height; i++) { - self.zeros[i] = Hash.sha256ToField(bytes.concat(self.zeros[i - 1], self.zeros[i - 1])); + _self.zeros[i] = Hash.sha256ToField(bytes.concat(_self.zeros[i - 1], _self.zeros[i - 1])); } } - function insertLeaf(Tree storage self, bytes32 _leaf) internal returns (uint256) { - uint256 index = self.nextIndex; - uint256 level = _computeLevel(index); + function insertLeaf(Tree storage _self, bytes32 _leaf) internal returns (uint256) { + uint256 index = _self.nextIndex; + uint256 level = computeLevel(index); bytes32 right = _leaf; for (uint256 i = 0; i < level; i++) { - right = Hash.sha256ToField(bytes.concat(self.frontier[i], right)); + right = Hash.sha256ToField(bytes.concat(_self.frontier[i], right)); } - self.frontier[level] = right; + _self.frontier[level] = right; - self.nextIndex++; + _self.nextIndex++; return index; } - function root(Tree storage self, Forest storage _forest, uint256 _height, uint256 _size) + function root(Tree storage _self, Forest storage _forest, uint256 _height, uint256 _size) internal view returns (bytes32) { - uint256 next = self.nextIndex; + uint256 next = _self.nextIndex; if (next == 0) { return _forest.zeros[_height]; } if (next == _size) { - return self.frontier[_height]; + return _self.frontier[_height]; } uint256 index = next - 1; - uint256 level = _computeLevel(index); + uint256 level = computeLevel(index); // We should start at the highest frontier level with a left leaf - bytes32 temp = self.frontier[level]; + bytes32 temp = _self.frontier[level]; uint256 bits = index >> level; for (uint256 i = level; i < _height; i++) { bool isRight = bits & 1 == 1; if (isRight) { - if (self.frontier[i] == temp) { + if (_self.frontier[i] == temp) { // We will never hit the case that frontier[i] == temp // because this require that frontier[i] is the right child // and in that case we started higher up the tree revert("Mistakes were made"); } - temp = Hash.sha256ToField(bytes.concat(self.frontier[i], temp)); + temp = Hash.sha256ToField(bytes.concat(_self.frontier[i], temp)); } else { temp = Hash.sha256ToField(bytes.concat(temp, _forest.zeros[i])); } @@ -79,11 +79,11 @@ library FrontierLib { return temp; } - function isFull(Tree storage self, uint256 _size) internal view returns (bool) { - return self.nextIndex == _size; + function isFull(Tree storage _self, uint256 _size) internal view returns (bool) { + return _self.nextIndex == _size; } - function _computeLevel(uint256 _leafIndex) internal pure returns (uint256) { + function computeLevel(uint256 _leafIndex) internal pure returns (uint256) { // The number of trailing ones is how many times in a row we are the right child. // e.g., each time this happens we go another layer up to update the parent. uint256 count = 0; diff --git a/l1-contracts/src/core/libraries/crypto/SampleLib.sol b/l1-contracts/src/core/libraries/crypto/SampleLib.sol index 973e316a3a9..bdca8f12628 100644 --- a/l1-contracts/src/core/libraries/crypto/SampleLib.sol +++ b/l1-contracts/src/core/libraries/crypto/SampleLib.sol @@ -195,24 +195,24 @@ library SampleLib { /** * @notice Computes the log2 of a uint256 number * - * @param x - The number to compute the log2 of + * @param _x - The number to compute the log2 of * * @return y - The log2 of the number */ - function log2(uint256 x) private pure returns (uint256 y) { + function log2(uint256 _x) private pure returns (uint256 y) { // https://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn assembly { - let arg := x - x := sub(x, 1) - x := or(x, div(x, 0x02)) - x := or(x, div(x, 0x04)) - x := or(x, div(x, 0x10)) - x := or(x, div(x, 0x100)) - x := or(x, div(x, 0x10000)) - x := or(x, div(x, 0x100000000)) - x := or(x, div(x, 0x10000000000000000)) - x := or(x, div(x, 0x100000000000000000000000000000000)) - x := add(x, 1) + let arg := _x + _x := sub(_x, 1) + _x := or(_x, div(_x, 0x02)) + _x := or(_x, div(_x, 0x04)) + _x := or(_x, div(_x, 0x10)) + _x := or(_x, div(_x, 0x100)) + _x := or(_x, div(_x, 0x10000)) + _x := or(_x, div(_x, 0x100000000)) + _x := or(_x, div(_x, 0x10000000000000000)) + _x := or(_x, div(_x, 0x100000000000000000000000000000000)) + _x := add(_x, 1) let m := mload(0x40) mstore(m, 0xf8f9cbfae6cc78fbefe7cdc3a1793dfcf4f0e8bbd8cec470b6a28a7a5a3e1efd) mstore(add(m, 0x20), 0xf5ecf1b3e9debc68e1d9cfabc5997135bfb7a7a3938b7b606b5b4b3f2f1f0ffe) @@ -225,7 +225,7 @@ library SampleLib { mstore(0x40, add(m, 0x100)) let magic := 0x818283848586878898a8b8c8d8e8f929395969799a9b9d9e9faaeb6bedeeff let shift := 0x100000000000000000000000000000000000000000000000000000000000000 - let a := div(mul(x, magic), shift) + let a := div(mul(_x, magic), shift) y := div(mload(add(m, sub(255, a))), shift) y := add(y, mul(256, gt(arg, 0x8000000000000000000000000000000000000000000000000000000000000000))) diff --git a/l1-contracts/src/governance/Apella.sol b/l1-contracts/src/governance/Apella.sol index da05aa10e3c..8331cc0cc9b 100644 --- a/l1-contracts/src/governance/Apella.sol +++ b/l1-contracts/src/governance/Apella.sol @@ -181,6 +181,7 @@ contract Apella is IApella { for (uint256 i = 0; i < actions.length; i++) { require(actions[i].target != address(ASSET), Errors.Apella__CannotCallAsset()); // We allow calls to EOAs. If you really want be my guest. + // solhint-disable-next-line avoid-low-level-calls (bool success,) = actions[i].target.call(actions[i].data); require(success, Errors.Apella__CallFailed(actions[i].target)); } @@ -190,6 +191,20 @@ contract Apella is IApella { return true; } + function dropProposal(uint256 _proposalId) external override(IApella) returns (bool) { + DataStructures.Proposal storage self = proposals[_proposalId]; + require( + self.state != DataStructures.ProposalState.Dropped, Errors.Apella__ProposalAlreadyDropped() + ); + require( + getProposalState(_proposalId) == DataStructures.ProposalState.Dropped, + Errors.Apella__ProposalCannotBeDropped() + ); + + self.state = DataStructures.ProposalState.Dropped; + return true; + } + function powerAt(address _owner, Timestamp _ts) external view override(IApella) returns (uint256) { if (_ts == Timestamp.wrap(block.timestamp)) { return users[_owner].powerNow(); @@ -204,36 +219,33 @@ contract Apella is IApella { return total.powerAt(_ts); } - function getConfiguration() external view returns (DataStructures.Configuration memory) { + function getConfiguration() + external + view + override(IApella) + returns (DataStructures.Configuration memory) + { return configuration; } - function getProposal(uint256 _proposalId) external view returns (DataStructures.Proposal memory) { + function getProposal(uint256 _proposalId) + external + view + override(IApella) + returns (DataStructures.Proposal memory) + { return proposals[_proposalId]; } function getWithdrawal(uint256 _withdrawalId) external view + override(IApella) returns (DataStructures.Withdrawal memory) { return withdrawals[_withdrawalId]; } - function dropProposal(uint256 _proposalId) external returns (bool) { - DataStructures.Proposal storage self = proposals[_proposalId]; - require( - self.state != DataStructures.ProposalState.Dropped, Errors.Apella__ProposalAlreadyDropped() - ); - require( - getProposalState(_proposalId) == DataStructures.ProposalState.Dropped, - Errors.Apella__ProposalCannotBeDropped() - ); - - self.state = DataStructures.ProposalState.Dropped; - return true; - } - /** * @notice Get the state of the proposal * diff --git a/l1-contracts/src/governance/Sysstia.sol b/l1-contracts/src/governance/Sysstia.sol index 15aa341e8e7..9cc787cce7c 100644 --- a/l1-contracts/src/governance/Sysstia.sol +++ b/l1-contracts/src/governance/Sysstia.sol @@ -25,7 +25,7 @@ contract Sysstia is ISysstia, Ownable { registry = _registry; } - function updateRegistry(IRegistry _registry) external onlyOwner { + function updateRegistry(IRegistry _registry) external override(ISysstia) onlyOwner { registry = _registry; emit RegistryUpdated(_registry); } @@ -53,7 +53,7 @@ contract Sysstia is ISysstia, Ownable { return reward; } - function canonicalRollup() public view returns (address) { + function canonicalRollup() public view override(ISysstia) returns (address) { return registry.getRollup(); } } diff --git a/l1-contracts/src/governance/interfaces/IApella.sol b/l1-contracts/src/governance/interfaces/IApella.sol index 52a84c2e1b0..43b14ac926d 100644 --- a/l1-contracts/src/governance/interfaces/IApella.sol +++ b/l1-contracts/src/governance/interfaces/IApella.sol @@ -24,10 +24,18 @@ interface IApella { function propose(IPayload _proposal) external returns (bool); function vote(uint256 _proposalId, uint256 _amount, bool _support) external returns (bool); function execute(uint256 _proposalId) external returns (bool); + function dropProposal(uint256 _proposalId) external returns (bool); + function powerAt(address _owner, Timestamp _ts) external view returns (uint256); function totalPowerAt(Timestamp _ts) external view returns (uint256); function getProposalState(uint256 _proposalId) external view returns (DataStructures.ProposalState); + function getConfiguration() external view returns (DataStructures.Configuration memory); + function getProposal(uint256 _proposalId) external view returns (DataStructures.Proposal memory); + function getWithdrawal(uint256 _withdrawalId) + external + view + returns (DataStructures.Withdrawal memory); } diff --git a/l1-contracts/src/governance/libraries/ConfigurationLib.sol b/l1-contracts/src/governance/libraries/ConfigurationLib.sol index 266e9c83ac7..e9661a361fa 100644 --- a/l1-contracts/src/governance/libraries/ConfigurationLib.sol +++ b/l1-contracts/src/governance/libraries/ConfigurationLib.sol @@ -18,9 +18,9 @@ library ConfigurationLib { Timestamp internal constant TIME_LOWER = Timestamp.wrap(3600); Timestamp internal constant TIME_UPPER = Timestamp.wrap(30 * 24 * 3600); - function lockDelay(DataStructures.Configuration storage self) internal view returns (Timestamp) { - return Timestamp.wrap(Timestamp.unwrap(self.votingDelay) / 5) + self.votingDuration - + self.executionDelay; + function lockDelay(DataStructures.Configuration storage _self) internal view returns (Timestamp) { + return Timestamp.wrap(Timestamp.unwrap(_self.votingDelay) / 5) + _self.votingDuration + + _self.executionDelay; } /** @@ -28,49 +28,49 @@ library ConfigurationLib { * @dev We specify `memory` here since it is called on outside import for validation * before writing it to state. */ - function assertValid(DataStructures.Configuration memory self) internal pure returns (bool) { - require(self.quorum >= QUORUM_LOWER, Errors.Apella__ConfigurationLib__QuorumTooSmall()); - require(self.quorum <= QUORUM_UPPER, Errors.Apella__ConfigurationLib__QuorumTooBig()); + function assertValid(DataStructures.Configuration memory _self) internal pure returns (bool) { + require(_self.quorum >= QUORUM_LOWER, Errors.Apella__ConfigurationLib__QuorumTooSmall()); + require(_self.quorum <= QUORUM_UPPER, Errors.Apella__ConfigurationLib__QuorumTooBig()); require( - self.voteDifferential <= DIFFERENTIAL_UPPER, + _self.voteDifferential <= DIFFERENTIAL_UPPER, Errors.Apella__ConfigurationLib__DifferentialTooBig() ); require( - self.minimumVotes >= VOTES_LOWER, Errors.Apella__ConfigurationLib__InvalidMinimumVotes() + _self.minimumVotes >= VOTES_LOWER, Errors.Apella__ConfigurationLib__InvalidMinimumVotes() ); require( - self.votingDelay >= TIME_LOWER, Errors.Apella__ConfigurationLib__TimeTooSmall("VotingDelay") + _self.votingDelay >= TIME_LOWER, Errors.Apella__ConfigurationLib__TimeTooSmall("VotingDelay") ); require( - self.votingDelay <= TIME_UPPER, Errors.Apella__ConfigurationLib__TimeTooBig("VotingDelay") + _self.votingDelay <= TIME_UPPER, Errors.Apella__ConfigurationLib__TimeTooBig("VotingDelay") ); require( - self.votingDuration >= TIME_LOWER, + _self.votingDuration >= TIME_LOWER, Errors.Apella__ConfigurationLib__TimeTooSmall("VotingDuration") ); require( - self.votingDuration <= TIME_UPPER, + _self.votingDuration <= TIME_UPPER, Errors.Apella__ConfigurationLib__TimeTooBig("VotingDuration") ); require( - self.executionDelay >= TIME_LOWER, + _self.executionDelay >= TIME_LOWER, Errors.Apella__ConfigurationLib__TimeTooSmall("ExecutionDelay") ); require( - self.executionDelay <= TIME_UPPER, + _self.executionDelay <= TIME_UPPER, Errors.Apella__ConfigurationLib__TimeTooBig("ExecutionDelay") ); require( - self.gracePeriod >= TIME_LOWER, Errors.Apella__ConfigurationLib__TimeTooSmall("GracePeriod") + _self.gracePeriod >= TIME_LOWER, Errors.Apella__ConfigurationLib__TimeTooSmall("GracePeriod") ); require( - self.gracePeriod <= TIME_UPPER, Errors.Apella__ConfigurationLib__TimeTooBig("GracePeriod") + _self.gracePeriod <= TIME_UPPER, Errors.Apella__ConfigurationLib__TimeTooBig("GracePeriod") ); return true; diff --git a/l1-contracts/src/governance/libraries/Errors.sol b/l1-contracts/src/governance/libraries/Errors.sol index df3ebc1cb55..69b237abccb 100644 --- a/l1-contracts/src/governance/libraries/Errors.sol +++ b/l1-contracts/src/governance/libraries/Errors.sol @@ -48,8 +48,8 @@ library Errors { error Gerousia__FailedToPropose(IPayload proposal); // 0x6ca2a2ed error Gerousia__InstanceHaveNoCode(address instance); // 0x20a3b441 error Gerousia__InsufficientVotes(); // 0xba1e05ef - error Gerousia__InvalidNAndMValues(uint256 N, uint256 M); // 0x520d9704 - error Gerousia__NCannotBeLargerTHanM(uint256 N, uint256 M); // 0x2fdfc063 + error Gerousia__InvalidNAndMValues(uint256 n, uint256 m); // 0x520d9704 + error Gerousia__NCannotBeLargerTHanM(uint256 n, uint256 m); // 0x2fdfc063 error Gerousia__OnlyProposerCanVote(address caller, address proposer); // 0xba27df38 error Gerousia__ProposalAlreadyExecuted(uint256 roundNumber); // 0x7aeacb17 error Gerousia__ProposalCannotBeAddressZero(); // 0xdb3e4b6e diff --git a/l1-contracts/src/governance/libraries/ProposalLib.sol b/l1-contracts/src/governance/libraries/ProposalLib.sol index 4a72201a887..8d6fb166a82 100644 --- a/l1-contracts/src/governance/libraries/ProposalLib.sol +++ b/l1-contracts/src/governance/libraries/ProposalLib.sol @@ -42,19 +42,19 @@ enum VoteTabulationInfo { * for example ending at 0, having a case where no votes are needed */ library ProposalLib { - function voteTabulation(DataStructures.Proposal storage self, uint256 _totalPower) + function voteTabulation(DataStructures.Proposal storage _self, uint256 _totalPower) internal view returns (VoteTabulationReturn, VoteTabulationInfo) { - if (self.config.minimumVotes == 0) { + if (_self.config.minimumVotes == 0) { return (VoteTabulationReturn.Invalid, VoteTabulationInfo.MinimumEqZero); } - if (_totalPower < self.config.minimumVotes) { + if (_totalPower < _self.config.minimumVotes) { return (VoteTabulationReturn.Rejected, VoteTabulationInfo.TotalPowerLtMinimum); } - uint256 votesNeeded = Math.mulDiv(_totalPower, self.config.quorum, 1e18, Math.Rounding.Ceil); + uint256 votesNeeded = Math.mulDiv(_totalPower, _self.config.quorum, 1e18, Math.Rounding.Ceil); if (votesNeeded == 0) { return (VoteTabulationReturn.Invalid, VoteTabulationInfo.VotesNeededEqZero); } @@ -62,7 +62,7 @@ library ProposalLib { return (VoteTabulationReturn.Invalid, VoteTabulationInfo.VotesNeededGtTotalPower); } - uint256 votesCast = self.summedBallot.nea + self.summedBallot.yea; + uint256 votesCast = _self.summedBallot.nea + _self.summedBallot.yea; if (votesCast < votesNeeded) { return (VoteTabulationReturn.Rejected, VoteTabulationInfo.VotesCastLtVotesNeeded); } @@ -70,11 +70,11 @@ library ProposalLib { // Edge case where all the votes are yea, no need to compute differential // Assumes a "sane" value for differential, e.g., you cannot require more votes // to be yes than total votes. - if (self.summedBallot.yea == votesCast) { + if (_self.summedBallot.yea == votesCast) { return (VoteTabulationReturn.Accepted, VoteTabulationInfo.YeaVotesEqVotesCast); } - uint256 yeaLimitFraction = Math.ceilDiv(1e18 + self.config.voteDifferential, 2); + uint256 yeaLimitFraction = Math.ceilDiv(1e18 + _self.config.voteDifferential, 2); uint256 yeaLimit = Math.mulDiv(votesCast, yeaLimitFraction, 1e18, Math.Rounding.Ceil); /*if (yeaLimit == 0) { @@ -91,7 +91,7 @@ library ProposalLib { // We explictly need MORE to ensure we don't "tie". // If we need as many yea as there are votes, we know it is impossible already. // due to the check earlier, that summedBallot.yea == votesCast. - if (self.summedBallot.yea <= yeaLimit) { + if (_self.summedBallot.yea <= yeaLimit) { return (VoteTabulationReturn.Rejected, VoteTabulationInfo.YeaVotesLeYeaLimit); } @@ -101,28 +101,28 @@ library ProposalLib { /** * @notice A stable state is one which cannoted be moved away from */ - function isStable(DataStructures.Proposal storage self) internal view returns (bool) { - DataStructures.ProposalState s = self.state; // cache + function isStable(DataStructures.Proposal storage _self) internal view returns (bool) { + DataStructures.ProposalState s = _self.state; // cache return s == DataStructures.ProposalState.Executed || s == DataStructures.ProposalState.Dropped; } - function pendingThrough(DataStructures.Proposal storage self) internal view returns (Timestamp) { - return self.creation + self.config.votingDelay; + function pendingThrough(DataStructures.Proposal storage _self) internal view returns (Timestamp) { + return _self.creation + _self.config.votingDelay; } - function activeThrough(DataStructures.Proposal storage self) internal view returns (Timestamp) { - return ProposalLib.pendingThrough(self) + self.config.votingDuration; + function activeThrough(DataStructures.Proposal storage _self) internal view returns (Timestamp) { + return ProposalLib.pendingThrough(_self) + _self.config.votingDuration; } - function queuedThrough(DataStructures.Proposal storage self) internal view returns (Timestamp) { - return ProposalLib.activeThrough(self) + self.config.executionDelay; + function queuedThrough(DataStructures.Proposal storage _self) internal view returns (Timestamp) { + return ProposalLib.activeThrough(_self) + _self.config.executionDelay; } - function executableThrough(DataStructures.Proposal storage self) + function executableThrough(DataStructures.Proposal storage _self) internal view returns (Timestamp) { - return ProposalLib.queuedThrough(self) + self.config.gracePeriod; + return ProposalLib.queuedThrough(_self) + _self.config.gracePeriod; } } diff --git a/l1-contracts/src/governance/libraries/UserLib.sol b/l1-contracts/src/governance/libraries/UserLib.sol index bc3ca1f7d34..869deb8df76 100644 --- a/l1-contracts/src/governance/libraries/UserLib.sol +++ b/l1-contracts/src/governance/libraries/UserLib.sol @@ -6,57 +6,57 @@ import {Timestamp} from "@aztec/core/libraries/TimeMath.sol"; import {Errors} from "@aztec/governance/libraries/Errors.sol"; library UserLib { - function add(DataStructures.User storage self, uint256 _amount) internal { + function add(DataStructures.User storage _self, uint256 _amount) internal { if (_amount == 0) { return; } - if (self.numCheckPoints == 0) { - self.checkpoints[0] = + if (_self.numCheckPoints == 0) { + _self.checkpoints[0] = DataStructures.CheckPoint({time: Timestamp.wrap(block.timestamp), power: _amount}); - self.numCheckPoints += 1; + _self.numCheckPoints += 1; } else { - DataStructures.CheckPoint storage last = self.checkpoints[self.numCheckPoints - 1]; + DataStructures.CheckPoint storage last = _self.checkpoints[_self.numCheckPoints - 1]; if (last.time == Timestamp.wrap(block.timestamp)) { last.power += _amount; } else { - self.checkpoints[self.numCheckPoints] = DataStructures.CheckPoint({ + _self.checkpoints[_self.numCheckPoints] = DataStructures.CheckPoint({ time: Timestamp.wrap(block.timestamp), power: last.power + _amount }); - self.numCheckPoints += 1; + _self.numCheckPoints += 1; } } } - function sub(DataStructures.User storage self, uint256 _amount) internal { + function sub(DataStructures.User storage _self, uint256 _amount) internal { if (_amount == 0) { return; } - require(self.numCheckPoints > 0, Errors.Apella__NoCheckpointsFound()); - DataStructures.CheckPoint storage last = self.checkpoints[self.numCheckPoints - 1]; + require(_self.numCheckPoints > 0, Errors.Apella__NoCheckpointsFound()); + DataStructures.CheckPoint storage last = _self.checkpoints[_self.numCheckPoints - 1]; require( last.power >= _amount, Errors.Apella__InsufficientPower(msg.sender, last.power, _amount) ); if (last.time == Timestamp.wrap(block.timestamp)) { last.power -= _amount; } else { - self.checkpoints[self.numCheckPoints] = DataStructures.CheckPoint({ + _self.checkpoints[_self.numCheckPoints] = DataStructures.CheckPoint({ time: Timestamp.wrap(block.timestamp), power: last.power - _amount }); - self.numCheckPoints += 1; + _self.numCheckPoints += 1; } } - function powerNow(DataStructures.User storage self) internal view returns (uint256) { - uint256 numCheckPoints = self.numCheckPoints; + function powerNow(DataStructures.User storage _self) internal view returns (uint256) { + uint256 numCheckPoints = _self.numCheckPoints; if (numCheckPoints == 0) { return 0; } - return self.checkpoints[numCheckPoints - 1].power; + return _self.checkpoints[numCheckPoints - 1].power; } - function powerAt(DataStructures.User storage self, Timestamp _time) + function powerAt(DataStructures.User storage _self, Timestamp _time) internal view returns (uint256) @@ -65,16 +65,16 @@ library UserLib { // We disallow using it to avoid potential misuse. require(_time < Timestamp.wrap(block.timestamp), Errors.Apella__UserLib__NotInPast()); - uint256 numCheckPoints = self.numCheckPoints; + uint256 numCheckPoints = _self.numCheckPoints; if (numCheckPoints == 0) { return 0; } - if (self.checkpoints[numCheckPoints - 1].time <= _time) { - return self.checkpoints[numCheckPoints - 1].power; + if (_self.checkpoints[numCheckPoints - 1].time <= _time) { + return _self.checkpoints[numCheckPoints - 1].power; } - if (self.checkpoints[0].time > _time) { + if (_self.checkpoints[0].time > _time) { return 0; } @@ -82,7 +82,7 @@ library UserLib { uint256 upper = numCheckPoints - 1; while (upper > lower) { uint256 center = upper - (upper - lower) / 2; // ceil, avoiding overflow - DataStructures.CheckPoint memory cp = self.checkpoints[center]; + DataStructures.CheckPoint memory cp = _self.checkpoints[center]; if (cp.time == _time) { return cp.power; } else if (cp.time < _time) { @@ -91,6 +91,6 @@ library UserLib { upper = center - 1; } } - return self.checkpoints[lower].power; + return _self.checkpoints[lower].power; } } diff --git a/l1-contracts/src/mock/MockFeeJuicePortal.sol b/l1-contracts/src/mock/MockFeeJuicePortal.sol index ec90fda40f9..a519da4560d 100644 --- a/l1-contracts/src/mock/MockFeeJuicePortal.sol +++ b/l1-contracts/src/mock/MockFeeJuicePortal.sol @@ -16,20 +16,20 @@ contract MockFeeJuicePortal is IFeeJuicePortal { UNDERLYING = new TestERC20(); } - function initialize() external override {} + function initialize() external override(IFeeJuicePortal) {} - function distributeFees(address, uint256) external override {} + function distributeFees(address, uint256) external override(IFeeJuicePortal) {} function depositToAztecPublic(bytes32, uint256, bytes32) external pure - override + override(IFeeJuicePortal) returns (bytes32, uint256) { return (bytes32(0), 0); } - function canonicalRollup() external pure override returns (address) { + function canonicalRollup() external pure override(IFeeJuicePortal) returns (address) { return address(0); } } diff --git a/l1-contracts/src/mock/TestERC20.sol b/l1-contracts/src/mock/TestERC20.sol index 3f0e54dc5f6..6236f94d758 100644 --- a/l1-contracts/src/mock/TestERC20.sol +++ b/l1-contracts/src/mock/TestERC20.sol @@ -1,14 +1,15 @@ // SPDX-License-Identifier: Apache-2.0 // docs:start:contract -pragma solidity ^0.8.0; +pragma solidity >=0.8.27; -import "@oz/token/ERC20/ERC20.sol"; +import {ERC20} from "@oz/token/ERC20/ERC20.sol"; +import {IMintableERC20} from "../governance/interfaces/IMintableERC20.sol"; -contract TestERC20 is ERC20 { +contract TestERC20 is ERC20, IMintableERC20 { constructor() ERC20("Portal", "PORTAL") {} - function mint(address to, uint256 amount) external { - _mint(to, amount); + function mint(address _to, uint256 _amount) external override(IMintableERC20) { + _mint(_to, _amount); } } // docs:end:contract From 10d080b9528df2f6ceb269ffc88f1d345a6a8d97 Mon Sep 17 00:00:00 2001 From: LHerskind Date: Thu, 24 Oct 2024 13:25:02 +0000 Subject: [PATCH 2/3] chore: solhint imports order --- l1-contracts/.solhint.json | 4 ++- l1-contracts/package.json | 1 + l1-contracts/src/core/FeeJuicePortal.sol | 9 +++-- l1-contracts/src/core/Leonidas.sol | 11 +++--- .../src/core/ProofCommitmentEscrow.sol | 7 ++-- l1-contracts/src/core/Rollup.sol | 34 ++++++++----------- .../src/core/interfaces/IFeeJuicePortal.sol | 2 +- .../src/core/libraries/EpochProofQuoteLib.sol | 2 +- .../src/core/libraries/TxsDecoder.sol | 2 +- .../src/core/libraries/crypto/MerkleLib.sol | 2 +- l1-contracts/src/core/messagebridge/Inbox.sol | 5 ++- .../src/core/messagebridge/Outbox.sol | 6 ++-- l1-contracts/src/governance/Apella.sol | 9 ++--- l1-contracts/src/governance/Gerousia.sol | 7 ++-- .../src/governance/Nomismatokopio.sol | 4 +-- l1-contracts/src/governance/Sysstia.sol | 6 ++-- .../src/governance/interfaces/IApella.sol | 2 +- .../governance/libraries/ConfigurationLib.sol | 2 +- .../src/governance/libraries/Errors.sol | 2 +- .../src/governance/libraries/ProposalLib.sol | 2 +- .../src/governance/libraries/UserLib.sol | 2 +- l1-contracts/src/mock/MockFeeJuicePortal.sol | 4 +-- 22 files changed, 55 insertions(+), 70 deletions(-) diff --git a/l1-contracts/.solhint.json b/l1-contracts/.solhint.json index e2eb8eb9628..f3b1b7f84df 100644 --- a/l1-contracts/.solhint.json +++ b/l1-contracts/.solhint.json @@ -34,6 +34,8 @@ "strict-override": "error", "ordering": "error", "comprehensive-interface": "error", - "no-unused-import": "error" + "no-unused-import": "error", + "imports-order": "error", + "check-send-result": "error" } } \ No newline at end of file diff --git a/l1-contracts/package.json b/l1-contracts/package.json index f01146a0382..d8f9c5e85f2 100644 --- a/l1-contracts/package.json +++ b/l1-contracts/package.json @@ -9,6 +9,7 @@ "scripts": { "format": "forge fmt", "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" } diff --git a/l1-contracts/src/core/FeeJuicePortal.sol b/l1-contracts/src/core/FeeJuicePortal.sol index 285e1fdbb86..860e3bef2fc 100644 --- a/l1-contracts/src/core/FeeJuicePortal.sol +++ b/l1-contracts/src/core/FeeJuicePortal.sol @@ -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 { diff --git a/l1-contracts/src/core/Leonidas.sol b/l1-contracts/src/core/Leonidas.sol index 05b42325253..14a85d3bce1 100644 --- a/l1-contracts/src/core/Leonidas.sol +++ b/l1-contracts/src/core/Leonidas.sol @@ -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 diff --git a/l1-contracts/src/core/ProofCommitmentEscrow.sol b/l1-contracts/src/core/ProofCommitmentEscrow.sol index dc7aff1f314..fb2997d17cb 100644 --- a/l1-contracts/src/core/ProofCommitmentEscrow.sol +++ b/l1-contracts/src/core/ProofCommitmentEscrow.sol @@ -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; diff --git a/l1-contracts/src/core/Rollup.sol b/l1-contracts/src/core/Rollup.sol index 10749015dea..ea56a02b429 100644 --- a/l1-contracts/src/core/Rollup.sol +++ b/l1-contracts/src/core/Rollup.sol @@ -2,36 +2,32 @@ // Copyright 2024 Aztec Labs. pragma solidity >=0.8.27; -import {EIP712} from "@oz/utils/cryptography/EIP712.sol"; - -import {IProofCommitmentEscrow} from "@aztec/core/interfaces/IProofCommitmentEscrow.sol"; -import {IInbox} from "@aztec/core/interfaces/messagebridge/IInbox.sol"; -import {IOutbox} from "@aztec/core/interfaces/messagebridge/IOutbox.sol"; import {IFeeJuicePortal} from "@aztec/core/interfaces/IFeeJuicePortal.sol"; +import {IProofCommitmentEscrow} from "@aztec/core/interfaces/IProofCommitmentEscrow.sol"; import {IRollup, ITestRollup} from "@aztec/core/interfaces/IRollup.sol"; import {IVerifier} from "@aztec/core/interfaces/IVerifier.sol"; -import {ISysstia} from "@aztec/governance/interfaces/ISysstia.sol"; -import {IERC20} from "@oz/token/ERC20/IERC20.sol"; - +import {IInbox} from "@aztec/core/interfaces/messagebridge/IInbox.sol"; +import {IOutbox} from "@aztec/core/interfaces/messagebridge/IOutbox.sol"; +import {Leonidas} from "@aztec/core/Leonidas.sol"; import {Constants} from "@aztec/core/libraries/ConstantsGen.sol"; +import {MerkleLib} from "@aztec/core/libraries/crypto/MerkleLib.sol"; +import {SignatureLib} from "@aztec/core/libraries/crypto/SignatureLib.sol"; import {DataStructures} from "@aztec/core/libraries/DataStructures.sol"; import {EpochProofQuoteLib} from "@aztec/core/libraries/EpochProofQuoteLib.sol"; import {Errors} from "@aztec/core/libraries/Errors.sol"; import {HeaderLib} from "@aztec/core/libraries/HeaderLib.sol"; +import {Timestamp, Slot, Epoch, SlotLib, EpochLib} from "@aztec/core/libraries/TimeMath.sol"; import {TxsDecoder} from "@aztec/core/libraries/TxsDecoder.sol"; -import {MerkleLib} from "@aztec/core/libraries/crypto/MerkleLib.sol"; -import {SignatureLib} from "@aztec/core/libraries/crypto/SignatureLib.sol"; -import {SafeCast} from "@oz/utils/math/SafeCast.sol"; -import {Math} from "@oz/utils/math/Math.sol"; -import {SafeERC20} from "@oz/token/ERC20/utils/SafeERC20.sol"; - import {Inbox} from "@aztec/core/messagebridge/Inbox.sol"; -import {Leonidas} from "@aztec/core/Leonidas.sol"; -import {MockVerifier} from "@aztec/mock/MockVerifier.sol"; -import {ProofCommitmentEscrow} from "@aztec/core/ProofCommitmentEscrow.sol"; import {Outbox} from "@aztec/core/messagebridge/Outbox.sol"; - -import {Timestamp, Slot, Epoch, SlotLib, EpochLib} from "@aztec/core/libraries/TimeMath.sol"; +import {ProofCommitmentEscrow} from "@aztec/core/ProofCommitmentEscrow.sol"; +import {ISysstia} from "@aztec/governance/interfaces/ISysstia.sol"; +import {MockVerifier} from "@aztec/mock/MockVerifier.sol"; +import {IERC20} from "@oz/token/ERC20/IERC20.sol"; +import {SafeERC20} from "@oz/token/ERC20/utils/SafeERC20.sol"; +import {EIP712} from "@oz/utils/cryptography/EIP712.sol"; +import {Math} from "@oz/utils/math/Math.sol"; +import {SafeCast} from "@oz/utils/math/SafeCast.sol"; /** * @title Rollup diff --git a/l1-contracts/src/core/interfaces/IFeeJuicePortal.sol b/l1-contracts/src/core/interfaces/IFeeJuicePortal.sol index 884430cb201..1bec19f4195 100644 --- a/l1-contracts/src/core/interfaces/IFeeJuicePortal.sol +++ b/l1-contracts/src/core/interfaces/IFeeJuicePortal.sol @@ -2,8 +2,8 @@ // Copyright 2024 Aztec Labs. pragma solidity >=0.8.27; -import {IERC20} from "@oz/token/ERC20/IERC20.sol"; import {IRegistry} from "@aztec/governance/interfaces/IRegistry.sol"; +import {IERC20} from "@oz/token/ERC20/IERC20.sol"; interface IFeeJuicePortal { event DepositToAztecPublic( diff --git a/l1-contracts/src/core/libraries/EpochProofQuoteLib.sol b/l1-contracts/src/core/libraries/EpochProofQuoteLib.sol index 4f270d2204d..be838b7a7ad 100644 --- a/l1-contracts/src/core/libraries/EpochProofQuoteLib.sol +++ b/l1-contracts/src/core/libraries/EpochProofQuoteLib.sol @@ -2,8 +2,8 @@ // Copyright 2024 Aztec Labs. pragma solidity >=0.8.27; -import {Slot, Epoch} from "@aztec/core/libraries/TimeMath.sol"; import {SignatureLib} from "@aztec/core/libraries/crypto/SignatureLib.sol"; +import {Slot, Epoch} from "@aztec/core/libraries/TimeMath.sol"; library EpochProofQuoteLib { /** diff --git a/l1-contracts/src/core/libraries/TxsDecoder.sol b/l1-contracts/src/core/libraries/TxsDecoder.sol index ade6097804d..e58dd5fe06b 100644 --- a/l1-contracts/src/core/libraries/TxsDecoder.sol +++ b/l1-contracts/src/core/libraries/TxsDecoder.sol @@ -3,8 +3,8 @@ pragma solidity >=0.8.27; import {Constants} from "@aztec/core/libraries/ConstantsGen.sol"; -import {Errors} from "@aztec/core/libraries/Errors.sol"; import {Hash} from "@aztec/core/libraries/crypto/Hash.sol"; +import {Errors} from "@aztec/core/libraries/Errors.sol"; /** * @title Txs Decoder Library diff --git a/l1-contracts/src/core/libraries/crypto/MerkleLib.sol b/l1-contracts/src/core/libraries/crypto/MerkleLib.sol index bd8d53a0df3..394c805044d 100644 --- a/l1-contracts/src/core/libraries/crypto/MerkleLib.sol +++ b/l1-contracts/src/core/libraries/crypto/MerkleLib.sol @@ -2,8 +2,8 @@ // Copyright 2024 Aztec Labs. pragma solidity >=0.8.27; -import {Errors} from "@aztec/core/libraries/Errors.sol"; import {Hash} from "@aztec/core/libraries/crypto/Hash.sol"; +import {Errors} from "@aztec/core/libraries/Errors.sol"; /** * @title Merkle Library diff --git a/l1-contracts/src/core/messagebridge/Inbox.sol b/l1-contracts/src/core/messagebridge/Inbox.sol index ade70b5f321..ade184eda55 100644 --- a/l1-contracts/src/core/messagebridge/Inbox.sol +++ b/l1-contracts/src/core/messagebridge/Inbox.sol @@ -3,12 +3,11 @@ pragma solidity >=0.8.27; import {IInbox} from "@aztec/core/interfaces/messagebridge/IInbox.sol"; - import {Constants} from "@aztec/core/libraries/ConstantsGen.sol"; +import {FrontierLib} from "@aztec/core/libraries/crypto/FrontierLib.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 {FrontierLib} from "@aztec/core/libraries/crypto/FrontierLib.sol"; /** * @title Inbox diff --git a/l1-contracts/src/core/messagebridge/Outbox.sol b/l1-contracts/src/core/messagebridge/Outbox.sol index 513f615c437..5583311517d 100644 --- a/l1-contracts/src/core/messagebridge/Outbox.sol +++ b/l1-contracts/src/core/messagebridge/Outbox.sol @@ -3,12 +3,10 @@ pragma solidity >=0.8.27; import {IOutbox} from "@aztec/core//interfaces/messagebridge/IOutbox.sol"; - +import {Hash} from "@aztec/core/libraries/crypto/Hash.sol"; +import {MerkleLib} from "@aztec/core/libraries/crypto/MerkleLib.sol"; import {DataStructures} from "@aztec/core/libraries/DataStructures.sol"; import {Errors} from "@aztec/core/libraries/Errors.sol"; -import {MerkleLib} from "@aztec/core/libraries/crypto/MerkleLib.sol"; -import {Hash} from "@aztec/core/libraries/crypto/Hash.sol"; - import {Rollup} from "@aztec/core/Rollup.sol"; /** diff --git a/l1-contracts/src/governance/Apella.sol b/l1-contracts/src/governance/Apella.sol index 8331cc0cc9b..67cd380c8b9 100644 --- a/l1-contracts/src/governance/Apella.sol +++ b/l1-contracts/src/governance/Apella.sol @@ -1,17 +1,14 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.27; -import {IPayload} from "@aztec/governance/interfaces/IPayload.sol"; +import {Timestamp} from "@aztec/core/libraries/TimeMath.sol"; import {IApella} from "@aztec/governance/interfaces/IApella.sol"; - -import {DataStructures} from "@aztec/governance/libraries/DataStructures.sol"; +import {IPayload} from "@aztec/governance/interfaces/IPayload.sol"; import {ConfigurationLib} from "@aztec/governance/libraries/ConfigurationLib.sol"; +import {DataStructures} from "@aztec/governance/libraries/DataStructures.sol"; import {Errors} from "@aztec/governance/libraries/Errors.sol"; import {ProposalLib, VoteTabulationReturn} from "@aztec/governance/libraries/ProposalLib.sol"; import {UserLib} from "@aztec/governance/libraries/UserLib.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"; diff --git a/l1-contracts/src/governance/Gerousia.sol b/l1-contracts/src/governance/Gerousia.sol index 58bfe80ab6d..4759869450e 100644 --- a/l1-contracts/src/governance/Gerousia.sol +++ b/l1-contracts/src/governance/Gerousia.sol @@ -1,15 +1,14 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.27; -import {IRegistry} from "@aztec/governance/interfaces/IRegistry.sol"; +import {ILeonidas} from "@aztec/core/interfaces/ILeonidas.sol"; +import {Slot, SlotLib} from "@aztec/core/libraries/TimeMath.sol"; import {IApella} from "@aztec/governance/interfaces/IApella.sol"; import {IGerousia} from "@aztec/governance/interfaces/IGerousia.sol"; import {IPayload} from "@aztec/governance/interfaces/IPayload.sol"; +import {IRegistry} from "@aztec/governance/interfaces/IRegistry.sol"; import {Errors} from "@aztec/governance/libraries/Errors.sol"; -import {Slot, SlotLib} from "@aztec/core/libraries/TimeMath.sol"; -import {ILeonidas} from "@aztec/core/interfaces/ILeonidas.sol"; - /** * @notice A Gerousia implementation following the empire model * Beware that while governance generally do not care about the implementation diff --git a/l1-contracts/src/governance/Nomismatokopio.sol b/l1-contracts/src/governance/Nomismatokopio.sol index 7a5e97be013..ab5543b92f8 100644 --- a/l1-contracts/src/governance/Nomismatokopio.sol +++ b/l1-contracts/src/governance/Nomismatokopio.sol @@ -2,10 +2,10 @@ // Copyright 2023 Aztec Labs. pragma solidity >=0.8.27; -import {Ownable} from "@oz/access/Ownable.sol"; -import {Errors} from "@aztec/governance/libraries/Errors.sol"; import {IMintableERC20} from "@aztec/governance/interfaces/IMintableERC20.sol"; import {INomismatokopio} from "@aztec/governance/interfaces/INomismatokopio.sol"; +import {Errors} from "@aztec/governance/libraries/Errors.sol"; +import {Ownable} from "@oz/access/Ownable.sol"; contract Nomismatokopio is INomismatokopio, Ownable { IMintableERC20 public immutable ASSET; diff --git a/l1-contracts/src/governance/Sysstia.sol b/l1-contracts/src/governance/Sysstia.sol index 9cc787cce7c..1dfaf0ca9d8 100644 --- a/l1-contracts/src/governance/Sysstia.sol +++ b/l1-contracts/src/governance/Sysstia.sol @@ -2,14 +2,12 @@ // Copyright 2023 Aztec Labs. pragma solidity >=0.8.27; -import {IERC20} from "@oz/token/ERC20/IERC20.sol"; -import {SafeERC20} from "@oz/token/ERC20/utils/SafeERC20.sol"; - import {IRegistry} from "@aztec/governance/interfaces/IRegistry.sol"; import {ISysstia} from "@aztec/governance/interfaces/ISysstia.sol"; - import {Errors} from "@aztec/governance/libraries/Errors.sol"; import {Ownable} from "@oz/access/Ownable.sol"; +import {IERC20} from "@oz/token/ERC20/IERC20.sol"; +import {SafeERC20} from "@oz/token/ERC20/utils/SafeERC20.sol"; contract Sysstia is ISysstia, Ownable { using SafeERC20 for IERC20; diff --git a/l1-contracts/src/governance/interfaces/IApella.sol b/l1-contracts/src/governance/interfaces/IApella.sol index 43b14ac926d..7709307fa48 100644 --- a/l1-contracts/src/governance/interfaces/IApella.sol +++ b/l1-contracts/src/governance/interfaces/IApella.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.27; +import {Timestamp} from "@aztec/core/libraries/TimeMath.sol"; import {IPayload} from "@aztec/governance/interfaces/IPayload.sol"; import {DataStructures} from "@aztec/governance/libraries/DataStructures.sol"; -import {Timestamp} from "@aztec/core/libraries/TimeMath.sol"; interface IApella { event Proposed(uint256 indexed proposalId, address indexed proposal); diff --git a/l1-contracts/src/governance/libraries/ConfigurationLib.sol b/l1-contracts/src/governance/libraries/ConfigurationLib.sol index e9661a361fa..9a4762b9efd 100644 --- a/l1-contracts/src/governance/libraries/ConfigurationLib.sol +++ b/l1-contracts/src/governance/libraries/ConfigurationLib.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.27; -import {DataStructures} from "@aztec/governance/libraries/DataStructures.sol"; import {Timestamp} from "@aztec/core/libraries/TimeMath.sol"; +import {DataStructures} from "@aztec/governance/libraries/DataStructures.sol"; import {Errors} from "@aztec/governance/libraries/Errors.sol"; library ConfigurationLib { diff --git a/l1-contracts/src/governance/libraries/Errors.sol b/l1-contracts/src/governance/libraries/Errors.sol index 69b237abccb..8132a84491e 100644 --- a/l1-contracts/src/governance/libraries/Errors.sol +++ b/l1-contracts/src/governance/libraries/Errors.sol @@ -2,8 +2,8 @@ // Copyright 2023 Aztec Labs. pragma solidity >=0.8.27; -import {IPayload} from "@aztec/governance/interfaces/IPayload.sol"; import {Slot, Timestamp} from "@aztec/core/libraries/TimeMath.sol"; +import {IPayload} from "@aztec/governance/interfaces/IPayload.sol"; /** * @title Errors Library diff --git a/l1-contracts/src/governance/libraries/ProposalLib.sol b/l1-contracts/src/governance/libraries/ProposalLib.sol index 8d6fb166a82..9798f88089b 100644 --- a/l1-contracts/src/governance/libraries/ProposalLib.sol +++ b/l1-contracts/src/governance/libraries/ProposalLib.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.27; -import {DataStructures} from "@aztec/governance/libraries/DataStructures.sol"; import {Timestamp} from "@aztec/core/libraries/TimeMath.sol"; +import {DataStructures} from "@aztec/governance/libraries/DataStructures.sol"; import {Math} from "@oz/utils/math/Math.sol"; enum VoteTabulationReturn { diff --git a/l1-contracts/src/governance/libraries/UserLib.sol b/l1-contracts/src/governance/libraries/UserLib.sol index 869deb8df76..1d08a333cfa 100644 --- a/l1-contracts/src/governance/libraries/UserLib.sol +++ b/l1-contracts/src/governance/libraries/UserLib.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.27; -import {DataStructures} from "@aztec/governance/libraries/DataStructures.sol"; import {Timestamp} from "@aztec/core/libraries/TimeMath.sol"; +import {DataStructures} from "@aztec/governance/libraries/DataStructures.sol"; import {Errors} from "@aztec/governance/libraries/Errors.sol"; library UserLib { diff --git a/l1-contracts/src/mock/MockFeeJuicePortal.sol b/l1-contracts/src/mock/MockFeeJuicePortal.sol index a519da4560d..a7d56cae0e8 100644 --- a/l1-contracts/src/mock/MockFeeJuicePortal.sol +++ b/l1-contracts/src/mock/MockFeeJuicePortal.sol @@ -2,10 +2,10 @@ // 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 {TestERC20} from "@aztec/mock/TestERC20.sol"; import {IRegistry} from "@aztec/governance/interfaces/IRegistry.sol"; +import {TestERC20} from "@aztec/mock/TestERC20.sol"; +import {IERC20} from "@oz/token/ERC20/IERC20.sol"; contract MockFeeJuicePortal is IFeeJuicePortal { IERC20 public immutable UNDERLYING; From db70936615247a68254ce42ede03b7c03d90ba0f Mon Sep 17 00:00:00 2001 From: LHerskind Date: Mon, 4 Nov 2024 10:19:43 +0000 Subject: [PATCH 3/3] chore: update solhint for free functions --- l1-contracts/src/core/interfaces/IRollup.sol | 2 - l1-contracts/src/core/libraries/TimeMath.sol | 92 ++++++++++---------- 2 files changed, 46 insertions(+), 48 deletions(-) diff --git a/l1-contracts/src/core/interfaces/IRollup.sol b/l1-contracts/src/core/interfaces/IRollup.sol index 292c89722c4..f730a160fb3 100644 --- a/l1-contracts/src/core/interfaces/IRollup.sol +++ b/l1-contracts/src/core/interfaces/IRollup.sol @@ -81,8 +81,6 @@ interface IRollup { // solhint-disable-next-line func-name-mixedcase function L1_BLOCK_AT_GENESIS() external view returns (uint256); - function canPrune() external view returns (bool); - function status(uint256 _myHeaderBlockNumber) external view diff --git a/l1-contracts/src/core/libraries/TimeMath.sol b/l1-contracts/src/core/libraries/TimeMath.sol index a2f0469773f..62f7da682dc 100644 --- a/l1-contracts/src/core/libraries/TimeMath.sol +++ b/l1-contracts/src/core/libraries/TimeMath.sol @@ -51,130 +51,130 @@ library EpochLib { using SlotLib for Slot; using EpochLib for Epoch; -function _addTimestamp(Timestamp _a, Timestamp _b) pure returns (Timestamp) { +function addTimestamp(Timestamp _a, Timestamp _b) pure returns (Timestamp) { return Timestamp.wrap(Timestamp.unwrap(_a) + Timestamp.unwrap(_b)); } -function _subTimestamp(Timestamp _a, Timestamp _b) pure returns (Timestamp) { +function subTimestamp(Timestamp _a, Timestamp _b) pure returns (Timestamp) { return Timestamp.wrap(Timestamp.unwrap(_a) - Timestamp.unwrap(_b)); } -function _ltTimestamp(Timestamp _a, Timestamp _b) pure returns (bool) { +function ltTimestamp(Timestamp _a, Timestamp _b) pure returns (bool) { return Timestamp.unwrap(_a) < Timestamp.unwrap(_b); } -function _lteTimestamp(Timestamp _a, Timestamp _b) pure returns (bool) { +function lteTimestamp(Timestamp _a, Timestamp _b) pure returns (bool) { return Timestamp.unwrap(_a) <= Timestamp.unwrap(_b); } -function _gtTimestamp(Timestamp _a, Timestamp _b) pure returns (bool) { +function gtTimestamp(Timestamp _a, Timestamp _b) pure returns (bool) { return Timestamp.unwrap(_a) > Timestamp.unwrap(_b); } -function _gteTimestamp(Timestamp _a, Timestamp _b) pure returns (bool) { +function gteTimestamp(Timestamp _a, Timestamp _b) pure returns (bool) { return Timestamp.unwrap(_a) >= Timestamp.unwrap(_b); } -function _neqTimestamp(Timestamp _a, Timestamp _b) pure returns (bool) { +function neqTimestamp(Timestamp _a, Timestamp _b) pure returns (bool) { return Timestamp.unwrap(_a) != Timestamp.unwrap(_b); } -function _eqTimestamp(Timestamp _a, Timestamp _b) pure returns (bool) { +function eqTimestamp(Timestamp _a, Timestamp _b) pure returns (bool) { return Timestamp.unwrap(_a) == Timestamp.unwrap(_b); } // Slot -function _addSlot(Slot _a, Slot _b) pure returns (Slot) { +function addSlot(Slot _a, Slot _b) pure returns (Slot) { return Slot.wrap(Slot.unwrap(_a) + Slot.unwrap(_b)); } -function _eqSlot(Slot _a, Slot _b) pure returns (bool) { +function eqSlot(Slot _a, Slot _b) pure returns (bool) { return Slot.unwrap(_a) == Slot.unwrap(_b); } -function _neqSlot(Slot _a, Slot _b) pure returns (bool) { +function neqSlot(Slot _a, Slot _b) pure returns (bool) { return Slot.unwrap(_a) != Slot.unwrap(_b); } -function _ltSlot(Slot _a, Slot _b) pure returns (bool) { +function ltSlot(Slot _a, Slot _b) pure returns (bool) { return Slot.unwrap(_a) < Slot.unwrap(_b); } -function _lteSlot(Slot _a, Slot _b) pure returns (bool) { +function lteSlot(Slot _a, Slot _b) pure returns (bool) { return Slot.unwrap(_a) <= Slot.unwrap(_b); } -function _gtSlot(Slot _a, Slot _b) pure returns (bool) { +function gtSlot(Slot _a, Slot _b) pure returns (bool) { return Slot.unwrap(_a) > Slot.unwrap(_b); } -function _gteSlot(Slot _a, Slot _b) pure returns (bool) { +function gteSlot(Slot _a, Slot _b) pure returns (bool) { return Slot.unwrap(_a) >= Slot.unwrap(_b); } // Epoch -function _eqEpoch(Epoch _a, Epoch _b) pure returns (bool) { +function eqEpoch(Epoch _a, Epoch _b) pure returns (bool) { return Epoch.unwrap(_a) == Epoch.unwrap(_b); } -function _neqEpoch(Epoch _a, Epoch _b) pure returns (bool) { +function neqEpoch(Epoch _a, Epoch _b) pure returns (bool) { return Epoch.unwrap(_a) != Epoch.unwrap(_b); } -function _subEpoch(Epoch _a, Epoch _b) pure returns (Epoch) { +function subEpoch(Epoch _a, Epoch _b) pure returns (Epoch) { return Epoch.wrap(Epoch.unwrap(_a) - Epoch.unwrap(_b)); } -function _addEpoch(Epoch _a, Epoch _b) pure returns (Epoch) { +function addEpoch(Epoch _a, Epoch _b) pure returns (Epoch) { return Epoch.wrap(Epoch.unwrap(_a) + Epoch.unwrap(_b)); } -function _gteEpoch(Epoch _a, Epoch _b) pure returns (bool) { +function gteEpoch(Epoch _a, Epoch _b) pure returns (bool) { return Epoch.unwrap(_a) >= Epoch.unwrap(_b); } -function _gtEpoch(Epoch _a, Epoch _b) pure returns (bool) { +function gtEpoch(Epoch _a, Epoch _b) pure returns (bool) { return Epoch.unwrap(_a) > Epoch.unwrap(_b); } -function _lteEpoch(Epoch _a, Epoch _b) pure returns (bool) { +function lteEpoch(Epoch _a, Epoch _b) pure returns (bool) { return Epoch.unwrap(_a) <= Epoch.unwrap(_b); } -function _ltEpoch(Epoch _a, Epoch _b) pure returns (bool) { +function ltEpoch(Epoch _a, Epoch _b) pure returns (bool) { return Epoch.unwrap(_a) < Epoch.unwrap(_b); } using { - _addTimestamp as +, - _subTimestamp as -, - _ltTimestamp as <, - _gtTimestamp as >, - _lteTimestamp as <=, - _gteTimestamp as >=, - _neqTimestamp as !=, - _eqTimestamp as == + addTimestamp as +, + subTimestamp as -, + ltTimestamp as <, + gtTimestamp as >, + lteTimestamp as <=, + gteTimestamp as >=, + neqTimestamp as !=, + eqTimestamp as == } for Timestamp global; using { - _addEpoch as +, - _subEpoch as -, - _eqEpoch as ==, - _neqEpoch as !=, - _gteEpoch as >=, - _gtEpoch as >, - _lteEpoch as <=, - _ltEpoch as < + addEpoch as +, + subEpoch as -, + eqEpoch as ==, + neqEpoch as !=, + gteEpoch as >=, + gtEpoch as >, + lteEpoch as <=, + ltEpoch as < } for Epoch global; using { - _eqSlot as ==, - _neqSlot as !=, - _gteSlot as >=, - _gtSlot as >, - _lteSlot as <=, - _ltSlot as <, - _addSlot as + + eqSlot as ==, + neqSlot as !=, + gteSlot as >=, + gtSlot as >, + lteSlot as <=, + ltSlot as <, + addSlot as + } for Slot global;