Skip to content

Commit 81f7f0e

Browse files
authored
fix precompile tests, add precompile test cases from besu-native (#18)
* fix precompile tests, add precompile test cases from besu-native Signed-off-by: garyschulte <garyschulte@gmail.com>
1 parent db110f9 commit 81f7f0e

19 files changed

+1811
-109
lines changed

build.zig

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,22 @@ pub fn build(b: *std.Build) void {
533533
const run_handler_tests = b.addRunArtifact(handler_tests);
534534
test_step.dependOn(&run_handler_tests.step);
535535

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

540553
// Example executable
541554
const example_exe = b.addExecutable(.{

src/precompile/bls12_381.zig

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,11 @@ pub fn bls12G2MsmRun(input: []const u8, gas_limit: u64) T.PrecompileResult {
356356

357357
/// BLS12-381 pairing check
358358
pub fn bls12PairingRun(input: []const u8, gas_limit: u64) T.PrecompileResult {
359-
if (input.len < PADDED_G1_LENGTH + PADDED_G2_LENGTH) {
360-
return T.PrecompileResult{ .err = T.PrecompileError.Bls12381PairingInputLength };
361-
}
362-
363359
const pair_len = PADDED_G1_LENGTH + PADDED_G2_LENGTH;
364-
if (input.len % pair_len != 0) {
360+
361+
// EIP-2537: input must be a non-zero multiple of pair_len (384 bytes).
362+
// Empty input is explicitly invalid per the spec and execution-spec-tests.
363+
if (input.len == 0 or input.len % pair_len != 0) {
365364
return T.PrecompileResult{ .err = T.PrecompileError.Bls12381PairingInputLength };
366365
}
367366

0 commit comments

Comments
 (0)