uint256

Fixed size 256-bit math library

BSD-3-CLAUSE License

Stars
301
Committers
18

Bot releases are hidden (Show)

uint256 - Nathaniel Martin (v1.3.1) Latest Release

Published by holiman 3 months ago

What's Changed

This release fixes one bug in the DivMod method, which under certain types of aliased inputs would produce faulty output. It also adds a method IntoBig for alloc-free conversion into big.Int.

Full Changelog: https://github.com/holiman/uint256/compare/v1.3.0...v1.3.1


Nathaniel Martin is a character from Patrick O'Brian's Aubrey/Maturin - books, set in the 1800s, the age of fighting sail. Nathaniel Martin is a natural philosopher and is a kind of sidekick to Stephen Maturin.

uint256 - Fitcher Penrose (v1.3.0)

Published by holiman 3 months ago

The 1.3.0-release contains a lot of optimizations, contributed by @AaronChen0. Thanks for all the contributions! Other than that, a breaking change in the ssz-interface implementation and a bugfix.

What's Changed

Full Changelog: https://github.com/holiman/uint256/compare/v1.2.4...v1.2.5


The uint256 release naming-convention is "fictional mathematicians", later expanded into "fictional scientists", due to the dearth of fiction about mathematicians.

Fitcher Penrose appears in Amitav Ghosh's Ibis-trilogy, part II, "River of Smoke". He is a botanist collecting rare plants in Asia.

uint256 - Stephen Maturin (v1.2.4)

Published by holiman 11 months ago

What's Changed

OBS! #144 is a bit of a breaking change, in some situations, since it changes the output-formats when converting to string, in order to better mirror big.Int behaviour. Please read the PR-description to understand the effects of the change.

New Contributors

Full Changelog: https://github.com/holiman/uint256/compare/v1.2.3...v1.2.4

uint256 - Kit Traverse (v1.2.3)

Published by holiman over 1 year ago

What's Changed

New API Methods

// Float64 returns the float64 value nearest to x.
//
// Note: The `big.Float` version of `Float64` also returns an 'Accuracy', indicating
// whether the value was too small or too large to be represented by a
// `float64`. However, the `uint256` type is unable to represent values
// out of scope (|x| < math.SmallestNonzeroFloat64 or |x| > math.MaxFloat64),
// therefore this method does not return any accuracy.
func (z *Int) Float64() float64

// CmpBig compares z and x and returns:
//
//	-1 if z <  x
//	 0 if z == x
//	+1 if z >  x
func (z *Int) CmpBig(x *big.Int) (r int)

// CmpUint64 compares z and x and returns:
//
//	-1 if z <  x
//	 0 if z == x
//	+1 if z >  x
func (z *Int) CmpUint64(x uint64) int 


// Log10 returns the log in base 10, floored to nearest integer.
// **OBS** This method returns '0' for '0', not `-Inf`.
func (z *Int) Log10() uint

Full Changelog: https://github.com/holiman/uint256/compare/v1.2.2...v1.2.3

uint256 - Will Hunting (v1.2.2)

Published by holiman over 1 year ago

What's Changed

New API-methods

Methods to create Ints

// FromDecimal is a convenience-constructor to create an Int from a
// decimal (base 10) string. Numbers larger than 256 bits are not accepted.
func FromDecimal(decimal string) (*Int, error) 

// MustFromBig is a convenience-constructor from big.Int.
// Returns a new Int and panics if overflow occurred.
func MustFromBig(b *big.Int) *Int

// MustFromHex is a convenience-constructor to create an Int from
// a hexadecimal string.
// Returns a new Int and panics if any error occurred.
func MustFromHex(hex string) *Int 

// MustFromDecimal is a convenience-constructor to create an Int from a
// decimal (base 10) string.
// Returns a new Int and panics if any error occurred.
func MustFromDecimal(decimal string) *Int 

Methods to initialize Int instances

// SetFromDecimal sets z from the given string, interpreted as a decimal number.
// OBS! This method is _not_ strictly identical to the (*big.Int).SetString(..., 10) method.
// Notable differences:
// - This method does not accept underscore input, e.g. "100_000",
// - This method does not accept negative zero as valid, e.g "-0",
//   - (this method does not accept any negative input as valid))
func (z *Int) SetFromDecimal(s string) (err error)

