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

Idempotency of MS deposits - closes #76 #80

Merged
merged 1 commit into from
May 25, 2018

Conversation

err508
Copy link
Contributor

@err508 err508 commented May 18, 2018

No description provided.

@err508 err508 requested a review from czepluch May 18, 2018 14:04
uint256 added_deposit;

// Calculate the actual amount of tokens that will be transferred
added_deposit = total_deposit - balances[beneficiary];
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not good. uint256 can only be positive integers, and if the new total_deposit is lower than the current balance you have a problem. You must add a check that doesn't allow for this to happen. Ideally you also add a small test to show that it works correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

.gitignore Outdated
@@ -12,6 +12,9 @@ venv/
# ignore private keys
*.pem

# virtualenv
.venv
Copy link
Contributor

Choose a reason for hiding this comment

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

We already have env/ for this purpose.

require(amount > 0);
/// @param beneficiary The account benefiting from the deposit
/// @param total_deposit Idempotent function that sets the total_deposit of
//// tokens of the beneficiary
Copy link
Contributor

Choose a reason for hiding this comment

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

//// -> ///

//// tokens of the beneficiary
function deposit(address beneficiary, uint256 total_deposit) public
{
require(total_deposit != 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using total_deposit > 0 . One might say it's redundant, because we are talking about a uint, but more complete and we keep consistency with the rest of the contracts code.

Copy link
Contributor Author

@err508 err508 May 22, 2018

Choose a reason for hiding this comment

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

I changed it, as I found that the > 0 looks like a wrong int-underflow safeguard, as it actually does not check what it states, i.e. the require will not throw when .deposit(Uint(-1)) is called. Does that make sense?

Copy link
Contributor

@loredanacirstea loredanacirstea May 22, 2018

Choose a reason for hiding this comment

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

When .deposit(-1) is called, there should be a type error thrown before it even gets to the require. Just because we are using uint as the input type. The check's scope is actually >0 and not only !=0.

Copy link
Contributor

@loredanacirstea loredanacirstea May 22, 2018

Choose a reason for hiding this comment

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

Ah, ok. I understand what you mean. But I see it as: the scope is to make sure total_deposit > 0. Because Solidity is still a young language that can still behave in unwanted ways, I would not completely trust it especially if it doesn't really cost us much. Plus, this > 0 pattern was agreed upon in a previous smart contracts review session for uRaiden. I would rather keep it like this for now. You can open an issue to discuss adv/disadv if you want.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it back to the way it was. I was referring to UINT(-1) above, but doesn't make a difference I think.

function deposit(address beneficiary, uint amount) public {
require(amount > 0);
/// @param beneficiary The account benefiting from the deposit
/// @param total_deposit Idempotent function that sets the total_deposit of
Copy link
Contributor

Choose a reason for hiding this comment

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

This should explain what the parameter is, not what the function does. The @notice is meant for explaining what the function does.


emit NewDeposit(beneficiary, amount);
require(balances[beneficiary] >= added_deposit);
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't we cover both require(total_deposit != 0); and require(balances[beneficiary] >= added_deposit); by doing total_deposit > balances[beneficary] instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

I used the pattern that was also used here in TokenNetwork.setDeposit because I was also trying to keep the checks grouped, as agreed. In this case, require(total_deposit > balances[beneficary]) can work.

Copy link
Contributor

@czepluch czepluch May 22, 2018

Choose a reason for hiding this comment

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

require(total_deposit > balances[beneficary]) Doesn't conflict with keeping the checks grouped, since there's only one check, but I get what you mean. I am fine with either. Just thought that Tobias might find it interesting to think about both options.

Copy link
Contributor Author

@err508 err508 May 22, 2018

Choose a reason for hiding this comment

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

I think require(total_deposit > balances[beneficiary]) solves under/overflow the shortest way, not sure though which conventions Loredana refers too.

Copy link
Contributor

Choose a reason for hiding this comment

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

@err508 #47. In TokenNetwork.setDeposit it wasn't so straight forward to get the participant deposit and do the check at the beginning of the function, so I opted for a check at the end. As said, for this case here, require(total_deposit > balances[beneficiary]) does the job.

Copy link
Contributor

Choose a reason for hiding this comment

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

As Loredana says, require(total_deposit > balances[beneficiary]) does the trick and we get the same checks guarantees from one line rather than two. So please use that instead.

Copy link
Contributor

@loredanacirstea loredanacirstea left a comment

Choose a reason for hiding this comment

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

From my side, it looks good.


emit NewDeposit(beneficiary, amount);
require(balances[beneficiary] >= added_deposit);
Copy link
Contributor

Choose a reason for hiding this comment

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

As Loredana says, require(total_deposit > balances[beneficiary]) does the trick and we get the same checks guarantees from one line rather than two. So please use that instead.

@err508 err508 force-pushed the issue_#76 branch 3 times, most recently from b8f3225 to 0422674 Compare May 25, 2018 14:26
@err508 err508 dismissed czepluch’s stale review May 25, 2018 15:38

Changes are adressed!

@err508 err508 merged commit 6682275 into raiden-network:master May 25, 2018
@err508 err508 deleted the issue_#76 branch May 25, 2018 15:38
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.

3 participants