Skip to content

Commit

Permalink
refactor: rename felt_array_to_ints into() felt_slice_to_ints()
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbinth committed Oct 3, 2024
1 parent fde47d0 commit a0e1076
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions stdlib/tests/collections/mmr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use test_utils::{
init_merkle_leaf, init_merkle_leaves, MerkleError, MerkleStore, MerkleTree, Mmr, NodeIndex,
RpoDigest,
},
felt_array_to_ints, hash_elements, Felt, StarkField, Word, EMPTY_WORD, ONE, ZERO,
felt_slice_to_ints, hash_elements, Felt, StarkField, Word, EMPTY_WORD, ONE, ZERO,
};

// TESTS
Expand Down Expand Up @@ -259,7 +259,7 @@ fn test_mmr_unpack() {
let hash = hash_elements(&hash_data.concat());

// Set up the VM stack with the MMR hash, and its target address
let mut stack = felt_array_to_ints(&*hash);
let mut stack = felt_slice_to_ints(&*hash);
let mmr_ptr = 1000_u32;
stack.insert(0, mmr_ptr as u64);

Expand Down Expand Up @@ -321,7 +321,7 @@ fn test_mmr_unpack_invalid_hash() {
let hash = hash_elements(&hash_data.concat());

// Set up the VM stack with the MMR hash, and its target address
let mut stack = felt_array_to_ints(&*hash);
let mut stack = felt_slice_to_ints(&*hash);
let mmr_ptr = 1000;
stack.insert(0, mmr_ptr);

Expand Down Expand Up @@ -383,7 +383,7 @@ fn test_mmr_unpack_large_mmr() {
let hash = hash_elements(&hash_data.concat());

// Set up the VM stack with the MMR hash, and its target address
let mut stack = felt_array_to_ints(&*hash);
let mut stack = felt_slice_to_ints(&*hash);
let mmr_ptr = 1000_u32;
stack.insert(0, mmr_ptr as u64);

Expand Down Expand Up @@ -443,7 +443,7 @@ fn test_mmr_pack_roundtrip() {
let hash = accumulator.hash_peaks();

// Set up the VM stack with the MMR hash, and its target address
let mut stack = felt_array_to_ints(&*hash);
let mut stack = felt_slice_to_ints(&*hash);
let mmr_ptr = 1000;
stack.insert(0, mmr_ptr); // first value is used by unpack, to load data to memory
stack.insert(0, mmr_ptr); // second is used by pack, to load data from memory
Expand Down Expand Up @@ -648,7 +648,7 @@ fn test_mmr_large_add_roundtrip() {
let hash = old_accumulator.hash_peaks();

// Set up the VM stack with the MMR hash, and its target address
let mut stack = felt_array_to_ints(&*hash);
let mut stack = felt_slice_to_ints(&*hash);
stack.insert(0, mmr_ptr as u64);

// both the advice stack and merkle store start empty (data is available in
Expand Down
12 changes: 6 additions & 6 deletions stdlib/tests/mem/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use processor::{ContextId, DefaultHost, ProcessState, Program};
use test_utils::{
build_expected_hash, build_expected_perm, felt_array_to_ints, ExecutionOptions, Process,
build_expected_hash, build_expected_perm, felt_slice_to_ints, ExecutionOptions, Process,
StackInputs, ONE, ZERO,
};

Expand Down Expand Up @@ -117,7 +117,7 @@ fn test_pipe_double_words_to_memory() {
let operand_stack = &[];
let data = &[1, 2, 3, 4, 5, 6, 7, 8];
let mut expected_stack =
felt_array_to_ints(&build_expected_perm(&[0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8]));
felt_slice_to_ints(&build_expected_perm(&[0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8]));
expected_stack.push(1002);
build_test!(source, operand_stack, &data).expect_stack_and_memory(
&expected_stack,
Expand All @@ -144,7 +144,7 @@ fn test_pipe_words_to_memory() {

let operand_stack = &[];
let data = &[1, 2, 3, 4];
let mut expected_stack = felt_array_to_ints(&build_expected_hash(data));
let mut expected_stack = felt_slice_to_ints(&build_expected_hash(data));
expected_stack.push(1001);
build_test!(one_word, operand_stack, &data).expect_stack_and_memory(
&expected_stack,
Expand All @@ -167,7 +167,7 @@ fn test_pipe_words_to_memory() {

let operand_stack = &[];
let data = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
let mut expected_stack = felt_array_to_ints(&build_expected_hash(data));
let mut expected_stack = felt_slice_to_ints(&build_expected_hash(data));
expected_stack.push(1003);
build_test!(three_words, operand_stack, &data).expect_stack_and_memory(
&expected_stack,
Expand Down Expand Up @@ -195,7 +195,7 @@ fn test_pipe_preimage_to_memory() {

let operand_stack = &[];
let data = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
let mut advice_stack = felt_array_to_ints(&build_expected_hash(data));
let mut advice_stack = felt_slice_to_ints(&build_expected_hash(data));
advice_stack.reverse();
advice_stack.extend(data);
build_test!(three_words, operand_stack, &advice_stack).expect_stack_and_memory(
Expand All @@ -221,7 +221,7 @@ fn test_pipe_preimage_to_memory_invalid_preimage() {

let operand_stack = &[];
let data = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
let mut advice_stack = felt_array_to_ints(&build_expected_hash(data));
let mut advice_stack = felt_slice_to_ints(&build_expected_hash(data));
advice_stack.reverse();
advice_stack[0] += 1; // corrupt the expected hash
advice_stack.extend(data);
Expand Down
6 changes: 3 additions & 3 deletions test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl Test {
let mem_state =
process.get_mem_value(ContextId::root(), mem_start_addr).unwrap_or(EMPTY_WORD);

let mem_state = felt_array_to_ints(&mem_state);
let mem_state = felt_slice_to_ints(&mem_state);
assert_eq!(
data, mem_state,
"Expected memory [{}] => {:?}, found {:?}",
Expand Down Expand Up @@ -423,8 +423,8 @@ impl Test {
// HELPER FUNCTIONS
// ================================================================================================

/// Converts an array of Felts into u64
pub fn felt_array_to_ints(values: &[Felt]) -> Vec<u64> {
/// Converts a slice of Felts into a vector of u64 values.
pub fn felt_slice_to_ints(values: &[Felt]) -> Vec<u64> {
values.iter().map(|e| (*e).as_int()).collect()
}

Expand Down

0 comments on commit a0e1076

Please sign in to comment.