-
Notifications
You must be signed in to change notification settings - Fork 47
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(Governor): remove CappedMath and tx order #1618
Conversation
WalkthroughThe changes in the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant KlerosGovernor
participant Blockchain
User->>KlerosGovernor: Submit Transaction
KlerosGovernor->>KlerosGovernor: Validate Submission Period
KlerosGovernor->>KlerosGovernor: Generate Hash
KlerosGovernor->>Blockchain: Store Transaction Hash
Blockchain-->>KlerosGovernor: Confirm Storage
KlerosGovernor-->>User: Transaction Submitted
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Deploy Preview for kleros-v2-university ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for kleros-v2-testnet ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for kleros-v2-neo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
|
6c62e4a
to
07b07f1
Compare
✅ Deploy Preview for kleros-v2-testnet-devtools ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Code Climate has analyzed commit 07b07f1 and detected 0 issues on this pull request. View more on Code Climate. |
|
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.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (1)
contracts/src/arbitration/KlerosGovernor.sol (1)
Line range hint
218-236
: Add validation for transaction listWhile the hash calculation logic is sound, additional validations would improve security:
- Empty transaction list check
- Empty transaction data validation
+require(_target.length > 0, "Empty transaction list"); bytes32 listHash; bytes32 currentTxHash; uint256 readingPosition; for (uint256 i = 0; i < _target.length; i++) { bytes memory readData = new bytes(_dataSize[i]); + require(_dataSize[i] > 0, "Empty transaction data"); Transaction storage transaction = submission.txs.push();
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
contracts/src/arbitration/KlerosGovernor.sol
(7 hunks)
🔇 Additional comments (2)
contracts/src/arbitration/KlerosGovernor.sol (2)
231-232
: LGTM: Secure hash calculation
The hash calculation using keccak256
with proper abi.encodePacked
is secure and prevents hash collisions.
217-217
: 🛠️ Refactor suggestion
Add explicit deposit calculation check
The deposit calculation should be checked for potential overflow, even though Solidity 0.8+ has built-in checks.
-submission.deposit = submissionBaseDeposit + arbitrator.arbitrationCost(arbitratorExtraData);
+uint256 arbitrationCost = arbitrator.arbitrationCost(arbitratorExtraData);
+require(arbitrationCost <= type(uint256).max - submissionBaseDeposit, "Deposit calculation overflow");
+submission.deposit = submissionBaseDeposit + arbitrationCost;
CappedMath is removed because for the most part it's not needed as it was initially used to prevent underflows/overflows which isn't relevant for 0.8.0. In a couple of cases it was relevant still and I implemented a manual check there.
Requirement for tx ordering is removed since it becomes an issue where the txs in the list must be executed in a particular order (e.g. during
minStake
changes in courts). On the other hand, removing it now makes possible to submit lists with the same txs but in different order with an attempt "to steal" the list in cases where order of execution doesn't matter. In this case the list that was submitted the first should be chosen.There is no way to automate this process within the contract, since it's not possible to determine automatically whether the order of the list matters or not, thus the process of choosing the list should be done by the jurors, which might require some policy changes to address the cases of duplication.
PR-Codex overview
This PR focuses on simplifying arithmetic operations in the
KlerosGovernor
contract by removing theCappedMath
library and replacing its methods with standard arithmetic operations. This enhances code clarity and reduces complexity.Detailed summary
using CappedMath for uint256;
.addCap
with standard addition.subCap
with standard subtraction.Summary by CodeRabbit
Bug Fixes
Refactor
CappedMath
library, simplifying arithmetic expressions.Documentation