Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 20 additions & 45 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion jolt-inlines/bigint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ jolt-inlines-sdk = { workspace = true, optional = true }
[dev-dependencies]
ark-ff.workspace = true
rand = { workspace = true, features = ["std", "std_rng"] }
tracer = { workspace = true, features = ["std", "test-utils"] }
46 changes: 0 additions & 46 deletions jolt-inlines/bigint/src/multiplication/exec.rs

This file was deleted.

6 changes: 2 additions & 4 deletions jolt-inlines/bigint/src/multiplication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ const OUTPUT_LIMBS: usize = 2 * INPUT_LIMBS;
pub mod sdk;
pub use sdk::*;

#[cfg(feature = "host")]
pub mod exec;
#[cfg(feature = "host")]
pub mod sequence_builder;
#[cfg(feature = "host")]
pub mod spec;

#[cfg(all(test, feature = "host"))]
pub mod test_utils;
#[cfg(all(test, feature = "host"))]
pub mod tests;
5 changes: 3 additions & 2 deletions jolt-inlines/bigint/src/multiplication/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ pub unsafe fn bigint256_mul_inline(_a: *const u64, _b: *const u64, _result: *mut
/// - `result` must point to at least 64 bytes of writable memory
#[cfg(feature = "host")]
pub unsafe fn bigint256_mul_inline(a: *const u64, b: *const u64, result: *mut u64) {
use crate::multiplication::exec;
use crate::multiplication::sequence_builder::BigintMul256;
use jolt_inlines_sdk::spec::InlineSpec;

let a_array = *(a as *const [u64; INPUT_LIMBS]);
let b_array = *(b as *const [u64; INPUT_LIMBS]);
let result_array = exec::bigint_mul(a_array, b_array);
let result_array = BigintMul256::reference(&(a_array, b_array));
core::ptr::copy_nonoverlapping(result_array.as_ptr(), result, OUTPUT_LIMBS);
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ impl InlineOp for BigintMul256 {
const FUNCT3: u32 = crate::BIGINT256_MUL_FUNCT3;
const FUNCT7: u32 = crate::BIGINT256_MUL_FUNCT7;
const NAME: &'static str = crate::BIGINT256_MUL_NAME;
type Advice = ();

fn build_sequence(asm: InstrAssembler, operands: FormatInline) -> Vec<Instruction> {
BigIntMulSequenceBuilder::new(asm, operands).build()
Expand Down
69 changes: 69 additions & 0 deletions jolt-inlines/bigint/src/multiplication/spec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use super::sequence_builder::BigintMul256;
use super::{INPUT_LIMBS, OUTPUT_LIMBS};
use jolt_inlines_sdk::host::Xlen;
use jolt_inlines_sdk::spec::rand::rngs::StdRng;
use jolt_inlines_sdk::spec::rand::Rng;
use jolt_inlines_sdk::spec::{InlineMemoryLayout, InlineSpec, InlineTestHarness};

impl InlineSpec for BigintMul256 {
type Input = ([u64; INPUT_LIMBS], [u64; INPUT_LIMBS]);
type Output = [u64; OUTPUT_LIMBS];

fn random_input(rng: &mut StdRng) -> Self::Input {
(
core::array::from_fn(|_| rng.gen()),
core::array::from_fn(|_| rng.gen()),
)
}

fn reference(input: &Self::Input) -> Self::Output {
let (lhs, rhs) = input;
let mut result = [0u64; OUTPUT_LIMBS];

for (i, &lhs_limb) in lhs.iter().enumerate() {
for (j, &rhs_limb) in rhs.iter().enumerate() {
let product = (lhs_limb as u128) * (rhs_limb as u128);
let low = product as u64;
let high = (product >> 64) as u64;

let result_position = i + j;

let (sum, carry1) = result[result_position].overflowing_add(low);
result[result_position] = sum;

let mut carry = carry1 as u64;
if high != 0 || carry != 0 {
let (sum_with_hi, carry_hi) = result[result_position + 1].overflowing_add(high);
let (sum_with_carry, carry_carry) = sum_with_hi.overflowing_add(carry);
result[result_position + 1] = sum_with_carry;
carry = (carry_hi as u64) + (carry_carry as u64);

let mut carry_position = result_position + 2;
while carry != 0 && carry_position < OUTPUT_LIMBS {
let (sum, c) = result[carry_position].overflowing_add(carry);
result[carry_position] = sum;
carry = c as u64;
carry_position += 1;
}
}
}
}
result
}

fn create_harness() -> InlineTestHarness {
let layout = InlineMemoryLayout::two_inputs(32, 32, 64);
InlineTestHarness::new(layout, Xlen::Bit64)
}

fn load(harness: &mut InlineTestHarness, input: &Self::Input) {
harness.setup_registers();
harness.load_input64(&input.0);
harness.load_input2_64(&input.1);
}

fn read(harness: &mut InlineTestHarness) -> Self::Output {
let vec = harness.read_output64(OUTPUT_LIMBS);
vec.try_into().unwrap()
}
}
Loading
Loading