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

feat: snapshot proxy #1872

Merged
merged 5 commits into from
Feb 5, 2025
Merged

feat: snapshot proxy #1872

merged 5 commits into from
Feb 5, 2025

Conversation

unknownunknown1
Copy link
Contributor

@unknownunknown1 unknownunknown1 commented Feb 1, 2025

PR-Codex overview

This PR introduces the KlerosCoreSnapshotProxy, a new proxy contract for managing staked Pinakion tokens. It includes deployment scripts and updates tests to validate the proxy's functionality and governance mechanisms.

Detailed summary

  • Added KlerosCoreSnapshotProxy contract for managing staked Pinakion.
  • Implemented functions for changing the governor and core.
  • Added balanceOf function to check staked PNK for an address.
  • Updated deployment scripts to include KlerosCoreSnapshotProxy.
  • Enhanced tests to validate the new proxy's behavior and governance.

The following files were skipped due to too many changes: contracts/deployments/arbitrumSepoliaDevnet/KlerosCoreSnapshotProxy.json

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Introduced a snapshot proxy that enables users to query staked balances and offers enhanced governance controls, including updates to the core system and designated roles.
  • Tests

    • Added tests to verify the proxy’s initialization, governance restrictions, and correct display of token characteristics.
  • Refactor

    • Updated dependencies and event notifications to align with improved, modular system functionality.

Copy link
Contributor

coderabbitai bot commented Feb 1, 2025

Warning

Rate limit exceeded

@jaybuidl has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 16 minutes and 46 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 20f5bb9 and ff46e40.

📒 Files selected for processing (6)
  • contracts/README.md (3 hunks)
  • contracts/deploy/00-home-chain-arbitration-neo.ts (1 hunks)
  • contracts/deploy/00-home-chain-arbitration.ts (2 hunks)
  • contracts/deployments/arbitrum/KlerosCoreSnapshotProxy.json (1 hunks)
  • contracts/deployments/arbitrumSepolia/KlerosCoreSnapshotProxy.json (1 hunks)
  • contracts/deployments/arbitrumSepoliaDevnet/KlerosCoreSnapshotProxy.json (1 hunks)

Walkthrough

This update modifies the Solidity testing suite and introduces a new snapshot proxy contract. The test file has updated import paths and event emissions that now reference new base classes, along with an added test function for validating snapshot proxy behavior. Meanwhile, the new snapshot proxy contract enables balance queries for staked tokens and incorporates governance functions for updating the core address and governor, aligning the system with the revised Kleros V2 architecture.

Changes

File Change Summary
contracts/test/foundry/KlerosCore.t.sol - Updated import for IArbitratorV2 (from .../KlerosCoreMock.sol to .../KlerosCoreBase.sol)
- Updated import for DisputeKitClassic to include DisputeKitClassicBase
- Added test_setStake_snapshotProxyCheck test function
- Modified event emissions to reference DisputeKitClassicBase
contracts/src/arbitration/view/KlerosCoreSnapshotProxy.sol - Added new contract KlerosCoreSnapshotProxy with state variables for core, governor, name, symbol, and decimals
- Added governance functions: changeGovernor and changeCore
- Added balanceOf() function to query staked tokens
- Introduced interface IKlerosCore with sortitionModule()
contracts/README.md - Added references for KlerosCoreSnapshotProxy under "V2 Neo (prelaunch)" for Arbitrum One and "Official Testnet" for Arbitrum Sepolia.
contracts/deploy/00-home-chain-arbitration-neo.ts - Added deployment step for KlerosCoreSnapshotProxy in deployArbitration.
contracts/deploy/00-home-chain-arbitration.ts - Added deployment step for KlerosCoreSnapshotProxy in deployArbitration.
contracts/deployments/arbitrum/KlerosCoreSnapshotProxy.json - Defined deployment details and ABI for KlerosCoreSnapshotProxy.
contracts/deployments/arbitrumSepolia/KlerosCoreSnapshotProxy.json - Defined deployment details and ABI for KlerosCoreSnapshotProxy on Arbitrum Sepolia.
contracts/deployments/arbitrumSepoliaDevnet/KlerosCoreSnapshotProxy.json - Defined deployment details and ABI for KlerosCoreSnapshotProxy on Arbitrum Sepolia Devnet.

