Skip to content

Commit

Permalink
Merge pull request #114 from PaulRBerg/refactor/remove-min-gas-reserve
Browse files Browse the repository at this point in the history
refactor: remove "minGasReserve"
  • Loading branch information
PaulRBerg authored Jun 17, 2023
2 parents afa7f7f + 559819c commit 2ebcbc6
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 225 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ Once the proxy is deployed, you can start interacting with target contracts. PRB
`PRBProxyAnnex`. This contract provides several auxiliary functions, including:

- `installPlugin`
- `setMinGasReserve`
- `setPermission`
- `uninstallPlugin`

Expand Down
6 changes: 1 addition & 5 deletions src/PRBProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ contract PRBProxy is
/// @notice Constructs the proxy by fetching the params from the registry.
/// @dev This is implemented like this so that the proxy's CREATE2 address doesn't depend on the constructor params.
constructor() {
minGasReserve = 5000;
registry = IPRBProxyRegistry(msg.sender);
owner = registry.transientProxyOwner();
}
Expand Down Expand Up @@ -138,11 +137,8 @@ contract PRBProxy is
// Save the owner address in memory so that this variable cannot be modified during the DELEGATECALL.
address owner_ = owner;

// Reserve some gas to ensure that the contract call will not run out of gas.
uint256 stipend = gasleft() - minGasReserve;

// Delegate call to the provided contract.
(success, response) = to.delegatecall{ gas: stipend }(data);
(success, response) = to.delegatecall(data);

// Check that the owner has not been changed.
if (owner_ != owner) {
Expand Down
12 changes: 0 additions & 12 deletions src/PRBProxyAnnex.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,6 @@ contract PRBProxyAnnex is
emit InstallPlugin(plugin);
}

/// @inheritdoc IPRBProxyAnnex
function setMinGasReserve(uint256 newMinGasReserve) external override {
// Load the current minimum gas reserve.
uint256 oldMinGasReserve = minGasReserve;

// Update the minimum gas reserve.
minGasReserve = newMinGasReserve;

// Log the minimum gas reserve update.
emit SetMinGasReserve(oldMinGasReserve, newMinGasReserve);
}

