Skip to content

Commit

Permalink
Merge the develop branch to the master branch, preparation to v2.0.0-rc0
Browse files Browse the repository at this point in the history
  • Loading branch information
akolotov authored Apr 6, 2021
2 parents d78333c + 3311f04 commit 23af4d4
Show file tree
Hide file tree
Showing 60 changed files with 2,471 additions and 531 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"global-require": "off",
"no-loop-func": "off",
"no-console": "off",
"node/no-missing-require": "off"
"node/no-missing-require": "off",
"import/no-unresolved": "off"
}
}
32 changes: 32 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,35 @@ jobs:
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
e2e:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run tests
run: yarn e2e-tests:local
publish:
runs-on: ubuntu-latest
needs:
- validate
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags')
steps:
- uses: actions/checkout@v2
- name: Prepare tag names
id: prep
run: |
DOCKER_IMAGE=poanetwork/nft-omnibridge-contracts
if [[ $GITHUB_REF == refs/tags/* ]]; then
echo ::set-output name=tags::${DOCKER_IMAGE}:${GITHUB_REF#refs/tags/},${DOCKER_IMAGE}:latest
else
echo ::set-output name=tags::${DOCKER_IMAGE}:${GITHUB_REF#refs/heads/}-${GITHUB_SHA::8}
fi
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- uses: docker/build-push-action@v2
with:
pull: true
push: true
tags: ${{ steps.prep.outputs.tags }}
2 changes: 2 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"avoid-low-level-calls": "off",
"no-inline-assembly": "off",
"reason-string": "off",
"no-empty-blocks": "off",
"var-name-mixedcase": "off",
"func-visibility": ["warn", { "ignoreConstructors": true } ],
"compiler-version": ["error", "0.7.5"]
}
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ RUN yarn flatten
COPY deploy.sh deploy.sh
COPY ./deploy ./deploy
COPY ./test ./test
COPY ./e2e-tests ./e2e-tests

ENV PATH="/contracts/:${PATH}"
15 changes: 15 additions & 0 deletions contracts/interfaces/IAMB.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
pragma solidity 0.7.5;

interface IAMB {
event UserRequestForAffirmation(bytes32 indexed messageId, bytes encodedData);
event UserRequestForSignature(bytes32 indexed messageId, bytes encodedData);
event CollectedSignatures(
address authorityResponsibleForRelay,
bytes32 messageHash,
uint256 numberOfCollectedSignatures
);
event AffirmationCompleted(
address indexed sender,
address indexed executor,
bytes32 indexed messageId,
bool status
);
event RelayedMessage(address indexed sender, address indexed executor, bytes32 indexed messageId, bool status);

function messageSender() external view returns (address);

function maxGasPerTx() external view returns (uint256);
Expand Down
6 changes: 3 additions & 3 deletions contracts/mocks/AMBMock.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pragma solidity 0.7.5;

contract AMBMock {
event MockedEvent(bytes32 indexed messageId, address executor, uint8 dataType, bytes data);
event MockedEvent(bytes32 indexed messageId, address executor, uint8 dataType, bytes data, uint256 gas);

address public messageSender;
uint256 public immutable maxGasPerTx;
Expand Down Expand Up @@ -62,7 +62,7 @@ contract AMBMock {
function _sendMessage(
address _contract,
bytes calldata _data,
uint256,
uint256 _gas,
uint256 _dataType
) internal returns (bytes32) {
require(messageId == bytes32(0));
Expand All @@ -73,7 +73,7 @@ contract AMBMock {
bytes32 _messageId = bytes32(uint256(0x11223344 << 224)) | bridgeId | bytes32(nonce);
nonce += 1;

emit MockedEvent(_messageId, _contract, uint8(_dataType), _data);
emit MockedEvent(_messageId, _contract, uint8(_dataType), _data, _gas);
return _messageId;
}

Expand Down
19 changes: 12 additions & 7 deletions contracts/upgradeability/UpgradeabilityOwnerStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,26 @@ pragma solidity 0.7.5;
* @dev This contract keeps track of the upgradeability owner
*/
contract UpgradeabilityOwnerStorage {
// Owner of the contract
address internal _upgradeabilityOwner;

/**
* @dev Tells the address of the owner
* @return the address of the owner
* @return owner the address of the owner
*/
function upgradeabilityOwner() public view returns (address) {
return _upgradeabilityOwner;
function upgradeabilityOwner() public view returns (address owner) {
assembly {
// EIP 1967
// bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1)
owner := sload(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103)
}
}

/**
* @dev Sets the address of the owner
*/
function setUpgradeabilityOwner(address newUpgradeabilityOwner) internal {
_upgradeabilityOwner = newUpgradeabilityOwner;
assembly {
// EIP 1967
// bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1)
sstore(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103, newUpgradeabilityOwner)
}
}
}
20 changes: 10 additions & 10 deletions contracts/upgradeability/UpgradeabilityProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ contract UpgradeabilityProxy is Proxy, UpgradeabilityStorage {
}

/**
* @dev Upgrades the implementation address
* @param version representing the version name of the new implementation to be set
* @param implementation representing the address of the new implementation to be set
* @dev Upgrades the implementation address.
* @param _version representing the version name of the new implementation to be set.
* @param _implementation representing the address of the new implementation to be set.
*/
function _upgradeTo(uint256 version, address implementation) internal {
require(_implementation != implementation);
function _upgradeTo(uint256 _version, address _implementation) internal {
require(_implementation != implementation());

// This additional check verifies that provided implementation is at least a contract
require(Address.isContract(implementation));
require(Address.isContract(_implementation));

// This additional check guarantees that new version will be at least greater than the privios one,
// so it is impossible to reuse old versions, or use the last version twice
require(version > _version);
require(_version > version());

_version = version;
_implementation = implementation;
emit Upgraded(version, implementation);
_setVersion(_version);
_setImplementation(_implementation);
emit Upgraded(_version, _implementation);
}
}
50 changes: 38 additions & 12 deletions contracts/upgradeability/UpgradeabilityStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,51 @@ pragma solidity 0.7.5;
* @dev This contract holds all the necessary state variables to support the upgrade functionality
*/
contract UpgradeabilityStorage {
// Version name of the current implementation
uint256 internal _version;

// Address of the current implementation
address internal _implementation;

/**
* @dev Tells the version name of the current implementation
* @return uint256 representing the name of the current version
* @return version uint256 representing the name of the current version
*/
function version() external view returns (uint256) {
return _version;
function version() public view returns (uint256 version) {
assembly {
// EIP 1967
// bytes32(uint256(keccak256('eip1967.proxy.version')) - 1)
version := sload(0x460994c355dbc8229336897ed9def5884fb6b26b0a995b156780d056c758577d)
}
}

/**
* @dev Tells the address of the current implementation
* @return address of the current implementation
* @return impl address of the current implementation
*/
function implementation() public view virtual returns (address impl) {
assembly {
// EIP 1967
// bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)
impl := sload(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc)
}
}

/**
* Internal function for updating version of the implementation contract.
* @param _version new version number.
*/
function _setVersion(uint256 _version) internal {
assembly {
// EIP 1967
// bytes32(uint256(keccak256('eip1967.proxy.version')) - 1)
sstore(0x460994c355dbc8229336897ed9def5884fb6b26b0a995b156780d056c758577d, _version)
}
}

/**
* Internal function for updating implementation contract address.
* @param _impl new implementation contract address.
*/
function implementation() public view virtual returns (address) {
return _implementation;
function _setImplementation(address _impl) internal {
assembly {
// EIP 1967
// bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)
sstore(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc, _impl)
}
}
}
46 changes: 6 additions & 40 deletions contracts/upgradeable_contracts/BasicAMBMediator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import "@openzeppelin/contracts/utils/Address.sol";
* @title BasicAMBMediator
* @dev Basic storage and methods needed by mediators to interact with AMB bridge.
*/
contract BasicAMBMediator is Ownable {
abstract contract BasicAMBMediator is Ownable {
bytes32 internal constant BRIDGE_CONTRACT = 0x811bbb11e8899da471f0e69a3ed55090fc90215227fc5fb1cb0d6e962ea7b74f; // keccak256(abi.encodePacked("bridgeContract"))
bytes32 internal constant MEDIATOR_CONTRACT = 0x98aa806e31e94a687a31c65769cb99670064dd7f5a87526da075c5fb4eab9880; // keccak256(abi.encodePacked("mediatorContract"))
bytes32 internal constant REQUEST_GAS_LIMIT = 0x2dfd6c9f781bb6bbb5369c114e949b69ebb440ef3d4dd6b2836225eb1dc3a2be; // keccak256(abi.encodePacked("requestGasLimit"))

/**
* @dev Throws if caller on the other side is not an associated mediator.
Expand All @@ -25,8 +24,9 @@ contract BasicAMBMediator is Ownable {
* @dev Internal function for reducing onlyMediator modifier bytecode overhead.
*/
function _onlyMediator() internal view {
require(msg.sender == address(bridgeContract()));
require(messageSender() == mediatorContractOnOtherSide());
IAMB bridge = bridgeContract();
require(msg.sender == address(bridge));
require(bridge.messageSender() == mediatorContractOnOtherSide());
}

/**
Expand All @@ -45,16 +45,6 @@ contract BasicAMBMediator is Ownable {
_setMediatorContractOnOtherSide(_mediatorContract);
}

/**
* @dev Sets the gas limit to be used in the message execution by the AMB bridge on the other network.
* This value can't exceed the parameter maxGasPerTx defined on the AMB bridge.
* Only the owner can call this method.
* @param _requestGasLimit the gas limit for the message execution.
*/
function setRequestGasLimit(uint256 _requestGasLimit) external onlyOwner {
_setRequestGasLimit(_requestGasLimit);
}

/**
* @dev Get the AMB interface for the bridge contract address
* @return AMB interface for the bridge contract address
Expand All @@ -71,14 +61,6 @@ contract BasicAMBMediator is Ownable {
return addressStorage[MEDIATOR_CONTRACT];
}

/**
* @dev Tells the gas limit to be used in the message execution by the AMB bridge on the other network.
* @return the gas limit for the message execution.
*/
function requestGasLimit() public view returns (uint256) {
return uintStorage[REQUEST_GAS_LIMIT];
}

/**
* @dev Stores a valid AMB bridge contract address.
* @param _bridgeContract the address of the bridge contract.
Expand All @@ -96,24 +78,6 @@ contract BasicAMBMediator is Ownable {
addressStorage[MEDIATOR_CONTRACT] = _mediatorContract;
}

/**
* @dev Stores the gas limit to be used in the message execution by the AMB bridge on the other network.
* @param _requestGasLimit the gas limit for the message execution.
*/
function _setRequestGasLimit(uint256 _requestGasLimit) internal {
require(_requestGasLimit <= maxGasPerTx());
uintStorage[REQUEST_GAS_LIMIT] = _requestGasLimit;
}

/**
* @dev Tells the address that generated the message on the other network that is currently being executed by
* the AMB bridge.
* @return the address of the message sender.
*/
function messageSender() internal view returns (address) {
return bridgeContract().messageSender();
}

/**
* @dev Tells the id of the message originated on the other network.
* @return the id of the message originated on the other network.
Expand All @@ -129,4 +93,6 @@ contract BasicAMBMediator is Ownable {
function maxGasPerTx() internal view returns (uint256) {
return bridgeContract().maxGasPerTx();
}

function _passMessage(bytes memory _data, bool _useOracleLane) internal virtual returns (bytes32);
}
Loading

0 comments on commit 23af4d4

Please sign in to comment.