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

Fix guardable #109

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
56 changes: 36 additions & 20 deletions contracts/core/Module.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ abstract contract Module is FactoryFriendly, Guardable {
bytes memory data,
Enum.Operation operation
) internal returns (bool success) {
/// Check if a transactioon guard is enabled.
if (guard != address(0)) {
IGuard(guard).checkTransaction(
address currentGuard = guard;
if (currentGuard != address(0)) {
IGuard(currentGuard).checkTransaction(
/// Transaction info used by module transactions.
to,
value,
Expand All @@ -63,15 +63,20 @@ abstract contract Module is FactoryFriendly, Guardable {
bytes("0x"),
msg.sender
);
}
success = IAvatar(target).execTransactionFromModule(
to,
value,
data,
operation
);
if (guard != address(0)) {
IGuard(guard).checkAfterExecution(bytes32("0x"), success);
success = IAvatar(target).execTransactionFromModule(
to,
value,
data,
operation
);
IGuard(currentGuard).checkAfterExecution(bytes32("0x"), success);
} else {
success = IAvatar(target).execTransactionFromModule(
to,
value,
data,
operation
);
}
return success;
}
Expand All @@ -88,9 +93,9 @@ abstract contract Module is FactoryFriendly, Guardable {
bytes memory data,
Enum.Operation operation
) internal returns (bool success, bytes memory returnData) {
/// Check if a transactioon guard is enabled.
if (guard != address(0)) {
IGuard(guard).checkTransaction(
address currentGuard = guard;
if (currentGuard != address(0)) {
IGuard(currentGuard).checkTransaction(
/// Transaction info used by module transactions.
to,
value,
Expand All @@ -105,11 +110,22 @@ abstract contract Module is FactoryFriendly, Guardable {
bytes("0x"),
msg.sender
);
}
(success, returnData) = IAvatar(target)
.execTransactionFromModuleReturnData(to, value, data, operation);
if (guard != address(0)) {
IGuard(guard).checkAfterExecution(bytes32("0x"), success);
(success, returnData) = IAvatar(target)
.execTransactionFromModuleReturnData(
to,
value,
data,
operation
);
IGuard(currentGuard).checkAfterExecution(bytes32("0x"), success);
} else {
(success, returnData) = IAvatar(target)
.execTransactionFromModuleReturnData(
to,
value,
data,
operation
);
}
return (success, returnData);
}
Expand Down
4 changes: 0 additions & 4 deletions contracts/guard/Guardable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,4 @@ contract Guardable is OwnableUpgradeable {
guard = _guard;
emit ChangedGuard(guard);
}

function getGuard() external view returns (address _guard) {
return guard;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, now this needs a major version bump. but good to remove this obsolete getter 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized that we can't remove this, otherwise it makes our guards incompatible with the Safe.

}
7 changes: 0 additions & 7 deletions test/04_Guard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ describe("Guardable", async () => {
.withArgs(guard.address);
});
});

describe("getGuard", async () => {
it("returns guard address", async () => {
const { module } = await setupTests();
await expect(await module.getGuard()).to.be.equals(AddressZero);
});
});
});

describe("BaseGuard", async () => {
Expand Down