Skip to content

Commit 4bfc0c8

Browse files
authored
Update StorageAccessible related function names (#291)
1 parent c460de8 commit 4bfc0c8

File tree

6 files changed

+21
-20
lines changed

6 files changed

+21
-20
lines changed

contracts/common/StorageAccessible.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ contract StorageAccessible {
3232
* @param targetContract Address of the contract containing the code to execute.
3333
* @param calldataPayload Calldata that should be sent to the target contract (encoded method name and arguments).
3434
*/
35-
function simulateDelegatecallInternal(address targetContract, bytes memory calldataPayload) external {
35+
function simulateAndRevert(address targetContract, bytes memory calldataPayload) external {
3636
// solhint-disable-next-line no-inline-assembly
3737
assembly {
3838
let success := delegatecall(gas(), targetContract, add(calldataPayload, 0x20), mload(calldataPayload), 0, 0)

contracts/handler/CompatibilityFallbackHandler.sol

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,16 @@ contract CompatibilityFallbackHandler is DefaultCallbackHandler, ISignatureValid
6363
* @param targetContract Address of the contract containing the code to execute.
6464
* @param calldataPayload Calldata that should be sent to the target contract (encoded method name and arguments).
6565
*/
66-
function simulateDelegatecall(
66+
function simulate(
6767
address targetContract, // solhint-disable-line no-unused-var
6868
bytes calldata calldataPayload // solhint-disable-line no-unused-var
6969
) public returns (bytes memory response) {
7070
// solhint-disable-next-line no-inline-assembly
7171
assembly {
7272
let internalCalldata := mload(0x40)
73-
// Store `simulateDelegatecallInternal.selector`.
74-
mstore(internalCalldata, "\x43\x21\x8e\x19")
73+
// Store `simulateAndRevert.selector`.
74+
// String representation is used to force right padding
75+
mstore(internalCalldata, "\xb4\xfa\xba\x09")
7576
// Abuse the fact that both this and the internal methods have the
7677
// same signature, and differ only in symbol name (and therefore,
7778
// selector) and copy calldata directly. This saves us approximately
@@ -91,7 +92,7 @@ contract CompatibilityFallbackHandler is DefaultCallbackHandler, ISignatureValid
9192
0,
9293
internalCalldata,
9394
calldatasize(),
94-
// The `simulateDelegatecallInternal` call always reverts, and
95+
// The `simulateAndRevert` call always reverts, and
9596
// instead encodes whether or not it was successful in the return
9697
// data. The first 32-byte word of the return data contains the
9798
// `success` value, so write it to memory address 0x00 (which is

contracts/interfaces/ViewStorageAccessible.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ pragma solidity >=0.5.0 <0.6.0;
44
/// @notice Adjusted version of https://github.com/gnosis/util-contracts/blob/3db1e531cb243a48ea91c60a800d537c1000612a/contracts/StorageAccessible.sol
55
interface ViewStorageAccessible {
66
/**
7-
* @dev Same as `simulateDelegatecall` on StorageAccessible. Marked as view so that it can be called from external contracts
7+
* @dev Same as `simulate` on StorageAccessible. Marked as view so that it can be called from external contracts
88
* that want to run simulations from within view functions. Will revert if the invoked simulation attempts to change state.
99
*/
10-
function simulateDelegatecall(address targetContract, bytes calldata calldataPayload) external view returns (bytes memory);
10+
function simulate(address targetContract, bytes calldata calldataPayload) external view returns (bytes memory);
1111
}

test/accessors/SimulateTxAccessor.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe("SimulateTxAccessor", async () => {
5757
const { safe, accessor, simulator } = await setupTests()
5858
const tx = buildContractCall(safe, "getOwners", [], 0)
5959
const simulationData = accessor.interface.encodeFunctionData("simulate", [tx.to, tx.value, tx.data, tx.operation])
60-
const acccessibleData = await simulator.callStatic.simulateDelegatecall(accessor.address, simulationData)
60+
const acccessibleData = await simulator.callStatic.simulate(accessor.address, simulationData)
6161
const simulation = accessor.interface.decodeFunctionResult("simulate", acccessibleData)
6262
expect(
6363
safe.interface.decodeFunctionResult("getOwners", simulation.returnData)[0]
@@ -76,7 +76,7 @@ describe("SimulateTxAccessor", async () => {
7676
const userBalance = await hre.ethers.provider.getBalance(user2.address)
7777
const tx = buildContractCall(interactor, "sendAndReturnBalance", [user2.address, parseEther("1")], 0, true)
7878
const simulationData = accessor.interface.encodeFunctionData("simulate", [tx.to, tx.value, tx.data, tx.operation])
79-
const acccessibleData = await simulator.callStatic.simulateDelegatecall(accessor.address, simulationData)
79+
const acccessibleData = await simulator.callStatic.simulate(accessor.address, simulationData)
8080
const simulation = accessor.interface.decodeFunctionResult("simulate", acccessibleData)
8181
expect(
8282
interactor.interface.decodeFunctionResult("sendAndReturnBalance", simulation.returnData)[0]
@@ -93,7 +93,7 @@ describe("SimulateTxAccessor", async () => {
9393
const { safe, accessor, interactor, simulator } = await setupTests()
9494
const tx = buildContractCall(interactor, "sendAndReturnBalance", [user2.address, parseEther("1")], 0, true)
9595
const simulationData = accessor.interface.encodeFunctionData("simulate", [tx.to, tx.value, tx.data, tx.operation])
96-
const acccessibleData = await simulator.callStatic.simulateDelegatecall(accessor.address, simulationData)
96+
const acccessibleData = await simulator.callStatic.simulate(accessor.address, simulationData)
9797
const simulation = accessor.interface.decodeFunctionResult("simulate", acccessibleData)
9898
expect(simulation.returnData).to.be.deep.eq("0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f5472616e73666572206661696c65640000000000000000000000000000000000")
9999
expect(

test/core/GnosisSafe.StorageAccessible.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,26 @@ describe("StorageAccessible", async () => {
4040
})
4141
})
4242

43-
describe("simulateDelegatecallInternal", async () => {
43+
describe("simulateAndRevert", async () => {
4444

4545
it('should revert changes', async () => {
4646
const { safe, killLib } = await setupTests()
4747
await expect(
48-
safe.callStatic.simulateDelegatecallInternal(killLib.address, killLib.interface.encodeFunctionData("killme"))
48+
safe.callStatic.simulateAndRevert(killLib.address, killLib.interface.encodeFunctionData("killme"))
4949
).to.be.reverted
5050
})
5151

5252
it('should revert the revert with message', async () => {
5353
const { safe, killLib } = await setupTests()
5454
await expect(
55-
safe.callStatic.simulateDelegatecallInternal(killLib.address, killLib.interface.encodeFunctionData("trever"))
55+
safe.callStatic.simulateAndRevert(killLib.address, killLib.interface.encodeFunctionData("trever"))
5656
).to.be.reverted
5757
})
5858

5959
it('should return estimate in revert', async () => {
6060
const { safe, killLib } = await setupTests()
6161
await expect(
62-
safe.callStatic.simulateDelegatecallInternal(killLib.address, killLib.interface.encodeFunctionData("estimate", [safe.address, "0x"]))
62+
safe.callStatic.simulateAndRevert(killLib.address, killLib.interface.encodeFunctionData("estimate", [safe.address, "0x"]))
6363
).to.be.reverted
6464
})
6565
})

test/handlers/CompatibilityFallbackHandler.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ describe("CompatibilityFallbackHandler", async () => {
149149
})
150150

151151

152-
describe("simulateDelegatecall", async () => {
152+
describe("simulate", async () => {
153153

154154
it.skip('can be called for any Safe', async () => {
155155
})
@@ -158,7 +158,7 @@ describe("CompatibilityFallbackHandler", async () => {
158158
const { validator, killLib } = await setupTests()
159159
const code = await ethers.provider.getCode(validator.address)
160160
expect(
161-
await validator.callStatic.simulateDelegatecall(killLib.address, killLib.interface.encodeFunctionData("killme"))
161+
await validator.callStatic.simulate(killLib.address, killLib.interface.encodeFunctionData("killme"))
162162
).to.be.eq("0x")
163163
expect(
164164
await ethers.provider.getCode(validator.address)
@@ -168,20 +168,20 @@ describe("CompatibilityFallbackHandler", async () => {
168168
it('should return result', async () => {
169169
const { validator, killLib, handler } = await setupTests()
170170
expect(
171-
await validator.callStatic.simulateDelegatecall(killLib.address, killLib.interface.encodeFunctionData("expose"))
171+
await validator.callStatic.simulate(killLib.address, killLib.interface.encodeFunctionData("expose"))
172172
).to.be.eq("0x000000000000000000000000" + handler.address.slice(2).toLowerCase())
173173
})
174174

175175
it('should propagate revert message', async () => {
176176
const { validator, killLib } = await setupTests()
177177
await expect(
178-
validator.callStatic.simulateDelegatecall(killLib.address, killLib.interface.encodeFunctionData("trever"))
178+
validator.callStatic.simulate(killLib.address, killLib.interface.encodeFunctionData("trever"))
179179
).to.revertedWith("Why are you doing this?")
180180
})
181181

182182
it('should simulate transaction', async () => {
183183
const { validator, killLib } = await setupTests()
184-
const estimate = await validator.callStatic.simulateDelegatecall(
184+
const estimate = await validator.callStatic.simulate(
185185
killLib.address,
186186
killLib.interface.encodeFunctionData("estimate", [validator.address, "0x"])
187187
)
@@ -190,7 +190,7 @@ describe("CompatibilityFallbackHandler", async () => {
190190

191191
it('should return modified state', async () => {
192192
const { validator, killLib } = await setupTests()
193-
const value = await validator.callStatic.simulateDelegatecall(
193+
const value = await validator.callStatic.simulate(
194194
killLib.address,
195195
killLib.interface.encodeFunctionData("updateAndGet", [])
196196
)

0 commit comments

Comments
 (0)