mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Update contracts and descriptions
This commit is contained in:
parent
4737100d00
commit
058e5f0159
@ -40,9 +40,9 @@ become the richest.
|
|||||||
|
|
||||||
function becomeRichest() returns (bool) {
|
function becomeRichest() returns (bool) {
|
||||||
if (msg.value > mostSent) {
|
if (msg.value > mostSent) {
|
||||||
|
pending[richest] = msg.value;
|
||||||
richest = msg.sender;
|
richest = msg.sender;
|
||||||
mostSent = msg.value;
|
mostSent = msg.value;
|
||||||
pending[richest] = msg.value;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -76,9 +76,14 @@ This is as opposed to the more intuitive sending pattern.
|
|||||||
|
|
||||||
function becomeRichest() returns (bool) {
|
function becomeRichest() returns (bool) {
|
||||||
if (msg.value > mostSent) {
|
if (msg.value > mostSent) {
|
||||||
|
// Check if call succeeds to prevent an attacker
|
||||||
|
// from trapping the previous person's funds in
|
||||||
|
// this contract through a callstack attack
|
||||||
|
if (!richest.send(msg.value)) {
|
||||||
|
throw;
|
||||||
|
}
|
||||||
richest = msg.sender;
|
richest = msg.sender;
|
||||||
mostSent = msg.value;
|
mostSent = msg.value;
|
||||||
richest.send(msg.value);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -88,8 +93,12 @@ This is as opposed to the more intuitive sending pattern.
|
|||||||
}
|
}
|
||||||
|
|
||||||
Notice that, in this example, an attacker could trap the
|
Notice that, in this example, an attacker could trap the
|
||||||
previous richest person's funds in the contract by causing
|
contract into an unusable state by causing the ``richest``
|
||||||
the execution of `send` to fail through a callstack attack.
|
to be a contract that has a fallback function which consumes
|
||||||
|
more than the 2300 gas stipend. That way, whenever ``send``
|
||||||
|
is called to deliver funds to the "poisoned" contract, it
|
||||||
|
will cause execution to always fail because there is not
|
||||||
|
enough gas to finish the execution of the fallback function.
|
||||||
|
|
||||||
.. index:: access;restricting
|
.. index:: access;restricting
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user