Skip to content

Conversation

@mykolas-alt
Copy link

No description provided.

Copy link
Contributor

@ArtiomTr ArtiomTr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase from main branch, and when you finish, squash all your commits into one


impl Scalar256 {
#[inline(always)]
fn bitlen_256(&self) -> u32 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a good idea to extend type for your custom usecase - move them to near scalar struct definition, or replace with simple functions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, don't make up your own functions - it is better to mirror standard library, e.g. instead of bitlen_256, you can easily make leading_zeros function, and then do something like Scalar256::BITS - scalar.leading_zeros() - so it looks the same, like for other types, e.g.: u64::BITS - something.leading_zeros().

Comment on lines 7 to 10
"arkworks3-sppark",
"arkworks3-sppark-wlc",
"blst",
"blst-sppark",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please keep CUDA backends, don't delete them

@@ -0,0 +1,65 @@
#![no_main]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all fuzzing is already merged into main branch, so need to be rebased

}

#[inline(always)]
fn shl_256(&self, n: u32) -> Scalar256 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't read code thoroughly, but it looks like << implementation for scalar type. For standard operations, please use traits defined in standard library, e.g. here it would be Shl. So you can then use them nicely:

let scalar: Scalar256;

scalar << 8;

Comment on lines 218 to 223
if heap.is_empty() {
return TG1::zero();
}

let pair = heap.pop().unwrap();
return pair.point.mul(&TFr::from_u64_arr(&pair.scalar.data));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be written a bit more idiomatically:

if let Some(pair) = heap.pop() {
    pair.point.mul(&TFr::from_u64_arr(&pair.scalar.data));
} else {
    TG1::zero()
}

allows to remove panicking .unwrap() call

for _ in 0..k {
new_point.dbl_assign();
}
pair2.point.add_assign(&new_point);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless you're absolutely sure that pair2 and new_point are not equal, you should use add_or_dbl_assign

}
let mut d = bitlen_x - bitlen_y;
let mut shifted_y = y.shl_256(d);
if shifted_y.cmp(&x) == std::cmp::Ordering::Greater {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not shifted_y > x?

}
}

// x >= y
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can make this comment as debug_assert, to detect errors early without slowing down runtime:

debug_assert!(x >= y);


// x >= y
#[inline(always)]
fn find_k(x: &Scalar256, y: &Scalar256) -> (u32, Scalar256) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really confusing function name - rename it

@@ -0,0 +1,101 @@
#[cfg(test)]
mod tests {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msm-benches crate is not for custom tests - keep them in backend crate(s)

@mykolas-alt
Copy link
Author

rebased, aligned api with the way arkmsm does it

@mykolas-alt mykolas-alt force-pushed the bos-coster-msm branch 2 times, most recently from 4ef9c02 to fc4a2db Compare December 14, 2025 21:09
}
}

impl Ord for Scalar256 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still not fixed - please keep all trait implementations near struct definition, not in separate file

}

trait Shr1Assign {
fn shr_once_assign(&mut self);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is good idea to create custom method just for >> 1 -- just implement general Shr, and with inline(always) compiler will optimize that usecase for you.


use crate::{Fr, G1Affine, G1Fp, G1Mul, G1ProjAddAffine, Scalar256, G1};

pub struct VariableBaseMSM;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be named "BosCosterMSM"

break;
};
let pair2_scalar = {
let Some(pair2) = heap.peek_mut() else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this no longer needs to be peek_mut

let Some(pair1) = heap.pop() else {
break;
};
let pair2_scalar = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you can remove this block entirely, and just put all its content into loop body

}
}

trait LeadingZeros {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to define extension trait, just implement needed method directly on struct

impl Shl<u32> for Scalar256 {
type Output = Scalar256;

// This function was generated with ChatGPT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to add unit tests for this function

precomputation: Option<&PrecomputationTable<TFr, TG1, TG1Fp, TG1Affine, TProjAddAffine>>,
) -> TG1 {
#[cfg(not(feature = "arkmsm"))]
#[cfg(not(any(feature = "arkmsm", feature = "bos_coster")))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe bos_coster shouldn't conflict with precomputation methods? you can probably just put it instead of pippenger call, if feature is enabled.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean by conflict? how does arkmsm conflict?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean change it like this?
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean by conflict?

For example, you can't use bgmw and wbits at the same time, pippenger and arkmsm, etc. - that is just does not make sense.

how does arkmsm conflict?

arkmsm doesn't, someone who implemented arkmsm just didn't think about this.

you mean change it like this?

exactly! maybe there are more places, where pippenger is being called, but that's fine for now.

Comment on lines +54 to +59
"rust-kzg-blst/bos_coster",
"rust-kzg-arkworks4/bos_coster",
"rust-kzg-arkworks5/bos_coster",
"rust-kzg-constantine/bos_coster",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mcl missing here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

"rust-kzg-mcl/parallel",
]
bos_coster = [
"rust-kzg-blst/bos_coster",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other backends are missing here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after #322 merged, zkcrypto backend also should be working. MCL is also missing here

@mykolas-alt mykolas-alt marked this pull request as ready for review December 17, 2025 06:54
Copy link
Contributor

@ArtiomTr ArtiomTr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, but still few changes needed. Also, don't forget to fix CI - kzg crate needs formatting to be fixed, and zkcrypto crate now has some issues with clippy. Those clippy issues would probably resolve after you remove feature checks between bos_coster and bgmw/arkmsm/wbits ones.

"rust-kzg-mcl/parallel",
]
bos_coster = [
"rust-kzg-blst/bos_coster",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after #322 merged, zkcrypto backend also should be working. MCL is also missing here

Comment on lines +14 to +17
all(feature = "bgmw", feature = "bos_coster"),
all(feature = "sppark", feature = "wbits"),
all(feature = "sppark", feature = "bos_coster"),
all(feature = "wbits", feature = "bos_coster"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to check this, bos_coster is compatible with all other features (except arkmsm, but you can ignore this for now)


// This function was generated with ChatGPT
#[inline(always)]
fn shl(self, n: u32) -> Scalar256 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still want to see unit tests for this function. you can put them in the same file, at the end, like so:

#[cfg(test)]
mod test {
    #[test]
    fn shl_must_shift_2_bits() {
        let scalar = /* some scalar */;
        let received = scalar << 2;
        let expected = /* scalar shifted 2 bits by hand */;
        assert_eq!(expected, received);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants