Skip to content

Commit 82b6146

Browse files
committed
Explain mechanism a bit
1 parent e11d9c3 commit 82b6146

1 file changed

Lines changed: 41 additions & 10 deletions

File tree

docs/SecurityMechanisms/reentrancy.md

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,51 @@ contract Uniswap {
3232
3333
function sellXForY(uint xSold)
3434
returns uint {
35-
uint prod = tX.getBal(this) *
36-
tY.getBal(this);
37-
uint yKept = prod /
38-
(tX.getBal(this) + xSold);
35+
uint prod = tX.getBal(this) * tY.getBal(this);
36+
uint yKept = prod / (tX.getBal(this) + xSold);
3937
uint yBought = tY.getBal(this) - yKept;
4038
41-
assert tX.transferFrom(msg.sender,
42-
this, xSold);(*\label{lst:li:uniswap-sol-trans-allowed}*)
43-
assert tY.transfer(this, msg.sender,
44-
yBought);(*\label{lst:li:uniswap-sol-trans-disallowed}*)
39+
assert tX.transferFrom(msg.sender, this, xSold);
40+
assert tY.transfer(this, msg.sender, yBought);
4541
return yBought;
4642
}
4743
}
4844
```
4945

50-
* More formally define reentrancy and reentrancy security.
51-
* How SCIF enforses enentrancy security.
46+
Reentrancy vulnerabilities arise because in general, smart-contract state
47+
must obey some invariants for the contract to be
48+
correct, but those invariants may be temporarily broken while a method executes.
49+
If an attacker gains control of execution while the contract
50+
is in this inconsistent state (such as through a callback),
51+
they can engineer a reentrant call into a public method.
52+
Though the call comes from attacker integrity, the public method endorses and accepts the call.
53+
Because contract invariants are temporarily broken, the contract might behave improperly.
54+
55+
56+
## Defining reentrancy and reentrancy security
57+
58+
## How SCIF enforses reentrancy security.
59+
60+
SCIF uses an mechanism based on information flow
61+
to prevent reentrancy attacks,
62+
combining static and dynamic _reentrancy locks_
63+
to prevent reentrant endorsement, so that reentrant
64+
calls do not enable new attacks.
65+
66+
SeRIF requires any untrusted call made without dynamic locks to be in tail position,
67+
forbidding any subsequent operations.
68+
This approach prevents dangerous reentrancy, but it also enforces two limiting constraints:
69+
* Trusted values computed before an untrusted call cannot be returned afterward.
70+
* In auto-endorse functions, untrusted operations cannot execute after an untrusted call returns,
71+
even though they inherently cannot create reentrancy concerns.
72+
73+
SCIF maintains the security of SeRIF's reentrancy protection,
74+
while improving precision to allow useful code patterns.
75+
First, methods define their return values by assigning to a special `result` variable.
76+
A method must assign to this variable on every return path.
77+
The usual syntax `return` _e_ is just syntactic
78+
sugar for assigning `result =` _e_ and then returning.
79+
Second, after an untrusted call, the control-flow integrity (the `pc` label)
80+
is modified, restricting future operations to only those that cannot
81+
violate high-integrity invariants.
82+
Neither of these changes can introduce reentrancy concerns, and both simplify programs.

0 commit comments

Comments
 (0)