-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhEvm.sol
More file actions
164 lines (143 loc) · 7.73 KB
/
PhEvm.sol
File metadata and controls
164 lines (143 loc) · 7.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
/// @title PhEvm
/// @author Phylax Systems
/// @notice Precompile interface for accessing transaction state within assertions
/// @dev This interface provides access to the Credible Layer's execution environment,
/// allowing assertions to inspect transaction state, logs, call inputs, and storage changes.
/// The precompile is available at a deterministic address during assertion execution.
interface PhEvm {
/// @notice Represents an Ethereum log emitted during transaction execution
/// @dev Used by getLogs() to return transaction logs for inspection
struct Log {
/// @notice The topics of the log, including the event signature if any
bytes32[] topics;
/// @notice The raw ABI-encoded data of the log
bytes data;
/// @notice The address of the contract that emitted the log
address emitter;
}
/// @notice Represents the inputs to a call made during transaction execution
/// @dev Used by getCallInputs() and related functions to inspect call details
struct CallInputs {
/// @notice The calldata of the call
bytes input;
/// @notice The gas limit of the call
uint64 gas_limit;
/// @notice The address of the bytecode being executed (code address)
address bytecode_address;
/// @notice The target address whose storage may be modified
address target_address;
/// @notice The address that initiated this call
address caller;
/// @notice The ETH value sent with the call
uint256 value;
/// @notice Unique identifier for this call, used with forkPreCall/forkPostCall
uint256 id;
}
/// @notice Contains data about the original assertion-triggering transaction
/// @dev Provides access to transaction envelope data for inspection in assertions
struct TxObject {
/// @notice The address that initiated the transaction (tx.origin equivalent)
address from;
/// @notice The transaction recipient, or address(0) for contract creation
address to;
/// @notice The ETH value sent with the transaction
uint256 value;
/// @notice The chain ID, or 0 if not present
uint64 chain_id;
/// @notice The gas limit for the transaction
uint64 gas_limit;
/// @notice The gas price or max_fee_per_gas for EIP-1559 transactions
uint128 gas_price;
/// @notice The transaction calldata
bytes input;
}
/// @notice Identifies a read-only transaction snapshot.
/// @dev forkType: 0 = PreTx, 1 = PostTx, 2 = PreCall, 3 = PostCall
/// callIndex is used only for call-scoped snapshots.
struct ForkId {
uint8 forkType;
uint256 callIndex;
}
/// @notice Fork to the state before the assertion-triggering transaction
/// @dev Allows inspection of pre-transaction state for comparison
function forkPreTx() external;
/// @notice Fork to the state after the assertion-triggering transaction
/// @dev Allows inspection of post-transaction state for validation
function forkPostTx() external;
/// @notice Fork to the state before a specific call execution
/// @dev Useful for inspecting state at specific points during transaction execution
/// @param id The call identifier from CallInputs.id
function forkPreCall(uint256 id) external;
/// @notice Fork to the state after a specific call execution
/// @dev Useful for inspecting state changes from specific calls
/// @param id The call identifier from CallInputs.id
function forkPostCall(uint256 id) external;
/// @notice Load a storage slot value from any address
/// @param target The address to read storage from
/// @param slot The storage slot to read
/// @return data The value stored at the slot
function load(address target, bytes32 slot) external view returns (bytes32 data);
/// @notice Read a storage slot from the current assertion adopter at a snapshot.
/// @param slot The storage slot to read.
/// @param fork The snapshot fork to read from.
/// @return value The raw 32-byte value at the slot.
function loadStateAt(bytes32 slot, ForkId calldata fork) external view returns (bytes32 value);
/// @notice Read a storage slot from any account at a snapshot.
/// @param target The address to read storage from.
/// @param slot The storage slot to read.
/// @param fork The snapshot fork to read from.
/// @return value The raw 32-byte value at the slot.
function loadStateAt(address target, bytes32 slot, ForkId calldata fork)
external
view
returns (bytes32 value);
/// @notice Get all logs emitted during the transaction
/// @dev Returns logs in emission order
/// @return logs Array of Log structs containing all emitted events
function getLogs() external returns (Log[] memory logs);
/// @notice Get all call inputs for a target and selector (all call types)
/// @dev Includes CALL, STATICCALL, DELEGATECALL, and CALLCODE
/// @param target The target contract address
/// @param selector The function selector to filter by
/// @return calls Array of CallInputs matching the criteria
function getAllCallInputs(address target, bytes4 selector) external view returns (CallInputs[] memory calls);
/// @notice Get call inputs for regular CALL opcode only
/// @param target The target contract address
/// @param selector The function selector to filter by
/// @return calls Array of CallInputs from CALL opcodes
function getCallInputs(address target, bytes4 selector) external view returns (CallInputs[] memory calls);
/// @notice Get call inputs for STATICCALL opcode only
/// @param target The target contract address
/// @param selector The function selector to filter by
/// @return calls Array of CallInputs from STATICCALL opcodes
function getStaticCallInputs(address target, bytes4 selector) external view returns (CallInputs[] memory calls);
/// @notice Get call inputs for DELEGATECALL opcode only
/// @param target The target/proxy contract address
/// @param selector The function selector to filter by
/// @return calls Array of CallInputs from DELEGATECALL opcodes
function getDelegateCallInputs(address target, bytes4 selector) external view returns (CallInputs[] memory calls);
/// @notice Get call inputs for CALLCODE opcode only
/// @param target The target contract address
/// @param selector The function selector to filter by
/// @return calls Array of CallInputs from CALLCODE opcodes
function getCallCodeInputs(address target, bytes4 selector) external view returns (CallInputs[] memory calls);
/// @notice Get all state changes for a specific storage slot
/// @dev Returns the sequence of values the slot held during transaction execution
/// @param contractAddress The contract whose storage to inspect
/// @param slot The storage slot to get changes for
/// @return stateChanges Array of values the slot held (in order of changes)
function getStateChanges(address contractAddress, bytes32 slot)
external
view
returns (bytes32[] memory stateChanges);
/// @notice Get the assertion adopter address for the current transaction
/// @dev The adopter is the contract that registered the assertion
/// @return The address of the assertion adopter contract
function getAssertionAdopter() external view returns (address);
/// @notice Get the original transaction object that triggered the assertion
/// @dev Returns the transaction envelope data for the assertion-triggering tx
/// @return txObject The transaction data struct
function getTxObject() external view returns (TxObject memory txObject);
}