Nethermind.Numerics.Int256 1.8.0-rc

This is a prerelease version of Nethermind.Numerics.Int256.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Nethermind.Numerics.Int256 --version 1.8.0-rc
                    
NuGet\Install-Package Nethermind.Numerics.Int256 -Version 1.8.0-rc
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Nethermind.Numerics.Int256" Version="1.8.0-rc" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nethermind.Numerics.Int256" Version="1.8.0-rc" />
                    
Directory.Packages.props
<PackageReference Include="Nethermind.Numerics.Int256" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Nethermind.Numerics.Int256 --version 1.8.0-rc
                    
#r "nuget: Nethermind.Numerics.Int256, 1.8.0-rc"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Nethermind.Numerics.Int256@1.8.0-rc
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Nethermind.Numerics.Int256&version=1.8.0-rc&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Nethermind.Numerics.Int256&version=1.8.0-rc&prerelease
                    
Install as a Cake Tool

Int256

Tests / Publish Nethermind.Numerics.Int256

The fastest 256-bit arithmetic for .NET.

Int256 provides UInt256 and Int256: unsigned and signed 256-bit value types used by the Nethermind Ethereum execution client. It brings the arithmetic behind EVM execution to your own .NET applications, from blockchain tooling to binary protocols and numeric workloads that need more than 128 bits.

Why Int256?

  • 256 bits, stored inline. Readonly structs with a 32-byte representation. Core arithmetic works directly on fixed-width limbs without allocating a backing array for each result.
  • Modular arithmetic that keeps the intermediate bits. UInt256.AddMod and UInt256.MultiplyMod reduce the full sum or product, including products up to 512 bits wide.
  • Optimized for the hardware you run. Specialized x64 and ARM64 paths use hardware intrinsics where available, with software fallbacks. A separate RISC-V zkVM build tunes execution for guest workloads.
  • Made for hot paths. in/out arithmetic APIs and span-based byte conversion let callers control copies and buffers.
  • Continuously maintained and optimized. Ongoing development improves arithmetic algorithms and tunes performance for evolving .NET runtimes, CPU architectures, and RISC-V zkVM workloads.
  • Correctness you can inspect. Tests compare arithmetic against System.Numerics.BigInteger, and CI exercises Windows, Linux, macOS, ARM64, and configurations with hardware intrinsics disabled.
  • MIT licensed. Use it in open-source or commercial projects.

Get started

Requires .NET 10.

dotnet add package Nethermind.Numerics.Int256

The package name is Nethermind.Numerics.Int256; the C# namespace is Nethermind.Int256.

using System;
using Nethermind.Int256;

UInt256 amount = UInt256.Parse("1000000000000000000");
UInt256 total = amount * 3UL;
Console.WriteLine(total); // 3000000000000000000

Int256 delta = -42L;
Console.WriteLine(delta + (Int256)10L); // -32

// Reduce the full 512-bit product, without truncating it to 256 bits first.
UInt256 modulus = 97UL;
UInt256.MultiplyMod(UInt256.MaxValue, UInt256.MaxValue, modulus, out UInt256 remainder);
Console.WriteLine(remainder); // 11

// Write directly into a caller-owned buffer and read it back.
Span<byte> bytes = stackalloc byte[32];
total.ToBigEndian(bytes);
UInt256 decoded = new(bytes, isBigEndian: true);
Console.WriteLine(decoded == total); // True

Choose the right arithmetic

Need API
Unsigned values from 0 to 2²⁵⁶ − 1 UInt256
Signed values from −2²⁵⁵ to 2²⁵⁵ − 1 Int256
Arithmetic, comparisons, bitwise operations, and shifts Operators and named methods; see UInt256 and Int256
Detect unsigned overflow or underflow UInt256.AddOverflow / UInt256.SubtractUnderflow
Modular addition, multiplication, or exponentiation AddMod, MultiplyMod, ExpMod
Read or write binary values Byte-span constructor, ToBigEndian(Span<byte>), ToLittleEndian(Span<byte>)
Interoperate with arbitrary-precision code Explicit conversions to and from BigInteger

The arithmetic has explicit fixed-width semantics. For UInt256:

  • + and * retain the low 256 bits on overflow.
  • The - operator throws on underflow; Subtract returns the wrapped result, while SubtractUnderflow also reports whether underflow occurred.
  • Division by zero throws DivideByZeroException.
  • AddMod and MultiplyMod preserve the full intermediate value before reduction and throw for a zero modulus. (a * b) % m can therefore differ from MultiplyMod(a, b, m, out result).

Use BigInteger when you need values of unbounded size. Use Int256 when 256 bits are part of your data model and fixed-width behavior matters.

Performance

The BenchmarkDotNet suite includes comparisons against BigInteger for arithmetic and modular operations, plus targeted benchmarks for operand widths, comparisons, and byte conversion.

Run the suite on your hardware, or select an operation:

dotnet run -c Release --project src/Nethermind.Int256.Benchmark -- --list flat
dotnet run -c Release --project src/Nethermind.Int256.Benchmark -- --filter '*MultiplyModUnsigned*'

Results depend on operand size, CPU instruction support, and runtime version. When sharing measurements, include those details, the commit, and the benchmark command so others can reproduce them.

RISC-V zkVM variant

The NuGet package includes standard and RISC-V zkVM implementations with the same assembly identity. The standard implementation is selected by default. To select the RISC-V zkVM implementation, set the existing EnableZkEvm property in your project or shared Directory.Build.props:

<PropertyGroup>
  <EnableZkEvm>true</EnableZkEvm>
</PropertyGroup>

This is a build-time choice for RISC-V zkVM guest workloads; ordinary .NET applications can use the default.

Build and contribute

Use the SDK specified in global.json. From the repository root:

dotnet build src/Nethermind.Int256/Nethermind.Int256.csproj -c Release
dotnet test --project src/Nethermind.Int256.Tests/Nethermind.Int256.Tests.csproj -c Release

Bug reports, regression tests, and performance improvements are welcome. For arithmetic bugs, include the operands, operation, expected result, and actual result. For optimizations, include reproducible before/after benchmarks and coverage for boundary values.

Contributors

Thanks to everyone who helps maintain and improve Int256.

Int256 contributors

License

MIT. See NOTICE for third-party notices.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Nethermind.Numerics.Int256:

Repository Stars
NethermindEth/nethermind
A robust, high-performance execution client for Ethereum node operators.
Version Downloads Last Updated
1.8.0-rc2 2 9/9/2026
1.8.0-rc 3 9/9/2026
1.7.1-mulmod120 3 9/7/2026
1.6.1-alpha.24c 6 8/29/2026
1.6.1-alpha.24b 3 8/29/2026
1.6.1-alpha.24a 4 8/29/2026
1.6.1-alpha.23b 3 8/29/2026
1.6.1-alpha.23a 4 8/29/2026
1.6.1-alpha.26.collective1 9 8/29/2026
1.6.1-alpha.25.diag1 3 8/29/2026
1.6.1-alpha.22 6 8/28/2026
1.6.1-alpha.21 4 8/28/2026
1.6.1-alpha.20 4 8/28/2026
1.6.1-alpha.19 4 8/28/2026
1.6.1-alpha.18 4 8/28/2026
1.6.1-alpha.17 3 8/28/2026
1.6.1-alpha.12.diag4 7 8/28/2026
1.6.1-alpha.12.diag3 5 8/28/2026
1.6.0 1 8/11/2026
1.6.0-candidate 4 9/3/2026
Loading failed