Skip to content

Commit 55008e1

Browse files
authored
AA-284 L-04: Incomplete Generalization in TokenPaymaster (eth-infinitism#425)
* AA-284 L-04: Incomplete Generalization in TokenPaymaster
1 parent 0f0d5e7 commit 55008e1

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

contracts/samples/TokenPaymaster.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ contract TokenPaymaster is BasePaymaster, UniswapHelper, OracleHelper {
126126
"TPM: invalid data length"
127127
);
128128
uint256 preChargeNative = requiredPreFund + (tokenPaymasterConfig.refundPostopCost * userOp.maxFeePerGas);
129-
// note: as price is in ether-per-token and we want more tokens increasing it means dividing it by markup
129+
// note: as price is in native-asset-per-token and we want more tokens increasing it means dividing it by markup
130130
uint256 cachedPriceWithMarkup = cachedPrice * PRICE_DENOMINATOR / priceMarkup;
131131
if (paymasterAndDataLength == 32) {
132132
uint256 clientSuppliedPrice = uint256(bytes32(userOp.paymasterAndData[PAYMASTER_DATA_OFFSET : PAYMASTER_DATA_OFFSET + 32]));
133133
if (clientSuppliedPrice < cachedPriceWithMarkup) {
134-
// note: smaller number means 'more ether per token'
134+
// note: smaller number means 'more native asset per token'
135135
cachedPriceWithMarkup = clientSuppliedPrice;
136136
}
137137
}
@@ -161,7 +161,7 @@ contract TokenPaymaster is BasePaymaster, UniswapHelper, OracleHelper {
161161
address userOpSender
162162
) = abi.decode(context, (uint256, address));
163163
uint256 _cachedPrice = updateCachedPrice(false);
164-
// note: as price is in ether-per-token and we want more tokens increasing it means dividing it by markup
164+
// note: as price is in native-asset-per-token and we want more tokens increasing it means dividing it by markup
165165
uint256 cachedPriceWithMarkup = _cachedPrice * PRICE_DENOMINATOR / priceMarkup;
166166
// Refund tokens based on actual gas cost
167167
uint256 actualChargeNative = actualGasCost + tokenPaymasterConfig.refundPostopCost * actualUserOpFeePerGas;

contracts/samples/utils/OracleHelper.sol

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@ abstract contract OracleHelper {
2929
/// @notice The Oracle contract used to fetch the latest token prices
3030
IOracle tokenOracle;
3131

32-
/// @notice The Oracle contract used to fetch the latest ETH prices. Only needed if tokenToNativeOracle flag is not set.
32+
/// @notice The Oracle contract used to fetch the latest native asset prices. Only needed if tokenToNativeOracle flag is not set.
3333
IOracle nativeOracle;
3434

3535
/// @notice If 'true' we will fetch price directly from tokenOracle
3636
/// @notice If 'false' we will use nativeOracle to establish a token price through a shared third currency
3737
bool tokenToNativeOracle;
3838

39-
/// @notice 'false' if price is dollars-per-token (or ether-per-token), 'true' if price is tokens-per-dollar
39+
/// @notice 'false' if price is bridging-asset-per-token (or native-asset-per-token), 'true' if price is tokens-per-bridging-asset
4040
bool tokenOracleReverse;
4141

42-
/// @notice 'false' if price is dollars-per-ether, 'true' if price is ether-per-dollar
42+
/// @notice 'false' if price is bridging-asset-per-native-asset, 'true' if price is native-asset-per-bridging-asset
4343
bool nativeOracleReverse;
4444

4545
/// @notice The price update threshold percentage from PRICE_DENOMINATOR that triggers a price update (1e26 = 100%)
4646
uint256 priceUpdateThreshold;
4747

4848
}
4949

50-
/// @notice The cached token price from the Oracle, always in (ether-per-token) * PRICE_DENOMINATOR format
50+
/// @notice The cached token price from the Oracle, always in (native-asset-per-token) * PRICE_DENOMINATOR format
5151
uint256 public cachedPrice;
5252

5353
/// @notice The timestamp of a block when the cached price was updated
@@ -130,30 +130,30 @@ abstract contract OracleHelper {
130130
* @param nativeAssetPrice - the price of the native asset relative to a bridging asset or 1 if no bridging needed.
131131
* @param tokenOracleReverse - flag indicating direction of the "tokenPrice".
132132
* @param nativeOracleReverse - flag indicating direction of the "nativeAssetPrice".
133-
* @return the ether-per-token price multiplied by the PRICE_DENOMINATOR constant.
133+
* @return the native-asset-per-token price multiplied by the PRICE_DENOMINATOR constant.
134134
*/
135135
function calculatePrice(
136136
uint256 tokenPrice,
137137
uint256 nativeAssetPrice,
138138
bool tokenOracleReverse,
139139
bool nativeOracleReverse
140140
) private view returns (uint256){
141-
// tokenPrice is normalized as dollars-per-token
141+
// tokenPrice is normalized as bridging-asset-per-token
142142
if (tokenOracleReverse) {
143-
// inverting tokenPrice that was tokens-per-dollar (or tokens-per-ether)
143+
// inverting tokenPrice that was tokens-per-bridging-asset (or tokens-per-native-asset)
144144
tokenPrice = PRICE_DENOMINATOR * tokenOracleDecimalPower / tokenPrice;
145145
} else {
146-
// tokenPrice already dollars-per-token (or ethers-per-token)
146+
// tokenPrice already bridging-asset-per-token (or native-asset-per-token)
147147
tokenPrice = PRICE_DENOMINATOR * tokenPrice / tokenOracleDecimalPower;
148148
}
149149

150150
if (nativeOracleReverse) {
151-
// multiplying by nativeAssetPrice that is ethers-per-dollar
152-
// => result = (dollar / token) * (ether / dollar) = ether / token
151+
// multiplying by nativeAssetPrice that is native-asset-per-bridging-asset
152+
// => result = (bridging-asset / token) * (native-asset / bridging-asset) = native-asset / token
153153
return nativeAssetPrice * tokenPrice / nativeOracleDecimalPower;
154154
} else {
155-
// dividing by nativeAssetPrice that is dollars-per-ether
156-
// => result = (dollar / token) / (dollar / ether) = ether / token
155+
// dividing by nativeAssetPrice that is bridging-asset-per-native-asset
156+
// => result = (bridging-asset / token) / (bridging-asset / native-asset) = native-asset / token
157157
return tokenPrice * nativeOracleDecimalPower / nativeAssetPrice;
158158
}
159159
}

reports/gas-checker.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
4949
║ token paymaster with diff │ 2 │ │ 66133 │ 37154 ║
5050
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
51-
║ token paymaster │ 10 │ 723875 │ │ ║
51+
║ token paymaster │ 10 │ 723899 │ │ ║
5252
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
53-
║ token paymaster with diff │ 11 │ │ 6625237273
53+
║ token paymaster with diff │ 11 │ │ 6621637237
5454
╚════════════════════════════════╧═══════╧═══════════════╧════════════════╧═════════════════════╝
5555

0 commit comments

Comments
 (0)