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

feat: biginteger implementation #495

Draft
wants to merge 63 commits into
base: main
Choose a base branch
from

Conversation

qalisander
Copy link
Member

Resolves #481

PR Checklist

  • Tests
  • Documentation
  • Changelog

Copy link

netlify bot commented Jan 15, 2025

Deploy Preview for contracts-stylus canceled.

Name Link
🔨 Latest commit d3df6cc
🔍 Latest deploy log https://app.netlify.com/sites/contracts-stylus/deploys/678798de0308f500080f51a4

Copy link

codecov bot commented Jan 15, 2025

Codecov Report

Attention: Patch coverage is 55.08850% with 406 lines in your changes missing coverage. Please review.

Project coverage is 84.4%. Comparing base (e8b6c7d) to head (d3df6cc).

Files with missing lines Patch % Lines
lib/crypto/src/arithmetic/mod.rs 52.8% 294 Missing ⚠️
lib/crypto/src/field/fp.rs 65.1% 90 Missing ⚠️
lib/crypto/src/const_helpers.rs 0.0% 22 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
lib/crypto/src/field/mod.rs 100.0% <ø> (ø)
lib/crypto/src/field/prime.rs 0.0% <ø> (ø)
lib/crypto/src/poseidon2/mod.rs 93.2% <ø> (ø)
lib/crypto/src/const_helpers.rs 0.0% <0.0%> (ø)
lib/crypto/src/field/fp.rs 57.5% <65.1%> (+8.9%) ⬆️
lib/crypto/src/arithmetic/mod.rs 52.8% <52.8%> (ø)

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's great you have done these benchmarks but I am not a fan of maintaining akr-ff or poseidon-renegades. We may want. to have just a separated branch with these benchmarks.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was about to drop it. It is just for comparison, when I was optimizing it

Copy link
Collaborator

@bidzyyys bidzyyys left a comment

Choose a reason for hiding this comment

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

Left some comments + many warnings from CI.
Overall great progress @qalisander!

erc1155::bench().boxed(),
erc1155_metadata_uri::bench().boxed(),
poseidon::bench().boxed(),
// access_control::bench().boxed(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

To be reverted or maintained on a dedicated branch.

@@ -84,12 +84,12 @@ pub trait Field:
+ for<'a> Div<&'a mut Self, Output = Self>
+ for<'a> DivAssign<&'a mut Self>
+ for<'a> Product<&'a Self>
+ From<u128>
// + From<u128> // TODO#q: add u128 conversion
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unresolved TODO

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it needed example?

educe.workspace = true
hex-literal.workspace = true
# TODO#q: have num-bigint dependency optional
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unresolved TODOs

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this bench?

const_for!((i in 0..N) {
let a = self.limbs[N - i - 1];
let b = other.limbs[N - i - 1];
if a < b {
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. Can't you have jus return a < b?
  2. What if a == b?

while self.const_is_even() {
self = self.const_shr();
}
assert!(self.const_is_odd());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I do not like these asserts but I believe it is the only way to assure proper execution :(

}
}

// TODO#q: rename to checked_add?
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you are about checked_add you should implement the proper trait then.

}
*/

impl<const N: usize> From<u64> for Uint<N> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should use macros to implement these traits.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fuzzing here is super needed 😅 @0xNeshi

Copy link
Collaborator

Choose a reason for hiding this comment

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

Proptests would be a bare minimum I'd say 😃

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.

[Feature]: BigInteger implementation
3 participants