Possibly related PRs

  • feat(KC): add foundry test file #1765: The changes in the main PR, particularly the addition of the test_setStake_snapshotProxyCheck function and modifications to event emissions in KlerosCore.t.sol, are related to the functionality being tested in the retrieved PR, which focuses on evaluating the KlerosCore contract and its related contracts. Both PRs involve testing and modifications to the KlerosCore system, indicating a direct connection at the code level.

  • Dispute kits refactor with shared classic logic + Upgradability improvements #1805: The changes in the main PR, particularly the updates to event emissions and the addition of the test_setStake_snapshotProxyCheck function in KlerosCore.t.sol, are related to the modifications in the retrieved PR, which also involves changes to the DisputeKitClassic and its base class, affecting how disputes are managed and emitted. Both PRs involve updates to the dispute management logic and event handling in the Kleros arbitration system.

Suggested labels

Type: Feature🗿, Package: Contracts

Suggested reviewers

  • alcercu

Poem

I'm a rabbit, hopping through lines of code,
In smart contracts where fresh features explode.
Snapshot proxies now leap with grace,
Testing and governance in a playful race.
My whiskers twitch in this digital abode!
🐇✨


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Feb 1, 2025

Deploy Preview for kleros-v2-testnet-devtools ready!

Name Link
🔨 Latest commit ff46e40
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet-devtools/deploys/67a3c9f0121f420008d5f2e5
😎 Deploy Preview https://deploy-preview-1872--kleros-v2-testnet-devtools.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Feb 1, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit ff46e40
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet/deploys/67a3c9f05088e50008885c9b
😎 Deploy Preview https://deploy-preview-1872--kleros-v2-testnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Feb 1, 2025

Deploy Preview for kleros-v2-university ready!

Name Link
🔨 Latest commit ff46e40
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-university/deploys/67a3c9f0b8a8230008c05316
😎 Deploy Preview https://deploy-preview-1872--kleros-v2-university.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (4)
contracts/src/snapshot-proxy/KlerosCoreSnapshotProxy.sol (3)

20-24: Consider using immutable state variables.

The name and symbol state variables could be made immutable since they are set at deployment and never change.

Apply this diff to optimize gas usage:

-    string public name = "Staked Pinakion";
-    string public symbol = "stPNK";
+    string public immutable name = "Staked Pinakion";
+    string public immutable symbol = "stPNK";

26-29: Consider adding events for access control.

The onlyByGovernor modifier should emit events when access is denied for better transparency and monitoring.

Add an event and emit it in the modifier:

+    event AccessDenied(address indexed caller, string reason);

     modifier onlyByGovernor() {
-        require(governor == msg.sender, "Access not allowed: Governor only.");
+        if (governor != msg.sender) {
+            emit AccessDenied(msg.sender, "Access not allowed: Governor only.");
+            revert("Access not allowed: Governor only.");
+        }
         _;
     }

34-37: Add events for initialization.

The constructor should emit events when setting the initial governor and core contract addresses.

Add events and emit them in the constructor:

+    event GovernorChanged(address indexed previousGovernor, address indexed newGovernor);
+    event CoreChanged(address indexed previousCore, address indexed newCore);

     constructor(address _governor, IKlerosCore _core) {
+        emit GovernorChanged(address(0), _governor);
+        emit CoreChanged(address(0), address(_core));
         governor = _governor;
         core = _core;
     }
contracts/test/foundry/KlerosCore.t.sol (1)

1283-1308: Enhance test coverage for snapshot proxy.

The test function test_setStake_snapshotProxyCheck should include additional test cases:

  1. Verify behavior when core contract is not set
  2. Test error handling for zero addresses
  3. Test balance updates after stake changes

Add these test cases to improve coverage:

     function test_setStake_snapshotProxyCheck() public {
         vm.prank(staker1);
         core.setStake(GENERAL_COURT, 12346);

         KlerosCoreSnapshotProxy snapshotProxy = new KlerosCoreSnapshotProxy(governor, IKlerosCore(address(core)));
+        // Test zero address validation
+        vm.expectRevert("New governor cannot be zero address");
+        vm.prank(governor);
+        snapshotProxy.changeGovernor(address(0));
+
+        vm.expectRevert("New core cannot be zero address");
+        vm.prank(governor);
+        snapshotProxy.changeCore(IKlerosCore(address(0)));
+
+        // Test balance updates after stake changes
+        vm.prank(staker1);
+        core.setStake(GENERAL_COURT, 20000);
+        assertEq(snapshotProxy.balanceOf(staker1), 20000, "Balance not updated after stake increase");
+
         // ... rest of the test
     }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2730163 and a703fdd.

