-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/chainlight remediations #81
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/chainlight-io/2024-01-biconomy-audit-issues-client/issues/5
Looks good.
https://github.com/chainlight-io/2024-01-biconomy-audit-issues-client/issues/6
-
Most oracles are still configured to fall back to the default update threshold of 2 days. Since the heartbeat interval varies for each token and network combination, the
priceUpdateThreshold
should be configured asheartbeat interval + block time + buffer
. You can find the information on Chainlink's feed here. -
Placing
priceUpdateThreshold
right aftertokenDecimals
here and loadingtokenInfo
into memory before using it here should reduce gas usage. -
In line with the code changes, comments should be added here and updated here.
https://github.com/chainlight-io/2024-01-biconomy-audit-issues-client/issues/7
There is a flaw in MathLib.sol
's min function. (It returns the max value rather than the min value.) Change the gt()
part in minuint256()
and minuint32()
as shown below.
function minuint256(uint256 a, uint256 b) internal pure returns (uint256 result) {
assembly {
result := xor(b, mul(xor(b, a), gt(b, a)))
}
}
function minuint32(uint32 a, uint32 b) internal pure returns (uint32 result) {
assembly {
result := xor(b, mul(xor(b, a), gt(b, a)))
}
}
can't open this link |
do you mean changing this from storage to memory? TokenInfo storage tokenInfo = tokensInfo[token]; |
Are you sure about this, it does break my test cases. |
ok I just confirmed in foundry, will check the tests |
fetch token's decimals directly + update the test cases
Sorry. We didn't know that the link was temporary. We are uploading the downloaded version. Yes. Yes. |
Thanks. For the deployment scripts will try to fin heartbeat for all supported oracles across supported chains. What value do you recommend for a buffer? btw, all the changes have been made. can you re-review and approve the PR please |
So the final threshold would be
Sure. Looks good. |
@@ -32,6 +32,8 @@ interface IBiconomyTokenPaymaster { | |||
*/ | |||
event FeeReceiverChanged(address indexed _oldfeeReceiver, address indexed _newfeeReceiver, address indexed _actor); | |||
|
|||
event TokensWithdrawn(address indexed _token, address indexed _to, uint256 indexed _amount, address actor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure _amount
should be indexed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can index 3 params and I think it's fine. also out of scope of remediations PR
require(priceMarkup <= 2e6, "BTPM: price markup percentage too high"); | ||
require( | ||
IERC20(feeToken).balanceOf(account) >= ((tokenRequiredPreFund * priceMarkup) / PRICE_DENOMINATOR), | ||
"BTPM: account does not have enough token balance" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To fit into 32 bytes we can use the following require msg: BTPM: Insufficient token balance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
tokensInfo[token].tokenDecimals = ERC20(token).decimals(); | ||
tokensInfo[token].isDerivedFeed = isDerivedFeed; | ||
tokensInfo[token].priceUpdateThreshold = priceUpdateThreshold; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current function setTokenOracle
updates TokenInfo in tokensInfo map separately.
I'll suggest to pass TokenInfo directly and update map once. Saves SSTORE operation
tokensInfo[token] = TokenInfo({
tokenDecimals: ERC20(token).decimals(),
priceUpdateThreshold,
tokenOracle,
nativeOracle,
isDerivedFeed
});
This way we use less gas
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we do this as part of another PR? first I will check gas consumptions on forge. this also requires major changes again in scripts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
Summary
Related Issue: #
https://github.com/chainlight-io/2024-01-biconomy-audit-issues-client/issues/7
https://github.com/chainlight-io/2024-01-biconomy-audit-issues-client/issues/5
https://github.com/chainlight-io/2024-01-biconomy-audit-issues-client/issues/6
https://github.com/chainlight-io/2024-01-biconomy-audit-issues-client/issues/7
Change Type
Checklist
Additional Information
Branch Naming