Skip to content

Commit ed49f87

Browse files
committed
Explain inverted revert mechanism
1 parent ee703d7 commit ed49f87

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

contracts/utils/SimulateCall.sol

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@ library SimulateCall {
2323
bytes memory data
2424
) internal returns (bool success, bytes memory retData) {
2525
(success, retData) = getSimulator().delegatecall(abi.encodePacked(target, value, data));
26-
success = !success;
26+
success = !success; // getSimulator() returns the success value inverted
2727
}
2828

29-
/// @dev Returns the simulator address.
29+
/**
30+
* @dev Returns the simulator address.
31+
*
32+
* The simulator REVERTs on success and RETURNs on failure, preserving the return data in both cases.
33+
*
34+
* * A failed target call returns the return data and succeeds in our context (no state changes).
35+
* * A successful target call causes a revert in our context (undoing all state changes) while still
36+
* capturing the return data.
37+
*/
3038
function getSimulator() internal returns (address instance) {
3139
// [Simulator details]
3240
// deployment prefix: 60315f8160095f39f3

0 commit comments

Comments
 (0)