-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit test for SyscallReadPreimage
#2305
Changes from all commits
4c35892
9e43c02
fee6e60
48837b1
122b409
3b66040
80cee36
6733f89
b3e2995
cacc29b
6e0eede
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -630,6 +630,7 @@ impl<Fp: Field, PreImageOracle: PreImageOracleT> InterpreterEnv for Env<Fp, PreI | |
len: &Self::Variable, | ||
pos: Self::Position, | ||
) -> Self::Variable { | ||
// The beginning of the syscall | ||
if self.registers.preimage_offset == 0 { | ||
let mut preimage_key = [0u8; 32]; | ||
for i in 0..8 { | ||
|
@@ -655,8 +656,14 @@ impl<Fp: Field, PreImageOracle: PreImageOracleT> InterpreterEnv for Env<Fp, PreI | |
let max_read_len = | ||
std::cmp::min(preimage_offset + len, (preimage_len + LENGTH_SIZE) as u64) | ||
- preimage_offset; | ||
|
||
// We read at most 4 bytes, ensuring that we respect word alignment. | ||
// Here, if the address is not aligned, the first call will read < 4 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this comment is true. The code could be asking to write into the address 4 the first 4 bytes, and at the address 42 the next 3 bytes, after that the next 2 bytes at the address 82, etc (just using random values here for the example) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah, that comment is outdated. I wrote that back when I thought that was the case, but after talking to you I learnt that that was not necessarily the case. I will delete it in the next commit. |
||
// but the next calls will be 4 bytes (because the actual address would | ||
// be updated with the offset) until reaching the end of the preimage | ||
// (where the last call could be less than 4 bytes). | ||
let actual_read_len = std::cmp::min(max_read_len, 4 - (addr & 3)); | ||
|
||
// This variable will contain the amount of bytes read which belong to | ||
// the actual preimage | ||
let mut preimage_read_len = 0; | ||
|
@@ -666,9 +673,9 @@ impl<Fp: Field, PreImageOracle: PreImageOracleT> InterpreterEnv for Env<Fp, PreI | |
// The first 8 bytes of the read preimage are the preimage length, | ||
// followed by the body of the preimage | ||
if idx < LENGTH_SIZE { | ||
// Do nothing for the count of bytes of the preimage. TODO: do | ||
// we want to check anything for these bytes as well? Like | ||
// length? | ||
// Do nothing for the count of bytes of the preimage. | ||
// TODO: do we want to check anything for these bytes as well? | ||
// Like length? | ||
let length_byte = u64::to_be_bytes(preimage_len as u64)[idx]; | ||
unsafe { | ||
self.push_memory(&(*addr + i), length_byte as u64); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is interesting to verify if the syscall works with writing into a contiguous piece of memory (addr/reg 5 is always increased by the (random) number of bytes that the user asks to read). However, what about this example? It doesn't need to be part of this PR, but it is a use case that might happen.