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

Contract limits #276

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions raiden_contracts/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ class ChannelState(IntEnum):
REMOVED = 4


# Temporary token deposit limits for the Red Eyes release
MAX_TOKENS_DEPLOY = 100
# Temporary deposit limits for the Red Eyes release in WEI
MAX_ETH_CHANNEL_PARTICIPANT = int(0.075 * 10**18)
MAX_ETH_TOKEN_NETWORK = int(250 * 10**18)


class ChannelInfoIndex(IntEnum):
Expand Down
32 changes: 19 additions & 13 deletions raiden_contracts/contracts/TokenNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,21 @@ contract TokenNetwork is Utils {
115792089237316195423570985008687907853269984665640564039457584007913129639935
);

// Red Eyes release deposit limit
uint256 public deposit_limit;
// Red Eyes release deposit limits
// The combined deposit of one channel is limited to 0.15 ETH.
// So 0.075 ETH per participant.
uint256 constant public channel_participant_deposit_limit = 75000000000000000 wei;
// The total combined deposit of all channels across the whole network is
// limited to 250 ETH.
uint256 constant public token_network_deposit_limit = 250000000000000000000 wei;

// Global, monotonically increasing counter that keeps track of all the
// opened channels in this contract
uint256 public channel_counter;

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

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

Expand Down Expand Up @@ -232,15 +237,6 @@ contract TokenNetwork is Utils {
// Make sure the contract is indeed a token contract
require(token.totalSupply() > 0);

// Try to get token decimals, otherwise assume 18
bool exists = address(token).call(abi.encodeWithSignature("decimals()"));
uint8 decimals = 18;
if (exists) {
decimals = token.decimals();
}

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

deprecation_executor = _deprecation_executor;
}

Expand All @@ -263,6 +259,9 @@ contract TokenNetwork is Utils {
bytes32 pair_hash;
uint256 channel_identifier;

// Red Eyes release token network limit
require(token.balanceOf(address(this)) < token_network_deposit_limit);

// First increment the counter
// There will never be a channel with channel_identifier == 0
channel_counter += 1;
Expand Down Expand Up @@ -317,7 +316,7 @@ contract TokenNetwork is Utils {
{
require(channel_identifier == getChannelIdentifier(participant, partner));
require(total_deposit > 0);
require(total_deposit <= deposit_limit);
require(total_deposit <= channel_participant_deposit_limit);

uint256 added_deposit;
uint256 channel_deposit;
Expand All @@ -328,14 +327,21 @@ contract TokenNetwork is Utils {

// Calculate the actual amount of tokens that will be transferred
added_deposit = total_deposit - participant_state.deposit;

// The actual amount of tokens that will be transferred must be > 0
require(added_deposit > 0);

// Underflow check; we use <= because added_deposit == total_deposit for the first deposit

require(added_deposit <= total_deposit);

// This should never fail at this point. Added check for security, because we directly set
// the participant_state.deposit = total_deposit, while we transfer `added_deposit` tokens.
assert(participant_state.deposit + added_deposit == total_deposit);

// Red Eyes release token network limit
require(token.balanceOf(address(this)) + added_deposit <= token_network_deposit_limit);

// Update the participant's channel deposit
participant_state.deposit = total_deposit;

Expand Down
85 changes: 0 additions & 85 deletions raiden_contracts/contracts/test/CustomTokenNoDecimals.sol

This file was deleted.

65 changes: 0 additions & 65 deletions raiden_contracts/contracts/test/StandardTokenNoDecimals.sol

This file was deleted.

38 changes: 0 additions & 38 deletions raiden_contracts/contracts/test/TokenNoDecimals.sol

This file was deleted.

38 changes: 0 additions & 38 deletions raiden_contracts/tests/fixtures/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,12 @@
(10 ** 26, 18, CONTRACT_CUSTOM_TOKEN, 'TKN')
]

token_args_7_decimals = [
(10 ** 26, 7, CONTRACT_CUSTOM_TOKEN, 'TD6')
]

token_args_no_decimals = [
(10 ** 26, CONTRACT_CUSTOM_TOKEN_NO_DECIMALS, 'TNO')
]


@pytest.fixture(params=token_args)
def custom_token_params(request):
return request.param


@pytest.fixture(params=token_args_7_decimals)
def custom_token_7_decimals_params(request):
return request.param


@pytest.fixture(params=token_args_no_decimals)
def custom_token_no_decimals_params(request):
return request.param


@pytest.fixture()
def custom_token(deploy_tester_contract, custom_token_params):
"""Deploy CustomToken contract"""
Expand All @@ -45,26 +27,6 @@ def custom_token(deploy_tester_contract, custom_token_params):
)


@pytest.fixture()
def custom_token_7_decimals(deploy_tester_contract, custom_token_7_decimals_params):
"""Deploy CustomToken contract"""
return deploy_tester_contract(
CONTRACT_CUSTOM_TOKEN,
[],
custom_token_7_decimals_params
)


@pytest.fixture()
def custom_token_no_decimals(deploy_tester_contract, custom_token_no_decimals_params):
"""Deploy CustomToken contract"""
return deploy_tester_contract(
CONTRACT_CUSTOM_TOKEN_NO_DECIMALS,
[],
custom_token_no_decimals_params
)


@pytest.fixture()
def human_standard_token(deploy_token_contract, custom_token_params):
"""Deploy HumanStandardToken contract"""
Expand Down
34 changes: 1 addition & 33 deletions raiden_contracts/tests/test_channel_deposit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from eth_tester.exceptions import TransactionFailed
from web3.exceptions import ValidationError
from raiden_contracts.constants import ChannelEvent, MAX_TOKENS_DEPLOY
from raiden_contracts.constants import ChannelEvent
from raiden_contracts.utils.events import check_new_deposit
from .fixtures.config import EMPTY_ADDRESS, FAKE_ADDRESS
from raiden_contracts.tests.utils import MAX_UINT256
Expand Down Expand Up @@ -180,38 +180,6 @@ def test_channel_deposit_overflow(token_network, get_accounts, create_channel, c
channel_deposit(channel_identifier, B, deposit_B_ok, A)


def test_channel_deposit_limit(token_network, get_accounts, create_channel, channel_deposit):
(A, B) = get_accounts(2)

contract_deposit_limit = MAX_TOKENS_DEPLOY * (10 ** 18)
assert token_network.functions.deposit_limit().call() == contract_deposit_limit

deposit_B_ok = contract_deposit_limit
deposit_B_fail = deposit_B_ok + 1

channel_identifier = create_channel(A, B)[0]

channel_deposit(channel_identifier, B, deposit_B_ok, A)

with pytest.raises(TransactionFailed):
channel_deposit(channel_identifier, B, deposit_B_fail, A)


def test_channel_deposit_limit_7_decimals_token(
token_network_7_decimals,
):
contract_deposit_limit = token_network_7_decimals.functions.deposit_limit().call()
assert contract_deposit_limit == MAX_TOKENS_DEPLOY * (10 ** 7)


def test_channel_deposit_limit_no_decimals_token(
token_network_no_decimals,
):
# When no decimals function is available assume 18
contract_deposit_limit = token_network_no_decimals.functions.deposit_limit().call()
assert contract_deposit_limit == MAX_TOKENS_DEPLOY * (10 ** 18)


def test_deposit_channel_state(token_network, create_channel, channel_deposit, get_accounts):
(A, B) = get_accounts(2)
deposit_A = 10
Expand Down
Loading