Skip to content

Commit 4565841

Browse files
authored
Merge pull request #1653 from CosmWasm/elaborate-on-depth-first
Improve section on depth-first execution order
2 parents ebdd97e + 15f996d commit 4565841

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

SEMANTICS.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,25 @@ will be ignored, and any messages they return will also be processed. If they
172172
return an error, the parent call will return an error, thus rolling back state
173173
of the whole transaction.
174174

175-
Note that the messages are executed _depth-first_. This means if contract A
176-
returns M1 (`WasmMsg::Execute`) and M2 (`BankMsg::Send`), and contract B (from
177-
the `WasmMsg::Execute`) returns N1 and N2 (eg. `StakingMsg` and
175+
Note that the messages are executed
176+
[_depth-first_](https://en.wikipedia.org/wiki/Depth-first_search). This means if
177+
contract A returns M1 (`WasmMsg::Execute`) and M2 (`BankMsg::Send`), and
178+
contract B (from the `WasmMsg::Execute`) returns N1 and N2 (eg. `StakingMsg` and
178179
`DistributionMsg`), the order of execution would be **M1, N1, N2, M2**.
179180

181+
```mermaid
182+
graph TD;
183+
A[contract A]
184+
M1[M1 / contract B]
185+
M2[M2 / bank send]
186+
N1[N1 / staking]
187+
N2[N2 / distribution]
188+
A --> M1;
189+
A --> M2;
190+
M1 --> N1;
191+
M1 --> N2;
192+
```
193+
180194
This may be hard to understand at first. "Why can't I just call another
181195
contract?", you may ask. However, we do this to prevent one of most widespread
182196
and hardest to detect security holes in Ethereum contracts - reentrancy. We do

0 commit comments

Comments
 (0)