Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -619,13 +619,12 @@ abstract contract Entropy is IEntropy, EntropyState {
);
clearRequest(provider, sequenceNumber);
} else if (
ret.length > 0 ||
(startingGas * 31) / 32 >
uint256(req.gasLimit10k) * TEN_THOUSAND
) {
// The callback reverted for some reason.
// If ret.length > 0, then we know the callback manually triggered a revert, so it's safe to mark it as failed.
// 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).
// We don't use ret to condition the behavior here (out-of-gas or other revert), as we have found that some user contracts
// catch out-of-gas errors and revert with a different error.
// In this case, ensure that the callback was provided with sufficient gas. Technically, 63/64ths of the startingGas is forwarded,
// but we're using 31/32 to introduce a margin of safety.
emit CallbackFailed(
Expand Down
10 changes: 10 additions & 0 deletions target_chains/ethereum/contracts/test/Entropy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,16 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
userRandomNumber
);

// If the callback reverts, the Entropy reveal also reverts unless
// provided enough gas to pass on.
vm.expectRevert();
random.revealWithCallback{gas: defaultGasLimit - 1000}(
provider1,
assignedSequenceNumber,
userRandomNumber,
provider1Proofs[assignedSequenceNumber]
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test used to fail before the change


// On the first attempt, the transaction should succeed and emit CallbackFailed event.
bytes memory revertReason = abi.encodeWithSelector(
0x08c379a0,
Expand Down
Loading