Skip to content

Commit

Permalink
Merge branch 'dev' into feat/periphery-one-txn
Browse files Browse the repository at this point in the history
  • Loading branch information
excaliborr authored Nov 23, 2023
2 parents 8bd5bb3 + 28d0193 commit f1ea82a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
9 changes: 6 additions & 3 deletions solidity/contracts/UpdateStorageMirrorGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {BaseGuard} from 'safe-contracts/base/GuardManager.sol';
import {Enum} from 'safe-contracts/common/Enum.sol';
import {IGuardCallbackModule} from 'interfaces/IGuardCallbackModule.sol';
import {IStorageMirror} from 'interfaces/IStorageMirror.sol';
import {ISafe} from 'interfaces/ISafe.sol';

/**
* @title UpdateStorageMirrorGuard
Expand Down Expand Up @@ -52,9 +53,11 @@ contract UpdateStorageMirrorGuard is BaseGuard {
*/
function checkAfterExecution(bytes32 _txHash, bool _success) external {
if (_success) {
address[] memory _owners = new address[](1);
_owners[0] = msg.sender;
IStorageMirror.SafeSettings memory _safeSettings = IStorageMirror.SafeSettings({owners: _owners, threshold: 1});
address[] memory _owners = ISafe(msg.sender).getOwners();
uint256 _threshold = ISafe(msg.sender).getThreshold();

IStorageMirror.SafeSettings memory _safeSettings =
IStorageMirror.SafeSettings({owners: _owners, threshold: _threshold});
bytes32 _settingsHash = keccak256(abi.encode(_safeSettings));

// NOTE: No need to reset settings as this function will only be called when the settings change
Expand Down
18 changes: 14 additions & 4 deletions solidity/contracts/VerifierModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ contract VerifierModule is IVerifierModule {
bytes memory _storageMirrorStorageProof,
SafeTxnParams calldata _arbitraryTxnParams
) internal {
uint256 _startingGas = gasleft();
bytes32 _hashedProposedSettings = _verifyNewSettings(_safe, _proposedSettings, _storageMirrorStorageProof);

// If we dont revert from the _verifyNewSettings() call, then we can update the safe
Expand All @@ -156,15 +157,24 @@ contract VerifierModule is IVerifierModule {
_arbitraryTxnParams.signatures
);

// Pay incentives
// TODO: Calculations for incentives so its not hardcoded to 1e18
ISafe(_safe).execTransactionFromModule(msg.sender, 1e18, '', Enum.Operation.Call);

// Make the storage updates at the end of the call to save gas in a revert scenario
latestVerifiedSettings[_safe] = _hashedProposedSettings;
latestVerifiedSettingsTimestamp[_safe] = block.timestamp;

emit VerifiedUpdate(_safe, _hashedProposedSettings);

// NOTE: This is not the exact gas spent as we still have to make the transaction after the calculation
// NOTE: We do all this at the end of the call to get the most accurate gas calculations

uint256 _gasLeft = gasleft();

uint256 _gasSpent = _startingGas - _gasLeft;

// Gas spent plus 10% incentive
uint256 _incentive = _gasSpent + _gasSpent * 10 / 100;

// Pay incentives
ISafe(_safe).execTransactionFromModule(msg.sender, _incentive, '', Enum.Operation.Call);
}

/**
Expand Down
10 changes: 10 additions & 0 deletions solidity/test/unit/UpdateStorageMirrorGuard.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Test} from 'forge-std/Test.sol';
import {UpdateStorageMirrorGuard} from 'contracts/UpdateStorageMirrorGuard.sol';
import {IGuardCallbackModule} from 'interfaces/IGuardCallbackModule.sol';
import {IStorageMirror} from 'interfaces/IStorageMirror.sol';
import {ISafe} from 'interfaces/ISafe.sol';

abstract contract Base is Test {
event SettingsChanged(address indexed _safe, bytes32 indexed _settingsHash, IStorageMirror.SafeSettings _settings);
Expand All @@ -30,6 +31,15 @@ abstract contract Base is Test {

contract UnitUpdateStorageMirrorGuard is Base {
function testCheckAfterExecution(bytes32 _txHash) public {
address[] memory _owners = new address[](1);
_owners[0] = safe;

uint256 _threshold = 1;

vm.mockCall(address(safe), abi.encodeCall(ISafe.getOwners, ()), abi.encode(_owners));

vm.mockCall(address(safe), abi.encodeCall(ISafe.getThreshold, ()), abi.encode(_threshold));

vm.mockCall(
address(guardCallbackModule),
abi.encodeCall(IGuardCallbackModule.saveUpdatedSettings, (safe, settingsHash)),
Expand Down

0 comments on commit f1ea82a

Please sign in to comment.