Skip to content

Commit

Permalink
Merge pull request #35 from AztecProtocol/jm/large_integer_support
Browse files Browse the repository at this point in the history
Support for large unsigned integer constants up to 256 bits
  • Loading branch information
jeanmon authored Dec 20, 2023
2 parents b8b1f57 + a8473d3 commit a1733e2
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion bberg/src/relation_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use ast::analyzed::{
};
use ast::parsed::SelectedExpressions;
use itertools::Itertools;
use num_bigint::BigUint;
use std::collections::HashMap;
use std::collections::HashSet;

Expand Down Expand Up @@ -328,7 +329,27 @@ fn craft_expression<T: FieldElement>(
collected_public_identities: &mut HashSet<String>,
) -> BBIdentity {
match expr {
Expression::Number(n) => (1, format!("FF({})", n.to_arbitrary_integer())),
Expression::Number(n) => {
let number: BigUint = n.to_arbitrary_integer();
if number.bits() < 32 {
return (1, format!("FF({})", number));
}
if number.bits() < 64 {
return (1, format!("FF({}UL)", number));
}
if number.bits() < 256 {
let mut chunks: Vec<u64> = number.iter_u64_digits().collect::<Vec<u64>>();
chunks.resize(4, 0);
return (
1,
format!(
"FF(uint256_t{{{}, {}, {}, {}}})",
chunks[0], chunks[1], chunks[2], chunks[3],
),
);
}
unimplemented!("{:?}", expr);
}
Expression::Reference(polyref) => {
let mut poly_name = polyref.name.replace('.', "_").to_string();
if polyref.next {
Expand Down

0 comments on commit a1733e2

Please sign in to comment.