Skip to content

Commit 709fdf8

Browse files
authored
fix: Dereference o_len ptr correctly (#289)
* fix: Dereference o_len ptr correctly * CI: Upgrade to rust 1.80 toolchain because rayon-core v1.13.0 requires it * bump rust again Signed-off-by: Bhargava Shastry <[email protected]> Signed-off-by: garyschulte <[email protected]>
1 parent f4019fe commit 709fdf8

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
tar -xzf go1.24.1.linux-amd64.tar.gz -C /usr/local && ln -s /usr/local/go/bin/go /usr/local/bin/go
2929
# rust dependencies
3030
export CARGO_HOME="$HOME/.cargo"
31-
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain 1.75.0
31+
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain 1.89.0
3232
# nim dependencies
3333
export CHOOSENIM_CHOOSE_VERSION=2.2.2
3434
curl https://nim-lang.org/choosenim/init.sh -sSf | sh -s -- -y
@@ -166,7 +166,7 @@ jobs:
166166
brew install [email protected] || true
167167
# rust dependencies
168168
export CARGO_HOME="$HOME/.cargo"
169-
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain 1.75.0
169+
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain 1.89.0
170170
# install both x86 and arm64 toolchains
171171
export PATH="$HOME/.cargo/bin:$PATH"
172172
rustup target add x86_64-apple-darwin
@@ -237,7 +237,7 @@ jobs:
237237
brew install [email protected] || true
238238
# rust dependencies
239239
export CARGO_HOME="$HOME/.cargo"
240-
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain 1.75.0
240+
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain 1.89.0
241241
# install both x86 and arm64 toolchains
242242
export PATH="$HOME/.cargo/bin:$PATH"
243243
rustup target add x86_64-apple-darwin

arithmetic/arithmetic/src/arith.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use crate::{
1414
mpnat::{DoubleWord, MPNat, Word, BASE, WORD_BITS},
1515
};
16-
pub use std::{vec, vec::Vec};
16+
pub use std::vec;
1717

1818
// Computes the "Montgomery Product" of two numbers.
1919
// See Coarsely Integrated Operand Scanning (CIOS) Method in

arithmetic/arithmetic/src/lib.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub extern "C" fn modexp_precompiled(
3838
let input_i8: &[libc::c_char] = unsafe { std::slice::from_raw_parts(i, i_len as usize) };
3939
let input: &[u8] = unsafe { std::mem::transmute(input_i8) };
4040

41-
let raw_out_i8: &mut [libc::c_char] = unsafe { std::slice::from_raw_parts_mut(o, o_len as usize) };
41+
let raw_out_i8: &mut [libc::c_char] = unsafe { std::slice::from_raw_parts_mut(o, *o_len as usize) };
4242
let mut raw_out: &mut [u8] = unsafe { std::mem::transmute(raw_out_i8) };
4343
let answer = modexp_precompiled_impl(input);
4444

@@ -133,3 +133,36 @@ pub fn modexp(base: &[u8], exp: &[u8], modulus: &[u8]) -> Vec<u8> {
133133
let result = x.modpow(exp, &m);
134134
result.to_big_endian()
135135
}
136+
137+
#[cfg(test)]
138+
mod tests {
139+
use super::*;
140+
141+
#[test]
142+
fn test_modexp_precompiled() {
143+
let mut output_len: u32 = 32;
144+
let o_len_ptr = &mut output_len as *mut u32;
145+
146+
let mut input = vec![0u8; 96];
147+
input[31] = 1; // base_len = 1
148+
input[63] = 1; // exp_len = 1
149+
input[95] = 1; // mod_len = 1
150+
input.push(2); // base = 2
151+
input.push(3); // exp = 3
152+
input.push(5); // mod = 5
153+
154+
let input_i8: Vec<i8> = input.iter().map(|&x| x as i8).collect();
155+
let mut output = vec![0i8; output_len as usize];
156+
157+
let result = modexp_precompiled(
158+
input_i8.as_ptr(),
159+
input_i8.len() as u32,
160+
output.as_mut_ptr(),
161+
o_len_ptr,
162+
);
163+
164+
assert_eq!(result, 0); // Expect success
165+
assert_eq!(output_len, 1); // Expect output length to be 1
166+
assert_eq!(output[0], 3); // Expect output to be 3 (2^3 % 5 = 3)
167+
}
168+
}

native-build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mkdir -p $GOPATH
1111
export GOROOT="$HOME/go"
1212
export PATH="$GOROOT/bin":$PATH
1313
export CARGO_HOME="$HOME/.cargo"
14-
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain 1.75.0
14+
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain 1.89.0
1515
export PATH=$PATH:$CARGO_HOME/bin
1616
git config --global --add safe.directory /home/ubuntu/secp256r1/besu-native-ec
1717
git config --global --add safe.directory /home/ubuntu/secp256r1/besu-native-ec/openssl

0 commit comments

Comments
 (0)