Skip to content

Commit

Permalink
fix /dev solhint issues (#10977)
Browse files Browse the repository at this point in the history
* fix /dev solhint issues

* move flags -> l2ep

* fix transmission warnings

* rm dup _configDigestFromConfigData

* gen wrapper

* fix document string

* fix test ref to flags
  • Loading branch information
RensR authored Oct 17, 2023
1 parent 34a5c3d commit c89866d
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 235 deletions.
2 changes: 0 additions & 2 deletions contracts/.solhintignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# 351 warnings
#./src/v0.8/automation
# 60 warnings
#./src/v0.8/dev
# 91 warnings
#./src/v0.8/functions

Expand Down
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"prepublishOnly": "pnpm compile && ./scripts/prepublish_generate_abi_folder",
"publish-beta": "pnpm publish --tag beta",
"publish-prod": "npm dist-tag add @chainlink/[email protected] latest",
"solhint": "solhint --max-warnings 493 \"./src/v0.8/**/*.sol\""
"solhint": "solhint --max-warnings 442 \"./src/v0.8/**/*.sol\""
},
"files": [
"src/v0.8",
Expand Down
134 changes: 0 additions & 134 deletions contracts/src/v0.8/dev/ocr2/OCR2Abstract.sol

This file was deleted.

42 changes: 21 additions & 21 deletions contracts/src/v0.8/dev/transmission/ERC-4337/Paymaster.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

import "../../../vendor/entrypoint/interfaces/IPaymaster.sol";
import "./SCALibrary.sol";
import "../../../vendor/entrypoint/core/Helpers.sol";
import "../../../shared/interfaces/LinkTokenInterface.sol";
import "../../../interfaces/AggregatorV3Interface.sol";
import "./SCALibrary.sol";
import "../../../shared/access/ConfirmedOwner.sol";
import {IPaymaster} from "../../../vendor/entrypoint/interfaces/IPaymaster.sol";
import {SCALibrary} from "./SCALibrary.sol";
import {LinkTokenInterface} from "../../../shared/interfaces/LinkTokenInterface.sol";
import {AggregatorV3Interface} from "../../../interfaces/AggregatorV3Interface.sol";
import {ConfirmedOwner} from "../../../shared/access/ConfirmedOwner.sol";
import {UserOperation} from "../../../vendor/entrypoint/interfaces/UserOperation.sol";
import {_packValidationData} from "../../../vendor/entrypoint/core/Helpers.sol";

/// @dev LINK token paymaster implementation.
/// TODO: more documentation.
Expand All @@ -28,8 +28,8 @@ contract Paymaster is IPaymaster, ConfirmedOwner {
}
Config public s_config;

mapping(bytes32 => bool) userOpHashMapping;
mapping(address => uint256) subscriptions;
mapping(bytes32 => bool) internal s_userOpHashMapping;
mapping(address => uint256) internal s_subscriptions;

constructor(
LinkTokenInterface linkToken,
Expand All @@ -54,7 +54,7 @@ contract Paymaster is IPaymaster, ConfirmedOwner {
}

address subscription = abi.decode(_data, (address));
subscriptions[subscription] += _amount;
s_subscriptions[subscription] += _amount;
}

function validatePaymasterUserOp(
Expand All @@ -65,24 +65,24 @@ contract Paymaster is IPaymaster, ConfirmedOwner {
if (msg.sender != i_entryPoint) {
revert Unauthorized(msg.sender, i_entryPoint);
}
if (userOpHashMapping[userOpHash]) {
if (s_userOpHashMapping[userOpHash]) {
revert UserOperationAlreadyTried(userOpHash);
}

uint256 extraCostJuels = handleExtraCostJuels(userOp);
uint256 costJuels = getCostJuels(maxCost) + extraCostJuels;
if (subscriptions[userOp.sender] < costJuels) {
revert InsufficientFunds(costJuels, subscriptions[userOp.sender]);
uint256 extraCostJuels = _handleExtraCostJuels(userOp);
uint256 costJuels = _getCostJuels(maxCost) + extraCostJuels;
if (s_subscriptions[userOp.sender] < costJuels) {
revert InsufficientFunds(costJuels, s_subscriptions[userOp.sender]);
}

userOpHashMapping[userOpHash] = true;
s_userOpHashMapping[userOpHash] = true;
return (abi.encode(userOp.sender, extraCostJuels), _packValidationData(false, 0, 0)); // success
}

/// @dev Calculates any extra LINK cost for the user operation, based on the funding type passed to the
/// @dev paymaster. Handles funding the LINK token funding described in the user operation.
/// TODO: add logic for subscription top-up.
function handleExtraCostJuels(UserOperation calldata userOp) internal returns (uint256 extraCost) {
function _handleExtraCostJuels(UserOperation calldata userOp) internal returns (uint256 extraCost) {
if (userOp.paymasterAndData.length == 20) {
return 0; // no extra data, stop here
}
Expand Down Expand Up @@ -111,14 +111,14 @@ contract Paymaster is IPaymaster, ConfirmedOwner {
revert Unauthorized(msg.sender, i_entryPoint);
}
(address sender, uint256 extraCostJuels) = abi.decode(context, (address, uint256));
subscriptions[sender] -= (getCostJuels(actualGasCost) + extraCostJuels);
s_subscriptions[sender] -= (_getCostJuels(actualGasCost) + extraCostJuels);
}

function getCostJuels(uint256 costWei) internal view returns (uint256 costJuels) {
costJuels = (1e18 * costWei) / uint256(getFeedData());
function _getCostJuels(uint256 costWei) internal view returns (uint256 costJuels) {
costJuels = (1e18 * costWei) / uint256(_getFeedData());
}

function getFeedData() internal view returns (int256) {
function _getFeedData() internal view returns (int256) {
uint32 stalenessSeconds = s_config.stalenessSeconds;
bool staleFallback = stalenessSeconds > 0;
uint256 timestamp;
Expand Down
13 changes: 7 additions & 6 deletions contracts/src/v0.8/dev/transmission/ERC-4337/SCA.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// SPDX-License-Identifier: MIT
import "../../../vendor/entrypoint/interfaces/IAccount.sol";
import "./SCALibrary.sol";
import "../../../vendor/entrypoint/core/Helpers.sol";

/// TODO: decide on a compiler version. Must not be dynamic, and must be > 0.8.12.
pragma solidity 0.8.15;

import {IAccount} from "../../../vendor/entrypoint/interfaces/IAccount.sol";
import {SCALibrary} from "./SCALibrary.sol";
import {UserOperation} from "../../../vendor/entrypoint/interfaces/UserOperation.sol";
import {_packValidationData} from "../../../vendor/entrypoint/core/Helpers.sol";

/// @dev Smart Contract Account, a contract deployed for a single user and that allows
/// @dev them to invoke meta-transactions.
/// TODO: Consider making the Smart Contract Account upgradeable.
Expand Down Expand Up @@ -39,9 +40,9 @@ contract SCA is IAccount {
}

// Verify signature on hash.
bytes32 fullHash = SCALibrary.getUserOpFullHash(userOpHash, address(this));
bytes32 fullHash = SCALibrary._getUserOpFullHash(userOpHash, address(this));
bytes memory signature = userOp.signature;
if (SCALibrary.recoverSignature(signature, fullHash) != i_owner) {
if (SCALibrary._recoverSignature(signature, fullHash) != i_owner) {
return _packValidationData(true, 0, 0); // signature error
}
s_nonce++;
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/v0.8/dev/transmission/ERC-4337/SCALibrary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ library SCALibrary {
uint256 topupAmount;
}

function getUserOpFullHash(bytes32 userOpHash, address scaAddress) internal view returns (bytes32 fullHash) {
function _getUserOpFullHash(bytes32 userOpHash, address scaAddress) internal view returns (bytes32 fullHash) {
bytes32 hashOfEncoding = keccak256(abi.encode(SCALibrary.TYPEHASH, userOpHash));
fullHash = keccak256(
abi.encodePacked(
Expand All @@ -33,7 +33,7 @@ library SCALibrary {
);
}

function recoverSignature(bytes memory signature, bytes32 fullHash) internal pure returns (address) {
function _recoverSignature(bytes memory signature, bytes32 fullHash) internal pure returns (address) {
bytes32 r;
bytes32 s;
assembly {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import "../ERC-4337/SCA.sol";
import "../ERC-4337/SmartContractAccountFactory.sol";
import "../ERC-4337/SCALibrary.sol";

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

import {SCA} from "../ERC-4337/SCA.sol";
import {SmartContractAccountFactory} from "../ERC-4337/SmartContractAccountFactory.sol";
import {SCALibrary} from "../ERC-4337/SCALibrary.sol";

library SmartContractAccountHelper {
bytes constant initailizeCode = type(SCA).creationCode;
bytes internal constant INITIALIZE_CODE = type(SCA).creationCode;

function getFullEndTxEncoding(
address endContract,
Expand All @@ -20,14 +21,14 @@ library SmartContractAccountHelper {
}

function getFullHashForSigning(bytes32 userOpHash, address scaAddress) public view returns (bytes32) {
return SCALibrary.getUserOpFullHash(userOpHash, scaAddress);
return SCALibrary._getUserOpFullHash(userOpHash, scaAddress);
}

function getSCAInitCodeWithConstructor(
address owner,
address entryPoint
) public pure returns (bytes memory initCode) {
initCode = bytes.concat(initailizeCode, abi.encode(owner, entryPoint));
initCode = bytes.concat(INITIALIZE_CODE, abi.encode(owner, entryPoint));
}

function getInitCode(
Expand All @@ -36,7 +37,7 @@ library SmartContractAccountHelper {
address entryPoint
) external pure returns (bytes memory initCode) {
bytes32 salt = bytes32(uint256(uint160(owner)) << 96);
bytes memory initializeCodeWithConstructor = bytes.concat(initailizeCode, abi.encode(owner, entryPoint));
bytes memory initializeCodeWithConstructor = bytes.concat(INITIALIZE_CODE, abi.encode(owner, entryPoint));
initCode = bytes.concat(
bytes20(address(factory)),
abi.encodeWithSelector(
Expand All @@ -54,7 +55,7 @@ library SmartContractAccountHelper {
address factory
) external pure returns (address) {
bytes32 salt = bytes32(uint256(uint160(owner)) << 96);
bytes memory initializeCodeWithConstructor = bytes.concat(initailizeCode, abi.encode(owner, entryPoint));
bytes memory initializeCodeWithConstructor = bytes.concat(INITIALIZE_CODE, abi.encode(owner, entryPoint));
bytes32 initializeCodeHash = keccak256(initializeCodeWithConstructor);
return address(uint160(uint256(keccak256(abi.encodePacked(hex"ff", address(factory), salt, initializeCodeHash)))));
}
Expand All @@ -63,7 +64,7 @@ library SmartContractAccountHelper {
address recipient,
uint256 topupThreshold,
uint256 topupAmount
) external view returns (bytes memory) {
) external pure returns (bytes memory) {
SCALibrary.DirectFundingData memory data = SCALibrary.DirectFundingData({
recipient: recipient,
topupThreshold: topupThreshold,
Expand Down
Loading

0 comments on commit c89866d

Please sign in to comment.