/// @inheritdoc IPRBProxyAnnex
function setPermission(address envoy, address target, bool permission) external override {
permissions[envoy][target] = permission;
Expand Down
3 changes: 0 additions & 3 deletions src/abstracts/PRBProxyStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ abstract contract PRBProxyStorage is IPRBProxyStorage {
/// @inheritdoc IPRBProxyStorage
address public override owner;

/// @inheritdoc IPRBProxyStorage
uint256 public override minGasReserve;

/// @inheritdoc IPRBProxyStorage
mapping(bytes4 method => IPRBProxyPlugin plugin) public plugins;

Expand Down
1 change: 0 additions & 1 deletion src/interfaces/IPRBProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ interface IPRBProxy is IPRBProxyStorage {
/// Requirements:
/// - The caller must be either an owner or an envoy with permission.
/// - `target` must be a contract.
/// - The gas stipend must be greater than or equal to `minGasReserve`.
/// - The owner must not be changed during the DELEGATECALL.
///
/// @param target The address of the target contract.
Expand Down
11 changes: 0 additions & 11 deletions src/interfaces/IPRBProxyAnnex.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ interface IPRBProxyAnnex {
/// @notice Emitted when a plugin is installed.
event InstallPlugin(IPRBProxyPlugin indexed plugin);

/// @notice Emitted when the minimum gas reserve is updated.
event SetMinGasReserve(uint256 oldMinGasReserve, uint256 newMinGasReserve);

/// @notice Emitted when the permission is updated for an (envoy,target) tuple.
event SetPermission(address indexed envoy, address indexed target, bool permission);

Expand Down Expand Up @@ -60,13 +57,6 @@ interface IPRBProxyAnnex {
/// @param plugin The address of the plugin to install.
function installPlugin(IPRBProxyPlugin plugin) external;

/// @notice Sets a new value for the minimum gas reserve.
///
/// @dev Emits a {SetMinGasReserve} event.
///
/// @param newMinGasReserve The new minimum gas reserve.
function setMinGasReserve(uint256 newMinGasReserve) external;

/// @notice Gives or takes a permission from an envoy to call the provided target contract and function selector
/// on behalf of the proxy owner.
///
Expand All @@ -90,7 +80,6 @@ interface IPRBProxyAnnex {
/// Requirements:
/// - The plugin must have at least one implemented method.
///
///
/// @param plugin The address of the plugin to uninstall.
function uninstallPlugin(IPRBProxyPlugin plugin) external;
}
6 changes: 0 additions & 6 deletions src/interfaces/IPRBProxyStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ interface IPRBProxyStorage {
/// @notice The address of the owner account or contract.
function owner() external view returns (address);

/// @notice The amount of gas to reserve for running the remainder of either the fallback or the execute
/// function after the delegate call.
/// @dev This precaution ensures that the proxy remains operational even if EVM opcode gas costs change in the
/// future.
function minGasReserve() external view returns (uint256);

/// @notice The address of the plugin contract installed for the provided method.
/// @dev The zero address is returned if no plugin contract is installed.
/// @param method The method's signature for the query.
Expand Down
9 changes: 0 additions & 9 deletions test/Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { TargetChangeOwner } from "./mocks/targets/TargetChangeOwner.sol";
import { TargetDummy } from "./mocks/targets/TargetDummy.sol";
import { TargetDummyWithFallback } from "./mocks/targets/TargetDummyWithFallback.sol";
import { TargetEcho } from "./mocks/targets/TargetEcho.sol";
import { TargetMinGasReserve } from "./mocks/targets/TargetMinGasReserve.sol";
import { TargetPanic } from "./mocks/targets/TargetPanic.sol";
import { TargetReverter } from "./mocks/targets/TargetReverter.sol";
import { TargetSelfDestructer } from "./mocks/targets/TargetSelfDestructer.sol";
Expand Down Expand Up @@ -53,7 +52,6 @@ abstract contract Base_Test is Assertions, Events, StdCheats, StdUtils {
TargetDummy dummy;
TargetDummyWithFallback dummyWithFallback;
TargetEcho echo;
TargetMinGasReserve minGasReserve;
TargetPanic panic;
TargetReverter reverter;
TargetSelfDestructer selfDestructer;
Expand Down Expand Up @@ -121,7 +119,6 @@ abstract contract Base_Test is Assertions, Events, StdCheats, StdUtils {
dummy: new TargetDummy(),
dummyWithFallback: new TargetDummyWithFallback(),
echo: new TargetEcho(),
minGasReserve: new TargetMinGasReserve(),
panic: new TargetPanic(),
reverter: new TargetReverter(),
selfDestructer: new TargetSelfDestructer()
Expand Down Expand Up @@ -200,12 +197,6 @@ abstract contract Base_Test is Assertions, Events, StdCheats, StdUtils {
proxy.execute({ target: address(annex), data: data });
}

/// @dev ABI encodes the parameters and calls {PRBProxyAnnex.setMinGasReserve}.
function setMinGasReserve(uint256 newMinGasReserve) internal {
bytes memory data = abi.encodeCall(annex.setMinGasReserve, (newMinGasReserve));
proxy.execute({ target: address(annex), data: data });
}

/// @dev ABI encodes the parameters and calls {PRBProxyAnnex.setPermission}.
function setPermission(address envoy, address target, bool permission) internal {
bytes memory data = abi.encodeCall(annex.setPermission, (envoy, target, permission));
Expand Down
18 changes: 0 additions & 18 deletions test/annex/set-min-gas-reserve/setMinGasReserve.t.sol

This file was deleted.

3 changes: 0 additions & 3 deletions test/annex/set-min-gas-reserve/setMinGasReserve.tree

This file was deleted.

10 changes: 0 additions & 10 deletions test/mocks/targets/TargetMinGasReserve.sol

This file was deleted.

45 changes: 1 addition & 44 deletions test/proxy/execute/execute.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,7 @@ contract Execute_Test is Proxy_Test {
_;
}

function test_RevertWhen_GasStipendCalculationUnderflows() external whenCallerAuthorized whenTargetContract {
// Set the min gas reserve.
uint256 gasLimit = 10_000;
proxy.execute(
address(targets.minGasReserve),
abi.encodeWithSelector(targets.minGasReserve.setMinGasReserve.selector, gasLimit + 1)
);

// Run the test.
bytes memory data = abi.encode(targets.echo.echoUint256.selector, 1729);
vm.expectRevert(stdError.arithmeticError);
proxy.execute{ gas: gasLimit }(address(targets.echo), data);
}

modifier whenGasStipendCalculationDoesNotUnderflow() {
_;
}

function test_RevertWhen_OwnerChangedDuringDelegateCall()
external
whenCallerAuthorized
whenTargetContract
whenGasStipendCalculationDoesNotUnderflow
{
function test_RevertWhen_OwnerChangedDuringDelegateCall() external whenCallerAuthorized whenTargetContract {
bytes memory data = bytes.concat(targets.changeOwner.changeIt.selector);
vm.expectRevert(abi.encodeWithSelector(IPRBProxy.PRBProxy_OwnerChanged.selector, owner, address(1729)));
proxy.execute(address(targets.changeOwner), data);
Expand All @@ -97,7 +74,6 @@ contract Execute_Test is Proxy_Test {
external
whenCallerAuthorized
whenTargetContract
whenGasStipendCalculationDoesNotUnderflow
whenOwnerNotChangedDuringDelegateCall
whenDelegateCallReverts
{
Expand All @@ -110,7 +86,6 @@ contract Execute_Test is Proxy_Test {
external
whenCallerAuthorized
whenTargetContract
whenGasStipendCalculationDoesNotUnderflow
whenOwnerNotChangedDuringDelegateCall
whenDelegateCallReverts
{
Expand All @@ -123,7 +98,6 @@ contract Execute_Test is Proxy_Test {
external
whenCallerAuthorized
whenTargetContract
whenGasStipendCalculationDoesNotUnderflow
whenOwnerNotChangedDuringDelegateCall
whenDelegateCallReverts
{
Expand All @@ -136,7 +110,6 @@ contract Execute_Test is Proxy_Test {
external
whenCallerAuthorized
whenTargetContract
whenGasStipendCalculationDoesNotUnderflow
whenOwnerNotChangedDuringDelegateCall
whenDelegateCallReverts
{
Expand All @@ -149,7 +122,6 @@ contract Execute_Test is Proxy_Test {
external
whenCallerAuthorized
whenTargetContract
whenGasStipendCalculationDoesNotUnderflow
whenOwnerNotChangedDuringDelegateCall
whenDelegateCallReverts
{
Expand All @@ -162,7 +134,6 @@ contract Execute_Test is Proxy_Test {
external
whenCallerAuthorized
whenTargetContract
whenGasStipendCalculationDoesNotUnderflow
whenOwnerNotChangedDuringDelegateCall
whenDelegateCallReverts
{
Expand All @@ -175,7 +146,6 @@ contract Execute_Test is Proxy_Test {
external
whenCallerAuthorized
whenTargetContract
whenGasStipendCalculationDoesNotUnderflow
whenOwnerNotChangedDuringDelegateCall
whenDelegateCallReverts
{
Expand All @@ -188,7 +158,6 @@ contract Execute_Test is Proxy_Test {
external
whenCallerAuthorized
whenTargetContract
whenGasStipendCalculationDoesNotUnderflow
whenOwnerNotChangedDuringDelegateCall
whenDelegateCallReverts
{
Expand All @@ -201,7 +170,6 @@ contract Execute_Test is Proxy_Test {
external
whenCallerAuthorized
whenTargetContract
whenGasStipendCalculationDoesNotUnderflow
whenOwnerNotChangedDuringDelegateCall
whenDelegateCallReverts
{
Expand All @@ -218,7 +186,6 @@ contract Execute_Test is Proxy_Test {
external
whenCallerAuthorized
whenTargetContract
whenGasStipendCalculationDoesNotUnderflow
whenOwnerNotChangedDuringDelegateCall
whenDelegateCallDoesNotRevert
{
Expand All @@ -237,7 +204,6 @@ contract Execute_Test is Proxy_Test {
external
whenCallerAuthorized
whenTargetContract
whenGasStipendCalculationDoesNotUnderflow
whenOwnerNotChangedDuringDelegateCall
whenDelegateCallDoesNotRevert
whenNoEtherSent
Expand Down Expand Up @@ -279,7 +245,6 @@ contract Execute_Test is Proxy_Test {
external
whenCallerAuthorized
whenTargetContract
whenGasStipendCalculationDoesNotUnderflow
whenOwnerNotChangedDuringDelegateCall
whenDelegateCallDoesNotRevert
whenNoEtherSent
Expand All @@ -296,7 +261,6 @@ contract Execute_Test is Proxy_Test {
external
whenCallerAuthorized
whenTargetContract
whenGasStipendCalculationDoesNotUnderflow
whenOwnerNotChangedDuringDelegateCall
whenDelegateCallDoesNotRevert
whenNoEtherSent
Expand All @@ -313,7 +277,6 @@ contract Execute_Test is Proxy_Test {
external
whenCallerAuthorized
whenTargetContract
whenGasStipendCalculationDoesNotUnderflow
whenOwnerNotChangedDuringDelegateCall
whenDelegateCallDoesNotRevert
whenNoEtherSent
Expand All @@ -330,7 +293,6 @@ contract Execute_Test is Proxy_Test {
external
whenCallerAuthorized
whenTargetContract
whenGasStipendCalculationDoesNotUnderflow
whenOwnerNotChangedDuringDelegateCall
whenDelegateCallDoesNotRevert
whenNoEtherSent
Expand All @@ -347,7 +309,6 @@ contract Execute_Test is Proxy_Test {
external
whenCallerAuthorized
whenTargetContract
whenGasStipendCalculationDoesNotUnderflow
whenOwnerNotChangedDuringDelegateCall
whenDelegateCallDoesNotRevert
whenNoEtherSent
Expand All @@ -364,7 +325,6 @@ contract Execute_Test is Proxy_Test {
external
whenCallerAuthorized
whenTargetContract
whenGasStipendCalculationDoesNotUnderflow
whenOwnerNotChangedDuringDelegateCall
whenDelegateCallDoesNotRevert
whenNoEtherSent
Expand All @@ -381,7 +341,6 @@ contract Execute_Test is Proxy_Test {
external
whenCallerAuthorized
whenTargetContract
whenGasStipendCalculationDoesNotUnderflow
whenOwnerNotChangedDuringDelegateCall
whenDelegateCallDoesNotRevert
whenNoEtherSent
Expand All @@ -398,7 +357,6 @@ contract Execute_Test is Proxy_Test {
external
whenCallerAuthorized
whenTargetContract
whenGasStipendCalculationDoesNotUnderflow
whenOwnerNotChangedDuringDelegateCall
whenDelegateCallDoesNotRevert
whenNoEtherSent
Expand All @@ -415,7 +373,6 @@ contract Execute_Test is Proxy_Test {
external
whenCallerAuthorized
whenTargetContract
whenGasStipendCalculationDoesNotUnderflow
whenOwnerNotChangedDuringDelegateCall
whenDelegateCallDoesNotRevert
whenNoEtherSent
Expand Down
Loading

0 comments on commit 2ebcbc6

Please sign in to comment.