Skip to content

chore(Docs): Replaced instances if - throw to require() where applicable.#2134

Closed
InfamousVague wants to merge 21 commits intoargotorg:developfrom
InfamousVague:develop
Closed

chore(Docs): Replaced instances if - throw to require() where applicable.#2134
InfamousVague wants to merge 21 commits intoargotorg:developfrom
InfamousVague:develop

Conversation

@InfamousVague
Copy link
Contributor

@InfamousVague
Copy link
Contributor Author

Looks like the test is failing because of a broken function trying to convert a line ending, is this my fault?

if (!richest.send(msg.value)) {
throw;
}
require(richest.send(msg.value));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be assert() here.

Perhaps we could also have a comment to say that the use of richest.transfer(msg.value) is preferred instead.

// "instance" will be the current contract.
if (!Set.insert(knownValues, value))
throw;
require(Set.insert(knownValues, value));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be assert.

shares[msg.sender] = 0;
if (!msg.sender.send(share))
throw;
require(msg.sender.send(share));
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 the withdraw pattern, in here probably we should prefer transfer() instead.

if (tx.origin != owner) { throw; }
if (!dest.call.value(amount)()) throw;
require(tx.origin == owner);
require(dest.call.value(amount)());
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be replaced with .transfer().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@axic 125 - 130 will need to be updated to reflect this change, I am not confident that I understand deeply enough to replace this paragraph; would you mind taking a look and if we still want to switch to transfer() let me know what you'd like me to replace that paragraph with.

Copy link
Contributor

Choose a reason for hiding this comment

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

Will make the change.

@axic
Copy link
Contributor

axic commented Apr 19, 2017

I guess no point to repeat the same. Where the code explains why .send() or .call() is problematic, those should be used, but I think in any other case we should stick to .transfer().

Note, that by moving to .transfer() (and require() / assert(), the pragma solidity must be updated to reflect the version those features were added in.

@axic axic closed this Apr 19, 2017
@axic axic removed the needs review label Apr 19, 2017
@axic axic reopened this Apr 19, 2017
docs/types.rst Outdated
c.amount = 0;
if (!c.beneficiary.send(amount))
throw;
require(c.beneficiary.transfer(amount));
Copy link
Contributor

Choose a reason for hiding this comment

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

transfer() will abort if it failed, no need for require() here

@@ -86,9 +86,7 @@ This is as opposed to the more intuitive sending pattern:
// Check if call succeeds to prevent an attacker
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is not relevant anymore. If you are not confident with making the relevant changes, then please just keep send and we will go over it in another iteration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay I'll leave that in for now.


modifier onlyAfter(uint _time) {
if (now < _time) throw;
require(now > _time);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be >= to have identical semantics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing now but wouldn't that signify it allows something to happen also at a given time and not just after a given time.

modifier costs(uint _amount) {
if (msg.value < _amount)
throw;
require(msg.value > _amount);
Copy link
Contributor

Choose a reason for hiding this comment

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

Also >= here.

// "instance" will be the current contract.
if (!Set.insert(knownValues, value))
throw;
assert(Set.insert(knownValues, value));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think even here, we should use require because it is not an internal error if this fails - it is still invalid usage of contract C.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wasn't the definition that require() is for input validation, while assert() is for everything else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know which is preferred and I'll update @chriseth @axic

Copy link
Contributor

Choose a reason for hiding this comment

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

The definition was that it is impossible to get a contract to trigger an assert unless it has a bug.

@chriseth
Copy link
Contributor

chriseth commented May 2, 2017

Replaced this by #2207

@chriseth chriseth closed this May 2, 2017
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.

4 participants