Skip to content

Commit 11198b4

Browse files
committed
fix error case
1 parent 0ae895b commit 11198b4

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)