Skip to content

Commit 7a395ed

Browse files
authored
Merge pull request #130 from OpenZeppelin/fix/erc4626-math-rendering
Fix ERC4626 math rendering in 4.x & 5.x
2 parents 742e54b + 332db77 commit 7a395ed

3 files changed

Lines changed: 26 additions & 24 deletions

File tree

content/contracts/4.x/erc4626.mdx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,26 @@ In math that gives:
5757
* $a_1$ the attacker donation
5858
* $u$ the user deposit
5959

60-
| |
60+
| | Assets | Shares | Rate |
6161
| --- | --- | --- | --- |
62-
| Assets | Shares | Rate | initial |
63-
| $0$ | $0$ | - | after attacker’s deposit |
64-
| $a_0$ | $a_0$ | $1$ | after attacker’s donation |
62+
| initial | $0$ | $0$ | - |
63+
| after attacker’s deposit | $a_0$ | $a_0$ | $1$ |
64+
| after attacker’s donation | $a_0 + a_1$ | $a_0$ | $\frac{a_0 +a_1}{a_0}$ |
6565

66-
This means a deposit of $u$ will give $\fracu \times a_0a_0 + a_1$ shares.
66+
This means a deposit of $u$ will give $\frac{u \times a_0}{a_0 + a_1}$ shares.
6767

6868
For the attacker to dilute that deposit to 0 shares, causing the user to lose all its deposit, it must ensure that
6969

7070
```math
71-
\fracu \times a_0a_0+a_1 < 1 \iff u < 1 + \fraca_1a_0
71+
\frac{u \times a_0}{a_0+a_1} < 1 \iff u < 1 + \frac{a_1}{a_0}
7272
```
7373

7474
Using $a_0 = 1$ and $a_1 = u$ is enough. So the attacker only needs $u+1$ assets to perform a successful attack.
7575

76-
It is easy to generalize the above results to scenarios where the attacker is going after a smaller fraction of the user’s deposit. In order to target $\fracun$, the user needs to suffer rounding of a similar fraction, which means the user must receive at most $n$ shares. This results in:
76+
It is easy to generalize the above results to scenarios where the attacker is going after a smaller fraction of the user’s deposit. In order to target $\frac{u}{n}$, the user needs to suffer rounding of a similar fraction, which means the user must receive at most $n$ shares. This results in:
7777

7878
```math
79-
\fracu \times a_0a_0+a_1 < n \iff \fracun < 1 + \fraca_1a_0
79+
\frac{u \times a_0}{a_0+a_1} < n \iff \frac{u}{n} < 1 + \frac{a_1}{a_0}
8080
```
8181

8282
In this scenario, the attack is $n$ times less powerful (in how much it is stealing) and costs $n$ times less to execute. In both cases, the amount of funds the attacker needs to commit is equivalent to its potential earnings.
@@ -97,40 +97,40 @@ Following the previous math definitions, we have:
9797
* $a_1$ the attacker donation
9898
* $u$ the user deposit
9999

100-
| |
100+
| | Assets | Shares | Rate |
101101
| --- | --- | --- | --- |
102-
| Assets | Shares | Rate | initial |
103-
| $1$ | $10^\delta$ | $10^\delta$ | after attacker’s deposit |
104-
| $1+a_0$ | $10^\delta \times (1+a_0)$ | $10^\delta$ | after attacker’s donation |
102+
| initial | $1$ | $10^\delta$ | $10^\delta$ |
103+
| after attacker’s deposit | $1+a_0$ | $10^\delta \times (1+a_0)$ | $10^\delta$
104+
| after attacker’s donation | $1+a_0+a_1$ | $10^\delta \times (1+a_0)$ | $10^\delta \times \frac{1+a_0}{1+a_0+a_1}$ |
105105

106-
One important thing to note is that the attacker only owns a fraction $\fraca_01 + a_0$ of the shares, so when doing the donation, he will only be able to recover that fraction $\fraca_1 \times a_01 + a_0$ of the donation. The remaining $\fraca_11+a_0$ are captured by the vault.
106+
One important thing to note is that the attacker only owns a fraction $\frac{a_0}{1 + a_0}$ of the shares, so when doing the donation, he will only be able to recover that fraction $\frac{a_1 \times a_0}{1 + a_0}$ of the donation. The remaining $\frac{a_1}{1+a_0}$ are captured by the vault.
107107

108108
```math
109-
\mathitloss = \fraca_11+a_0
109+
\mathit{loss} = \frac{a_1}{1+a_0}
110110
```
111111

112112
When the user deposits $u$, he receives
113113

114114
```math
115-
10^\delta \times u \times \frac1+a_01+a_0+a_1
115+
10^\delta \times u \times \frac{1+a_0}{1+a_0+a_1}
116116
```
117117

