Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,22 @@ pub fn build(b: *std.Build) void {
const run_handler_tests = b.addRunArtifact(handler_tests);
test_step.dependOn(&run_handler_tests.step);

// Precompile unit tests - these are run via zig test command in CI
// The command needs to link libc and include all modules
// See .github/workflows/ci.yml for the full command
// Precompile unit tests (runs tests.zig + bn254_tests.zig etc. via main.zig)
const precompile_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = .{ .src_path = .{ .owner = b, .sub_path = "src/precompile/main.zig" } },
.target = target,
.optimize = optimize,
}),
});
precompile_tests.root_module.addImport("primitives", primitives_module);
precompile_tests.root_module.addImport("zevm_allocator", zevm_allocator_module);
precompile_tests.root_module.addImport("precompile_types", precompile_types_module);
precompile_tests.root_module.addImport("precompile_implementations", native_impls_module);
precompile_tests.root_module.addImport("build_options", lib_options_module);
addCryptoLibraries(b, precompile_tests, enable_blst, enable_mcl, blst_include_path, mcl_include_path, is_windows, target_info.os.tag == .macos);
const run_precompile_tests = b.addRunArtifact(precompile_tests);
test_step.dependOn(&run_precompile_tests.step);

// Example executable
const example_exe = b.addExecutable(.{
Expand Down
9 changes: 4 additions & 5 deletions src/precompile/bls12_381.zig
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,11 @@ pub fn bls12G2MsmRun(input: []const u8, gas_limit: u64) T.PrecompileResult {

/// BLS12-381 pairing check
pub fn bls12PairingRun(input: []const u8, gas_limit: u64) T.PrecompileResult {
if (input.len < PADDED_G1_LENGTH + PADDED_G2_LENGTH) {
return T.PrecompileResult{ .err = T.PrecompileError.Bls12381PairingInputLength };
}

const pair_len = PADDED_G1_LENGTH + PADDED_G2_LENGTH;
if (input.len % pair_len != 0) {

// EIP-2537: input must be a non-zero multiple of pair_len (384 bytes).
// Empty input is explicitly invalid per the spec and execution-spec-tests.
if (input.len == 0 or input.len % pair_len != 0) {
return T.PrecompileResult{ .err = T.PrecompileError.Bls12381PairingInputLength };
}

Expand Down
Loading
Loading