Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(hub): re-entrancy guard finally with tstore by setting cancun hardfork #151

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ src = "src"
out = "out"
libs = ["lib"]

evm_version = 'cancun'

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
31 changes: 6 additions & 25 deletions src/hub/Hub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,6 @@ contract Hub is Circles, MetadataDefinitions, IHubErrors {
*/
mapping(address => mapping(address => TrustMarker)) public trustMarkers;

/**
* @dev Normal storage slot for the reentrancy guard.
* todo: the original task was to use a transient storage slot,
* but solc v0.8.24 still didn't recognize the tload/tstore assembly.
* see
*/
bool private _reentrancyGuard;

// Events

event RegisterHuman(address indexed avatar);
Expand Down Expand Up @@ -191,25 +183,14 @@ contract Hub is Circles, MetadataDefinitions, IHubErrors {
* see https://soliditylang.org/blog/2024/01/26/transient-storage/
*/
modifier nonReentrant(uint8 _code) {
// todo: this should use a transient storage slot
// but doesn't compile through `forge build`, but does compile with solc directly
// assembly {
// if tload(0) { revert(0, 0) }
// tstore(0, 1)
// }
// _;
// assembly {
// tstore(0, 0)
// }

// for now, default to normal storage slot
// replace this later with transient storage slot
if (_reentrancyGuard) {
revert CirclesReentrancyGuard(_code);
assembly {
if tload(0) { revert(0, 0) }
tstore(0, 1)
}
_reentrancyGuard = true;
_;
_reentrancyGuard = false;
assembly {
tstore(0, 0)
}
}

// Constructor
Expand Down
Loading