📒 Files selected for processing (2)
  • contracts/src/snapshot-proxy/KlerosCoreSnapshotProxy.sol (1 hunks)
  • contracts/test/foundry/KlerosCore.t.sol (10 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (14)
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet-devtools
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet-devtools
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-testnet-devtools
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Analyze (javascript)
  • GitHub Check: contracts-testing
🔇 Additional comments (2)
contracts/src/snapshot-proxy/KlerosCoreSnapshotProxy.sol (1)

13-15: LGTM! Clean interface definition.

The interface is minimal and focused on the required functionality.

contracts/test/foundry/KlerosCore.t.sol (1)

1358-1358: LGTM! Event emission updates.

The event emissions have been correctly updated to use base classes.

Also applies to: 1624-1624, 1640-1640, 1945-1945, 1954-1954, 1956-1956, 2724-2724, 2728-2728

Copy link

netlify bot commented Feb 1, 2025

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit ff46e40
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-neo/deploys/67a3c9f092160d000846fe24
😎 Deploy Preview https://deploy-preview-1872--kleros-v2-neo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 5, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (2)
contracts/src/arbitration/view/KlerosCoreSnapshotProxy.sol (2)

13-15: Add NatSpec documentation to the interface.

Consider adding NatSpec documentation to the interface and its function for better code documentation.

 interface IKlerosCore {
+    /// @dev Returns the sortition module instance used by KlerosCore.
+    /// @return The ISortitionModule interface of the sortition module.
     function sortitionModule() external view returns (ISortitionModule);
 }

75-77: Consider adding input validation and optimizing gas usage.

  1. Add zero-address validation for the input parameter.
  2. Use assembly to optimize the tuple destructuring if gas efficiency is a concern.
     function balanceOf(address _account) external view returns (uint256 totalStaked) {
+        require(_account != address(0), "Account cannot be zero address");
-        (totalStaked, , , ) = core.sortitionModule().getJurorBalance(_account, 0);
+        assembly {
+            // Store the function selector for getJurorBalance
+            mstore(0x00, 0x12345678) // Replace with actual selector
+            // Store the account address
+            mstore(0x04, _account)
+            // Store courtID (0)
+            mstore(0x24, 0)
+            
+            // Call getJurorBalance
+            let success := staticcall(
+                gas(),
+                // Get the sortition module address
+                sload(core.slot),
+                0x00,
+                0x44,
+                0x00,
+                0x20
+            )
+            
+            // Revert if call failed
+            if iszero(success) {
+                revert(0, 0)
+            }
+            
+            // Load the total staked amount
+            totalStaked := mload(0x00)
+        }
     }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a703fdd and 20f5bb9.

📒 Files selected for processing (1)
  • contracts/src/arbitration/view/KlerosCoreSnapshotProxy.sol (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: contracts-testing
  • GitHub Check: SonarCloud
🔇 Additional comments (2)
contracts/src/arbitration/view/KlerosCoreSnapshotProxy.sol (2)

34-37: LGTM!

The modifier implementation is correct and includes a clear error message.


9-9: Verify compatibility with the specified Solidity version.

The contract uses a very recent Solidity version (0.8.24). Ensure this version is compatible with all dependencies and deployment targets.

✅ Verification successful

🌐 Web query:

What is the latest stable version of Solidity and when was version 0.8.24 released?

Length of output: 2845


Solidity Version Compatibility Verified

The contract’s pragma solidity 0.8.24; is using a stable release that was published on January 26, 2024. Although the latest stable version is 0.8.28 (released October 9, 2024), version 0.8.24 remains in the 0.8.x series, ensuring feature compatibility with our dependencies and deployment targets. No immediate update is necessary unless you plan to leverage improvements or fixes present in later releases.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 5, 2025
Copy link

codeclimate bot commented Feb 5, 2025

Code Climate has analyzed commit ff46e40 and detected 0 issues on this pull request.

View more on Code Climate.

@jaybuidl jaybuidl merged commit 25b462b into dev Feb 5, 2025
6 of 7 checks passed
@jaybuidl jaybuidl deleted the feat/snapshot-proxy branch February 5, 2025 20:30
Copy link

sonarqubecloud bot commented Feb 5, 2025

@coderabbitai coderabbitai bot mentioned this pull request Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants