Skip to content

Commit

Permalink
Constrain uninitialized memory to 0 (#1318)
Browse files Browse the repository at this point in the history
  • Loading branch information
hratoanina authored Nov 3, 2023
1 parent f71f227 commit d2b549a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions evm/src/memory/memory_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,14 @@ impl<F: RichField + Extendable<D>, const D: usize> Stark<F, D> for MemoryStark<F
yield_constr.constraint_transition(range_check - computed_range_check);

// Enumerate purportedly-ordered log.
// We assume that memory is initialized with 0. This means that if the first operation of a new address
// is a read, then its value must be 0.
for i in 0..8 {
yield_constr.constraint_transition(
next_is_read * address_unchanged * (next_values_limbs[i] - value_limbs[i]),
);
yield_constr
.constraint_transition(next_is_read * not_address_unchanged * next_values_limbs[i]);
}
}

Expand Down Expand Up @@ -445,11 +449,17 @@ impl<F: RichField + Extendable<D>, const D: usize> Stark<F, D> for MemoryStark<F
yield_constr.constraint_transition(builder, range_check_diff);

// Enumerate purportedly-ordered log.
// We assume that memory is initialized with 0. This means that if the first operation of a new address
// is a read, then its value must be 0.
for i in 0..8 {
let value_diff = builder.sub_extension(next_values_limbs[i], value_limbs[i]);
let zero_if_read = builder.mul_extension(address_unchanged, value_diff);
let read_constraint = builder.mul_extension(next_is_read, zero_if_read);
yield_constr.constraint_transition(builder, read_constraint);
let first_read_value =
builder.mul_extension(next_values_limbs[i], not_address_unchanged);
let first_read_constraint = builder.mul_extension(first_read_value, next_is_read);
yield_constr.constraint_transition(builder, first_read_constraint);
}
}

Expand Down

0 comments on commit d2b549a

Please sign in to comment.