Random Number Generators
Pyth.sol
[MEDIUM] Unable to recover Pyth fees
The Pyth protocol takes fees by using the ETH held within the contract. This covers the cost of the random number generation by the external protocol. If there is not enough ETH within the contract, then the call will fail and prevent users from spinning.
// Get the fee for the Pyth Entropy request
uint fee = entropy.getFeeV2();
// Make call to Pyth Entropy to generate a random modulator and cast it to a uint
requestId_ = uint(entropy.requestV2{value: fee}());
For this reason, it's vital that if this external protocol is used that there is sufficient ETH held in the contract. However, there is currently no method of withdrawing ETH from the contract. This means that if the SlabMachine is shutdown, or the RandomNumberGenerator implementation is changed, then any unused ETH is effectively burned.
Recommended Solution
By allowing the owner to withdraw from the ETH balance on the contract, we can bypass this concern.
/**
* Allows the owner to rescue ETH from the contract.
*
* @param _recipient The address to send the ETH to
* @param _amount The amount of ETH to send
*/
function rescueETH(address _recipient, uint _amount) public onlyOwner {
payable(_recipient).transfer(_amount);
}
Alternatively, you could add a generic fee() function to the RandomNumberGenerator.sol to allow the SlabMachine to change the user extra ETH for their transaction. However, we would advise against this approach and instead fund the contract yourselves as this would require both ETH and USDC to be transferred per-pull which may be a negative experience.