Skip to content

Commit f6df66d

Browse files
authored
fix(entropy): Only mark callbacks as failed if enough gas was provided, regardless of revert code (#3106)
Summary This PR removes the check that allows us to mark callbacks as failed (even if enough gas wasn't provided) if they revert with a non-empty return code. Rationale When we wrote this initally, we thought that all out-of-gas reverts from calling contracts would bubble up and be caught by the ret.length == 0 condition. However, we have found that some contracts catch out-of-gas reverts and then revert with a different error code. This means we can end up calling these callbacks without enough gas. Simple fix here is to require enough gas to be provided regardless of the revert code.
1 parent 0ae895b commit f6df66d

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

target_chains/ethereum/contracts/contracts/entropy/Entropy.sol

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,13 +619,12 @@ abstract contract Entropy is IEntropy, EntropyState {
619619
);
620620
clearRequest(provider, sequenceNumber);
621621
} else if (
622-
ret.length > 0 ||
623622
(startingGas * 31) / 32 >
624623
uint256(req.gasLimit10k) * TEN_THOUSAND
625624
) {
626625
// The callback reverted for some reason.
627-
// If ret.length > 0, then we know the callback manually triggered a revert, so it's safe to mark it as failed.
628-
// If ret.length == 0, then the callback might have run out of gas (though there are other ways to trigger a revert with ret.length == 0).
626+
// We don't use ret to condition the behavior here (out-of-gas or other revert), as we have found that some user contracts
627+
// catch out-of-gas errors and revert with a different error.
629628
// In this case, ensure that the callback was provided with sufficient gas. Technically, 63/64ths of the startingGas is forwarded,
630629
// but we're using 31/32 to introduce a margin of safety.
631630
emit CallbackFailed(

target_chains/ethereum/contracts/test/Entropy.t.sol

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,16 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
11131113
userRandomNumber
11141114
);
11151115

1116+
// If the callback reverts, the Entropy reveal also reverts unless
1117+
// provided enough gas to pass on.
1118+
vm.expectRevert();
1119+
random.revealWithCallback{gas: defaultGasLimit - 1000}(
1120+
provider1,
1121+
assignedSequenceNumber,
1122+
userRandomNumber,
1123+
provider1Proofs[assignedSequenceNumber]
1124+
);
1125+
11161126
// On the first attempt, the transaction should succeed and emit CallbackFailed event.
11171127
bytes memory revertReason = abi.encodeWithSelector(
11181128
0x08c379a0,

0 commit comments

Comments
 (0)