Skip to content

Commit 17adcd6

Browse files
authored
feat: add spec registration (#43)
* feat: add spec stuff * fix: update specRecorder address
1 parent 7b803cd commit 17adcd6

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/Assertion.sol

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pragma solidity ^0.8.13;
33

44
import {Credible} from "./Credible.sol";
55
import {TriggerRecorder} from "./TriggerRecorder.sol";
6+
import {SpecRecorder, AssertionSpec} from "./SpecRecorder.sol";
67
import {StateChanges} from "./StateChanges.sol";
78

89
/// @title Assertion
@@ -30,6 +31,10 @@ abstract contract Assertion is Credible, StateChanges {
3031
/// @dev Address is derived from a deterministic hash for consistency
3132
TriggerRecorder constant triggerRecorder = TriggerRecorder(address(uint160(uint256(keccak256("TriggerRecorder")))));
3233

34+
/// @notice The spec recorder precompile for registering the assertion spec
35+
/// @dev Address is derived from keccak256("SpecRecorder")
36+
SpecRecorder constant specRecorder = SpecRecorder(address(uint160(uint256(keccak256("SpecRecorder")))));
37+
3338
/// @notice Used to record fn selectors and their triggers.
3439
function triggers() external view virtual;
3540

@@ -65,4 +70,12 @@ abstract contract Assertion is Credible, StateChanges {
6570
function registerBalanceChangeTrigger(bytes4 fnSelector) internal view {
6671
triggerRecorder.registerBalanceChangeTrigger(fnSelector);
6772
}
73+
74+
/// @notice Registers the desired assertion spec. Must be called within the constructor.
75+
/// The assertion spec defines what subset of precompiles are available.
76+
/// Can only be called once. For an assertion to be valid, it needs a defined spec.
77+
/// @param spec The desired AssertionSpec.
78+
function registerAssertionSpec(AssertionSpec spec) internal view {
79+
specRecorder.registerAssertionSpec(spec);
80+
}
6881
}

src/SpecRecorder.sol

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.13;
3+
4+
/// @notice The assertion spec defines what subset of precompiles are available.
5+
/// All new specs derive and expose all precompiles from the old definitions,
6+
/// unless specified otherwise.
7+
enum AssertionSpec {
8+
/// @notice Standard set of PhEvm precompiles available at launch.
9+
Legacy,
10+
/// @notice Contains tx object precompiles.
11+
Reshiram,
12+
/// @notice Unrestricted access to all available precompiles. May be untested and dangerous.
13+
Experimental
14+
}
15+
16+
/// @title SpecRecorder
17+
/// @author Phylax Systems
18+
/// @notice Precompile interface for registering the desired assertion spec
19+
/// @dev Used within the constructor of assertion contracts to specify which
20+
/// subset of PhEvm precompiles should be available during assertion execution.
21+
/// You can only call registerAssertionSpec once per assertion.
22+
interface SpecRecorder {
23+
/// @notice Called within the constructor to set the desired assertion spec.
24+
/// The assertion spec defines what subset of precompiles are available.
25+
/// You can only call this function once. For an assertion to be valid,
26+
/// it needs to have a defined spec.
27+
/// @param spec The desired AssertionSpec.
28+
function registerAssertionSpec(AssertionSpec spec) external view;
29+
}

0 commit comments

Comments
 (0)