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(ethexe): Support slash commitments in router #4403

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

ukint-vs
Copy link
Member

@ukint-vs ukint-vs commented Dec 13, 2024

Resolves #4383 .

  • implement IMiddleware
  • implement request/execute slash commitment in Router
  • add test in POC

@reviewer-or-team

@ukint-vs ukint-vs added the A1-inprogress Issue is in progress or PR draft is not ready to be reviewed label Dec 13, 2024
@ukint-vs ukint-vs self-assigned this Dec 13, 2024
@ukint-vs ukint-vs changed the title feat(ethexe): Support slash in router feat(ethexe): Support slash commitments in router Dec 17, 2024
@ukint-vs ukint-vs marked this pull request as ready for review December 18, 2024 09:59
@ukint-vs ukint-vs added A0-pleasereview PR is ready to be reviewed by the team C1-feature Feature request and removed A1-inprogress Issue is in progress or PR draft is not ready to be reviewed labels Dec 18, 2024
@@ -34,6 +36,7 @@ contract DeploymentScript is Script {

address mirrorAddress = vm.computeCreateAddress(deployerAddress, vm.getNonce(deployerAddress) + 2);
address mirrorProxyAddress = vm.computeCreateAddress(deployerAddress, vm.getNonce(deployerAddress) + 3);
address middlewareAddress = vm.computeCreateAddress(deployerAddress, vm.getNonce(deployerAddress) + 4);

Choose a reason for hiding this comment

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

vm.computeCreateAddress(deployerAddress, deployerNonce) is used to compute the future contract address. after mirrorProxy = new MirrorProxy(address(router)) you need to create middleware to make this address valid.

@@ -154,6 +154,7 @@ impl Ethereum {
_mirror: mirror_address,
_mirrorProxy: mirror_proxy_address,
_wrappedVara: wvara_address,
_middleware: Address::default(),

Choose a reason for hiding this comment

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

this place should be the same as ethexe/contracts/script/Deployment.s.sol

Choose a reason for hiding this comment

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

I think you can do it in the next PR such as #4403 for the Rust part, and do the Solidity part in this PR

Comment on lines +73 to +79
event RequestSlashCommitmentProcessed(bytes32 indexed commitmentHash, IMiddleware.SlashData[] slashData);

/**
* @dev Emitted when a slash request is executed by the middleware.
* @param slashId An array of SlashIdentifier structures containing details of the slash execution.
*/
event ExecuteSlashCommitmentProcessed(bytes32 indexed commitmentHash, IMiddleware.SlashIdentifier[] slashId);

Choose a reason for hiding this comment

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

indexed is not needed, because the observer is watching many events at once

Suggested change
event RequestSlashCommitmentProcessed(bytes32 indexed commitmentHash, IMiddleware.SlashData[] slashData);
/**
* @dev Emitted when a slash request is executed by the middleware.
* @param slashId An array of SlashIdentifier structures containing details of the slash execution.
*/
event ExecuteSlashCommitmentProcessed(bytes32 indexed commitmentHash, IMiddleware.SlashIdentifier[] slashId);
event RequestSlashCommitmentProcessed(bytes32 commitmentHash, IMiddleware.SlashData[] slashData);
/**
* @dev Emitted when a slash request is executed by the middleware.
* @param slashId An array of SlashIdentifier structures containing details of the slash execution.
*/
event ExecuteSlashCommitmentProcessed(bytes32 commitmentHash, IMiddleware.SlashIdentifier[] slashId);

vm.startPrank(admin);
{
middleware.changeSlashRequester(address(router));
middleware.changeSlashExecutor(address(router));
}
vm.stopPrank();

// For understanding where symbiotic ecosystem is using
sym = POCBaseTest(address(this));
Copy link
Member

Choose a reason for hiding this comment

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

Not used ?

import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol";
import {EnumerableMap} from "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
import "forge-std/Test.sol";

import {POCBaseTest} from "symbiotic-core/test/POCBase.t.sol";
Copy link
Member

Choose a reason for hiding this comment

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

Not used ?

@@ -101,6 +103,16 @@ library Gear {
Message[] messages;
}

struct RequestSlashCommitment {
Copy link
Member

Choose a reason for hiding this comment

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

Looks like better to use naming SlashRequestCommitment, SlashExecuteCommitment and the same in other places. Because when read function names like requestSlashCommitmentHash - this understands like a calling some function which send a request for hash.

uint256 currentEraIndex = (block.timestamp - router.genesisBlock.timestamp) / router.timelines.era;

// Validate the era index
require(commitment.eraIndex == currentEraIndex, "commitment era index is invalid");
Copy link
Member

Choose a reason for hiding this comment

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

Is not possible to sent a slash for the previous era? for example we found that validator from the previous era did something wrong - why we cannot to sent a slash for the funds it had in the previous era?

Copy link
Member

Choose a reason for hiding this comment

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

Ah now I can see. I think era param should be removed from commitment. Cannot see why do we need it. Slashes have already all informations about timestamps.

Comment on lines +343 to +344
uint256 eraStart = router.genesisBlock.timestamp + router.timelines.era * currentEraIndex;
require(block.timestamp >= eraStart, "current era has not started yet");
Copy link
Member

Choose a reason for hiding this comment

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

This is mathematically impossible case


// Ensure middleware is set
address middlewareAddress = router.implAddresses.middleware;
require(middlewareAddress != address(0), "Middleware address not set");
Copy link
Member

Choose a reason for hiding this comment

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

Not important: Looks like over-checking. This must be checked in constructor

// Call the middleware's `requestSlash` function
middlewareInstance.requestSlash(commitment.slashes);

emit RequestSlashCommitmentProcessed(commitmentHash, commitment.slashes);
Copy link
Member

Choose a reason for hiding this comment

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

I think is enough to sent a commitmentHash. This is cheaper. And validators could save their slashes in db by hash and access them if they need in future.

uint256 currentEraIndex = (block.timestamp - router.genesisTimestamp()) / eraDuration;
uint256 nextEraIndex = currentEraIndex + 1;

// Move to the election period for the next era
Copy link
Member

Choose a reason for hiding this comment

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

Your are not going to election period

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A0-pleasereview PR is ready to be reviewed by the team C1-feature Feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ethexe: support slashing in router
3 participants