From 11198b49579f39148a2911b4a0a7123bc310a0d4 Mon Sep 17 00:00:00 2001 From: Jayant Krishnamurthy Date: Fri, 3 Oct 2025 11:14:03 -0700 Subject: [PATCH] fix error case --- .../ethereum/contracts/contracts/entropy/Entropy.sol | 5 ++--- target_chains/ethereum/contracts/test/Entropy.t.sol | 10 ++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/target_chains/ethereum/contracts/contracts/entropy/Entropy.sol b/target_chains/ethereum/contracts/contracts/entropy/Entropy.sol index fad430922f..bb28d25b6e 100644 --- a/target_chains/ethereum/contracts/contracts/entropy/Entropy.sol +++ b/target_chains/ethereum/contracts/contracts/entropy/Entropy.sol @@ -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( diff --git a/target_chains/ethereum/contracts/test/Entropy.t.sol b/target_chains/ethereum/contracts/test/Entropy.t.sol index 62c53639bf..ad9e0feacd 100644 --- a/target_chains/ethereum/contracts/test/Entropy.t.sol +++ b/target_chains/ethereum/contracts/test/Entropy.t.sol @@ -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] + ); + // On the first attempt, the transaction should succeed and emit CallbackFailed event. bytes memory revertReason = abi.encodeWithSelector( 0x08c379a0,