Skip to content

Commit

Permalink
feat(core): updated solidity version to 0.8.x (UMAprotocol#2924)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismaree authored May 5, 2021
1 parent e5a43f2 commit 5db0d71
Show file tree
Hide file tree
Showing 127 changed files with 507 additions and 674 deletions.
21 changes: 0 additions & 21 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,6 @@ jobs:
- run:
name: Lint
command: ./ci/lint.sh
docs:
docker:
- image: circleci/node:lts
working_directory: ~/protocol
steps:
- restore_cache:
key: protocol-{{ .Environment.CIRCLE_SHA1 }}
- run:
name: Install Pandoc
command: wget https://github.com/jgm/pandoc/releases/download/2.7.3/pandoc-2.7.3-linux.tar.gz
- run:
name: Untar Pandoc
command: sudo tar xvzf pandoc-2.7.3-linux.tar.gz --strip-components 1 -C /usr/local
- run:
name: Generate Docs
command: ./scripts/build_docs_site.sh
- store_artifacts:
path: build/site
test:
executor: continuation/default
steps:
Expand Down Expand Up @@ -158,9 +140,6 @@ workflows:
context: api_keys
requires:
- build
- docs:
requires:
- checkout_and_install
- dapp_build:
requires:
- build
Expand Down
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ coverage
coverage.json
out.log
.GckmsOverride.js
docs
modules
public
ui
Expand Down
6 changes: 0 additions & 6 deletions ci/docgen.sh

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"prettier-plugin-solidity": "^1.0.0-beta.1",
"pretty-quick": "^2.0.1",
"secp256k1": "^3.7.1",
"solidity-docgen": "^0.5.3",
"solc-0.8": "npm:solc@^0.8.4",
"truffle": "^5.2.3",
"web3": "^1.3.4"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/HardhatConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function getHardhatConfig(configOverrides) {
require("@nomiclabs/hardhat-web3");

// Solc version defined here so etherscan-verification has access to it
const solcVersion = "0.6.12";
const solcVersion = "0.8.4";

task("test")
.addFlag("debug", "Compile without optimizer")
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/TruffleConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ function getTruffleConfig(truffleContextDir = "./") {
},
compilers: {
solc: {
version: "0.6.12",
version: "0.8.4",
settings: {
optimizer: {
enabled: true,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.6.0;
pragma solidity ^0.8.0;

/**
* @title Used internally by Truffle migrations.
Expand All @@ -9,7 +9,7 @@ contract Migrations {
address public owner;
uint256 public last_completed_migration;

constructor() public {
constructor() {
owner = msg.sender;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.0;
pragma abicoder v2;

import "../../common/implementation/FixedPoint.sol";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.0;
pragma abicoder v2;

import "../../common/implementation/FixedPoint.sol";
import "@uniswap/lib/contracts/libraries/TransferHelper.sol";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
pragma solidity ^0.8.0;
pragma abicoder v2;

import "../../common/implementation/ExpandedERC20.sol";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.0;
pragma abicoder v2;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import "@uniswap/lib/contracts/libraries/TransferHelper.sol";
Expand Down
147 changes: 133 additions & 14 deletions packages/core/contracts/bot-helpers/uniswap-broker/UniswapBroker.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
pragma solidity ^0.6.0;
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";

import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";
import "@uniswap/lib/contracts/libraries/Babylonian.sol";
import "@uniswap/lib/contracts/libraries/TransferHelper.sol";
import "@uniswap/lib/contracts/libraries/FullMath.sol";
import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router01.sol";

/**
Expand Down Expand Up @@ -128,10 +128,7 @@ contract UniswapBroker {

// The methods below are taken from https://github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/libraries/UniswapV2Library.sol
// We could import this library into this contract but this library is dependent Uniswap's SafeMath, which is bound
// to solidity 6.6.6. Hardhat can easily deal with two different sets of solidity versions within one project so
// unit tests would continue to work fine. However, this would break truffle support in the repo as truffle cant
// handel having two different solidity versions. As a work around, the specific methods needed in the UniswapBroker
// are simply moved here to maintain truffle support.
// to solidity 6.6.6. UMA uses 0.8.0 and so a modified version is needed to accomidate this solidity version.
function getReserves(
address factory,
address tokenA,
Expand All @@ -156,16 +153,138 @@ contract UniswapBroker {
) internal pure returns (address pair) {
(address token0, address token1) = sortTokens(tokenA, tokenB);
pair = address(
uint256(
keccak256(
abi.encodePacked(
hex"ff",
factory,
keccak256(abi.encodePacked(token0, token1)),
hex"96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f" // init code hash
uint160(
uint256(
keccak256(
abi.encodePacked(
hex"ff",
factory,
keccak256(abi.encodePacked(token0, token1)),
hex"96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f" // init code hash
)
)
)
)
);
}
}

// The library below is taken from @uniswap/lib/contracts/libraries/FullMath.sol. It has been modified to work with solidity 0.8
library FullMath {
/// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
/// @param a The multiplicand
/// @param b The multiplier
/// @param denominator The divisor
/// @return result The 256-bit result
/// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv
function mulDiv(
uint256 a,
uint256 b,
uint256 denominator
) internal pure returns (uint256 result) {
// 512-bit multiply [prod1 prod0] = a * b
// Compute the product mod 2**256 and mod 2**256 - 1
// then use the Chinese Remainder Theorem to reconstruct
// the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2**256 + prod0
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(a, b, not(0))
prod0 := mul(a, b)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}

// Handle non-overflow cases, 256 by 256 division
if (prod1 == 0) {
require(denominator > 0);
assembly {
result := div(prod0, denominator)
}
return result;
}

// Make sure the result is less than 2**256.
// Also prevents denominator == 0
require(denominator > prod1);

///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////

// Make division exact by subtracting the remainder from [prod1 prod0]
// Compute remainder using mulmod
uint256 remainder;
assembly {
remainder := mulmod(a, b, denominator)
}
// Subtract 256 bit number from 512 bit number
assembly {
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}

// Factor powers of two out of denominator
// Compute largest power of two divisor of denominator.
// Always >= 1.
uint256 twos = denominator & (~denominator + 1);
// Divide denominator by power of two
assembly {
denominator := div(denominator, twos)
}

// Divide [prod1 prod0] by the factors of two
assembly {
prod0 := div(prod0, twos)
}
// Shift in bits from prod1 into prod0. For this we need
// to flip `twos` such that it is 2**256 / twos.
// If twos is zero, then it becomes one
assembly {
twos := add(div(sub(0, twos), twos), 1)
}
prod0 |= prod1 * twos;

// Invert denominator mod 2**256
// Now that denominator is an odd number, it has an inverse
// modulo 2**256 such that denominator * inv = 1 mod 2**256.
// Compute the inverse by starting with a seed that is correct
// correct for four bits. That is, denominator * inv = 1 mod 2**4
uint256 inv = (3 * denominator) ^ 2;
// Now use Newton-Raphson iteration to improve the precision.
// Thanks to Hensel's lifting lemma, this also works in modular
// arithmetic, doubling the correct bits in each step.
inv *= 2 - denominator * inv; // inverse mod 2**8
inv *= 2 - denominator * inv; // inverse mod 2**16
inv *= 2 - denominator * inv; // inverse mod 2**32
inv *= 2 - denominator * inv; // inverse mod 2**64
inv *= 2 - denominator * inv; // inverse mod 2**128
inv *= 2 - denominator * inv; // inverse mod 2**256

// Because the division is now exact we can divide by multiplying
// with the modular inverse of denominator. This will give us the
// correct result modulo 2**256. Since the precoditions guarantee
// that the outcome is less than 2**256, this is the final result.
// We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inv;
return result;
}

/// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
/// @param a The multiplicand
/// @param b The multiplier
/// @param denominator The divisor
/// @return result The 256-bit result
function mulDivRoundingUp(
uint256 a,
uint256 b,
uint256 denominator
) internal pure returns (uint256 result) {
result = mulDiv(a, b, denominator);
if (mulmod(a, b, denominator) > 0) {
require(result < type(uint256).max);
result++;
}
}
}
17 changes: 9 additions & 8 deletions packages/core/contracts/chainbridge/Bridge.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.0;
pragma abicoder v2;

import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/utils/Pausable.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "./IDepositExecute.sol";
import "./IBridge.sol";
import "./IERCHandler.sol";
Expand Down Expand Up @@ -83,18 +84,18 @@ contract Bridge is Pausable, AccessControl {
_;
}

function _onlyAdminOrRelayer() private {
function _onlyAdminOrRelayer() private view {
require(
hasRole(DEFAULT_ADMIN_ROLE, msg.sender) || hasRole(RELAYER_ROLE, msg.sender),
"sender is not relayer or admin"
);
}

function _onlyAdmin() private {
function _onlyAdmin() private view {
require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "sender doesn't have admin role");
}

function _onlyRelayers() private {
function _onlyRelayers() private view {
require(hasRole(RELAYER_ROLE, msg.sender), "sender doesn't have relayer role");
}

Expand All @@ -111,7 +112,7 @@ contract Bridge is Pausable, AccessControl {
uint256 initialRelayerThreshold,
uint256 fee,
uint256 expiry
) public {
) {
_chainID = chainID;
_relayerThreshold = initialRelayerThreshold;
_fee = fee;
Expand Down
7 changes: 4 additions & 3 deletions packages/core/contracts/chainbridge/GenericHandler.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.0;
pragma abicoder v2;

import "./IGenericHandler.sol";

Expand Down Expand Up @@ -68,7 +69,7 @@ contract GenericHandler is IGenericHandler {
address[] memory initialContractAddresses,
bytes4[] memory initialDepositFunctionSignatures,
bytes4[] memory initialExecuteFunctionSignatures
) public {
) {
require(
initialResourceIDs.length == initialContractAddresses.length,
"initialResourceIDs and initialContractAddresses len mismatch"
Expand Down
3 changes: 2 additions & 1 deletion packages/core/contracts/chainbridge/IBridge.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.6.0;
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.0;

/**
@title Interface for Bridge contract.
Expand Down
3 changes: 2 additions & 1 deletion packages/core/contracts/chainbridge/IDepositExecute.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.6.0;
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.0;

/**
@title Interface for handler contracts that support deposits and deposit executions.
Expand Down
3 changes: 2 additions & 1 deletion packages/core/contracts/chainbridge/IERCHandler.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.6.0;
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.0;

/**
@title Interface to be used with handlers that support ERC20s and ERC721s.
Expand Down
3 changes: 2 additions & 1 deletion packages/core/contracts/chainbridge/IGenericHandler.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.6.0;
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.0;

/**
@title Interface for handler that handles generic deposits and deposit executions.
Expand Down
Loading

0 comments on commit 5db0d71

Please sign in to comment.