From b81be57c14a2a5f7e32cc0fd1aa72ad3689a1ee1 Mon Sep 17 00:00:00 2001 From: nhtyy Date: Thu, 21 Nov 2024 12:26:04 -0800 Subject: [PATCH] chore: eprintln on violations --- crates/core/executor/src/events/precompiles/ec.rs | 10 ++++++++-- .../executor/src/syscalls/precompiles/fptower/fp.rs | 4 +++- .../src/syscalls/precompiles/fptower/fp2_addsub.rs | 1 + .../src/syscalls/precompiles/fptower/fp2_mul.rs | 1 + .../core/executor/src/syscalls/precompiles/uint256.rs | 1 + 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/core/executor/src/events/precompiles/ec.rs b/crates/core/executor/src/events/precompiles/ec.rs index 6e6a60bb3..b68d8cb79 100644 --- a/crates/core/executor/src/events/precompiles/ec.rs +++ b/crates/core/executor/src/events/precompiles/ec.rs @@ -109,10 +109,12 @@ pub fn create_ec_add_event( let start_clk = rt.clk; let p_ptr = arg1; if p_ptr % 4 > 0 { + eprintln!("EC_ADD: ptr alignment violation"); return rt.invariant_violated(); } let q_ptr = arg2; if q_ptr % 4 > 0 { + eprintln!("EC_ADD: ptr alignment violation"); return rt.invariant_violated(); } @@ -127,11 +129,13 @@ pub fn create_ec_add_event( let p_affine = AffinePoint::::from_words_le(&p); if !E::is_valid_point(&p_affine) { + eprintln!("EC_ADD: invalid p point, invariant violation"); return rt.invariant_violated(); } let q_affine = AffinePoint::::from_words_le(&q); if !E::is_valid_point(&q_affine) { + eprintln!("EC_ADD: invalid q point, invariant violation"); return rt.invariant_violated(); } @@ -176,6 +180,7 @@ pub fn create_ec_double_event( let p_affine = AffinePoint::::from_words_le(&p); if !E::is_valid_point(&p_affine) { + eprintln!("EC_DOUBLE: invalid point, invariant violation"); return rt.invariant_violated(); } @@ -226,9 +231,9 @@ pub fn create_ec_decompress_event( x_bytes_be.reverse(); x_bytes_be }; - + // The decompress_fn takes in an X coordinate and a parity, - // This means whatever point we get is guarnteed to be on the curve + // This means whatever point we get is guarnteed to be on the curve // (it computes the corresponding y) // // However its falliable if the X coordinate is not in the field @@ -240,6 +245,7 @@ pub fn create_ec_decompress_event( }; let Some(computed_point) = decompress_fn(&x_bytes_be, sign_bit) else { + eprintln!("EC_DECOMPRESS: decompression failed, invariant violation"); return rt.invariant_violated(); }; diff --git a/crates/core/executor/src/syscalls/precompiles/fptower/fp.rs b/crates/core/executor/src/syscalls/precompiles/fptower/fp.rs index a6336dc69..0d7fecd1b 100644 --- a/crates/core/executor/src/syscalls/precompiles/fptower/fp.rs +++ b/crates/core/executor/src/syscalls/precompiles/fptower/fp.rs @@ -35,10 +35,10 @@ impl Syscall for FpOpSyscall

{ let y_ptr = arg2; // Need to check alignment if x_ptr % 4 > 0 || y_ptr % 4 > 0 { + eprintln!("FpOpSyscall: alignment violation"); return rt.invariant_violated(); } - let num_words =

::WordsFieldElement::USIZE; let x = rt.slice_unsafe(x_ptr, num_words); @@ -47,11 +47,13 @@ impl Syscall for FpOpSyscall

{ let modulus = &BigUint::from_bytes_le(P::MODULUS); let a = BigUint::from_slice(&x); if &a >= modulus { + eprintln!("FpOpSyscall: a >= modulus, invariant violation"); return rt.invariant_violated(); } let b = BigUint::from_slice(&y); if &b >= modulus { + eprintln!("FpOpSyscall: b >= modulus, invariant violation"); return rt.invariant_violated(); } diff --git a/crates/core/executor/src/syscalls/precompiles/fptower/fp2_addsub.rs b/crates/core/executor/src/syscalls/precompiles/fptower/fp2_addsub.rs index c1f7f2701..1528370d6 100644 --- a/crates/core/executor/src/syscalls/precompiles/fptower/fp2_addsub.rs +++ b/crates/core/executor/src/syscalls/precompiles/fptower/fp2_addsub.rs @@ -54,6 +54,7 @@ impl Syscall for Fp2AddSubSyscall

{ let modulus = &BigUint::from_bytes_le(P::MODULUS); if ac0 >= modulus || ac1 >= modulus || bc0 >= modulus || bc1 >= modulus { + eprintln!("Fp2AddSubSyscall: invariant violation, inputs greater than modulus"); return rt.invariant_violated(); } diff --git a/crates/core/executor/src/syscalls/precompiles/fptower/fp2_mul.rs b/crates/core/executor/src/syscalls/precompiles/fptower/fp2_mul.rs index bed5c241d..f5f4b4a32 100644 --- a/crates/core/executor/src/syscalls/precompiles/fptower/fp2_mul.rs +++ b/crates/core/executor/src/syscalls/precompiles/fptower/fp2_mul.rs @@ -54,6 +54,7 @@ impl Syscall for Fp2MulSyscall

{ let modulus = &BigUint::from_bytes_le(P::MODULUS); if ac0 >= modulus || ac1 >= modulus || bc0 >= modulus || bc1 >= modulus { + eprintln!("Fp2MulSyscall: invariant violation, inputs greater than modulus"); return rt.invariant_violated(); } diff --git a/crates/core/executor/src/syscalls/precompiles/uint256.rs b/crates/core/executor/src/syscalls/precompiles/uint256.rs index 2731f5cbe..411854186 100644 --- a/crates/core/executor/src/syscalls/precompiles/uint256.rs +++ b/crates/core/executor/src/syscalls/precompiles/uint256.rs @@ -25,6 +25,7 @@ impl Syscall for Uint256MulSyscall { // Check alignment. if x_ptr % 4 > 0 || y_ptr % 4 > 0 { + eprintln!("Uint256 Precompile: Ptr alignment violation."); return rt.invariant_violated(); }