Skip to content

Commit 340ff96

Browse files
committed
readme
1 parent a720f8c commit 340ff96

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

ethereum/circuits/lib/README.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,22 +237,33 @@ U256 is a structure to use as a type for big numbers.
237237
It is used when dealing with numbers up to 2<sup>256</sup>. They can exceed Field maximum value.
238238
In particular it is a word size in ETH and therefore it is a basic type used in both storage and slot values calculations.
239239

240-
[There](.src/uint256.nr) is an unoptimized implementation of this type using two U128 structures. Optimized version will appear in Noir.
240+
This library uses `U256` from the [noir-bignum](https://github.com/noir-lang/noir-bignum) library. The [`uint256.nr`](./src/uint256.nr) module provides conversion utilities between `U256` and `Bytes32`/`Field` types.
241241

242-
Traits implemented for U256:
242+
Traits implemented for U256 (from bignum library):
243243

244244
- Add
245245
- Eq
246-
- Serde
246+
- Serde (via this library's implementation)
247247

248248
```rust
249-
global u128_number = 0x10000000000000000000000000000000;
249+
use dep::bignum::bignum::BigNum;
250+
use dep::bignum::U256;
251+
use crate::uint256::{from, from_field};
250252

251-
let big_number = U256::new(u128_number, u128_number);
253+
// Create U256 values
254+
let zero = U256::zero();
255+
let one = U256::from(1);
256+
let big_number = U256::modulus().udiv(U256::from(16));
252257

253-
let sum = big_number + U256::one();
254-
assert_eq(sum, U256 { high: u128_number, low: u128_number + U128::one()});
258+
// Convert from Bytes32
259+
let bytes: Bytes32 = [0x10; 32];
260+
let u256_from_bytes = from(bytes);
255261

256-
let serialized: [Field; 4] = big_number.serialize();
262+
// Convert from Field
263+
let field_value: Field = 100;
264+
let u256_from_field = from_field(field_value);
265+
266+
// Serialization (uses 3 limbs)
267+
let serialized: [Field; 3] = big_number.serialize();
257268
assert_eq(U256::deserialize(serialized), big_number);
258269
```

0 commit comments

Comments
 (0)