Skip to content

Commit

Permalink
Merge pull request #151 from CirclesUBI/20240510-reentrancy-guard
Browse files Browse the repository at this point in the history
(hub): re-entrancy guard finally with tstore by setting cancun hardfork
  • Loading branch information
benjaminbollen authored May 10, 2024
2 parents dea17c1 + 28ffc8e commit 6819670
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
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

0 comments on commit 6819670

Please sign in to comment.