Skip to content
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

tests for update #23

Open
Alexangelj opened this issue Feb 23, 2024 · 1 comment
Open

tests for update #23

Alexangelj opened this issue Feb 23, 2024 · 1 comment
Assignees
Labels
📃 contracts Anything related to the DFMM contracts (or strategies) 🧹 improvement Code improvements or cleanup 🧪 tests Tests

Comments

@Alexangelj
Copy link
Contributor

function update(
address sender,
uint256 poolId,
IDFMM.Pool calldata pool,
bytes calldata data
) external onlyDFMM {
if (sender != internalParams[poolId].controller) revert InvalidSender();
LogNormalLib.LogNormalUpdateCode updateCode =
abi.decode(data, (LogNormalLib.LogNormalUpdateCode));
if (updateCode == LogNormalLib.LogNormalUpdateCode.SwapFee) {
internalParams[poolId].swapFee = LogNormalLib.decodeFeeUpdate(data);
} else if (updateCode == LogNormalLib.LogNormalUpdateCode.Sigma) {
(uint256 targetSigma, uint256 targetTimestamp) =
LogNormalLib.decodeSigmaUpdate(data);
internalParams[poolId].sigma.set(targetSigma, targetTimestamp);
} else if (updateCode == LogNormalLib.LogNormalUpdateCode.Tau) {
(uint256 targetTau, uint256 targetTimestamp) =
LogNormalLib.decodeTauUpdate(data);
internalParams[poolId].tau.set(targetTau, targetTimestamp);
} else if (updateCode == LogNormalLib.LogNormalUpdateCode.Strike) {
(uint256 targetStrike, uint256 targetTimestamp) =
LogNormalLib.decodeStrikeUpdate(data);
internalParams[poolId].strike.set(targetStrike, targetTimestamp);
} else if (updateCode == LogNormalLib.LogNormalUpdateCode.Controller) {
internalParams[poolId].controller =
LogNormalLib.decodeControllerUpdate(data);
} else {
revert InvalidUpdateCode();
}
}

This function is externally exposed in the core dfmm contract update() which can be called by anyone. I'm pretty sure it is possible to update the pool to a state that would require the arbitrageur to deposit funds into the pool (+ both sides), which they would not be incentivized to do. This would lead to a pool that does not get arbitraged after update. But, I'm not sure. We should work on some dedicated tests for this to figure it out, and get the insights on this behavior from the sim

@0xJepsen 0xJepsen added this to the 🔍 Contracts Audit milestone Feb 24, 2024
@0xJepsen 0xJepsen added 🧹 improvement Code improvements or cleanup 🧪 tests Tests labels Feb 24, 2024
@clemlak clemlak self-assigned this Feb 26, 2024
@clemlak
Copy link
Contributor

clemlak commented Feb 26, 2024

I'm not entirely sure about the scenario you're describing. We've already identified a few potential "attacks" using update though, such as "flash updates" that could take the form of two updates in a row, sandwiching the transactions of the liquidity providers or arbitragers to abuse them. However this attack is only possible if the pool controller is malicious.

@clemlak clemlak added the 📃 contracts Anything related to the DFMM contracts (or strategies) label Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📃 contracts Anything related to the DFMM contracts (or strategies) 🧹 improvement Code improvements or cleanup 🧪 tests Tests
Projects
None yet
Development

No branches or pull requests

3 participants