Skip to content

Commit

Permalink
refactor to compile without viaIR
Browse files Browse the repository at this point in the history
  • Loading branch information
spengrah committed Dec 2, 2024
1 parent f898dae commit 8f24b85
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 154 deletions.
20 changes: 9 additions & 11 deletions src/HatsSignerGate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,6 @@ contract HatsSignerGate is
// ensure that the call is coming from the safe
if (msg.sender != address(safe)) revert NotCalledFromSafe();

ISafe s = safe; // save SLOADs

// Disallow entering this function from a) inside a Safe.execTransaction call or b) inside an
// execTransactionFromModule call
if (_inSafeExecTransaction || _inModuleExecTransaction) revert NoReentryAllowed();
Expand All @@ -429,11 +427,11 @@ contract HatsSignerGate is
/// that the Safe nonce increments exactly once per Safe.execTransaction call, we require that nonce diff matches
/// the number of times this function has been called.
// Record the initial nonce of the Safe at the beginning of the transaction
if (_checkTransactionCounter == 0) _initialNonce = s.nonce() - 1;
if (_checkTransactionCounter == 0) _initialNonce = safe.nonce() - 1;
// Increment the entrancy counter
_checkTransactionCounter++;
// Ensure that this function is called exactly once per Safe.execTransaction call
if (s.nonce() - _initialNonce != _checkTransactionCounter) revert NoReentryAllowed();
if (safe.nonce() - _initialNonce != _checkTransactionCounter) revert NoReentryAllowed();

// module guard preflight check
if (guard != address(0)) {
Expand All @@ -449,13 +447,13 @@ contract HatsSignerGate is
address(0),
payable(0),
"",
address(s)
address(safe)
);
}

// get the existing owners and threshold
address[] memory owners = s.getOwners();
uint256 threshold = s.getThreshold();
address[] memory owners = safe.getOwners();
uint256 threshold = safe.getThreshold();

// We record the operation type to guide the post-flight checks
_operation = operation;
Expand All @@ -469,8 +467,8 @@ contract HatsSignerGate is
// been altered
_existingOwnersHash = keccak256(abi.encode(owners));
_existingThreshold = threshold;
_existingFallbackHandler = s.getSafeFallbackHandler();
} else if (to == address(s)) {
_existingFallbackHandler = safe.getSafeFallbackHandler();
} else if (to == address(safe)) {
// case: CALL to the safe
// We disallow external calls to the safe itself. Together with the above check, this ensures there are no
// unauthorized calls into the Safe itself
Expand All @@ -486,7 +484,7 @@ contract HatsSignerGate is
if (threshold != _getRequiredValidSignatures(owners.length)) revert ThresholdTooLow();

// get the tx hash
bytes32 txHash = s.getTransactionHash(
bytes32 txHash = safe.getTransactionHash(
to,
value,
data,
Expand All @@ -497,7 +495,7 @@ contract HatsSignerGate is
gasToken,
refundReceiver,
// We subtract 1 since nonce was just incremented in the parent function call
s.nonce() - 1
safe.nonce() - 1
);

// count the number of valid signatures and revert if there aren't enough
Expand Down
Loading

0 comments on commit 8f24b85

Please sign in to comment.