diff --git a/contracts/common/BiconomyTokenPaymasterErrors.sol b/contracts/common/BiconomyTokenPaymasterErrors.sol index 6188f11..845d87f 100644 --- a/contracts/common/BiconomyTokenPaymasterErrors.sol +++ b/contracts/common/BiconomyTokenPaymasterErrors.sol @@ -71,6 +71,11 @@ contract BiconomyTokenPaymasterErrors { */ error InvalidOracleDecimals(); + /** + * @notice Throws when price expiry duration is in the past + */ + error InvalidPriceExpiryDuration(); + /** * @notice Throws when external signer's signature has invalid length */ diff --git a/contracts/token/BiconomyTokenPaymaster.sol b/contracts/token/BiconomyTokenPaymaster.sol index 07ce080..ff2d048 100644 --- a/contracts/token/BiconomyTokenPaymaster.sol +++ b/contracts/token/BiconomyTokenPaymaster.sol @@ -104,7 +104,9 @@ contract BiconomyTokenPaymaster is // ETH -> USD will always have 8 decimals for Chainlink and TWAP revert InvalidOracleDecimals(); } - require(block.timestamp >= priceExpiryDurationArg, "Price expiry duration cannot be in the past"); + if (block.timestamp < priceExpiryDurationArg) { + revert InvalidPriceExpiryDuration(); + } // Set state variables assembly ("memory-safe") { @@ -271,7 +273,7 @@ contract BiconomyTokenPaymaster is * @notice only to be called by the owner of the contract. */ function setPriceExpiryDuration(uint256 newPriceExpiryDuration) external payable onlyOwner { - require(block.timestamp >= newPriceExpiryDuration, "Price expiry duration cannot be in the past"); + if(block.timestamp < newPriceExpiryDuration) revert InvalidPriceExpiryDuration(); uint256 oldPriceExpiryDuration = priceExpiryDuration; assembly ("memory-safe") { sstore(priceExpiryDuration.slot, newPriceExpiryDuration) @@ -515,7 +517,7 @@ contract BiconomyTokenPaymaster is // deduct max penalty from the token amount we pass to the postOp // so we don't refund it at postOp - context = abi.encode(userOp.sender, tokenAddress, tokenAmount-((maxPenalty*tokenPrice*externalPriceMarkup)/(1e18*_PRICE_DENOMINATOR)), tokenPrice, externalPriceMarkup, userOpHash); + context = abi.encode(userOp.sender, tokenAddress, tokenAmount-((maxPenalty*tokenPrice*externalPriceMarkup)/(_NATIVE_TOKEN_DECIMALS*_PRICE_DENOMINATOR)), tokenPrice, externalPriceMarkup, userOpHash); validationData = _packValidationData(false, validUntil, validAfter); } else if (mode == PaymasterMode.INDEPENDENT) { // Use only oracles for the token specified in modeSpecificData @@ -543,7 +545,7 @@ contract BiconomyTokenPaymaster is SafeTransferLib.safeTransferFrom(tokenAddress, userOp.sender, address(this), tokenAmount); context = - abi.encode(userOp.sender, tokenAddress, tokenAmount-((maxPenalty*tokenPrice*independentPriceMarkup)/(1e18*_PRICE_DENOMINATOR)), tokenPrice, independentPriceMarkup, userOpHash); + abi.encode(userOp.sender, tokenAddress, tokenAmount-((maxPenalty*tokenPrice*independentPriceMarkup)/(_NATIVE_TOKEN_DECIMALS*_PRICE_DENOMINATOR)), tokenPrice, independentPriceMarkup, userOpHash); validationData = 0; // Validation success and price is valid indefinetly } }