// SetFromHex sets z from the given string, interpreted as a hexadecimal number.
// OBS! This method is _not_ strictly identical to the (*big.Int).SetString(..., 16) method.
// Notable differences:
// - This method _require_ "0x" or "0X" prefix.
// - This method does not accept zero-prefixed hex, e.g. "0x0001"
// - This method does not accept underscore input, e.g. "100_000",
// - This method does not accept negative zero as valid, e.g "-0x0",
//   - (this method does not accept any negative input as valid)
func (z *Int) SetFromHex(hex string) error

// Scan implements the database/sql Scanner interface.
// It decodes a string, because that is what postgres uses for its numeric type
func (dst *Int) Scan(src interface{}) error

Methods to output into strings

// MarshalJSON implements json.Marshaler.
func (z *Int) MarshalJSON() ([]byte, error)

// Value implements the database/sql/driver Valuer interface.
func (src *Int) Value() (driver.Value, error)

// Dec returns the decimal representation of z.
func (z *Int) Dec() string

// PrettyDec returns the decimal representation of z, with thousands-separators.
func (z *Int) PrettyDec(separator byte) string 

Methods related to ssz encoding

// MarshalSSZTo implements the fastssz.Marshaler interface and serializes the
// integer into an already pre-allocated buffer.
func (z *Int) MarshalSSZTo(dst []byte) ([]byte, error) 

// MarshalSSZ implements the fastssz.Marshaler interface and returns the integer
// marshalled into a newly allocated byte slice.
func (z *Int) MarshalSSZ() ([]byte, error) 

// SizeSSZ implements the fastssz.Marshaler interface and returns the byte size
// of the 256 bit int.
func (*Int) SizeSSZ() int 

// UnmarshalSSZ implements the fastssz.Unmarshaler interface and parses an encoded
// integer into the local struct.
func (z *Int) UnmarshalSSZ(buf []byte) error

// HashTreeRoot implements the fastssz.HashRoot interface's non-dependent part.
func (z *Int) HashTreeRoot() ([32]byte, error)

New Contributors

Full Changelog: https://github.com/holiman/uint256/compare/v1.2.1...v1.2.2

uint256 - Hari Seldon

Published by holiman about 2 years ago

The v1.2.1 release, "Hari Seldon", contains some new API-methods and a lot of improvements under the hood and in the surrounding infrastructure.

  • OSS-fuzz integration has finally happened, as of (#98) and https://github.com/google/oss-fuzz/pull/6497. The uint256 library is now continuously fuzzed by the fine folks at OSS-Fuzz.
  • Optimised modular arithmetic targeting elliptic curve operations (#86). This was a major overhaul and complete rewrite of the modular arithmetic operations.
  • Added DivMod() (#113)
  • Added MulDivOverflow() (#110)
  • Added Sqrt() (#104)
  • Improvements ot Cmp() (#85)
  • Test improvements (#112, #95, #93, #92, #91, #89, #88)

Thanks to all contributors to this release: @holiman, @chfast,@daosvik, @Planxnx and @fyrchik.

uint256 - Enoch Root

Published by holiman over 3 years ago

The 1.2.0 release, "Enoch Root", contains an important fix to SubUint64, which was flaweed (see https://github.com/holiman/uint256/pull/82 ).
Other than that some API methods have been changed, to make uint256.Int closer resemble big.Int, to be easier to use as a drop-in replacement (also https://github.com/holiman/uint256/pull/82 ).

uint256 - Daniel Waterhouse

Published by holiman about 4 years ago

This release adds various methods for marshalling from text/json, to make integration with go-ethereum easier

uint256 - Lawrence Waterhouse

Published by holiman over 4 years ago

The 1.1.0 release of uint256 contains some improvements and new features.

uint256 - Roger Mexico

Published by holiman over 4 years ago

This is the first official production release of uint256.

Most of the really great changes recently are due to @chfast, who has done tremendous work on:

  • Ensuring a 100% test coverage,
  • Ensuring allocation free operations,
  • Improve the public API,
  • Verify functionality on big endian architecture

And last but not least, further improve speeds everywhere.

Release-names are mathematicians in fiction