forked from lambdaclass/starknet_in_rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_syscalls.cairo
163 lines (137 loc) · 3.82 KB
/
new_syscalls.cairo
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
// Syscall selectors.
const CALL_CONTRACT_SELECTOR = 'CallContract';
const DEPLOY_SELECTOR = 'Deploy';
const EMIT_EVENT_SELECTOR = 'EmitEvent';
const GET_EXECUTION_INFO_SELECTOR = 'GetExecutionInfo';
const LIBRARY_CALL_SELECTOR = 'LibraryCall';
const REPLACE_CLASS_SELECTOR = 'ReplaceClass';
const SEND_MESSAGE_TO_L1_SELECTOR = 'SendMessageToL1';
const STORAGE_READ_SELECTOR = 'StorageRead';
const STORAGE_WRITE_SELECTOR = 'StorageWrite';
// Syscall structs.
struct ExecutionInfo {
block_info: BlockInfo*,
tx_info: TxInfo*,
// Entry-point-specific info.
caller_address: felt,
// The execution is done in the context of the contract at this address.
// It controls the storage being used, messages sent to L1, calling contracts, etc.
contract_address: felt,
// The entry point selector.
selector: felt,
}
struct BlockInfo {
block_number: felt,
block_timestamp: felt,
// The address of the sequencer that is creating this block.
sequencer_address: felt,
}
struct TxInfo {
// The version of the transaction. It is fixed in the OS, and should be signed by the account
// contract.
// This field allows invalidating old transactions, whenever the meaning of the other
// transaction fields is changed (in the OS).
version: felt,
// The account contract from which this transaction originates.
account_contract_address: felt,
// The max_fee field of the transaction.
max_fee: felt,
// The signature of the transaction.
signature_start: felt*,
signature_end: felt*,
// The hash of the transaction.
transaction_hash: felt,
// The identifier of the chain.
// This field can be used to prevent replay of testnet transactions on mainnet.
chain_id: felt,
// The transaction's nonce.
nonce: felt,
}
// Shared attributes.
struct RequestHeader {
// The syscall selector.
selector: felt,
// The amount of gas left before the syscall execution.
gas: felt,
}
struct ResponseHeader {
// The amount of gas left after the syscall execution.
gas: felt,
// 0 if the syscall succeeded; 1 otherwise.
failure_flag: felt,
}
struct FailureReason {
start: felt*,
end: felt*,
}
// Syscall requests.
struct CallContractRequest {
// The address of the L2 contract to call.
contract_address: felt,
// The selector of the function to call.
selector: felt,
// The calldata.
calldata_start: felt*,
calldata_end: felt*,
}
struct LibraryCallRequest {
// The hash of the class to run.
class_hash: felt,
// The selector of the function to call.
selector: felt,
// The calldata.
calldata_start: felt*,
calldata_end: felt*,
}
struct EmptyRequest {
}
struct DeployRequest {
// The hash of the class to deploy.
class_hash: felt,
// A salt for the new contract address calculation.
contract_address_salt: felt,
// The calldata for the constructor.
constructor_calldata_start: felt*,
constructor_calldata_end: felt*,
// Used for deterministic contract address deployment.
deploy_from_zero: felt,
}
struct StorageReadRequest {
reserved: felt,
key: felt,
}
struct StorageWriteRequest {
reserved: felt,
key: felt,
value: felt,
}
struct EmitEventRequest {
keys_start: felt*,
keys_end: felt*,
data_start: felt*,
data_end: felt*,
}
struct ReplaceClassRequest {
class_hash: felt,
}
struct SendMessageToL1Request {
to_address: felt,
payload_start: felt*,
payload_end: felt*,
}
// Syscall responses.
struct CallContractResponse {
retdata_start: felt*,
retdata_end: felt*,
}
struct DeployResponse {
contract_address: felt,
constructor_retdata_start: felt*,
constructor_retdata_end: felt*,
}
struct StorageReadResponse {
value: felt,
}
struct GetExecutionInfoResponse {
execution_info: ExecutionInfo*,
}