Skip to content

Commit 5f00c84

Browse files
authored
Safer readme example (#961)
Ensuring that `unlockCallback` is only called by the `poolManager` is almost always a critically important security feature, so imo it should be included even in the most basic of examples
1 parent df421dd commit 5f00c84

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,14 @@ contract MyContract is IUnlockCallback {
8989
}
9090
9191
function unlockCallback(bytes calldata data) external returns (bytes memory) {
92+
// disallow arbitrary caller
93+
if (msg.sender != address(poolManager) revert Unauthorized();
9294
// perform pool actions
9395
poolManager.swap(...)
9496
}
9597
}
9698
99+
error Unauthorized();
97100
```
98101

99102
## License

0 commit comments

Comments
 (0)