Skip to content
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

Merged
merged 9 commits into from
Mar 13, 2018
Merged

Conversation

rstormsf
Copy link
Contributor

@rstormsf rstormsf commented Mar 2, 2018

rstormsf added 2 commits March 3, 2018 00:38
2. Add governance for validators
3. Make Home and Foreign Bridges operated from ValidatorsContract
@ghost ghost added the in progress label Mar 2, 2018
/// Pending signatures and authorities who confirmed them
BridgeValidators public validatorsContract;
mapping (bytes32 => bool) tokenAddressApprovalSigns;
mapping (address => uint256) public numTokenAddressApprovalSigns;
Copy link
Collaborator

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.


/// Collected signatures which should be relayed to home chain.
event CollectedSignatures(address authorityResponsibleForRelay, bytes32 messageHash);

event TokenAddress(address token);
Copy link
Collaborator

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.

}

function setGasLimitDepositRelay(uint256 gas) onlyValidator {
Copy link
Collaborator

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

GasConsumptionLimitsUpdated(gasLimitDepositRelay, gasLimitWithdrawConfirm);
}

function setGasLimitWithdrawConfirm(uint256 gas) onlyValidator {
Copy link
Collaborator

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

GasConsumptionLimitsUpdated(gasLimitDepositRelay, gasLimitWithdrawConfirm);
}

function setGasLimitWithdrawConfirm(uint256 gas) onlyValidator {
Copy link
Collaborator

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.

Copy link
Contributor Author

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

Deposit(recipient, value);
}
SignedForDeposit(msg.sender, transactionHash);
Copy link
Collaborator

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


// TODO: this may cause troubles if requiredSignatures len is changed
// if (signatures[hash].signed.length == requiredSignatures) {
if (signed == validatorContract.requiredSignatures()) {
Copy link
Collaborator

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 {
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// 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;
Copy link
Collaborator

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.

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;
Copy link
Collaborator

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


// The following two statements guard against reentry into this function.
// Duplicated withdraw or reentry.
uint256 homeGasPrice = Message.getHomeGasPrice(message);
Copy link
Collaborator

@akolotov akolotov Mar 6, 2018

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Collaborator

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.

Copy link
Contributor Author

@rstormsf rstormsf Mar 12, 2018

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

IBridgeValidators _validatorContract) internal view returns (bool) {
uint8 requiredSignatures = _validatorContract.requiredSignatures();
require(_vs.length <= requiredSignatures);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Должно быть

require(_vs.length >= requiredSignatures);


function getHomeGasPrice(bytes message) internal pure returns (uint256) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не используется больше

@akolotov akolotov merged commit d53ae35 into omni:master Mar 13, 2018
@ghost ghost removed the in progress label Mar 13, 2018
@akolotov
Copy link
Collaborator

I've merged PR.

Does it make sense to put getCurrentDay(), setDailyLimit and withinLimit() in a separate contract which will be inherited both by HomeBridge and ForeignBridge. Seems that they have a common code part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants