Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SC-989][SC-990] Solidity 0.8.23, OZ 5.0.0 #31

Merged
merged 11 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runs:
steps:
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20

- run: npm install -g yarn
shell: bash
Expand Down
24 changes: 12 additions & 12 deletions .solcover.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@zZoMROT zZoMROT Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With config from solidity-utils we have Stack Too Deep error

YulException: Cannot swap Variable expr with Slot TMP[eq, 0]: too deep in the stack by 2 slots in [ _6 expr var_account expr expr_2 _11 _10 _9 _8 _7 expr_2186_mpos _5 _4 _3 RET _2 _13 var_i var_account TMP[eq, 0] ]
memoryguard was present.

Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ module.exports = {
yul: true,
yulDetails: {
optimizerSteps:
"dhfoDgvlfnTUtnIf" + // None of these can make stack problems worse
"dhfoDgvlfnTUtnIf" + // None of these can make stack problems worse
"[" +
"xa[r]EscLM" + // Turn into SSA and simplify
"cCTUtTOntnfDIl" + // Perform structural simplification
"Lcl" + // Simplify again
"Vcl [j]" + // Reverse SSA
"xa[r]EsLM" + // Turn into SSA and simplify
"CTUtTOntnfDIl" + // Perform structural simplification
"Ll" + // Simplify again
"Vl [j]" + // Reverse SSA

// should have good "compilability" property here.

"Tpel" + // Run functional expression inliner
"xa[rl]" + // Prune a bit more in SSA
"xa[r]cL" + // Turn into SSA again and simplify
"gvf" + // Run full inliner
"CTUca[r]LSsTFOtfDnca[r]Ilc" + // SSA plus simplify
"Tpel" + // Run functional expression inliner
"xa[rl]" + // Prune a bit more in SSA
"xa[r]L" + // Turn into SSA again and simplify
"gvf" + // Run full inliner
"CTUa[r]LSsTFOtfDna[r]Il" + // SSA plus simplify
"]" +
"jml[jl] VcTOcl jml",
"jml[jl] VTOl jml : fDnTOm",
},
},
skipFiles: [
'mocks'
'mocks', 'tests', 'interfaces',
],
}
18 changes: 9 additions & 9 deletions contracts/ERC20Plugins.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ abstract contract ERC20Plugins is ERC20, IERC20Plugins, ReentrancyGuardExt {
using ReentrancyGuardLib for ReentrancyGuardLib.Data;

/// @dev Limit of plugins per account
uint256 public immutable maxPluginsPerAccount;
uint256 public immutable MAX_PLUGINS_PER_ACCOUNT;
/// @dev Gas limit for a single plugin call
uint256 public immutable pluginCallGasLimit;
uint256 public immutable PLUGIN_CALL_GAS_LIMIT;

ReentrancyGuardLib.Data private _guard;
mapping(address => AddressSet.Data) private _plugins;
Expand All @@ -34,8 +34,8 @@ abstract contract ERC20Plugins is ERC20, IERC20Plugins, ReentrancyGuardExt {
*/
constructor(uint256 pluginsLimit_, uint256 pluginCallGasLimit_) {
if (pluginsLimit_ == 0) revert ZeroPluginsLimit();
maxPluginsPerAccount = pluginsLimit_;
pluginCallGasLimit = pluginCallGasLimit_;
MAX_PLUGINS_PER_ACCOUNT = pluginsLimit_;
PLUGIN_CALL_GAS_LIMIT = pluginCallGasLimit_;
_guard.init();
}

Expand Down Expand Up @@ -109,9 +109,9 @@ abstract contract ERC20Plugins is ERC20, IERC20Plugins, ReentrancyGuardExt {

function _addPlugin(address account, address plugin) internal virtual {
if (plugin == address(0)) revert InvalidPluginAddress();
if (IPlugin(plugin).token() != IERC20Plugins(address(this))) revert InvalidTokenInPlugin();
if (IPlugin(plugin).TOKEN() != IERC20Plugins(address(this))) revert InvalidTokenInPlugin();
if (!_plugins[account].add(plugin)) revert PluginAlreadyAdded();
if (_plugins[account].length() > maxPluginsPerAccount) revert PluginsLimitReachedForAccount();
if (_plugins[account].length() > MAX_PLUGINS_PER_ACCOUNT) revert PluginsLimitReachedForAccount();

emit PluginAdded(account, plugin);
uint256 balance = balanceOf(account);
Expand Down Expand Up @@ -150,7 +150,7 @@ abstract contract ERC20Plugins is ERC20, IERC20Plugins, ReentrancyGuardExt {
/// @dev try IPlugin(plugin).updateBalances{gas: _PLUGIN_CALL_GAS_LIMIT}(from, to, amount) {} catch {}
function _updateBalances(address plugin, address from, address to, uint256 amount) private {
bytes4 selector = IPlugin.updateBalances.selector;
uint256 gasLimit = pluginCallGasLimit;
uint256 gasLimit = PLUGIN_CALL_GAS_LIMIT;
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
let ptr := mload(0x40)
mstore(ptr, selector)
Expand All @@ -168,8 +168,8 @@ abstract contract ERC20Plugins is ERC20, IERC20Plugins, ReentrancyGuardExt {
}
}

function _afterTokenTransfer(address from, address to, uint256 amount) internal nonReentrant(_guard) override virtual {
super._afterTokenTransfer(from, to, amount);
function _update(address from, address to, uint256 amount) internal nonReentrant(_guard) override virtual {
super._update(from, to, amount);

unchecked {
if (amount > 0 && from != to) {
Expand Down
6 changes: 3 additions & 3 deletions contracts/Plugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import { IERC20Plugins } from "./interfaces/IERC20Plugins.sol";
abstract contract Plugin is IPlugin {
error AccessDenied();

IERC20Plugins public immutable token;
IERC20Plugins public immutable TOKEN;

/// @dev Throws an error if the caller is not the token contract
modifier onlyToken {
if (msg.sender != address(token)) revert AccessDenied();
if (msg.sender != address(TOKEN)) revert AccessDenied();
_;
}

Expand All @@ -24,7 +24,7 @@ abstract contract Plugin is IPlugin {
* @param token_ The address of the token contract
*/
constructor(IERC20Plugins token_) {
token = token_;
TOKEN = token_;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions contracts/interfaces/IERC20Plugins.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ interface IERC20Plugins is IERC20 {
* @dev Returns the maximum allowed number of plugins per account.
* @return pluginsLimit The maximum allowed number of plugins per account.
*/
function maxPluginsPerAccount() external view returns(uint256 pluginsLimit);
function MAX_PLUGINS_PER_ACCOUNT() external view returns(uint256 pluginsLimit); // solhint-disable-line func-name-mixedcase

/**
* @dev Returns the gas limit allowed to be spend by plugin per call.
* @return gasLimit The gas limit allowed to be spend by plugin per call.
*/
function pluginCallGasLimit() external view returns(uint256 gasLimit);
function PLUGIN_CALL_GAS_LIMIT() external view returns(uint256 gasLimit); // solhint-disable-line func-name-mixedcase

/**
* @dev Returns whether an account has a specific plugin.
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface IPlugin {
* @dev Returns the token which this plugin belongs to.
* @return erc20 The IERC20Plugins token.
*/
function token() external view returns(IERC20Plugins erc20);
function TOKEN() external view returns(IERC20Plugins erc20); // solhint-disable-line func-name-mixedcase

/**
* @dev Updates the balances of two addresses in the plugin as a result of any balance changes.
Expand Down
2 changes: 2 additions & 0 deletions contracts/libs/ReentrancyGuard.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: MIT

// solhint-disable one-contract-per-file

pragma solidity ^0.8.0;

/**
Expand Down
6 changes: 3 additions & 3 deletions contracts/mocks/GasLimitedPluginMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { IERC20Plugins, Plugin } from "../Plugin.sol";
contract GasLimitedPluginMock is ERC20, Plugin {
error InsufficientGas();

uint256 public immutable gasLimit;
uint256 public immutable GAS_LIMIT;

constructor(uint256 gasLimit_, IERC20Plugins token)
ERC20(type(GasLimitedPluginMock).name, "GLPM")
Plugin(token)
{
gasLimit = gasLimit_;
GAS_LIMIT = gasLimit_;
}

function _updateBalances(address from, address to, uint256 amount) internal override {
Expand All @@ -26,7 +26,7 @@ contract GasLimitedPluginMock is ERC20, Plugin {
_transfer(from, to, amount);
}

if (gasleft() < gasLimit) {
if (gasleft() < GAS_LIMIT) {
revert InsufficientGas();
}
}
Expand Down
6 changes: 4 additions & 2 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ require('solidity-coverage');
require('hardhat-deploy');
require('hardhat-gas-reporter');
require('dotenv').config();
const { Networks, getNetwork } = require('@1inch/solidity-utils/hardhat-setup');

const { networks, etherscan } = require('./hardhat.networks');
const { networks, etherscan } = (new Networks()).registerAll();

module.exports = {
etherscan,
solidity: {
version: '0.8.17',
version: '0.8.23',
settings: {
optimizer: {
enabled: true,
runs: 1000000,
},
evmVersion: networks[getNetwork()]?.hardfork || 'shanghai',
viaIR: true,
},
},
Expand Down
88 changes: 0 additions & 88 deletions hardhat.networks.js

This file was deleted.

32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@1inch/token-plugins",
"version": "1.2.1",
"version": "1.3.0",
"description": "ERC20 extension enabling external smart contract based plugins to track balances of those users who opted-in to those plugins",
"repository": {
"type": "git",
Expand All @@ -13,28 +13,28 @@
"author": "1inch",
"license": "MIT",
"dependencies": {
"@1inch/solidity-utils": "3.0.1",
"@openzeppelin/contracts": "4.9.2"
"@1inch/solidity-utils": "3.5.5",
"@openzeppelin/contracts": "5.0.1"
},
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "2.0.1",
"@nomicfoundation/hardhat-ethers": "3.0.4",
"@nomicfoundation/hardhat-verify": "1.0.4",
"@nomicfoundation/hardhat-chai-matchers": "2.0.2",
"@nomicfoundation/hardhat-ethers": "3.0.5",
"@nomicfoundation/hardhat-verify": "2.0.2",
"@openzeppelin/test-helpers": "0.5.16",
"chai": "4.3.7",
"chai": "4.3.10",
"dotenv": "16.3.1",
"eslint": "8.45.0",
"eslint": "8.56.0",
"eslint-config-standard": "17.1.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-n": "16.0.1",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-n": "16.4.0",
"eslint-plugin-promise": "6.1.1",
"ethers": "6.6.5",
"hardhat": "2.17.0",
"hardhat-deploy": "0.11.34",
"ethers": "6.9.0",
"hardhat": "2.19.2",
"hardhat-deploy": "0.11.45",
"hardhat-gas-reporter": "1.0.9",
"rimraf": "5.0.1",
"solhint": "3.4.1",
"solidity-coverage": "0.8.4"
"rimraf": "5.0.5",
"solhint": "3.6.2",
"solidity-coverage": "0.8.5"
},
"scripts": {
"clean": "rimraf artifacts cache coverage coverage.json contracts/hardhat-dependency-compiler",
Expand Down
2 changes: 1 addition & 1 deletion test/behaviors/ERC20Plugins.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function shouldBehaveLikeERC20Plugins (initContracts) {

it('should not add more plugins than limit', async function () {
const { erc20Plugins, plugins } = await loadFixture(initAndCreatePlugins);
const maxPluginsPerAccount = await erc20Plugins.maxPluginsPerAccount();
const maxPluginsPerAccount = await erc20Plugins.MAX_PLUGINS_PER_ACCOUNT();
for (let i = 0; i < maxPluginsPerAccount; i++) {
await erc20Plugins.addPlugin(plugins[i]);
}
Expand Down
Loading
Loading