Skip to content

Commit

Permalink
fix: remove unnecessary loads in ecall_sha (risc0#1280)
Browse files Browse the repository at this point in the history
Currently this will read past the first digest until the block is full
(2*digest). In the case that the second digest is directly after the
first in memory, this read is just redundant. In the case that they are
not, when reading just one, there are unnecessary reads done past the
first digest in memory.

I might be missing something here, but checking manually and running
some basic tests work, so just opening this to see if and what
changes/breaks to see if I am missing something.

---------

Co-authored-by: Frank Laub <[email protected]>
  • Loading branch information
austinabell and flaub authored Jan 7, 2024
1 parent c7f1552 commit e80775e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions risc0/zkvm/src/host/server/exec/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,15 +619,16 @@ impl<'a> ExecutorImpl<'a> {
}

tracing::debug!("Initial sha state: {state:08x?}");
let mut block = [0u32; BLOCK_WORDS];
for _ in 0..count {
let mut block = [0u32; BLOCK_WORDS];
for (i, word) in block.iter_mut().enumerate() {
let (digest1, digest2) = block.split_at_mut(DIGEST_WORDS);
for (i, word) in digest1.iter_mut().enumerate() {
*word = self
.monitor
.load_u32_from_guest_addr(block1_ptr + (i * WORD_SIZE) as u32)?;
}
for i in 0..DIGEST_WORDS {
block[DIGEST_WORDS + i] = self
for (i, word) in digest2.iter_mut().enumerate() {
*word = self
.monitor
.load_u32_from_guest_addr(block2_ptr + (i * WORD_SIZE) as u32)?;
}
Expand Down

0 comments on commit e80775e

Please sign in to comment.