-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
67 changed files
with
1,698 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2024 Aztec Labs. | ||
pragma solidity >=0.8.27; | ||
|
||
import {IPayload} from "@aztec/governance/interfaces/IPayload.sol"; | ||
|
||
interface ISlasher { | ||
function slash(IPayload _payload) external returns (bool); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2024 Aztec Labs. | ||
pragma solidity >=0.8.27; | ||
|
||
import {ISlasher} from "@aztec/core/interfaces/ISlasher.sol"; | ||
import {SlashingProposer} from "@aztec/core/staking/SlashingProposer.sol"; | ||
import {IPayload} from "@aztec/governance/interfaces/IPayload.sol"; | ||
|
||
contract Slasher is ISlasher { | ||
SlashingProposer public immutable PROPOSER; | ||
|
||
event SlashFailed(address target, bytes data, bytes returnData); | ||
|
||
error Slasher__CallerNotProposer(address caller, address proposer); // 0x44c1f74f | ||
|
||
constructor(uint256 _n, uint256 _m) { | ||
PROPOSER = new SlashingProposer(msg.sender, this, _n, _m); | ||
} | ||
|
||
function slash(IPayload _payload) external override(ISlasher) returns (bool) { | ||
require( | ||
msg.sender == address(PROPOSER), Slasher__CallerNotProposer(msg.sender, address(PROPOSER)) | ||
); | ||
|
||
IPayload.Action[] memory actions = _payload.getActions(); | ||
|
||
for (uint256 i = 0; i < actions.length; i++) { | ||
// Allow failure of individual calls but emit the failure! | ||
(bool success, bytes memory returnData) = actions[i].target.call(actions[i].data); | ||
if (!success) { | ||
emit SlashFailed(actions[i].target, actions[i].data, returnData); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2024 Aztec Labs. | ||
pragma solidity >=0.8.27; | ||
|
||
import {ISlasher} from "@aztec/core/interfaces/ISlasher.sol"; | ||
import {IGovernanceProposer} from "@aztec/governance/interfaces/IGovernanceProposer.sol"; | ||
import {IPayload} from "@aztec/governance/interfaces/IPayload.sol"; | ||
import {EmpireBase} from "@aztec/governance/proposer/EmpireBase.sol"; | ||
|
||
/** | ||
* @notice A SlashingProposer implementation following the empire model | ||
*/ | ||
contract SlashingProposer is IGovernanceProposer, EmpireBase { | ||
address public immutable INSTANCE; | ||
ISlasher public immutable SLASHER; | ||
|
||
constructor(address _instance, ISlasher _slasher, uint256 _slashingQuorum, uint256 _roundSize) | ||
EmpireBase(_slashingQuorum, _roundSize) | ||
{ | ||
INSTANCE = _instance; | ||
SLASHER = _slasher; | ||
} | ||
|
||
function getExecutor() public view override(EmpireBase, IGovernanceProposer) returns (address) { | ||
return address(SLASHER); | ||
} | ||
|
||
function getInstance() public view override(EmpireBase, IGovernanceProposer) returns (address) { | ||
return INSTANCE; | ||
} | ||
|
||
function _execute(IPayload _proposal) internal override(EmpireBase) returns (bool) { | ||
return SLASHER.slash(_proposal); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.