Skip to content

Commit

Permalink
fix: statemind - inconsistent reset hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
1kresh committed Dec 27, 2024
1 parent 2d75430 commit 3305e47
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
16 changes: 9 additions & 7 deletions src/contracts/fullRestakeDelegator/FullRestakeResetHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ contract FullRestakeResetHook is IFullRestakeResetHook {
*/
uint256 public immutable SLASH_COUNT;

mapping(address vault => mapping(address operator => CircularBuffer.Bytes32CircularBuffer buffer)) private
_slashings;
mapping(
address vault
=> mapping(bytes32 subnetwork => mapping(address operator => CircularBuffer.Bytes32CircularBuffer buffer))
) private _slashings;

constructor(uint48 period, uint256 slashCount) {
if (slashCount == 0) {
Expand Down Expand Up @@ -56,19 +58,19 @@ contract FullRestakeResetHook is IFullRestakeResetHook {
revert NotVaultDelegator();
}

if (_slashings[vault][operator].count() == 0) {
_slashings[vault][operator].setup(SLASH_COUNT);
if (_slashings[vault][subnetwork][operator].count() == 0) {
_slashings[vault][subnetwork][operator].setup(SLASH_COUNT);
}

if (IFullRestakeDelegator(msg.sender).operatorNetworkLimit(subnetwork, operator) == 0) {
return;
}

_slashings[vault][operator].push(bytes32(uint256(Time.timestamp())));
_slashings[vault][subnetwork][operator].push(bytes32(uint256(Time.timestamp())));

if (
_slashings[vault][operator].count() == SLASH_COUNT
&& Time.timestamp() - uint256(_slashings[vault][operator].last(SLASH_COUNT - 1)) <= PERIOD
_slashings[vault][subnetwork][operator].count() == SLASH_COUNT
&& Time.timestamp() - uint256(_slashings[vault][subnetwork][operator].last(SLASH_COUNT - 1)) <= PERIOD
) {
IFullRestakeDelegator(msg.sender).setOperatorNetworkLimit(subnetwork, operator, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ contract NetworkRestakeResetHook is INetworkRestakeResetHook {
*/
uint256 public immutable SLASH_COUNT;

mapping(address vault => mapping(address operator => CircularBuffer.Bytes32CircularBuffer buffer)) private
_slashings;
mapping(
address vault
=> mapping(bytes32 subnetwork => mapping(address operator => CircularBuffer.Bytes32CircularBuffer buffer))
) private _slashings;

constructor(uint48 period, uint256 slashCount) {
if (slashCount == 0) {
Expand Down Expand Up @@ -56,19 +58,19 @@ contract NetworkRestakeResetHook is INetworkRestakeResetHook {
revert NotVaultDelegator();
}

if (_slashings[vault][operator].count() == 0) {
_slashings[vault][operator].setup(SLASH_COUNT);
if (_slashings[vault][subnetwork][operator].count() == 0) {
_slashings[vault][subnetwork][operator].setup(SLASH_COUNT);
}

if (INetworkRestakeDelegator(msg.sender).operatorNetworkShares(subnetwork, operator) == 0) {
return;
}

_slashings[vault][operator].push(bytes32(uint256(Time.timestamp())));
_slashings[vault][subnetwork][operator].push(bytes32(uint256(Time.timestamp())));

if (
_slashings[vault][operator].count() == SLASH_COUNT
&& Time.timestamp() - uint256(_slashings[vault][operator].last(SLASH_COUNT - 1)) <= PERIOD
_slashings[vault][subnetwork][operator].count() == SLASH_COUNT
&& Time.timestamp() - uint256(_slashings[vault][subnetwork][operator].last(SLASH_COUNT - 1)) <= PERIOD
) {
INetworkRestakeDelegator(msg.sender).setOperatorNetworkShares(subnetwork, operator, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ contract OperatorSpecificResetHook is IOperatorSpecificResetHook {
*/
uint256 public immutable SLASH_COUNT;

mapping(address vault => CircularBuffer.Bytes32CircularBuffer buffer) private _slashings;
mapping(address vault => mapping(bytes32 subnetwork => CircularBuffer.Bytes32CircularBuffer buffer)) private
_slashings;

constructor(uint48 period, uint256 slashCount) {
if (slashCount == 0) {
Expand Down Expand Up @@ -55,19 +56,19 @@ contract OperatorSpecificResetHook is IOperatorSpecificResetHook {
revert NotVaultDelegator();
}

if (_slashings[vault].count() == 0) {
_slashings[vault].setup(SLASH_COUNT);
if (_slashings[vault][subnetwork].count() == 0) {
_slashings[vault][subnetwork].setup(SLASH_COUNT);
}

if (IOperatorSpecificDelegator(msg.sender).networkLimit(subnetwork) == 0) {
return;
}

_slashings[vault].push(bytes32(uint256(Time.timestamp())));
_slashings[vault][subnetwork].push(bytes32(uint256(Time.timestamp())));

if (
_slashings[vault].count() == SLASH_COUNT
&& Time.timestamp() - uint256(_slashings[vault].last(SLASH_COUNT - 1)) <= PERIOD
_slashings[vault][subnetwork].count() == SLASH_COUNT
&& Time.timestamp() - uint256(_slashings[vault][subnetwork].last(SLASH_COUNT - 1)) <= PERIOD
) {
IOperatorSpecificDelegator(msg.sender).setNetworkLimit(subnetwork, 0);
}
Expand Down

0 comments on commit 3305e47

Please sign in to comment.