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

Updating Core smart contracts to Solidity 0.8 #11141

Draft
wants to merge 50 commits into
base: release/core-contracts/12
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
6a3cecf
updateTo0.8
pahor167 Jul 15, 2024
c53ed37
sorted linked lists
pahor167 Jul 15, 2024
382d99d
buildable
pahor167 Jul 15, 2024
4435b0c
validators update
pahor167 Jul 15, 2024
8bb3102
added multiple core smart contracts
pahor167 Jul 23, 2024
687d550
FeeCurrencyWhitelist
pahor167 Jul 24, 2024
871f88a
FeeHandler
pahor167 Jul 24, 2024
10a8425
FeeHandler tests
pahor167 Jul 24, 2024
24304d4
goldTokenFixes
pahor167 Jul 24, 2024
ee62e31
Locked gold test fix
pahor167 Jul 24, 2024
c98e637
update of mocks to bytes from bytes32
pahor167 Jul 24, 2024
52a5148
test fixes
pahor167 Jul 24, 2024
3c1f8a1
utils fix
pahor167 Jul 24, 2024
5e9eae0
FeeHandler fix
pahor167 Jul 25, 2024
0be18f8
Validators tests fixes
pahor167 Jul 25, 2024
50b8e7f
FeeHandler tests fixed
pahor167 Jul 25, 2024
cc5d010
EpochRewards test
pahor167 Jul 25, 2024
93f68fa
update celo-foudnry-8
pahor167 Jul 25, 2024
a3e8d56
extract function signature
pahor167 Jul 25, 2024
d274f6c
Governance slasher tests
pahor167 Jul 25, 2024
cc34cd2
Escrow tests
pahor167 Jul 25, 2024
00c3361
identity proxy + multisig
pahor167 Jul 25, 2024
d66d2fb
release gold tests
pahor167 Jul 25, 2024
fc417a8
RevokeCeloAfterL2Transition tests
pahor167 Jul 25, 2024
3a38322
removal of libraries and report
pahor167 Jul 25, 2024
59a8fe0
Attestations tests added
pahor167 Jul 25, 2024
fe83c67
federated attestations tests
pahor167 Jul 25, 2024
cccf339
OdisPayments
pahor167 Jul 25, 2024
8a40ebb
big shuffle :D
pahor167 Jul 25, 2024
6fa75ad
update paths according to truffle
pahor167 Jul 25, 2024
a10b55b
Byteslib fix
pahor167 Jul 25, 2024
ce3f42d
Address sorted linked list with median fix
pahor167 Jul 25, 2024
bfbc75d
08 buildable in both turfle and foundry
pahor167 Jul 25, 2024
0c64a50
Heap fix
pahor167 Jul 25, 2024
0cd3b3c
remove ExtractFunctionSignatureTest
pahor167 Jul 25, 2024
b793c73
SortedOracles fix
pahor167 Jul 25, 2024
dcb8920
mock reserve
pahor167 Jul 25, 2024
1a976f5
MockERC20
pahor167 Jul 25, 2024
68e2aeb
truffle & foundry build working
pahor167 Jul 25, 2024
a6746e3
typescript buildable
pahor167 Jul 25, 2024
d9d2795
conflicts resolved
pahor167 Jul 25, 2024
3ed41d3
bump npm version
pahor167 Jul 26, 2024
2a423d6
update devchain constants
pahor167 Jul 26, 2024
ae477a2
lint
pahor167 Jul 26, 2024
4c9f919
lint2
pahor167 Jul 26, 2024
04b1fa9
migrations partially fixed
pahor167 Jul 26, 2024
f5321bf
Merge branch 'release/core-contracts/12' into pahor/update08
pahor167 Aug 20, 2024
d852c2b
merge fix
pahor167 Aug 20, 2024
5140e1c
build fix
pahor167 Aug 20, 2024
3dab1b1
extra logging
pahor167 Aug 20, 2024
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/workflows/celo-monorepo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defaults:

env:
# Increment these to force cache rebuilding
NODE_MODULE_CACHE_VERSION: 7
NODE_MODULE_CACHE_VERSION: 8
NODE_OPTIONS: '--max-old-space-size=4096'
TERM: dumb
GRADLE_OPTS: '-Dorg.gradle.daemon=false -Dorg.gradle.parallel=false -Dorg.gradle.configureondemand=true -Dorg.gradle.jvmargs="-Xmx4096m -XX:+HeapDumpOnOutOfMemoryError"'
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
[submodule "packages/protocol/lib/mento-core"]
path = packages/protocol/lib/mento-core
url = https://github.com/mento-protocol/mento-core
[submodule "packages/protocol/lib/solidity-bytes-utils.sol"]
path = packages/protocol/lib/solidity-bytes-utils.sol
url = https://github.com/GNSPS/solidity-bytes-utils
[submodule "packages/protocol/lib/memview.sol"]
path = packages/protocol/lib/memview.sol
url = https://github.com/summa-tx/memview.sol
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contractPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const SOLIDITY_08_PACKAGE = {
proxiesPath: '/', // Proxies are still with 0.5 contracts
// Proxies shouldn't have to be added to a list manually
// https://github.com/celo-org/celo-monorepo/issues/10555
contracts: ['GasPriceMinimum', 'FeeCurrencyDirectory', 'CeloDistributionSchedule'],
contracts: ['GasPriceMinimum', 'FeeCurrencyDirectory', 'CeloDistributionSchedule', 'Proposals', 'LockedGold', 'GoldToken', 'Governance', 'Election', 'Validators', 'Attestations', 'Escrow', 'Random', 'ReleaseGold', 'Freezer', 'MultiSig', 'FeeCurrencyWhitelist', 'FeeHandler', 'MentoFeeHandlerSeller', 'UniswapFeeHandlerSeller', 'Accounts', 'DoubleSigningSlasher', 'DowntimeSlasher', 'EpochRewards', 'GovernanceApproverMultiSig', 'Signatures', 'AttestationsTest', 'FederatedAttestations'],
proxyContracts: [
'GasPriceMinimumProxy',
'FeeCurrencyDirectoryProxy',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
pragma solidity ^0.5.13;
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.7 <0.8.20;

import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "@openzeppelin/contracts8/utils/math/SafeMath.sol";
import "@openzeppelin/contracts8/access/Ownable.sol";

import "./interfaces/IAccounts.sol";
import "../../contracts/common/interfaces/IAccounts.sol";

import "../common/FixidityLib.sol";
import "../common/Initializable.sol";
import "../common/interfaces/ICeloVersionedContract.sol";
import "../../contracts/common/FixidityLib.sol";
import "../../contracts/common/Initializable.sol";
import "../../contracts/common/interfaces/ICeloVersionedContract.sol";
import "../common/Signatures.sol";
import "../common/UsingRegistry.sol";
import "../common/libraries/ReentrancyGuard.sol";
import "../../contracts-0.8/common/IsL2Check.sol";
import "../../contracts/common/libraries/ReentrancyGuard.sol";
import "../common/IsL2Check.sol";

contract Accounts is
IAccounts,
Expand Down Expand Up @@ -198,7 +199,7 @@ contract Accounts is
uint256 lastIndex = offchainStorageRoots[msg.sender].length - 1;
bytes memory url = offchainStorageRoots[msg.sender][index];
offchainStorageRoots[msg.sender][index] = offchainStorageRoots[msg.sender][lastIndex];
offchainStorageRoots[msg.sender].length--;
offchainStorageRoots[msg.sender].pop();
emit OffchainStorageRootRemoved(msg.sender, url, index);
}

Expand Down Expand Up @@ -986,7 +987,7 @@ contract Accounts is
function _setEip712DomainSeparator() internal {
uint256 chainId;
assembly {
chainId := chainid
chainId := chainid()
}

eip712DomainSeparator = keccak256(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.7 <0.8.20;

import "@openzeppelin/contracts8/security/ReentrancyGuard.sol";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pragma solidity ^0.5.13;
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.7 <0.8.20;

import "openzeppelin-solidity/contracts/utils/Address.sol";
import "@openzeppelin/contracts8/utils/Address.sol";

library ExternalCall {
/**
Expand All @@ -18,7 +19,7 @@ library ExternalCall {
if (data.length > 0) require(Address.isContract(destination), "Invalid contract address");
bool success;
bytes memory returnData;
(success, returnData) = destination.call.value(value)(data);
(success, returnData) = destination.call{ value: value }(data);
require(success, "Transaction execution failed.");
return returnData;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
pragma solidity ^0.5.13;
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.7 <0.8.20;

import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "@openzeppelin/contracts8/access/Ownable.sol";

import "./interfaces/IFeeCurrencyWhitelist.sol";
import "../../contracts/common/Initializable.sol";

import "../common/Initializable.sol";

import "../common/interfaces/ICeloVersionedContract.sol";
import "../../contracts/common/interfaces/ICeloVersionedContract.sol";
import "../../contracts/common/interfaces/IFeeCurrencyWhitelist.sol";

/**
* @title Holds a whitelist of the ERC20+ tokens that can be used to pay for gas
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
pragma solidity ^0.5.13;

import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/math/Math.sol";
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
import "openzeppelin-solidity/contracts/utils/EnumerableSet.sol";

import "./UsingRegistry.sol";
import "../common/Freezable.sol";
import "../common/FixidityLib.sol";
import "../common/Initializable.sol";

import "../common/interfaces/IFeeHandler.sol";
import "../common/interfaces/IFeeHandlerSeller.sol";
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.7 <0.8.20;

import "@openzeppelin/contracts8/access/Ownable.sol";
import "@openzeppelin/contracts8/utils/math/Math.sol";
import "@openzeppelin/contracts8/utils/math/SafeMath.sol";
import "@openzeppelin/contracts8/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts8/interfaces/IERC20.sol";

import "../../contracts-0.8/common/UsingRegistry.sol";
import "../../contracts-0.8/common/Freezable.sol";
import "../../contracts/common/FixidityLib.sol";
import "../../contracts/common/Initializable.sol";
import "../../contracts/common/interfaces/IFeeHandler.sol";
import "../../contracts/common/interfaces/IFeeHandlerSeller.sol";
import "../../contracts/common/interfaces/ICeloVersionedContract.sol";
import "../../contracts/common/interfaces/IStableTokenMento.sol";
import "../../contracts/stability/interfaces/ISortedOracles.sol";

// TODO move to IStableToken when it adds method getExchangeRegistryId
import "./interfaces/IStableTokenMento.sol";
import "../common/interfaces/ICeloVersionedContract.sol";
import "../common/interfaces/ICeloToken.sol";
import "../stability/interfaces/ISortedOracles.sol";
import "../../contracts/common/interfaces/ICeloToken.sol";

// Using the minimal required signatures in the interfaces so more contracts could be compatible
import "../common/libraries/ReentrancyGuard.sol";
import "../../contracts/common/libraries/ReentrancyGuard.sol";

// An implementation of FeeHandler as described in CIP-52
// See https://github.com/celo-org/celo-proposals/blob/master/CIPs/cip-0052.md
Expand Down Expand Up @@ -119,7 +119,7 @@ contract FeeHandler is
}

// Without this the contract cant receive Celo as native transfer
function() external payable {}
receive() external payable {}

/**
@dev Sets the fee beneficiary address to the specified address.
Expand Down Expand Up @@ -342,7 +342,7 @@ contract FeeHandler is
return false;
}

uint256 currentDay = now / 1 days;
uint256 currentDay = block.timestamp / 1 days;
// Pattern borrowed from Reserve.sol
if (currentDay > lastLimitDay) {
lastLimitDay = currentDay;
Expand All @@ -353,7 +353,7 @@ contract FeeHandler is
}

function getActiveTokens() public view returns (address[] memory) {
return activeTokens.values;
return activeTokens.values();
}

function _setFeeBeneficiary(address beneficiary) private {
Expand Down Expand Up @@ -497,7 +497,7 @@ contract FeeHandler is

function _distributeAll() private {
for (uint256 i = 0; i < EnumerableSet.length(activeTokens); i++) {
address token = activeTokens.get(i);
address token = activeTokens.at(i);
_distribute(token);
}
// distribute Celo
Expand All @@ -508,7 +508,7 @@ contract FeeHandler is
for (uint256 i = 0; i < EnumerableSet.length(activeTokens); i++) {
// calling _handle would trigger may burn Celo and distributions
// that can be just batched at the end
address token = activeTokens.get(i);
address token = activeTokens.at(i);
_sell(token);
}
_distributeAll(); // distributes Celo as well
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
pragma solidity ^0.5.13;
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.7 <0.8.20;

import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "../common/FixidityLib.sol";
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
import "./UsingRegistry.sol";
import "../common/Initializable.sol";
import "@openzeppelin/contracts8/access/Ownable.sol";
import "@openzeppelin/contracts8/utils/math/SafeMath.sol";
import "@openzeppelin/contracts8/interfaces/IERC20.sol";

import "../../contracts/common/FixidityLib.sol";
import "../../contracts-0.8/common/UsingRegistry.sol";
import "../../contracts/common/Initializable.sol";

// Abstract class for a FeeHandlerSeller, as defined in CIP-52
// https://github.com/celo-org/celo-proposals/blob/master/CIPs/cip-0052.md
contract FeeHandlerSeller is Ownable, Initializable, UsingRegistry {
abstract contract FeeHandlerSeller is Ownable, Initializable, UsingRegistry {
using SafeMath for uint256;
using FixidityLib for FixidityLib.Fraction;

Expand Down Expand Up @@ -41,7 +43,11 @@ contract FeeHandlerSeller is Ownable, Initializable, UsingRegistry {
@param to The address of the recipient to transfer the tokens to.
@return A boolean indicating whether the transfer was successful or not.
*/
function transfer(address token, uint256 amount, address to) external onlyOwner returns (bool) {
function transfer(
address token,
uint256 amount,
address to
) external virtual onlyOwner returns (bool) {
return IERC20(token).transfer(to, amount);
}

Expand Down
13 changes: 13 additions & 0 deletions packages/protocol/contracts-0.8/common/Freezable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.0 <0.8.20;

import "./UsingRegistry.sol";

contract Freezable is UsingRegistry {
// onlyWhenNotFrozen functions can only be called when `frozen` is false, otherwise they will
// revert.
modifier onlyWhenNotFrozen() {
require(!getFreezer().isFrozen(address(this)), "can't call when contract is frozen");
_;
}
}
37 changes: 37 additions & 0 deletions packages/protocol/contracts-0.8/common/Freezer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.7 <0.8.20;

import "@openzeppelin/contracts8/access/Ownable.sol";

import "../../contracts/common/Initializable.sol";
import "../../contracts/common/interfaces/IFreezer.sol";

contract Freezer is Ownable, Initializable, IFreezer {
mapping(address => bool) public isFrozen;

/**
* @notice Sets initialized == true on implementation contracts
* @param test Set to true to skip implementation initialization
*/
constructor(bool test) public Initializable(test) {}

function initialize() external initializer {
_transferOwnership(msg.sender);
}

/**
* @notice Freezes the target contract, disabling `onlyWhenNotFrozen` functions.
* @param target The address of the contract to freeze.
*/
function freeze(address target) external onlyOwner {
isFrozen[target] = true;
}

/**
* @notice Unfreezes the contract, enabling `onlyWhenNotFrozen` functions.
* @param target The address of the contract to freeze.
*/
function unfreeze(address target) external onlyOwner {
isFrozen[target] = false;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.7 <0.8.20;

import "@openzeppelin/contracts8/access/Ownable.sol";
Expand Down
Loading
Loading