Skip to content

Commit

Permalink
Fix security error message
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianGCalderon committed Sep 20, 2024
1 parent 399c14c commit 43c2d41
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions vm/src/vm/runners/builtin_runner/modulo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ pub enum ModBuiltinType {
Add,
}

impl ModBuiltinType {
pub(crate) fn operation_string(&self) -> &'static str {

Check warning on line 60 in vm/src/vm/runners/builtin_runner/modulo.rs

View check run for this annotation

Codecov / codecov/patch

vm/src/vm/runners/builtin_runner/modulo.rs#L60

Added line #L60 was not covered by tests
match self {
ModBuiltinType::Mul => "*",
ModBuiltinType::Add => "+",

Check warning on line 63 in vm/src/vm/runners/builtin_runner/modulo.rs

View check run for this annotation

Codecov / codecov/patch

vm/src/vm/runners/builtin_runner/modulo.rs#L62-L63

Added lines #L62 - L63 were not covered by tests
}
}
}

#[derive(Debug, Default)]
struct Inputs {
p: BigUint,
Expand Down Expand Up @@ -612,8 +621,8 @@ impl ModBuiltinRunner {
if a_op_b.mod_floor(&inputs.p) != c.mod_floor(&inputs.p) {

Check warning on line 621 in vm/src/vm/runners/builtin_runner/modulo.rs

View check run for this annotation

Codecov / codecov/patch

vm/src/vm/runners/builtin_runner/modulo.rs#L620-L621

Added lines #L620 - L621 were not covered by tests
// Build error string
let p = inputs.p;
let op = &self.builtin_type;
let error_string = format!("Expected a {op:?} b == c (mod p). Got: instance={instance}, batch={index_in_batch}, p={p}, a={a}, b={b}, c={c}.");
let op = self.builtin_type.operation_string();

Check warning on line 624 in vm/src/vm/runners/builtin_runner/modulo.rs

View check run for this annotation

Codecov / codecov/patch

vm/src/vm/runners/builtin_runner/modulo.rs#L624

Added line #L624 was not covered by tests
let error_string = format!("Expected a {op} b == c (mod p). Got: instance={instance}, batch={index_in_batch}, p={p}, a={a}, b={b}, c={c}.");
return Err(RunnerError::ModBuiltinSecurityCheck(Box::new((
self.name(),
error_string,
Expand Down

0 comments on commit 43c2d41

Please sign in to comment.