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

Improve resolvers change #58

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/contracts/hints/SlasherHints.sol
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ contract VetoSlasherHints is Hints, VetoSlasher {
uint48 captureTimestamp
) external view returns (bytes memory) {
bytes memory captureResolverHint = resolverHint(slasher, subnetwork, captureTimestamp);
bytes memory currentResolverHint = resolverHint(slasher, subnetwork, Time.timestamp());
bytes memory currentResolverHint = resolverHint(slasher, subnetwork, Time.timestamp() - 1);
bytes memory slashableStakeHints =
BaseSlasherHints(BASE_SLASHER_HINTS).slashableStakeHints(slasher, subnetwork, operator, captureTimestamp);

Expand All @@ -214,7 +214,7 @@ contract VetoSlasherHints is Hints, VetoSlasher {
uint48 captureTimestamp
) external view returns (bytes memory) {
bytes memory captureResolverHint = resolverHint(slasher, subnetwork, captureTimestamp);
bytes memory currentResolverHint = resolverHint(slasher, subnetwork, Time.timestamp());
bytes memory currentResolverHint = resolverHint(slasher, subnetwork, Time.timestamp() - 1);

if (captureResolverHint.length > 0 || currentResolverHint.length > 0) {
return abi.encode(
Expand Down
22 changes: 13 additions & 9 deletions src/contracts/slasher/VetoSlasher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ contract VetoSlasher is BaseSlasher, IVetoSlasher {
if (
resolverAt(request.subnetwork, request.captureTimestamp, executeSlashHints.captureResolverHint)
!= address(0)
&& resolverAt(request.subnetwork, Time.timestamp(), executeSlashHints.currentResolverHint) != address(0)
&& resolverAt(request.subnetwork, Time.timestamp() - 1, executeSlashHints.currentResolverHint) != address(0)
&& request.vetoDeadline > Time.timestamp()
) {
revert VetoPeriodNotEnded();
Expand Down Expand Up @@ -205,7 +205,7 @@ contract VetoSlasher is BaseSlasher, IVetoSlasher {
resolverAt(request.subnetwork, request.captureTimestamp, vetoSlashHints.captureResolverHint);
if (
captureResolver == address(0)
|| resolverAt(request.subnetwork, Time.timestamp(), vetoSlashHints.currentResolverHint) == address(0)
|| resolverAt(request.subnetwork, Time.timestamp() - 1, vetoSlashHints.currentResolverHint) == address(0)
) {
revert NoResolver();
}
Expand Down Expand Up @@ -239,13 +239,17 @@ contract VetoSlasher is BaseSlasher, IVetoSlasher {

address vault_ = vault;
bytes32 subnetwork = (msg.sender).subnetwork(identifier);
uint48 timestamp = resolver(subnetwork, setResolverHints.resolverHint) == address(0)
? Time.timestamp()
: (IVault(vault_).currentEpochStart() + resolverSetEpochsDelay * IVault(vault_).epochDuration()).toUint48();

(, uint48 latestTimestamp,) = _resolver[subnetwork].latestCheckpoint();
if (latestTimestamp > Time.timestamp()) {
_resolver[subnetwork].pop();
(bool exists, uint48 latestTimestamp,) = _resolver[subnetwork].latestCheckpoint();
uint48 timestamp;
if (exists) {
if (latestTimestamp > Time.timestamp()) {
_resolver[subnetwork].pop();
}

timestamp = (IVault(vault_).currentEpochStart() + resolverSetEpochsDelay * IVault(vault_).epochDuration())
.toUint48();
} else {
timestamp = Time.timestamp();
}

_resolver[subnetwork].push(timestamp, uint160(resolver_));
Expand Down
30 changes: 27 additions & 3 deletions test/slasher/VetoSlasher.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,36 @@ contract VetoSlasherTest is Test {
);
assertEq(slasher.resolver(network.subnetwork(0), ""), resolver1);

_setResolver(network, 0, resolver1, "");
_setResolver(network, 0, address(0), "");

assertEq(
slasher.resolverAt(network.subnetwork(0), uint48(blockTimestamp + 2 * vault.epochDuration()), ""), resolver1
);
assertEq(slasher.resolver(network.subnetwork(0), ""), resolver1);
assertEq(
slasher.resolverAt(network.subnetwork(0), uint48(blockTimestamp + 3 * vault.epochDuration()), ""),
address(0)
);

blockTimestamp = blockTimestamp + 3 * vault.epochDuration();
vm.warp(blockTimestamp);

assertEq(
slasher.resolverAt(network.subnetwork(0), uint48(blockTimestamp + 3 * vault.epochDuration()), ""),
address(0)
);
assertEq(slasher.resolver(network.subnetwork(0), ""), address(0));

_setResolver(network, 0, resolver1, "");

assertEq(
slasher.resolverAt(network.subnetwork(0), uint48(blockTimestamp + 2 * vault.epochDuration()), ""),
address(0)
);
assertEq(
slasher.resolverAt(network.subnetwork(0), uint48(blockTimestamp + 3 * vault.epochDuration()), ""), resolver1
);
assertEq(slasher.resolver(network.subnetwork(0), ""), address(0));
}

function test_setResolverRevertNotNetwork(uint48 epochDuration, uint48 vetoDuration) public {
Expand Down Expand Up @@ -1023,7 +1047,7 @@ contract VetoSlasherTest is Test {

_setResolver(alice, 0, address(0), "");

blockTimestamp = blockTimestamp + 3 * epochDuration;
blockTimestamp = blockTimestamp + 3 * epochDuration + 1;
vm.warp(blockTimestamp);

uint256 slashAmountReal1 =
Expand Down Expand Up @@ -1693,7 +1717,7 @@ contract VetoSlasherTest is Test {

_setResolver(alice, 0, address(0), "");

blockTimestamp = blockTimestamp + 3 * epochDuration;
blockTimestamp = blockTimestamp + 3 * epochDuration + 1;
vm.warp(blockTimestamp);

slashAmount1 = Math.min(slashAmount1, Math.min(depositAmount, Math.min(networkLimit, operatorNetworkLimit1)));
Expand Down
Loading