-
Notifications
You must be signed in to change notification settings - Fork 44
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
switching on SafeMath for uint256 in MultiPartyEscrow.sol #49
switching on SafeMath for uint256 in MultiPartyEscrow.sol #49
Conversation
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's not enough. The main point of SafeMath is using helper functions instead of native Solidity arithmetic.
eg. https://github.com/singnet/token-contracts/blob/master/contracts/AgiCrowdsale.sol#L101
It makes sense.
|
So I think we should check only "+= value" in deposit function, because we don't check it by ourselves . All other checks seems to be direct doublechecks (because we check it in require in the same function).... Of course, we can still double-check everything... |
Though we have the require conditions in place I will suggest to use the SafeMath helper functions for any math operations. This will make us aligned with the coding standards for contracts. |
…into add-SafeMath-in-MultiPartyEscrow
I've added SafaMath for all operations in MultiPartyEscrow, even though I think it is not completely right to force innocent people to pay for our paranoia :) . But difference in gas is not so catastrophic: And this modification should not be consider as an excuse to not write more tests: #46 |
|
||
balances[channel.sender] = balances[channel.sender].add(channel.value); | ||
channel.value = 0; | ||
channel.nonce += 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.
Here's different. Use the add method also here to make it consistent
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.
No, It doesn't make sense here.
- "1" doesn't come from outside word, we shoudn't check it.
- overflow wouldn't be an issue here (even if we could overflow with +1, uint256), because logic of the channel will work, we only need nonce to be different, even bool would work here with some constrains in sender/recipient logic.
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 want to say it again, but I'm feeling rather strange arguing that we shouldn't make extra checks, because I usually teach people to always make extra checks. But let's not forget that here we pay real money for each operation. And adding extra cost only to be "consistent" is really really strange.
I want to underline again, MPE is very small contract, which will be used the most in SingularityNet, so our consumers will pay most of their gas here.
We need to be consistent only in the situation where we might forget to make checks in important places. But here it is not the case.
We are already using SafeMath in places where they are direct double checks (in all places except deposit, where using SafeMath might be justified if we assume that token contract could be compromised), so we already spend extra gas for nothing. I really don't see the reason why you want to push it to an extreme.
switch on SafeMath for uint256 in MultiPartyEscrow.sol