118118
For the attacker to dilute that deposit to 0 shares, causing the user to lose all its deposit, it must ensure that
119119

120120
```math
121-
10^\delta \times u \times \frac1+a_01+a_0+a_1 < 1
121+
10^\delta \times u \times \frac{1+a_0}{1+a_0+a_1} < 1
122122
```
123123

124124
```math
125-
\iff 10^\delta \times u < \frac1+a_0+a_11+a_0
125+
\iff 10^\delta \times u < \frac{1+a_0+a_1}{1+a_0}
126126
```
127127

128128
```math
129-
\iff 10^\delta \times u < 1 + \fraca_11+a_0
129+
\iff 10^\delta \times u < 1 + \frac{a_1}{1+a_0}
130130
```
131131

132132
```math
133-
\iff 10^\delta \times u \le \mathitloss
133+
\iff 10^\delta \times u \le \mathit{loss}
134134
```
135135

136136
* If the offset is 0, the attacker loss is at least equal to the user’s deposit.

content/contracts/5.x/erc4626.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ In math that gives:
6161
| --- | --- | --- | --- |
6262
| initial | $0$ | $0$ | - |
6363
| after attacker's deposit | $a_0$ | $a_0$ | $1$ |
64-
| after attacker's donation | $a_0 + a_1$ | $a_0$ | $\fraca_0 + a_1a_0$ |
64+
| after attacker's donation | $a_0 + a_1$ | $a_0$ | $\frac{a_0 + a_1}{a_0}$ |
6565

66-
This means a deposit of $u$ will give $\fracu \times a_0a_0 + a_1$ shares.
66+
This means a deposit of $u$ will give $\frac{u \times a_0}{a_0 + a_1}$ shares.
6767

6868
For the attacker to dilute that deposit to 0 shares, causing the user to lose all its deposit, it must ensure that
6969

@@ -73,7 +73,7 @@ For the attacker to dilute that deposit to 0 shares, causing the user to lose al
7373

7474
Using $a_0 = 1$ and $a_1 = u$ is enough. So the attacker only needs $u+1$ assets to perform a successful attack.
7575

76-
It is easy to generalize the above results to scenarios where the attacker is going after a smaller fraction of the user’s deposit. In order to target $\fracun$, the user needs to suffer rounding of a similar fraction, which means the user must receive at most $n$ shares. This results in:
76+
It is easy to generalize the above results to scenarios where the attacker is going after a smaller fraction of the user’s deposit. In order to target $\frac{u}{n}$, the user needs to suffer rounding of a similar fraction, which means the user must receive at most $n$ shares. This results in:
7777

7878
```math
7979
\frac{u \times a_0}{a_0+a_1} < n \iff \frac{u}{n} < 1 + \frac{a_1}{a_0}
@@ -101,9 +101,9 @@ Following the previous math definitions, we have:
101101
| --- | --- | --- | --- |
102102
| initial | $1$ | $10^\delta$ | $10^\delta$ |
103103
| after attacker's deposit | $1+a_0$ | $10^\delta \times (1+a_0)$ | $10^\delta$ |
104-
| after attacker's donation | $1+a_0+a_1$ | $10^\delta \times (1+a_0)$ | $10^\delta$ |
104+
| after attacker's donation | $1+a_0+a_1$ | $10^\delta \times (1+a_0)$ | $10^\delta \times \frac{1+a_0}{1+a_0+a_1}$ |
105105

106-
One important thing to note is that the attacker only owns a fraction $\fraca_01 + a_0$ of the shares, so when doing the donation, he will only be able to recover that fraction $\fraca_1 \times a_01 + a_0$ of the donation. The remaining $\fraca_11+a_0$ are captured by the vault.
106+
One important thing to note is that the attacker only owns a fraction $\frac{a_0}{1 + a_0}$ of the shares, so when doing the donation, he will only be able to recover that fraction $\frac{a_1 \times a_0}{1 + a_0}$ of the donation. The remaining $\frac{a_1}{1+a_0}$ are captured by the vault.
107107

108108
```math
109109
\mathit{loss} = \frac{a_1}{1+a_0}

scripts/link-validation.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
scanURLs,
55
validateFiles,
66
} from "next-validate-link";
7+
import remarkMath from "remark-math";
78
import type { InferPageType } from "fumadocs-core/source";
89
import { source } from "@/lib/source";
910
import { writeFileSync } from "fs";
@@ -60,6 +61,7 @@ async function checkLinks() {
6061
components: {
6162
Card: { attributes: ["href"] },
6263
},
64+
remarkPlugins: [remarkMath],
6365
},
6466
ignoreFragment: ignoreFragments,
6567
// check relative paths

0 commit comments

Comments
 (0)