Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UInt128 for u128 #21

Merged
merged 4 commits into from
Nov 23, 2020
Merged

Add UInt128 for u128 #21

merged 4 commits into from
Nov 23, 2020

Conversation

weikengchen
Copy link
Member

No description provided.

@weikengchen
Copy link
Member Author

On the way of fixing multiple errors. May take a longer time.

It seems that u128 would be much more complicated because addmany uses u128 to compute the middle result, which would support u64but not u128.

A separate implementation would be needed for u128, likely via num-bigint or the BigInteger256.

@Pratyush
Copy link
Member

Maybe you can use BigInteger256?

@weikengchen
Copy link
Member Author

Passing. But a code review is needed. This implementation uses num-bigint, and it did not use BigInteger256 due to the complexity of implementing it due to a more restrictive interface. However, adding another trait to the arkworks stack may always be a drawback.

@weikengchen weikengchen requested a review from Pratyush November 22, 2020 22:04
@weikengchen
Copy link
Member Author

I would merge this for now. But we likely need a revisit later (I will create an issue), very likely to replace with BigInteger256, since it is better to reduce the number of crates we depend on.

@weikengchen weikengchen merged commit 68f08b9 into master Nov 23, 2020
@weikengchen weikengchen deleted the uint128 branch November 23, 2020 23:26
let b = AllocatedBit::new_witness(cs.clone(), || {
result_value.map(|v| (v >> i) & 1 == 1).get()
})?;
let b = AllocatedBit::new_witness(cs.clone(), || result_value.clone().map(|v| (v >> i) & BigUint::one() == BigUint::one()).get())?;
Copy link
Member

Choose a reason for hiding this comment

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

I think we can rewrite this more simply as

let b = AllocatedBit::new_witness(cs.clone(), || result_value.as_ref().map(|v| (v >> i) == BigUint::one()).get())?;

@@ -246,7 +251,12 @@ macro_rules! make_uint {
}

// The value of the actual result is modulo 2^$size
let modular_value = result_value.map(|v| v as $native);
let modular_value = result_value.clone().map(|v|
Copy link
Member

Choose a reason for hiding this comment

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

We can avoid the clone here by doing as_ref() instead

let modular_value = result_value.map(|v| v as $native);
let modular_value = result_value.clone().map(|v|
{
let modulus = BigUint::from(1u64) << ($size as u32);
Copy link
Member

Choose a reason for hiding this comment

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

BigUint::from(1u64) -> BigUint::one().

@Pratyush
Copy link
Member

Sorry this review is kinda late lol

Pratyush pushed a commit that referenced this pull request Aug 8, 2021
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