Skip to content

Commit

Permalink
refactor: make AdviceProvider::insert_into_map infallible
Browse files Browse the repository at this point in the history
Since the behavior if the key is already present is to replace the value
with the new one there is no other error that can possibly arise in this
method.
  • Loading branch information
greenhat committed Nov 20, 2024
1 parent 37430cc commit d175784
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
6 changes: 3 additions & 3 deletions processor/src/host/advice/injectors/adv_map_injectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub(crate) fn insert_mem_values_into_adv_map<A: AdviceProvider>(
}

let key = process.get_stack_word(0);
advice_provider.insert_into_map(key, values)?;
advice_provider.insert_into_map(key, values);

Ok(HostResponse::None)
}
Expand Down Expand Up @@ -76,7 +76,7 @@ pub(crate) fn insert_hdword_into_adv_map<A: AdviceProvider>(
let mut values = Vec::with_capacity(2 * WORD_SIZE);
values.extend_from_slice(&word1);
values.extend_from_slice(&word0);
advice_provider.insert_into_map(key.into(), values)?;
advice_provider.insert_into_map(key.into(), values);

Ok(HostResponse::None)
}
Expand Down Expand Up @@ -125,7 +125,7 @@ pub(crate) fn insert_hperm_into_adv_map<A: AdviceProvider>(
.expect("failed to extract digest from state"),
);

advice_provider.insert_into_map(key.into(), values)?;
advice_provider.insert_into_map(key.into(), values);

Ok(HostResponse::None)
}
Expand Down
4 changes: 2 additions & 2 deletions processor/src/host/advice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ pub trait AdviceProvider: Sized {
///
/// If the specified key is already present in the advice map, the values under the key
/// are replaced with the specified values.
fn insert_into_map(&mut self, key: Word, values: Vec<Felt>) -> Result<(), ExecutionError>;
fn insert_into_map(&mut self, key: Word, values: Vec<Felt>);

/// Returns a signature on a message using a public key.
fn get_signature(
Expand Down Expand Up @@ -729,7 +729,7 @@ where
T::push_stack(self, source)
}

fn insert_into_map(&mut self, key: Word, values: Vec<Felt>) -> Result<(), ExecutionError> {
fn insert_into_map(&mut self, key: Word, values: Vec<Felt>) {
T::insert_into_map(self, key, values)
}

Expand Down
7 changes: 3 additions & 4 deletions processor/src/host/advice/providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ where
self.map.get(key).map(|v| v.as_slice())
}

fn insert_into_map(&mut self, key: Word, values: Vec<Felt>) -> Result<(), ExecutionError> {
fn insert_into_map(&mut self, key: Word, values: Vec<Felt>) {
self.map.insert(key.into(), values);
Ok(())
}

// MERKLE STORE
Expand Down Expand Up @@ -272,7 +271,7 @@ impl AdviceProvider for MemAdviceProvider {
self.provider.push_stack(source)
}

fn insert_into_map(&mut self, key: Word, values: Vec<Felt>) -> Result<(), ExecutionError> {
fn insert_into_map(&mut self, key: Word, values: Vec<Felt>) {
self.provider.insert_into_map(key, values)
}

Expand Down Expand Up @@ -390,7 +389,7 @@ impl AdviceProvider for RecAdviceProvider {
self.provider.push_stack(source)
}

fn insert_into_map(&mut self, key: Word, values: Vec<Felt>) -> Result<(), ExecutionError> {
fn insert_into_map(&mut self, key: Word, values: Vec<Felt>) {
self.provider.insert_into_map(key, values)
}

Expand Down

0 comments on commit d175784

Please sign in to comment.