Skip to content

Commit

Permalink
Merge pull request #23 from AlexShukel/fix-java-bindings-tests
Browse files Browse the repository at this point in the history
Fixed constantine java bindings tests
  • Loading branch information
ArtiomTr authored Nov 6, 2024
2 parents 701ebd3 + 5424978 commit 5462859
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions constantine/src/eip_4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ pub unsafe extern "C" fn load_trusted_setup(
num_g2_monomial_bytes: u64,
_precompute: u64,
) -> C_KZG_RET {
*out = CKZGSettings {
brp_roots_of_unity: ptr::null_mut(),
roots_of_unity: ptr::null_mut(),
reverse_roots_of_unity: ptr::null_mut(),
g1_values_monomial: ptr::null_mut(),
g1_values_lagrange_brp: ptr::null_mut(),
g2_values_monomial: ptr::null_mut(),
x_ext_fft_columns: ptr::null_mut(),
tables: ptr::null_mut(),
wbits: 0,
scratch_size: 0,
};

let g1_monomial_bytes =
core::slice::from_raw_parts(g1_monomial_bytes, num_g1_monomial_bytes as usize);
let g1_lagrange_bytes =
Expand Down Expand Up @@ -121,6 +134,19 @@ pub unsafe extern "C" fn load_trusted_setup_file(
out: *mut CKZGSettings,
in_: *mut FILE,
) -> C_KZG_RET {
*out = CKZGSettings {
brp_roots_of_unity: ptr::null_mut(),
roots_of_unity: ptr::null_mut(),
reverse_roots_of_unity: ptr::null_mut(),
g1_values_monomial: ptr::null_mut(),
g1_values_lagrange_brp: ptr::null_mut(),
g2_values_monomial: ptr::null_mut(),
x_ext_fft_columns: ptr::null_mut(),
tables: ptr::null_mut(),
wbits: 0,
scratch_size: 0,
};

let mut buf = vec![0u8; 1024 * 1024];
let len: usize = libc::fread(buf.as_mut_ptr() as *mut libc::c_void, 1, buf.len(), in_);
let s = handle_ckzg_badargs!(String::from_utf8(buf[..len].to_vec()));
Expand Down Expand Up @@ -180,6 +206,8 @@ pub unsafe extern "C" fn free_trusted_setup(s: *mut CKZGSettings) {
return;
}

PRECOMPUTATION_TABLES.remove_precomputation(&*s);

if !(*s).g1_values_monomial.is_null() {
let v = Box::from_raw(core::slice::from_raw_parts_mut(
(*s).g1_values_monomial,
Expand Down Expand Up @@ -242,8 +270,6 @@ pub unsafe extern "C" fn free_trusted_setup(s: *mut CKZGSettings) {
drop(v);
(*s).brp_roots_of_unity = ptr::null_mut();
}

PRECOMPUTATION_TABLES.remove_precomputation(&*s);
}

/// # Safety
Expand Down

0 comments on commit 5462859

Please sign in to comment.