@@ -4,14 +4,19 @@ use serde::{Deserialize, Serialize};
4
4
5
5
pub type Label = usize ;
6
6
7
+ /// Represents an address in the VM's memory.
8
+ /// Supports both direct and relative addressing.
7
9
#[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash , Serialize , Deserialize ) ]
8
10
#[ cfg_attr( feature = "arb" , derive( proptest_derive:: Arbitrary ) ) ]
9
11
pub enum MemoryAddress {
12
+ /// Specifies an exact index in the VM's memory
10
13
Direct ( usize ) ,
14
+ /// Specifies an index relative to the stack pointer.
15
+ ///
16
+ /// It is resolved as the current stack pointer plus the offset stored here.
11
17
Relative ( usize ) ,
12
18
}
13
19
14
- /// `MemoryAddress` refers to the index in VM memory.
15
20
impl MemoryAddress {
16
21
pub fn direct ( address : usize ) -> Self {
17
22
MemoryAddress :: Direct ( address)
@@ -209,7 +214,7 @@ pub enum ValueOrArray {
209
214
pub enum BrilligOpcode < F > {
210
215
/// Takes the fields in addresses `lhs` and `rhs`
211
216
/// Performs the specified binary operation
212
- /// and stores the value in the `result ` address.
217
+ /// and stores the value in the `destination ` address.
213
218
BinaryFieldOp {
214
219
destination : MemoryAddress ,
215
220
op : BinaryFieldOp ,
@@ -218,7 +223,7 @@ pub enum BrilligOpcode<F> {
218
223
} ,
219
224
/// Takes the `bit_size` size integers in addresses `lhs` and `rhs`
220
225
/// Performs the specified binary operation
221
- /// and stores the value in the `result ` address.
226
+ /// and stores the value in the `destination ` address.
222
227
BinaryIntOp {
223
228
destination : MemoryAddress ,
224
229
op : BinaryIntOp ,
@@ -236,17 +241,19 @@ pub enum BrilligOpcode<F> {
236
241
source : MemoryAddress ,
237
242
bit_size : BitSize ,
238
243
} ,
244
+ /// Sets the program counter to the value of `location` if
245
+ /// the value at the `condition` address is zero.
239
246
JumpIfNot {
240
247
condition : MemoryAddress ,
241
248
location : Label ,
242
249
} ,
243
- /// Sets the program counter to the value located at `destination `
250
+ /// Sets the program counter to the value of `location `
244
251
/// If the value at `condition` is non-zero
245
252
JumpIf {
246
253
condition : MemoryAddress ,
247
254
location : Label ,
248
255
} ,
249
- /// Sets the program counter to the label .
256
+ /// Sets the program counter to the value of `location` .
250
257
Jump {
251
258
location : Label ,
252
259
} ,
@@ -258,19 +265,27 @@ pub enum BrilligOpcode<F> {
258
265
} ,
259
266
/// We don't support dynamic jumps or calls
260
267
/// See <https://github.com/ethereum/aleth/issues/3404> for reasoning
268
+ ///
269
+ /// Pushes the current program counter to the call stack as to set a return location.
270
+ /// Sets the program counter to the value of `location`.
261
271
Call {
262
272
location : Label ,
263
273
} ,
274
+ /// Stores a constant `value` with a `bit_size` in the `destination` address.
264
275
Const {
265
276
destination : MemoryAddress ,
266
277
bit_size : BitSize ,
267
278
value : F ,
268
279
} ,
280
+ /// Reads the address from `destination_pointer`, then stores a constant `value` with a `bit_size` at that address.
269
281
IndirectConst {
270
282
destination_pointer : MemoryAddress ,
271
283
bit_size : BitSize ,
272
284
value : F ,
273
285
} ,
286
+ /// Pops the top element from the call stack, which represents the return location,
287
+ /// and sets the program counter to that value. This operation is used to return
288
+ /// from a function call.
274
289
Return ,
275
290
/// Used to get data from an outside source.
276
291
/// Also referred to as an Oracle. However, we don't use that name as
@@ -290,6 +305,7 @@ pub enum BrilligOpcode<F> {
290
305
/// retrieve the elements)
291
306
input_value_types : Vec < HeapValueType > ,
292
307
} ,
308
+ /// Moves the content in the `source` address to the `destination` address.
293
309
Mov {
294
310
destination : MemoryAddress ,
295
311
source : MemoryAddress ,
@@ -301,20 +317,26 @@ pub enum BrilligOpcode<F> {
301
317
source_b : MemoryAddress ,
302
318
condition : MemoryAddress ,
303
319
} ,
320
+ /// Reads the `source_pointer` to obtain a memory address, then retrieves the data
321
+ /// stored at that address and writes it to the `destination` address.
304
322
Load {
305
323
destination : MemoryAddress ,
306
324
source_pointer : MemoryAddress ,
307
325
} ,
326
+ /// Reads the `destination_pointer` to obtain a memory address, then stores the value
327
+ /// from the `source` address at that location.
308
328
Store {
309
329
destination_pointer : MemoryAddress ,
310
330
source : MemoryAddress ,
311
331
} ,
332
+ /// Native functions in the VM.
333
+ /// These are equivalent to the black box functions in ACIR.
312
334
BlackBox ( BlackBoxOp ) ,
313
- /// Used to denote execution failure, returning data after the offset
335
+ /// Used to denote execution failure, halting the VM and returning data specified by a dynamically-sized vector.
314
336
Trap {
315
337
revert_data : HeapVector ,
316
338
} ,
317
- /// Stop execution, returning data after the offset
339
+ /// Halts execution and returns data specified by a dynamically-sized vector.
318
340
Stop {
319
341
return_data : HeapVector ,
320
342
} ,
0 commit comments