Skip to content

Commit 8b7e961

Browse files
authored
tweak proof wording
1 parent 95bcb57 commit 8b7e961

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

contracts/metatx/ERC2771Forwarder.sol

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,25 +257,24 @@ contract ERC2771Forwarder is EIP712, Nonces {
257257
// To avoid insufficient gas griefing attacks, as referenced in https://ronan.eth.limo/blog/ethereum-gas-dangers/
258258
//
259259
// A malicious relayer can attempt to shrink the gas forwarded so that the underlying call reverts out-of-gas
260-
// and the top-level call still passes, so in order to make sure that the subcall received the requested gas,
261-
// the define this model and adding a check:
260+
// but the forwarding itself still succeeds. In order to make sure that the subcall received sufficient gas,
261+
// we will inspect gasleft() after the forwarding.
262262
//
263-
// Let X be the gas available before the subcall, such that the subcall gets X * 63 / 64.
263+
// Let X be the gas available before the subcall, such that the subcall gets at most X * 63 / 64.
264264
// We can't know X after CALL dynamic costs, but we want it to be such that X * 63 / 64 >= req.gas.
265-
// Let Y be the gas used in the subcall gasleft() measured immediately after the subcall will be gasleft() = X - Y.
265+
// Let Y be the gas used in the subcall. gasleft() measured immediately after the subcall will be gasleft() = X - Y.
266266
// If the subcall ran out of gas, then Y = X * 63 / 64 and gasleft() = X - Y = X / 64.
267-
// Then we restrict the model by checking if req.gas / 63 > gasleft(), which is true is true if and only if
267+
// Under this assumption req.gas / 63 > gasleft() is true is true if and only if
268268
// req.gas / 63 > X / 64, or equivalently req.gas > X * 63 / 64.
269-
//
270269
// This means that if the subcall runs out of gas we are able to detect that insufficient gas was passed.
270+
//
271271
// We will now also see that req.gas / 63 > gasleft() implies that req.gas >= X * 63 / 64.
272272
// The contract guarantees Y <= req.gas, thus gasleft() = X - Y >= X - req.gas.
273273
// - req.gas / 63 > gasleft()
274274
// - req.gas / 63 >= X - req.gas
275275
// - req.gas >= X * 63 / 64
276-
//
277276
// In other words if req.gas < X * 63 / 64 then req.gas / 63 <= gasleft(), thus if the relayer behaves honestly
278-
// the relay does not revert.
277+
// the forwarding does not revert.
279278
if (gasleft() < request.gas / 63) {
280279
// We explicitly trigger invalid opcode to consume all gas and bubble-up the effects, since
281280
// neither revert or assert consume all gas since Solidity 0.8.0

0 commit comments

Comments
 (0)