Skip to content

Commit

Permalink
Merge pull request #275 from loredanacirstea/deprecation-switch
Browse files Browse the repository at this point in the history
Deprecation switch for Bug Bounty release
  • Loading branch information
loredanacirstea authored Sep 20, 2018
2 parents 678b0aa + ce2b1c8 commit 9b24c8e
Show file tree
Hide file tree
Showing 8 changed files with 366 additions and 20 deletions.
28 changes: 26 additions & 2 deletions raiden_contracts/contracts/TokenNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract TokenNetwork is Utils {
115792089237316195423570985008687907853269984665640564039457584007913129639935
);

// Bug bounty release deposit limit
// Red Eyes release deposit limit
uint256 public deposit_limit;

// Global, monotonically increasing counter that keeps track of all the
Expand All @@ -40,6 +40,10 @@ contract TokenNetwork is Utils {

string public constant signature_prefix = '\x19Ethereum Signed Message:\n';

// Only for the limited Bug Bounty release
address public deprecation_executor;
bool public safety_deprecation_switch = false;

// channel_identifier => Channel
// channel identifier is the channel_counter value at the time of opening
// the channel
Expand Down Expand Up @@ -178,6 +182,16 @@ contract TokenNetwork is Utils {
uint256 participant2_amount
);

modifier onlyDeprecationExecutor() {
require(msg.sender == deprecation_executor);
_;
}

modifier isSafe() {
require(safety_deprecation_switch == false);
_;
}

modifier isOpen(uint256 channel_identifier) {
require(channels[channel_identifier].state == ChannelState.Opened);
_;
Expand All @@ -194,12 +208,14 @@ contract TokenNetwork is Utils {
address _secret_registry,
uint256 _chain_id,
uint256 _settlement_timeout_min,
uint256 _settlement_timeout_max
uint256 _settlement_timeout_max,
address _deprecation_executor
)
public
{
require(_token_address != address(0x0));
require(_secret_registry != address(0x0));
require(_deprecation_executor != address(0x0));
require(_chain_id > 0);
require(_settlement_timeout_min > 0);
require(_settlement_timeout_max > _settlement_timeout_min);
Expand All @@ -224,6 +240,12 @@ contract TokenNetwork is Utils {
}

deposit_limit = 100 * (10 ** uint256(decimals));

deprecation_executor = _deprecation_executor;
}

function deprecate() isSafe onlyDeprecationExecutor public {
safety_deprecation_switch = true;
}

/// @notice Opens a new channel between `participant1` and `participant2`.
Expand All @@ -233,6 +255,7 @@ contract TokenNetwork is Utils {
/// @param settle_timeout Number of blocks that need to be mined between a
/// call to closeChannel and settleChannel.
function openChannel(address participant1, address participant2, uint256 settle_timeout)
isSafe
settleTimeoutValid(settle_timeout)
public
returns (uint256)
Expand Down Expand Up @@ -288,6 +311,7 @@ contract TokenNetwork is Utils {
uint256 total_deposit,
address partner
)
isSafe
isOpen(channel_identifier)
public
{
Expand Down
18 changes: 17 additions & 1 deletion raiden_contracts/contracts/TokenNetworkRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@ contract TokenNetworkRegistry is Utils {
uint256 public settlement_timeout_min;
uint256 public settlement_timeout_max;

// Only for the limited Red Eyes release
address public deprecation_executor;
bool public token_network_created = false;

// Token address => TokenNetwork address
mapping(address => address) public token_to_token_networks;

event TokenNetworkCreated(address indexed token_address, address indexed token_network_address);

modifier canCreateTokenNetwork() {
require(token_network_created == false);
_;
}

constructor(
address _secret_registry_address,
uint256 _chain_id,
Expand All @@ -39,18 +48,24 @@ contract TokenNetworkRegistry is Utils {
chain_id = _chain_id;
settlement_timeout_min = _settlement_timeout_min;
settlement_timeout_max = _settlement_timeout_max;

deprecation_executor = msg.sender;
}

/// @notice Deploy a new TokenNetwork contract for the Token deployed at
/// `_token_address`.
/// @param _token_address Ethereum address of an already deployed token, to
/// be used in the new TokenNetwork contract.
function createERC20TokenNetwork(address _token_address)
canCreateTokenNetwork
external
returns (address token_network_address)
{
require(token_to_token_networks[_token_address] == address(0x0));

// We limit the number of token networks to 1 for the Bug Bounty release
token_network_created = true;

TokenNetwork token_network;

// Token contract checks are in the corresponding TokenNetwork contract
Expand All @@ -59,7 +74,8 @@ contract TokenNetworkRegistry is Utils {
secret_registry_address,
chain_id,
settlement_timeout_min,
settlement_timeout_max
settlement_timeout_max,
deprecation_executor
);

token_network_address = address(token_network);
Expand Down
9 changes: 6 additions & 3 deletions raiden_contracts/contracts/test/TokenNetworkInternalsTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ contract TokenNetworkInternalStorageTest is TokenNetwork {
_secret_registry,
_chain_id,
_settlement_timeout_min,
_settlement_timeout_max
_settlement_timeout_max,
msg.sender
)
public
{
Expand Down Expand Up @@ -150,7 +151,8 @@ contract TokenNetworkSignatureTest is TokenNetwork {
_secret_registry,
_chain_id,
_settlement_timeout_min,
_settlement_timeout_max
_settlement_timeout_max,
msg.sender
)
public
{
Expand Down Expand Up @@ -253,7 +255,8 @@ contract TokenNetworkUtilsTest is TokenNetwork {
_secret_registry,
_chain_id,
_settlement_timeout_min,
_settlement_timeout_max
_settlement_timeout_max,
msg.sender
)
public
{
Expand Down
9 changes: 8 additions & 1 deletion raiden_contracts/tests/fixtures/token_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,18 @@ def token_network_contract(


@pytest.fixture()
def token_network_external(web3, get_token_network, custom_token, secret_registry_contract):
def token_network_external(
web3,
contract_deployer_address,
get_token_network,
custom_token,
secret_registry_contract,
):
return get_token_network([
custom_token.address,
secret_registry_contract.address,
int(web3.version.network),
TEST_SETTLE_TIMEOUT_MIN,
TEST_SETTLE_TIMEOUT_MAX,
contract_deployer_address,
])
Loading

0 comments on commit 9b24c8e

Please sign in to comment.