-
Notifications
You must be signed in to change notification settings - Fork 228
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
Create Governance based bridge contracts #3
Conversation
2. Add governance for validators 3. Make Home and Foreign Bridges operated from ValidatorsContract
contracts/ForeignBridge.sol
Outdated
/// Pending signatures and authorities who confirmed them | ||
BridgeValidators public validatorsContract; | ||
mapping (bytes32 => bool) tokenAddressApprovalSigns; | ||
mapping (address => uint256) public numTokenAddressApprovalSigns; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not used any more. Could be removed.
contracts/ForeignBridge.sol
Outdated
|
||
/// Collected signatures which should be relayed to home chain. | ||
event CollectedSignatures(address authorityResponsibleForRelay, bytes32 messageHash); | ||
|
||
event TokenAddress(address token); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also not used. Please remove.
contracts/ForeignBridge.sol
Outdated
} | ||
|
||
function setGasLimitDepositRelay(uint256 gas) onlyValidator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onlyValidator
needs to be changed to onlyOwner
contracts/ForeignBridge.sol
Outdated
GasConsumptionLimitsUpdated(gasLimitDepositRelay, gasLimitWithdrawConfirm); | ||
} | ||
|
||
function setGasLimitWithdrawConfirm(uint256 gas) onlyValidator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onlyValidator
needs to be changed to onlyOwner
contracts/ForeignBridge.sol
Outdated
GasConsumptionLimitsUpdated(gasLimitDepositRelay, gasLimitWithdrawConfirm); | ||
} | ||
|
||
function setGasLimitWithdrawConfirm(uint256 gas) onlyValidator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's consider to combine setGasLimitDepositRelay()
and setGasLimitWithdrawConfirm
in one method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's good idea
contracts/ForeignBridge.sol
Outdated
Deposit(recipient, value); | ||
} | ||
SignedForDeposit(msg.sender, transactionHash); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's have:
SignedForDeposit(msg.sender, transactionHash);
if (signed == validatorContract.requiredSignatures()) {
// If the bridge contract does not own enough tokens to transfer
// it will couse funds lock on the home side of the bridge
erc677token.mint(recipient, value);
Deposit(recipient, value);
}
It will be more logical: SignedDeposit
prior to Deposit
contracts/ForeignBridge.sol
Outdated
|
||
// TODO: this may cause troubles if requiredSignatures len is changed | ||
// if (signatures[hash].signed.length == requiredSignatures) { | ||
if (signed == validatorContract.requiredSignatures()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's consider to have it more logical:
SignedForWithdraw(msg.sender, hash);
if (signed == validatorContract.requiredSignatures()) {
CollectedSignatures(msg.sender, hash);
}
GasConsumptionLimitsUpdated(gasLimitDepositRelay, gasLimitWithdrawConfirm); | ||
} | ||
|
||
function deposit(address recipient, uint value, bytes32 transactionHash) public onlyValidator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To not forget: create an issue to implement functionality that the bridge calls isValidator
before sending a transaction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contracts/HomeBridge.sol
Outdated
/// this shuts down attacks that exhaust authorities funds on home chain. | ||
contract HomeBridge is Validatable, BridgeDeploymentAddressStorage { | ||
using SafeMath for uint256; | ||
uint256 public gasLimitWithdrawRelay; | ||
uint256 public estimatedGasCostOfWithdraw; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not needed any more. Please remove.
contracts/ForeignBridge.sol
Outdated
require(!deposits_signed[hash_sender]); | ||
deposits_signed[hash_sender] = true; | ||
|
||
uint8 signed = num_deposits_signed[hash_msg] + 1; | ||
uint signed = num_deposits_signed[hash_msg] + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's specify exact size of integer here: uint8
or uint256
contracts/HomeBridge.sol
Outdated
|
||
// The following two statements guard against reentry into this function. | ||
// Duplicated withdraw or reentry. | ||
uint256 homeGasPrice = Message.getHomeGasPrice(message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove all homeGasPrice
related logic and work with value
only. Later we will remove it from the bridge binary and from ForeignBridge
contract.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it does not make sense to cover expenses of bridge validators on Home side since Home is POA network and all transactions are "free" here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not the only use case here, people can also withdraw if they provide the correct gasPrice value
contracts/libraries/Helpers.sol
Outdated
IBridgeValidators _validatorContract) internal view returns (bool) { | ||
uint8 requiredSignatures = _validatorContract.requiredSignatures(); | ||
require(_vs.length <= requiredSignatures); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Должно быть
require(_vs.length >= requiredSignatures);
contracts/libraries/Message.sol
Outdated
|
||
function getHomeGasPrice(bytes message) internal pure returns (uint256) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не используется больше
I've merged PR. Does it make sense to put |
Fixes:
omni/poa-bridge#8
omni/poa-bridge#15
omni/poa-bridge#17
omni/poa-bridge#18
omni/poa-bridge#20
omni/poa-bridge#9
Accepts ERC677 token
@akolotov