Skip to content

Commit

Permalink
Merge pull request #1350 from skalenetwork/beta-to-develop
Browse files Browse the repository at this point in the history
Beta to develop
  • Loading branch information
DimaStebaev authored Dec 15, 2022
2 parents 1dd5d4e + 1fbf3ed commit ed448e3
Show file tree
Hide file tree
Showing 16 changed files with 672 additions and 210 deletions.
2 changes: 1 addition & 1 deletion proxy/DEPLOYED
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.2-stable.1
1.3.4-stable.0
204 changes: 115 additions & 89 deletions proxy/contracts/mainnet/DepositBoxes/DepositBoxERC20.sol

Large diffs are not rendered by default.

78 changes: 47 additions & 31 deletions proxy/contracts/mainnet/MessageProxyForMainnet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import "./CommunityPool.sol";
/**
* @title Message Proxy for Mainnet
* @dev Runs on Mainnet, contains functions to manage the incoming messages from
* `targetSchainName` and outgoing messages to `fromSchainName`. Every SKALE chain with
* `targetSchainName` and outgoing messages to `fromSchainName`. Every SKALE chain with
* IMA is therefore connected to MessageProxyForMainnet.
*
* Messages from SKALE chains are signed using BLS threshold signatures from the
Expand Down Expand Up @@ -103,6 +103,20 @@ contract MessageProxyForMainnet is SkaleManagerClient, MessageProxy, IMessagePro
uint256 newValue
);

/**
* @dev Emitted when the schain is paused
*/
event SchainPaused(
bytes32 indexed schainHash
);

/**
* @dev Emitted when the schain is resumed
*/
event SchainResumed(
bytes32 indexed schainHash
);

/**
* @dev Emitted when reimbursed contract was added
*/
Expand Down Expand Up @@ -139,9 +153,9 @@ contract MessageProxyForMainnet is SkaleManagerClient, MessageProxy, IMessagePro

/**
* @dev Allows `msg.sender` to connect schain with MessageProxyOnMainnet for transferring messages.
*
*
* Requirements:
*
*
* - Schain name must not be `Mainnet`.
*/
function addConnectedChain(string calldata schainName) external override {
Expand All @@ -154,9 +168,9 @@ contract MessageProxyForMainnet is SkaleManagerClient, MessageProxy, IMessagePro

/**
* @dev Allows owner of the contract to set CommunityPool address for gas reimbursement.
*
*
* Requirements:
*
*
* - `msg.sender` must be granted as DEFAULT_ADMIN_ROLE.
* - Address of CommunityPool contract must not be null.
*/
Expand All @@ -168,9 +182,9 @@ contract MessageProxyForMainnet is SkaleManagerClient, MessageProxy, IMessagePro

/**
* @dev Allows `msg.sender` to register extra contract for being able to transfer messages from custom contracts.
*
*
* Requirements:
*
*
* - `msg.sender` must be granted as EXTRA_CONTRACT_REGISTRAR_ROLE.
* - Schain name must not be `Mainnet`.
*/
Expand All @@ -181,16 +195,16 @@ contract MessageProxyForMainnet is SkaleManagerClient, MessageProxy, IMessagePro
isSchainOwner(msg.sender, schainHash),
"Not enough permissions to register extra contract"
);
require(schainHash != MAINNET_HASH, "Schain hash can not be equal Mainnet");
require(schainHash != MAINNET_HASH, "Schain hash can not be equal Mainnet");
_registerExtraContract(schainHash, extraContract);
}

/**
* @dev Allows `msg.sender` to remove extra contract,
* thus `extraContract` will no longer be available to transfer messages from mainnet to schain.
*
*
* Requirements:
*
*
* - `msg.sender` must be granted as EXTRA_CONTRACT_REGISTRAR_ROLE.
* - Schain name must not be `Mainnet`.
*/
Expand Down Expand Up @@ -256,10 +270,10 @@ contract MessageProxyForMainnet is SkaleManagerClient, MessageProxy, IMessagePro
}

