Commit 7f57ac87 authored by elenadimitrova's avatar elenadimitrova Committed by Kelvin Fichter

Remove SafeMatch usage and rely on Solidity 0.8 built in safe math functionality

parent ae24e852
......@@ -10,7 +10,6 @@ import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/* Library Imports */
import { CrossDomainEnabled } from "../../libraries/bridge/CrossDomainEnabled.sol";
import { Lib_PredeployAddresses } from "../../libraries/constants/Lib_PredeployAddresses.sol";
import { SafeMath } from "@openzeppelin/contracts/utils/math/SafeMath.sol";
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
......@@ -23,7 +22,6 @@ import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.s
* Runtime target: EVM
*/
contract L1StandardBridge is IL1StandardBridge, CrossDomainEnabled {
using SafeMath for uint;
using SafeERC20 for IERC20;
/********************************
......@@ -263,7 +261,7 @@ contract L1StandardBridge is IL1StandardBridge, CrossDomainEnabled {
message
);
deposits[_l1Token][_l2Token] = deposits[_l1Token][_l2Token].add(_amount);
deposits[_l1Token][_l2Token] = deposits[_l1Token][_l2Token] + _amount;
emit ERC20DepositInitiated(_l1Token, _l2Token, _from, _to, _amount, _data);
}
......@@ -306,7 +304,7 @@ contract L1StandardBridge is IL1StandardBridge, CrossDomainEnabled {
override
onlyFromCrossDomainAccount(l2TokenBridge)
{
deposits[_l1Token][_l2Token] = deposits[_l1Token][_l2Token].sub(_amount);
deposits[_l1Token][_l2Token] = deposits[_l1Token][_l2Token] - _amount;
// When a withdrawal is finalized on L1, the L1 Bridge transfers the funds to the withdrawer
IERC20(_l1Token).safeTransfer(_to, _amount);
......
......@@ -12,9 +12,6 @@ import { ICanonicalTransactionChain } from "./ICanonicalTransactionChain.sol";
import { IBondManager } from "../verification/IBondManager.sol";
import { IChainStorageContainer } from "./IChainStorageContainer.sol";
/* External Imports */
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
/**
* @title StateCommitmentChain
* @dev The State Commitment Chain (SCC) contract contains a list of proposed state roots which
......@@ -243,7 +240,7 @@ contract StateCommitmentChain is IStateCommitmentChain, Lib_AddressResolver {
timestamp != 0,
"Batch header timestamp cannot be zero"
);
return SafeMath.add(timestamp, FRAUD_PROOF_WINDOW) > block.timestamp;
return (timestamp + FRAUD_PROOF_WINDOW) > block.timestamp;
}
......
......@@ -3,8 +3,6 @@ pragma solidity ^0.8.4;
// a test ERC20 token with an open mint function
contract TestERC20 {
using SafeMath for uint;
string public constant name = "Test";
string public constant symbol = "TST";
uint8 public constant decimals = 18;
......@@ -18,8 +16,8 @@ contract TestERC20 {
constructor() {}
function mint(address to, uint256 value) public {
totalSupply = totalSupply.add(value);
balanceOf[to] = balanceOf[to].add(value);
totalSupply = totalSupply + value;
balanceOf[to] = balanceOf[to] + value;
emit Transfer(address(0), to, value);
}
......@@ -29,8 +27,8 @@ contract TestERC20 {
}
function _transfer(address from, address to, uint256 value) private {
balanceOf[from] = balanceOf[from].sub(value);
balanceOf[to] = balanceOf[to].add(value);
balanceOf[from] = balanceOf[from] - value;
balanceOf[to] = balanceOf[to] + value;
emit Transfer(from, to, value);
}
......@@ -46,23 +44,9 @@ contract TestERC20 {
function transferFrom(address from, address to, uint256 value) external returns (bool) {
if (allowance[from][msg.sender] != type(uint).max) {
allowance[from][msg.sender] = allowance[from][msg.sender].sub(value);
allowance[from][msg.sender] = allowance[from][msg.sender] - value;
}
_transfer(from, to, value);
return true;
}
}
library SafeMath {
function add(uint256 x, uint256 y) internal pure returns (uint256 z) {
require((z = x + y) >= x, "ds-math-add-overflow");
}
function sub(uint256 x, uint256 y) internal pure returns (uint256 z) {
require((z = x - y) <= x, "ds-math-sub-underflow");
}
function mul(uint256 x, uint256 y) internal pure returns (uint256 z) {
require(y == 0 || (z = x * y) / y == x, "ds-math-mul-overflow");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment