diff --git a/codegen/payments.ts b/codegen/payments.ts index 2b54bb4c..2f13ff9f 100644 --- a/codegen/payments.ts +++ b/codegen/payments.ts @@ -15,6 +15,14 @@ export function generateFHEPayment(priceData: PriceData): string { import "./TFHEExecutorAddress.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; import "@openzeppelin/contracts/access/Ownable2Step.sol"; + + error FHEGasBlockLimitExceeded(); + error CallerMustBeTFHEExecutorContract(); + error OnlyScalarOperationsAreSupported(); + error OnlyNonScalarOperationsAreSupported(); + error RecoveryFailed(); + error WithdrawalFailed(); + error AccountNotEnoughFunded(); contract FHEPayment is Ownable2Step { /// @notice Name of the contract @@ -40,7 +48,7 @@ export function generateFHEPayment(priceData: PriceData): string { uint64 claimableUsedFHEGas_ = claimableUsedFHEGas; claimableUsedFHEGas = 0; (bool success, ) = receiver.call{value: claimableUsedFHEGas_}(""); - require(success, "Withdrawal failed"); + if(!success) revert RecoveryFailed(); } function depositETH(address account) external payable { @@ -50,12 +58,22 @@ export function generateFHEPayment(priceData: PriceData): string { function withdrawETH(uint256 amount, address receiver) external { depositsETH[msg.sender] -= amount; (bool success, ) = receiver.call{value: amount}(""); - require(success, "Withdrawal failed"); + if(!success) revert WithdrawalFailed(); } function getAvailableDepositsETH(address account) external view returns (uint256) { return depositsETH[account]; } + + function updateFunding(address payer, uint256 paidAmount) private { + uint256 depositedAmount = depositsETH[payer]; + if(paidAmount>depositedAmount) revert AccountNotEnoughFunded(); + unchecked{ + depositsETH[payer] = depositedAmount - paidAmount; + } + currentBlockConsumption += uint64(paidAmount); + claimableUsedFHEGas += uint64(paidAmount); + } function checkIfNewBlock() private { uint64 lastBlock_ = uint64(block.number); @@ -69,12 +87,12 @@ export function generateFHEPayment(priceData: PriceData): string { const functionName = `payFor${operation.charAt(0).toUpperCase() + operation.slice(1)}`; if (data.binary) { output += ` function ${functionName}(address payer, uint8 resultType, bytes1 scalarByte) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if(msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); checkIfNewBlock(); `; } else { output += ` function ${functionName}(address payer, uint8 resultType) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if(msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); `; } @@ -85,16 +103,16 @@ ${generatePriceChecks(data.scalar)} ${generatePriceChecks(data.nonScalar)} }`; } else if (data.scalar) { - output += ` require(scalarByte == 0x01, "Only scalar operations are supported");`; + output += ` if(scalarByte != 0x01) revert OnlyScalarOperationsAreSupported();`; output += `${generatePriceChecks(data.scalar)}`; } else if (data.nonScalar) { - output += ` require(scalarByte == 0x00, "Only non-scalar operations are supported");`; + output += ` if(scalarByte != 0x00) revert OnlyNonScalarOperationsAreSupported();`; output += `${generatePriceChecks(data.nonScalar)}`; } else { if (data.types) output += `${generatePriceChecks(data.types)}`; } - output += `require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + output += `if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); }\n\n`; } @@ -124,9 +142,7 @@ function generatePriceChecks(prices: { [key: string]: number }): string { return Object.entries(prices) .map( ([resultType, price]) => ` if (resultType == ${resultType}) { - depositsETH[payer] -= ${price}; - currentBlockConsumption += ${price}; - claimableUsedFHEGas += ${price}; + updateFunding(payer, ${price}); }`, ) .join(' else '); diff --git a/lib/FHEPayment.sol b/lib/FHEPayment.sol index 52d88f84..a9ddd4b9 100644 --- a/lib/FHEPayment.sol +++ b/lib/FHEPayment.sol @@ -6,6 +6,14 @@ import "./TFHEExecutorAddress.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; import "@openzeppelin/contracts/access/Ownable2Step.sol"; +error FHEGasBlockLimitExceeded(); +error CallerMustBeTFHEExecutorContract(); +error OnlyScalarOperationsAreSupported(); +error OnlyNonScalarOperationsAreSupported(); +error RecoveryFailed(); +error WithdrawalFailed(); +error AccountNotEnoughFunded(); + contract FHEPayment is Ownable2Step { /// @notice Name of the contract string private constant CONTRACT_NAME = "FHEPayment"; @@ -30,7 +38,7 @@ contract FHEPayment is Ownable2Step { uint64 claimableUsedFHEGas_ = claimableUsedFHEGas; claimableUsedFHEGas = 0; (bool success, ) = receiver.call{value: claimableUsedFHEGas_}(""); - require(success, "Withdrawal failed"); + if (!success) revert RecoveryFailed(); } function depositETH(address account) external payable { @@ -40,13 +48,23 @@ contract FHEPayment is Ownable2Step { function withdrawETH(uint256 amount, address receiver) external { depositsETH[msg.sender] -= amount; (bool success, ) = receiver.call{value: amount}(""); - require(success, "Withdrawal failed"); + if (!success) revert WithdrawalFailed(); } function getAvailableDepositsETH(address account) external view returns (uint256) { return depositsETH[account]; } + function updateFunding(address payer, uint256 paidAmount) private { + uint256 depositedAmount = depositsETH[payer]; + if (paidAmount > depositedAmount) revert AccountNotEnoughFunded(); + unchecked { + depositsETH[payer] = depositedAmount - paidAmount; + } + currentBlockConsumption += uint64(paidAmount); + claimableUsedFHEGas += uint64(paidAmount); + } + function checkIfNewBlock() private { uint64 lastBlock_ = uint64(block.number); if (block.number > lastBlock) { @@ -56,1142 +74,696 @@ contract FHEPayment is Ownable2Step { } function payForFheAdd(address payer, uint8 resultType, bytes1 scalarByte) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); checkIfNewBlock(); if (scalarByte == 0x01) { if (resultType == 1) { - depositsETH[payer] -= 65000; - currentBlockConsumption += 65000; - claimableUsedFHEGas += 65000; + updateFunding(payer, 65000); } else if (resultType == 2) { - depositsETH[payer] -= 94000; - currentBlockConsumption += 94000; - claimableUsedFHEGas += 94000; + updateFunding(payer, 94000); } else if (resultType == 3) { - depositsETH[payer] -= 133000; - currentBlockConsumption += 133000; - claimableUsedFHEGas += 133000; + updateFunding(payer, 133000); } else if (resultType == 4) { - depositsETH[payer] -= 162000; - currentBlockConsumption += 162000; - claimableUsedFHEGas += 162000; + updateFunding(payer, 162000); } else if (resultType == 5) { - depositsETH[payer] -= 188000; - currentBlockConsumption += 188000; - claimableUsedFHEGas += 188000; + updateFunding(payer, 188000); } } else { if (resultType == 1) { - depositsETH[payer] -= 65000; - currentBlockConsumption += 65000; - claimableUsedFHEGas += 65000; + updateFunding(payer, 65000); } else if (resultType == 2) { - depositsETH[payer] -= 94000; - currentBlockConsumption += 94000; - claimableUsedFHEGas += 94000; + updateFunding(payer, 94000); } else if (resultType == 3) { - depositsETH[payer] -= 133000; - currentBlockConsumption += 133000; - claimableUsedFHEGas += 133000; + updateFunding(payer, 133000); } else if (resultType == 4) { - depositsETH[payer] -= 162000; - currentBlockConsumption += 162000; - claimableUsedFHEGas += 162000; + updateFunding(payer, 162000); } else if (resultType == 5) { - depositsETH[payer] -= 188000; - currentBlockConsumption += 188000; - claimableUsedFHEGas += 188000; + updateFunding(payer, 188000); } } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheSub(address payer, uint8 resultType, bytes1 scalarByte) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); checkIfNewBlock(); if (scalarByte == 0x01) { if (resultType == 1) { - depositsETH[payer] -= 65000; - currentBlockConsumption += 65000; - claimableUsedFHEGas += 65000; + updateFunding(payer, 65000); } else if (resultType == 2) { - depositsETH[payer] -= 94000; - currentBlockConsumption += 94000; - claimableUsedFHEGas += 94000; + updateFunding(payer, 94000); } else if (resultType == 3) { - depositsETH[payer] -= 133000; - currentBlockConsumption += 133000; - claimableUsedFHEGas += 133000; + updateFunding(payer, 133000); } else if (resultType == 4) { - depositsETH[payer] -= 162000; - currentBlockConsumption += 162000; - claimableUsedFHEGas += 162000; + updateFunding(payer, 162000); } else if (resultType == 5) { - depositsETH[payer] -= 188000; - currentBlockConsumption += 188000; - claimableUsedFHEGas += 188000; + updateFunding(payer, 188000); } } else { if (resultType == 1) { - depositsETH[payer] -= 65000; - currentBlockConsumption += 65000; - claimableUsedFHEGas += 65000; + updateFunding(payer, 65000); } else if (resultType == 2) { - depositsETH[payer] -= 94000; - currentBlockConsumption += 94000; - claimableUsedFHEGas += 94000; + updateFunding(payer, 94000); } else if (resultType == 3) { - depositsETH[payer] -= 133000; - currentBlockConsumption += 133000; - claimableUsedFHEGas += 133000; + updateFunding(payer, 133000); } else if (resultType == 4) { - depositsETH[payer] -= 162000; - currentBlockConsumption += 162000; - claimableUsedFHEGas += 162000; + updateFunding(payer, 162000); } else if (resultType == 5) { - depositsETH[payer] -= 188000; - currentBlockConsumption += 188000; - claimableUsedFHEGas += 188000; + updateFunding(payer, 188000); } } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheMul(address payer, uint8 resultType, bytes1 scalarByte) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); checkIfNewBlock(); if (scalarByte == 0x01) { if (resultType == 1) { - depositsETH[payer] -= 88000; - currentBlockConsumption += 88000; - claimableUsedFHEGas += 88000; + updateFunding(payer, 88000); } else if (resultType == 2) { - depositsETH[payer] -= 159000; - currentBlockConsumption += 159000; - claimableUsedFHEGas += 159000; + updateFunding(payer, 159000); } else if (resultType == 3) { - depositsETH[payer] -= 208000; - currentBlockConsumption += 208000; - claimableUsedFHEGas += 208000; + updateFunding(payer, 208000); } else if (resultType == 4) { - depositsETH[payer] -= 264000; - currentBlockConsumption += 264000; - claimableUsedFHEGas += 264000; + updateFunding(payer, 264000); } else if (resultType == 5) { - depositsETH[payer] -= 356000; - currentBlockConsumption += 356000; - claimableUsedFHEGas += 356000; + updateFunding(payer, 356000); } } else { if (resultType == 1) { - depositsETH[payer] -= 150000; - currentBlockConsumption += 150000; - claimableUsedFHEGas += 150000; + updateFunding(payer, 150000); } else if (resultType == 2) { - depositsETH[payer] -= 197000; - currentBlockConsumption += 197000; - claimableUsedFHEGas += 197000; + updateFunding(payer, 197000); } else if (resultType == 3) { - depositsETH[payer] -= 262000; - currentBlockConsumption += 262000; - claimableUsedFHEGas += 262000; + updateFunding(payer, 262000); } else if (resultType == 4) { - depositsETH[payer] -= 359000; - currentBlockConsumption += 359000; - claimableUsedFHEGas += 359000; + updateFunding(payer, 359000); } else if (resultType == 5) { - depositsETH[payer] -= 641000; - currentBlockConsumption += 641000; - claimableUsedFHEGas += 641000; + updateFunding(payer, 641000); } } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheDiv(address payer, uint8 resultType, bytes1 scalarByte) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); checkIfNewBlock(); - require(scalarByte == 0x01, "Only scalar operations are supported"); + if (scalarByte != 0x01) revert OnlyScalarOperationsAreSupported(); if (resultType == 1) { - depositsETH[payer] -= 139000; - currentBlockConsumption += 139000; - claimableUsedFHEGas += 139000; + updateFunding(payer, 139000); } else if (resultType == 2) { - depositsETH[payer] -= 238000; - currentBlockConsumption += 238000; - claimableUsedFHEGas += 238000; + updateFunding(payer, 238000); } else if (resultType == 3) { - depositsETH[payer] -= 314000; - currentBlockConsumption += 314000; - claimableUsedFHEGas += 314000; + updateFunding(payer, 314000); } else if (resultType == 4) { - depositsETH[payer] -= 398000; - currentBlockConsumption += 398000; - claimableUsedFHEGas += 398000; + updateFunding(payer, 398000); } else if (resultType == 5) { - depositsETH[payer] -= 584000; - currentBlockConsumption += 584000; - claimableUsedFHEGas += 584000; + updateFunding(payer, 584000); } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheRem(address payer, uint8 resultType, bytes1 scalarByte) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); checkIfNewBlock(); - require(scalarByte == 0x01, "Only scalar operations are supported"); + if (scalarByte != 0x01) revert OnlyScalarOperationsAreSupported(); if (resultType == 1) { - depositsETH[payer] -= 286000; - currentBlockConsumption += 286000; - claimableUsedFHEGas += 286000; + updateFunding(payer, 286000); } else if (resultType == 2) { - depositsETH[payer] -= 460000; - currentBlockConsumption += 460000; - claimableUsedFHEGas += 460000; + updateFunding(payer, 460000); } else if (resultType == 3) { - depositsETH[payer] -= 622000; - currentBlockConsumption += 622000; - claimableUsedFHEGas += 622000; + updateFunding(payer, 622000); } else if (resultType == 4) { - depositsETH[payer] -= 805000; - currentBlockConsumption += 805000; - claimableUsedFHEGas += 805000; + updateFunding(payer, 805000); } else if (resultType == 5) { - depositsETH[payer] -= 1095000; - currentBlockConsumption += 1095000; - claimableUsedFHEGas += 1095000; + updateFunding(payer, 1095000); } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheBitAnd(address payer, uint8 resultType, bytes1 scalarByte) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); checkIfNewBlock(); - require(scalarByte == 0x00, "Only non-scalar operations are supported"); + if (scalarByte != 0x00) revert OnlyNonScalarOperationsAreSupported(); if (resultType == 0) { - depositsETH[payer] -= 26000; - currentBlockConsumption += 26000; - claimableUsedFHEGas += 26000; + updateFunding(payer, 26000); } else if (resultType == 1) { - depositsETH[payer] -= 32000; - currentBlockConsumption += 32000; - claimableUsedFHEGas += 32000; + updateFunding(payer, 32000); } else if (resultType == 2) { - depositsETH[payer] -= 34000; - currentBlockConsumption += 34000; - claimableUsedFHEGas += 34000; + updateFunding(payer, 34000); } else if (resultType == 3) { - depositsETH[payer] -= 34000; - currentBlockConsumption += 34000; - claimableUsedFHEGas += 34000; + updateFunding(payer, 34000); } else if (resultType == 4) { - depositsETH[payer] -= 35000; - currentBlockConsumption += 35000; - claimableUsedFHEGas += 35000; + updateFunding(payer, 35000); } else if (resultType == 5) { - depositsETH[payer] -= 38000; - currentBlockConsumption += 38000; - claimableUsedFHEGas += 38000; + updateFunding(payer, 38000); } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheBitOr(address payer, uint8 resultType, bytes1 scalarByte) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); checkIfNewBlock(); - require(scalarByte == 0x00, "Only non-scalar operations are supported"); + if (scalarByte != 0x00) revert OnlyNonScalarOperationsAreSupported(); if (resultType == 0) { - depositsETH[payer] -= 26000; - currentBlockConsumption += 26000; - claimableUsedFHEGas += 26000; + updateFunding(payer, 26000); } else if (resultType == 1) { - depositsETH[payer] -= 32000; - currentBlockConsumption += 32000; - claimableUsedFHEGas += 32000; + updateFunding(payer, 32000); } else if (resultType == 2) { - depositsETH[payer] -= 34000; - currentBlockConsumption += 34000; - claimableUsedFHEGas += 34000; + updateFunding(payer, 34000); } else if (resultType == 3) { - depositsETH[payer] -= 34000; - currentBlockConsumption += 34000; - claimableUsedFHEGas += 34000; + updateFunding(payer, 34000); } else if (resultType == 4) { - depositsETH[payer] -= 35000; - currentBlockConsumption += 35000; - claimableUsedFHEGas += 35000; + updateFunding(payer, 35000); } else if (resultType == 5) { - depositsETH[payer] -= 38000; - currentBlockConsumption += 38000; - claimableUsedFHEGas += 38000; + updateFunding(payer, 38000); } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheBitXor(address payer, uint8 resultType, bytes1 scalarByte) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); checkIfNewBlock(); - require(scalarByte == 0x00, "Only non-scalar operations are supported"); + if (scalarByte != 0x00) revert OnlyNonScalarOperationsAreSupported(); if (resultType == 0) { - depositsETH[payer] -= 26000; - currentBlockConsumption += 26000; - claimableUsedFHEGas += 26000; + updateFunding(payer, 26000); } else if (resultType == 1) { - depositsETH[payer] -= 32000; - currentBlockConsumption += 32000; - claimableUsedFHEGas += 32000; + updateFunding(payer, 32000); } else if (resultType == 2) { - depositsETH[payer] -= 34000; - currentBlockConsumption += 34000; - claimableUsedFHEGas += 34000; + updateFunding(payer, 34000); } else if (resultType == 3) { - depositsETH[payer] -= 34000; - currentBlockConsumption += 34000; - claimableUsedFHEGas += 34000; + updateFunding(payer, 34000); } else if (resultType == 4) { - depositsETH[payer] -= 35000; - currentBlockConsumption += 35000; - claimableUsedFHEGas += 35000; + updateFunding(payer, 35000); } else if (resultType == 5) { - depositsETH[payer] -= 38000; - currentBlockConsumption += 38000; - claimableUsedFHEGas += 38000; + updateFunding(payer, 38000); } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheShl(address payer, uint8 resultType, bytes1 scalarByte) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); checkIfNewBlock(); if (scalarByte == 0x01) { if (resultType == 1) { - depositsETH[payer] -= 35000; - currentBlockConsumption += 35000; - claimableUsedFHEGas += 35000; + updateFunding(payer, 35000); } else if (resultType == 2) { - depositsETH[payer] -= 35000; - currentBlockConsumption += 35000; - claimableUsedFHEGas += 35000; + updateFunding(payer, 35000); } else if (resultType == 3) { - depositsETH[payer] -= 35000; - currentBlockConsumption += 35000; - claimableUsedFHEGas += 35000; + updateFunding(payer, 35000); } else if (resultType == 4) { - depositsETH[payer] -= 35000; - currentBlockConsumption += 35000; - claimableUsedFHEGas += 35000; + updateFunding(payer, 35000); } else if (resultType == 5) { - depositsETH[payer] -= 38000; - currentBlockConsumption += 38000; - claimableUsedFHEGas += 38000; + updateFunding(payer, 38000); } } else { if (resultType == 1) { - depositsETH[payer] -= 116000; - currentBlockConsumption += 116000; - claimableUsedFHEGas += 116000; + updateFunding(payer, 116000); } else if (resultType == 2) { - depositsETH[payer] -= 133000; - currentBlockConsumption += 133000; - claimableUsedFHEGas += 133000; + updateFunding(payer, 133000); } else if (resultType == 3) { - depositsETH[payer] -= 153000; - currentBlockConsumption += 153000; - claimableUsedFHEGas += 153000; + updateFunding(payer, 153000); } else if (resultType == 4) { - depositsETH[payer] -= 183000; - currentBlockConsumption += 183000; - claimableUsedFHEGas += 183000; + updateFunding(payer, 183000); } else if (resultType == 5) { - depositsETH[payer] -= 227000; - currentBlockConsumption += 227000; - claimableUsedFHEGas += 227000; + updateFunding(payer, 227000); } } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheShr(address payer, uint8 resultType, bytes1 scalarByte) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); checkIfNewBlock(); if (scalarByte == 0x01) { if (resultType == 1) { - depositsETH[payer] -= 35000; - currentBlockConsumption += 35000; - claimableUsedFHEGas += 35000; + updateFunding(payer, 35000); } else if (resultType == 2) { - depositsETH[payer] -= 35000; - currentBlockConsumption += 35000; - claimableUsedFHEGas += 35000; + updateFunding(payer, 35000); } else if (resultType == 3) { - depositsETH[payer] -= 35000; - currentBlockConsumption += 35000; - claimableUsedFHEGas += 35000; + updateFunding(payer, 35000); } else if (resultType == 4) { - depositsETH[payer] -= 35000; - currentBlockConsumption += 35000; - claimableUsedFHEGas += 35000; + updateFunding(payer, 35000); } else if (resultType == 5) { - depositsETH[payer] -= 38000; - currentBlockConsumption += 38000; - claimableUsedFHEGas += 38000; + updateFunding(payer, 38000); } } else { if (resultType == 1) { - depositsETH[payer] -= 116000; - currentBlockConsumption += 116000; - claimableUsedFHEGas += 116000; + updateFunding(payer, 116000); } else if (resultType == 2) { - depositsETH[payer] -= 133000; - currentBlockConsumption += 133000; - claimableUsedFHEGas += 133000; + updateFunding(payer, 133000); } else if (resultType == 3) { - depositsETH[payer] -= 153000; - currentBlockConsumption += 153000; - claimableUsedFHEGas += 153000; + updateFunding(payer, 153000); } else if (resultType == 4) { - depositsETH[payer] -= 183000; - currentBlockConsumption += 183000; - claimableUsedFHEGas += 183000; + updateFunding(payer, 183000); } else if (resultType == 5) { - depositsETH[payer] -= 227000; - currentBlockConsumption += 227000; - claimableUsedFHEGas += 227000; + updateFunding(payer, 227000); } } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheRotl(address payer, uint8 resultType, bytes1 scalarByte) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); checkIfNewBlock(); if (scalarByte == 0x01) { if (resultType == 1) { - depositsETH[payer] -= 35000; - currentBlockConsumption += 35000; - claimableUsedFHEGas += 35000; + updateFunding(payer, 35000); } else if (resultType == 2) { - depositsETH[payer] -= 35000; - currentBlockConsumption += 35000; - claimableUsedFHEGas += 35000; + updateFunding(payer, 35000); } else if (resultType == 3) { - depositsETH[payer] -= 35000; - currentBlockConsumption += 35000; - claimableUsedFHEGas += 35000; + updateFunding(payer, 35000); } else if (resultType == 4) { - depositsETH[payer] -= 35000; - currentBlockConsumption += 35000; - claimableUsedFHEGas += 35000; + updateFunding(payer, 35000); } else if (resultType == 5) { - depositsETH[payer] -= 38000; - currentBlockConsumption += 38000; - claimableUsedFHEGas += 38000; + updateFunding(payer, 38000); } } else { if (resultType == 1) { - depositsETH[payer] -= 116000; - currentBlockConsumption += 116000; - claimableUsedFHEGas += 116000; + updateFunding(payer, 116000); } else if (resultType == 2) { - depositsETH[payer] -= 133000; - currentBlockConsumption += 133000; - claimableUsedFHEGas += 133000; + updateFunding(payer, 133000); } else if (resultType == 3) { - depositsETH[payer] -= 153000; - currentBlockConsumption += 153000; - claimableUsedFHEGas += 153000; + updateFunding(payer, 153000); } else if (resultType == 4) { - depositsETH[payer] -= 183000; - currentBlockConsumption += 183000; - claimableUsedFHEGas += 183000; + updateFunding(payer, 183000); } else if (resultType == 5) { - depositsETH[payer] -= 227000; - currentBlockConsumption += 227000; - claimableUsedFHEGas += 227000; + updateFunding(payer, 227000); } } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheRotr(address payer, uint8 resultType, bytes1 scalarByte) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); checkIfNewBlock(); if (scalarByte == 0x01) { if (resultType == 1) { - depositsETH[payer] -= 35000; - currentBlockConsumption += 35000; - claimableUsedFHEGas += 35000; + updateFunding(payer, 35000); } else if (resultType == 2) { - depositsETH[payer] -= 35000; - currentBlockConsumption += 35000; - claimableUsedFHEGas += 35000; + updateFunding(payer, 35000); } else if (resultType == 3) { - depositsETH[payer] -= 35000; - currentBlockConsumption += 35000; - claimableUsedFHEGas += 35000; + updateFunding(payer, 35000); } else if (resultType == 4) { - depositsETH[payer] -= 35000; - currentBlockConsumption += 35000; - claimableUsedFHEGas += 35000; + updateFunding(payer, 35000); } else if (resultType == 5) { - depositsETH[payer] -= 38000; - currentBlockConsumption += 38000; - claimableUsedFHEGas += 38000; + updateFunding(payer, 38000); } } else { if (resultType == 1) { - depositsETH[payer] -= 116000; - currentBlockConsumption += 116000; - claimableUsedFHEGas += 116000; + updateFunding(payer, 116000); } else if (resultType == 2) { - depositsETH[payer] -= 133000; - currentBlockConsumption += 133000; - claimableUsedFHEGas += 133000; + updateFunding(payer, 133000); } else if (resultType == 3) { - depositsETH[payer] -= 153000; - currentBlockConsumption += 153000; - claimableUsedFHEGas += 153000; + updateFunding(payer, 153000); } else if (resultType == 4) { - depositsETH[payer] -= 183000; - currentBlockConsumption += 183000; - claimableUsedFHEGas += 183000; + updateFunding(payer, 183000); } else if (resultType == 5) { - depositsETH[payer] -= 227000; - currentBlockConsumption += 227000; - claimableUsedFHEGas += 227000; + updateFunding(payer, 227000); } } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheEq(address payer, uint8 resultType, bytes1 scalarByte) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); checkIfNewBlock(); if (scalarByte == 0x01) { if (resultType == 1) { - depositsETH[payer] -= 51000; - currentBlockConsumption += 51000; - claimableUsedFHEGas += 51000; + updateFunding(payer, 51000); } else if (resultType == 2) { - depositsETH[payer] -= 53000; - currentBlockConsumption += 53000; - claimableUsedFHEGas += 53000; + updateFunding(payer, 53000); } else if (resultType == 3) { - depositsETH[payer] -= 54000; - currentBlockConsumption += 54000; - claimableUsedFHEGas += 54000; + updateFunding(payer, 54000); } else if (resultType == 4) { - depositsETH[payer] -= 82000; - currentBlockConsumption += 82000; - claimableUsedFHEGas += 82000; + updateFunding(payer, 82000); } else if (resultType == 5) { - depositsETH[payer] -= 86000; - currentBlockConsumption += 86000; - claimableUsedFHEGas += 86000; + updateFunding(payer, 86000); } else if (resultType == 7) { - depositsETH[payer] -= 90000; - currentBlockConsumption += 90000; - claimableUsedFHEGas += 90000; + updateFunding(payer, 90000); } else if (resultType == 11) { - depositsETH[payer] -= 300000; - currentBlockConsumption += 300000; - claimableUsedFHEGas += 300000; + updateFunding(payer, 300000); } } else { if (resultType == 1) { - depositsETH[payer] -= 51000; - currentBlockConsumption += 51000; - claimableUsedFHEGas += 51000; + updateFunding(payer, 51000); } else if (resultType == 2) { - depositsETH[payer] -= 53000; - currentBlockConsumption += 53000; - claimableUsedFHEGas += 53000; + updateFunding(payer, 53000); } else if (resultType == 3) { - depositsETH[payer] -= 54000; - currentBlockConsumption += 54000; - claimableUsedFHEGas += 54000; + updateFunding(payer, 54000); } else if (resultType == 4) { - depositsETH[payer] -= 82000; - currentBlockConsumption += 82000; - claimableUsedFHEGas += 82000; + updateFunding(payer, 82000); } else if (resultType == 5) { - depositsETH[payer] -= 86000; - currentBlockConsumption += 86000; - claimableUsedFHEGas += 86000; + updateFunding(payer, 86000); } else if (resultType == 7) { - depositsETH[payer] -= 90000; - currentBlockConsumption += 90000; - claimableUsedFHEGas += 90000; + updateFunding(payer, 90000); } else if (resultType == 11) { - depositsETH[payer] -= 300000; - currentBlockConsumption += 300000; - claimableUsedFHEGas += 300000; + updateFunding(payer, 300000); } } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheNe(address payer, uint8 resultType, bytes1 scalarByte) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); checkIfNewBlock(); if (scalarByte == 0x01) { if (resultType == 1) { - depositsETH[payer] -= 51000; - currentBlockConsumption += 51000; - claimableUsedFHEGas += 51000; + updateFunding(payer, 51000); } else if (resultType == 2) { - depositsETH[payer] -= 53000; - currentBlockConsumption += 53000; - claimableUsedFHEGas += 53000; + updateFunding(payer, 53000); } else if (resultType == 3) { - depositsETH[payer] -= 54000; - currentBlockConsumption += 54000; - claimableUsedFHEGas += 54000; + updateFunding(payer, 54000); } else if (resultType == 4) { - depositsETH[payer] -= 82000; - currentBlockConsumption += 82000; - claimableUsedFHEGas += 82000; + updateFunding(payer, 82000); } else if (resultType == 5) { - depositsETH[payer] -= 86000; - currentBlockConsumption += 86000; - claimableUsedFHEGas += 86000; + updateFunding(payer, 86000); } else if (resultType == 7) { - depositsETH[payer] -= 90000; - currentBlockConsumption += 90000; - claimableUsedFHEGas += 90000; + updateFunding(payer, 90000); } else if (resultType == 11) { - depositsETH[payer] -= 300000; - currentBlockConsumption += 300000; - claimableUsedFHEGas += 300000; + updateFunding(payer, 300000); } } else { if (resultType == 1) { - depositsETH[payer] -= 51000; - currentBlockConsumption += 51000; - claimableUsedFHEGas += 51000; + updateFunding(payer, 51000); } else if (resultType == 2) { - depositsETH[payer] -= 53000; - currentBlockConsumption += 53000; - claimableUsedFHEGas += 53000; + updateFunding(payer, 53000); } else if (resultType == 3) { - depositsETH[payer] -= 54000; - currentBlockConsumption += 54000; - claimableUsedFHEGas += 54000; + updateFunding(payer, 54000); } else if (resultType == 4) { - depositsETH[payer] -= 82000; - currentBlockConsumption += 82000; - claimableUsedFHEGas += 82000; + updateFunding(payer, 82000); } else if (resultType == 5) { - depositsETH[payer] -= 86000; - currentBlockConsumption += 86000; - claimableUsedFHEGas += 86000; + updateFunding(payer, 86000); } else if (resultType == 7) { - depositsETH[payer] -= 90000; - currentBlockConsumption += 90000; - claimableUsedFHEGas += 90000; + updateFunding(payer, 90000); } else if (resultType == 11) { - depositsETH[payer] -= 300000; - currentBlockConsumption += 300000; - claimableUsedFHEGas += 300000; + updateFunding(payer, 300000); } } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheGe(address payer, uint8 resultType, bytes1 scalarByte) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); checkIfNewBlock(); if (scalarByte == 0x01) { if (resultType == 1) { - depositsETH[payer] -= 70000; - currentBlockConsumption += 70000; - claimableUsedFHEGas += 70000; + updateFunding(payer, 70000); } else if (resultType == 2) { - depositsETH[payer] -= 82000; - currentBlockConsumption += 82000; - claimableUsedFHEGas += 82000; + updateFunding(payer, 82000); } else if (resultType == 3) { - depositsETH[payer] -= 105000; - currentBlockConsumption += 105000; - claimableUsedFHEGas += 105000; + updateFunding(payer, 105000); } else if (resultType == 4) { - depositsETH[payer] -= 128000; - currentBlockConsumption += 128000; - claimableUsedFHEGas += 128000; + updateFunding(payer, 128000); } else if (resultType == 5) { - depositsETH[payer] -= 156000; - currentBlockConsumption += 156000; - claimableUsedFHEGas += 156000; + updateFunding(payer, 156000); } } else { if (resultType == 1) { - depositsETH[payer] -= 70000; - currentBlockConsumption += 70000; - claimableUsedFHEGas += 70000; + updateFunding(payer, 70000); } else if (resultType == 2) { - depositsETH[payer] -= 82000; - currentBlockConsumption += 82000; - claimableUsedFHEGas += 82000; + updateFunding(payer, 82000); } else if (resultType == 3) { - depositsETH[payer] -= 105000; - currentBlockConsumption += 105000; - claimableUsedFHEGas += 105000; + updateFunding(payer, 105000); } else if (resultType == 4) { - depositsETH[payer] -= 128000; - currentBlockConsumption += 128000; - claimableUsedFHEGas += 128000; + updateFunding(payer, 128000); } else if (resultType == 5) { - depositsETH[payer] -= 156000; - currentBlockConsumption += 156000; - claimableUsedFHEGas += 156000; + updateFunding(payer, 156000); } } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheGt(address payer, uint8 resultType, bytes1 scalarByte) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); checkIfNewBlock(); if (scalarByte == 0x01) { if (resultType == 1) { - depositsETH[payer] -= 70000; - currentBlockConsumption += 70000; - claimableUsedFHEGas += 70000; + updateFunding(payer, 70000); } else if (resultType == 2) { - depositsETH[payer] -= 82000; - currentBlockConsumption += 82000; - claimableUsedFHEGas += 82000; + updateFunding(payer, 82000); } else if (resultType == 3) { - depositsETH[payer] -= 105000; - currentBlockConsumption += 105000; - claimableUsedFHEGas += 105000; + updateFunding(payer, 105000); } else if (resultType == 4) { - depositsETH[payer] -= 128000; - currentBlockConsumption += 128000; - claimableUsedFHEGas += 128000; + updateFunding(payer, 128000); } else if (resultType == 5) { - depositsETH[payer] -= 156000; - currentBlockConsumption += 156000; - claimableUsedFHEGas += 156000; + updateFunding(payer, 156000); } } else { if (resultType == 1) { - depositsETH[payer] -= 70000; - currentBlockConsumption += 70000; - claimableUsedFHEGas += 70000; + updateFunding(payer, 70000); } else if (resultType == 2) { - depositsETH[payer] -= 82000; - currentBlockConsumption += 82000; - claimableUsedFHEGas += 82000; + updateFunding(payer, 82000); } else if (resultType == 3) { - depositsETH[payer] -= 105000; - currentBlockConsumption += 105000; - claimableUsedFHEGas += 105000; + updateFunding(payer, 105000); } else if (resultType == 4) { - depositsETH[payer] -= 128000; - currentBlockConsumption += 128000; - claimableUsedFHEGas += 128000; + updateFunding(payer, 128000); } else if (resultType == 5) { - depositsETH[payer] -= 156000; - currentBlockConsumption += 156000; - claimableUsedFHEGas += 156000; + updateFunding(payer, 156000); } } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheLe(address payer, uint8 resultType, bytes1 scalarByte) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); checkIfNewBlock(); if (scalarByte == 0x01) { if (resultType == 1) { - depositsETH[payer] -= 70000; - currentBlockConsumption += 70000; - claimableUsedFHEGas += 70000; + updateFunding(payer, 70000); } else if (resultType == 2) { - depositsETH[payer] -= 82000; - currentBlockConsumption += 82000; - claimableUsedFHEGas += 82000; + updateFunding(payer, 82000); } else if (resultType == 3) { - depositsETH[payer] -= 105000; - currentBlockConsumption += 105000; - claimableUsedFHEGas += 105000; + updateFunding(payer, 105000); } else if (resultType == 4) { - depositsETH[payer] -= 128000; - currentBlockConsumption += 128000; - claimableUsedFHEGas += 128000; + updateFunding(payer, 128000); } else if (resultType == 5) { - depositsETH[payer] -= 156000; - currentBlockConsumption += 156000; - claimableUsedFHEGas += 156000; + updateFunding(payer, 156000); } } else { if (resultType == 1) { - depositsETH[payer] -= 70000; - currentBlockConsumption += 70000; - claimableUsedFHEGas += 70000; + updateFunding(payer, 70000); } else if (resultType == 2) { - depositsETH[payer] -= 82000; - currentBlockConsumption += 82000; - claimableUsedFHEGas += 82000; + updateFunding(payer, 82000); } else if (resultType == 3) { - depositsETH[payer] -= 105000; - currentBlockConsumption += 105000; - claimableUsedFHEGas += 105000; + updateFunding(payer, 105000); } else if (resultType == 4) { - depositsETH[payer] -= 128000; - currentBlockConsumption += 128000; - claimableUsedFHEGas += 128000; + updateFunding(payer, 128000); } else if (resultType == 5) { - depositsETH[payer] -= 156000; - currentBlockConsumption += 156000; - claimableUsedFHEGas += 156000; + updateFunding(payer, 156000); } } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheLt(address payer, uint8 resultType, bytes1 scalarByte) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); checkIfNewBlock(); if (scalarByte == 0x01) { if (resultType == 1) { - depositsETH[payer] -= 70000; - currentBlockConsumption += 70000; - claimableUsedFHEGas += 70000; + updateFunding(payer, 70000); } else if (resultType == 2) { - depositsETH[payer] -= 82000; - currentBlockConsumption += 82000; - claimableUsedFHEGas += 82000; + updateFunding(payer, 82000); } else if (resultType == 3) { - depositsETH[payer] -= 105000; - currentBlockConsumption += 105000; - claimableUsedFHEGas += 105000; + updateFunding(payer, 105000); } else if (resultType == 4) { - depositsETH[payer] -= 128000; - currentBlockConsumption += 128000; - claimableUsedFHEGas += 128000; + updateFunding(payer, 128000); } else if (resultType == 5) { - depositsETH[payer] -= 156000; - currentBlockConsumption += 156000; - claimableUsedFHEGas += 156000; + updateFunding(payer, 156000); } } else { if (resultType == 1) { - depositsETH[payer] -= 70000; - currentBlockConsumption += 70000; - claimableUsedFHEGas += 70000; + updateFunding(payer, 70000); } else if (resultType == 2) { - depositsETH[payer] -= 82000; - currentBlockConsumption += 82000; - claimableUsedFHEGas += 82000; + updateFunding(payer, 82000); } else if (resultType == 3) { - depositsETH[payer] -= 105000; - currentBlockConsumption += 105000; - claimableUsedFHEGas += 105000; + updateFunding(payer, 105000); } else if (resultType == 4) { - depositsETH[payer] -= 128000; - currentBlockConsumption += 128000; - claimableUsedFHEGas += 128000; + updateFunding(payer, 128000); } else if (resultType == 5) { - depositsETH[payer] -= 156000; - currentBlockConsumption += 156000; - claimableUsedFHEGas += 156000; + updateFunding(payer, 156000); } } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheMin(address payer, uint8 resultType, bytes1 scalarByte) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); checkIfNewBlock(); if (scalarByte == 0x01) { if (resultType == 1) { - depositsETH[payer] -= 121000; - currentBlockConsumption += 121000; - claimableUsedFHEGas += 121000; + updateFunding(payer, 121000); } else if (resultType == 2) { - depositsETH[payer] -= 128000; - currentBlockConsumption += 128000; - claimableUsedFHEGas += 128000; + updateFunding(payer, 128000); } else if (resultType == 3) { - depositsETH[payer] -= 150000; - currentBlockConsumption += 150000; - claimableUsedFHEGas += 150000; + updateFunding(payer, 150000); } else if (resultType == 4) { - depositsETH[payer] -= 164000; - currentBlockConsumption += 164000; - claimableUsedFHEGas += 164000; + updateFunding(payer, 164000); } else if (resultType == 5) { - depositsETH[payer] -= 192000; - currentBlockConsumption += 192000; - claimableUsedFHEGas += 192000; + updateFunding(payer, 192000); } } else { if (resultType == 1) { - depositsETH[payer] -= 121000; - currentBlockConsumption += 121000; - claimableUsedFHEGas += 121000; + updateFunding(payer, 121000); } else if (resultType == 2) { - depositsETH[payer] -= 128000; - currentBlockConsumption += 128000; - claimableUsedFHEGas += 128000; + updateFunding(payer, 128000); } else if (resultType == 3) { - depositsETH[payer] -= 153000; - currentBlockConsumption += 153000; - claimableUsedFHEGas += 153000; + updateFunding(payer, 153000); } else if (resultType == 4) { - depositsETH[payer] -= 183000; - currentBlockConsumption += 183000; - claimableUsedFHEGas += 183000; + updateFunding(payer, 183000); } else if (resultType == 5) { - depositsETH[payer] -= 210000; - currentBlockConsumption += 210000; - claimableUsedFHEGas += 210000; + updateFunding(payer, 210000); } } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheMax(address payer, uint8 resultType, bytes1 scalarByte) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); checkIfNewBlock(); if (scalarByte == 0x01) { if (resultType == 1) { - depositsETH[payer] -= 121000; - currentBlockConsumption += 121000; - claimableUsedFHEGas += 121000; + updateFunding(payer, 121000); } else if (resultType == 2) { - depositsETH[payer] -= 128000; - currentBlockConsumption += 128000; - claimableUsedFHEGas += 128000; + updateFunding(payer, 128000); } else if (resultType == 3) { - depositsETH[payer] -= 150000; - currentBlockConsumption += 150000; - claimableUsedFHEGas += 150000; + updateFunding(payer, 150000); } else if (resultType == 4) { - depositsETH[payer] -= 164000; - currentBlockConsumption += 164000; - claimableUsedFHEGas += 164000; + updateFunding(payer, 164000); } else if (resultType == 5) { - depositsETH[payer] -= 192000; - currentBlockConsumption += 192000; - claimableUsedFHEGas += 192000; + updateFunding(payer, 192000); } } else { if (resultType == 1) { - depositsETH[payer] -= 121000; - currentBlockConsumption += 121000; - claimableUsedFHEGas += 121000; + updateFunding(payer, 121000); } else if (resultType == 2) { - depositsETH[payer] -= 128000; - currentBlockConsumption += 128000; - claimableUsedFHEGas += 128000; + updateFunding(payer, 128000); } else if (resultType == 3) { - depositsETH[payer] -= 153000; - currentBlockConsumption += 153000; - claimableUsedFHEGas += 153000; + updateFunding(payer, 153000); } else if (resultType == 4) { - depositsETH[payer] -= 183000; - currentBlockConsumption += 183000; - claimableUsedFHEGas += 183000; + updateFunding(payer, 183000); } else if (resultType == 5) { - depositsETH[payer] -= 210000; - currentBlockConsumption += 210000; - claimableUsedFHEGas += 210000; + updateFunding(payer, 210000); } } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheNeg(address payer, uint8 resultType) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); if (resultType == 1) { - depositsETH[payer] -= 60000; - currentBlockConsumption += 60000; - claimableUsedFHEGas += 60000; + updateFunding(payer, 60000); } else if (resultType == 2) { - depositsETH[payer] -= 95000; - currentBlockConsumption += 95000; - claimableUsedFHEGas += 95000; + updateFunding(payer, 95000); } else if (resultType == 3) { - depositsETH[payer] -= 131000; - currentBlockConsumption += 131000; - claimableUsedFHEGas += 131000; + updateFunding(payer, 131000); } else if (resultType == 4) { - depositsETH[payer] -= 160000; - currentBlockConsumption += 160000; - claimableUsedFHEGas += 160000; + updateFunding(payer, 160000); } else if (resultType == 5) { - depositsETH[payer] -= 199000; - currentBlockConsumption += 199000; - claimableUsedFHEGas += 199000; + updateFunding(payer, 199000); } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheNot(address payer, uint8 resultType) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); if (resultType == 0) { - depositsETH[payer] -= 30000; - currentBlockConsumption += 30000; - claimableUsedFHEGas += 30000; + updateFunding(payer, 30000); } else if (resultType == 1) { - depositsETH[payer] -= 33000; - currentBlockConsumption += 33000; - claimableUsedFHEGas += 33000; + updateFunding(payer, 33000); } else if (resultType == 2) { - depositsETH[payer] -= 34000; - currentBlockConsumption += 34000; - claimableUsedFHEGas += 34000; + updateFunding(payer, 34000); } else if (resultType == 3) { - depositsETH[payer] -= 35000; - currentBlockConsumption += 35000; - claimableUsedFHEGas += 35000; + updateFunding(payer, 35000); } else if (resultType == 4) { - depositsETH[payer] -= 36000; - currentBlockConsumption += 36000; - claimableUsedFHEGas += 36000; + updateFunding(payer, 36000); } else if (resultType == 5) { - depositsETH[payer] -= 37000; - currentBlockConsumption += 37000; - claimableUsedFHEGas += 37000; + updateFunding(payer, 37000); } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForCast(address payer, uint8 resultType) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); if (resultType == 1) { - depositsETH[payer] -= 200; - currentBlockConsumption += 200; - claimableUsedFHEGas += 200; + updateFunding(payer, 200); } else if (resultType == 2) { - depositsETH[payer] -= 200; - currentBlockConsumption += 200; - claimableUsedFHEGas += 200; + updateFunding(payer, 200); } else if (resultType == 3) { - depositsETH[payer] -= 200; - currentBlockConsumption += 200; - claimableUsedFHEGas += 200; + updateFunding(payer, 200); } else if (resultType == 4) { - depositsETH[payer] -= 200; - currentBlockConsumption += 200; - claimableUsedFHEGas += 200; + updateFunding(payer, 200); } else if (resultType == 5) { - depositsETH[payer] -= 200; - currentBlockConsumption += 200; - claimableUsedFHEGas += 200; + updateFunding(payer, 200); } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForTrivialEncrypt(address payer, uint8 resultType) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); if (resultType == 0) { - depositsETH[payer] -= 100; - currentBlockConsumption += 100; - claimableUsedFHEGas += 100; + updateFunding(payer, 100); } else if (resultType == 1) { - depositsETH[payer] -= 100; - currentBlockConsumption += 100; - claimableUsedFHEGas += 100; + updateFunding(payer, 100); } else if (resultType == 2) { - depositsETH[payer] -= 100; - currentBlockConsumption += 100; - claimableUsedFHEGas += 100; + updateFunding(payer, 100); } else if (resultType == 3) { - depositsETH[payer] -= 200; - currentBlockConsumption += 200; - claimableUsedFHEGas += 200; + updateFunding(payer, 200); } else if (resultType == 4) { - depositsETH[payer] -= 300; - currentBlockConsumption += 300; - claimableUsedFHEGas += 300; + updateFunding(payer, 300); } else if (resultType == 5) { - depositsETH[payer] -= 600; - currentBlockConsumption += 600; - claimableUsedFHEGas += 600; + updateFunding(payer, 600); } else if (resultType == 7) { - depositsETH[payer] -= 700; - currentBlockConsumption += 700; - claimableUsedFHEGas += 700; + updateFunding(payer, 700); } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForIfThenElse(address payer, uint8 resultType) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); if (resultType == 1) { - depositsETH[payer] -= 45000; - currentBlockConsumption += 45000; - claimableUsedFHEGas += 45000; + updateFunding(payer, 45000); } else if (resultType == 2) { - depositsETH[payer] -= 47000; - currentBlockConsumption += 47000; - claimableUsedFHEGas += 47000; + updateFunding(payer, 47000); } else if (resultType == 3) { - depositsETH[payer] -= 47000; - currentBlockConsumption += 47000; - claimableUsedFHEGas += 47000; + updateFunding(payer, 47000); } else if (resultType == 4) { - depositsETH[payer] -= 50000; - currentBlockConsumption += 50000; - claimableUsedFHEGas += 50000; + updateFunding(payer, 50000); } else if (resultType == 5) { - depositsETH[payer] -= 53000; - currentBlockConsumption += 53000; - claimableUsedFHEGas += 53000; + updateFunding(payer, 53000); } else if (resultType == 7) { - depositsETH[payer] -= 80000; - currentBlockConsumption += 80000; - claimableUsedFHEGas += 80000; + updateFunding(payer, 80000); } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheRand(address payer, uint8 resultType) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); if (resultType == 2) { - depositsETH[payer] -= 100000; - currentBlockConsumption += 100000; - claimableUsedFHEGas += 100000; + updateFunding(payer, 100000); } else if (resultType == 3) { - depositsETH[payer] -= 100000; - currentBlockConsumption += 100000; - claimableUsedFHEGas += 100000; + updateFunding(payer, 100000); } else if (resultType == 4) { - depositsETH[payer] -= 100000; - currentBlockConsumption += 100000; - claimableUsedFHEGas += 100000; + updateFunding(payer, 100000); } else if (resultType == 5) { - depositsETH[payer] -= 100000; - currentBlockConsumption += 100000; - claimableUsedFHEGas += 100000; + updateFunding(payer, 100000); } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } function payForFheRandBounded(address payer, uint8 resultType) external { - require(msg.sender == tfheExecutorAddress, "Caller must be TFHEExecutor contract"); + if (msg.sender != tfheExecutorAddress) revert CallerMustBeTFHEExecutorContract(); if (resultType == 2) { - depositsETH[payer] -= 100000; - currentBlockConsumption += 100000; - claimableUsedFHEGas += 100000; + updateFunding(payer, 100000); } else if (resultType == 3) { - depositsETH[payer] -= 100000; - currentBlockConsumption += 100000; - claimableUsedFHEGas += 100000; + updateFunding(payer, 100000); } else if (resultType == 4) { - depositsETH[payer] -= 100000; - currentBlockConsumption += 100000; - claimableUsedFHEGas += 100000; + updateFunding(payer, 100000); } else if (resultType == 5) { - depositsETH[payer] -= 100000; - currentBlockConsumption += 100000; - claimableUsedFHEGas += 100000; + updateFunding(payer, 100000); } - require(currentBlockConsumption <= FHE_GAS_BLOCKLIMIT, "FHEGas block limit exceeded"); + if (currentBlockConsumption >= FHE_GAS_BLOCKLIMIT) revert FHEGasBlockLimitExceeded(); } /// @notice Getter for the name and version of the contract