/**
* @dev Posts incoming message from `fromSchainName`.
*
* @dev Posts incoming message from `fromSchainName`.
*
* Requirements:
*
*
* - `msg.sender` must be authorized caller.
* - `fromSchainName` must be initialized.
* - `startingCounter` must be equal to the chain's incoming message counter.
Expand Down Expand Up @@ -290,7 +304,7 @@ contract MessageProxyForMainnet is SkaleManagerClient, MessageProxy, IMessagePro
fromSchainName,
_hashedArray(messages, startingCounter, fromSchainName), sign),
"Signature is not verified");
uint additionalGasPerMessage =
uint additionalGasPerMessage =
(gasTotal - gasleft() + headerMessageGasCost + messages.length * messageGasCost) / messages.length;
uint notReimbursedGas = 0;
connectedChains[fromSchainHash].incomingMessageCounter += messages.length;
Expand All @@ -315,9 +329,9 @@ contract MessageProxyForMainnet is SkaleManagerClient, MessageProxy, IMessagePro

/**
* @dev Sets headerMessageGasCost to a new value.
*
*
* Requirements:
*
*
* - `msg.sender` must be granted as CONSTANT_SETTER_ROLE.
*/
function setNewHeaderMessageGasCost(uint256 newHeaderMessageGasCost) external override onlyConstantSetter {
Expand All @@ -327,9 +341,9 @@ contract MessageProxyForMainnet is SkaleManagerClient, MessageProxy, IMessagePro

/**
* @dev Sets messageGasCost to a new value.
*
*
* Requirements:
*
*
* - `msg.sender` must be granted as CONSTANT_SETTER_ROLE.
*/
function setNewMessageGasCost(uint256 newMessageGasCost) external override onlyConstantSetter {
Expand All @@ -339,9 +353,9 @@ contract MessageProxyForMainnet is SkaleManagerClient, MessageProxy, IMessagePro

/**
* @dev Sets new version of contracts on mainnet
*
*
* Requirements:
*
*
* - `msg.sender` must be granted DEFAULT_ADMIN_ROLE.
*/
function setVersion(string calldata newVersion) external override {
Expand All @@ -352,9 +366,9 @@ contract MessageProxyForMainnet is SkaleManagerClient, MessageProxy, IMessagePro

/**
* @dev Allows PAUSABLE_ROLE to pause IMA bridge unlimited
*
*
* Requirements:
*
*
* - IMA bridge to current schain was not paused
* - Sender should be PAUSABLE_ROLE
*/
Expand All @@ -363,13 +377,14 @@ contract MessageProxyForMainnet is SkaleManagerClient, MessageProxy, IMessagePro
require(hasRole(PAUSABLE_ROLE, msg.sender), "Incorrect sender");
require(!pauseInfo[schainHash].paused, "Already paused");
pauseInfo[schainHash].paused = true;
emit SchainPaused(schainHash);
}

/**
* @dev Allows DEFAULT_ADMIN_ROLE or schain owner to resume IMA bridge
*
* @dev Allows DEFAULT_ADMIN_ROLE or schain owner to resume IMA bridge
*
* Requirements:
*
*
* - IMA bridge to current schain was paused
* - Sender should be DEFAULT_ADMIN_ROLE or schain owner
*/
Expand All @@ -378,6 +393,7 @@ contract MessageProxyForMainnet is SkaleManagerClient, MessageProxy, IMessagePro
require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender) || isSchainOwner(msg.sender, schainHash), "Incorrect sender");
require(pauseInfo[schainHash].paused, "Already unpaused");
pauseInfo[schainHash].paused = false;
emit SchainResumed(schainHash);
}

/**
Expand Down Expand Up @@ -440,12 +456,12 @@ contract MessageProxyForMainnet is SkaleManagerClient, MessageProxy, IMessagePro

/**
* @dev Checks whether chain is currently connected.
*
* Note: Mainnet chain does not have a public key, and is implicitly
*
* Note: Mainnet chain does not have a public key, and is implicitly
* connected to MessageProxy.
*
*
* Requirements:
*
*
* - `schainName` must not be Mainnet.
*/
function isConnectedChain(
Expand Down Expand Up @@ -484,7 +500,7 @@ contract MessageProxyForMainnet is SkaleManagerClient, MessageProxy, IMessagePro
|| isContractRegistered(targetChainHash, msg.sender)
|| isSchainOwner(msg.sender, targetChainHash),
"Sender contract is not registered"
);
);
}

/**
Expand Down Expand Up @@ -514,7 +530,7 @@ contract MessageProxyForMainnet is SkaleManagerClient, MessageProxy, IMessagePro
}

/**
* @dev Checks whether balance of schain wallet is sufficient for
* @dev Checks whether balance of schain wallet is sufficient for
* for reimbursement custom message.
*/
function _checkSchainBalance(bytes32 schainHash) internal view returns (bool) {
Expand Down
25 changes: 25 additions & 0 deletions proxy/contracts/test/erc20/ERC20IncorrectTransfer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: AGPL-3.0-only

pragma solidity 0.8.16;

import "./ERC20WithoutTransfer.sol";

interface IERC20IncorrectTransfer is IERC20WithoutTransfer {
function transferFrom(address sender, address recipient, uint256 amount, bytes memory) external;
}


contract ERC20IncorrectTransfer is IERC20IncorrectTransfer, ERC20WithoutTransfer {

// solhint-disable-next-line no-empty-blocks
constructor(string memory tokenName, string memory tokenSymbol) ERC20WithoutTransfer(tokenName, tokenSymbol) {}

function transferFrom(address sender, address recipient, uint256 amount, bytes memory) public override {
_transfer(sender, recipient, amount);
_approve(
sender,
msg.sender,
allowance(sender, msg.sender) - amount
);
}
}
25 changes: 25 additions & 0 deletions proxy/contracts/test/erc20/ERC20TransferWithFalseReturn.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: AGPL-3.0-only

pragma solidity 0.8.16;

import "./ERC20WithoutTransfer.sol";

interface IERC20TransferWithFalseReturn is IERC20WithoutTransfer {
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
}

contract ERC20TransferWithFalseReturn is IERC20TransferWithFalseReturn, ERC20WithoutTransfer {

// solhint-disable-next-line no-empty-blocks
constructor(string memory tokenName, string memory tokenSymbol) ERC20WithoutTransfer(tokenName, tokenSymbol) {}

function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(
sender,
msg.sender,
allowance(sender, msg.sender) - amount
);
return false;
}
}
24 changes: 24 additions & 0 deletions proxy/contracts/test/erc20/ERC20TransferWithoutReturn.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: AGPL-3.0-only

pragma solidity 0.8.16;

import "./ERC20WithoutTransfer.sol";

interface IERC20TransferWithoutReturn is IERC20WithoutTransfer {
function transferFrom(address sender, address recipient, uint256 amount) external;
}

contract ERC20TransferWithoutReturn is IERC20TransferWithoutReturn, ERC20WithoutTransfer {

// solhint-disable-next-line no-empty-blocks
constructor(string memory tokenName, string memory tokenSymbol) ERC20WithoutTransfer(tokenName, tokenSymbol) {}

function transferFrom(address sender, address recipient, uint256 amount) public override {
_transfer(sender, recipient, amount);
_approve(
sender,
msg.sender,
allowance(sender, msg.sender) - amount
);
}
}
Loading

0 comments on commit ed448e3

Please sign in to comment.