Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library returns invalid keys since v1.34.1 without AVX instructions #63

Closed
pk910 opened this issue Aug 30, 2024 · 8 comments
Closed

Library returns invalid keys since v1.34.1 without AVX instructions #63

pk910 opened this issue Aug 30, 2024 · 8 comments

Comments

@pk910
Copy link

pk910 commented Aug 30, 2024

Heya,

The library returns invalid keys since v1.34.1 when running on a machine without AVX instructions.

I've made a small test tool, that just tries generating some keys from a mnemonic:

$ CGO_ENABLED=1 go run github.com/pk910/go-bls-test@v1.33.0
go: downloading github.com/pk910/go-bls-test v1.33.0
BLS version: v1.33.0
BLS test: passed

$ CGO_ENABLED=1 go run github.com/pk910/go-bls-test@v1.34.1
BLS version: v1.34.1
BLS test: failed
  validator pubkey 0 mismatch: 0x817b7be3a698c2ff383982b959d1f044af6e538ed4f0cdf2a57b3b02ac64bb8ce8199e318f3911f70b11489dc6fb5a1d != 0xb3c59dd04900cdcd10be94e31a9bf302ad9a323a1bb3fb710c44e7f5b7acd4ce35a590de88a640dce9b8dff3fc188a39
  validator pubkey 1 mismatch: 0x8aba9de1b463444c822672ff5d06b4a52112d9d75152a856f9ab8638e302e14b755cc77a52a00121f26ee2b45fa5db10 != 0xa2caa2dc8b2295fe6ff78815cbe42a5103c668fb3a4e796a56d40145a192a2ce7e2be0d38cda931b6373e5c96d0f8a50
  validator pubkey 2 mismatch: 0x9298aba7a48c34ebb40b2495cc01b0167a6fd0cc47663aef1b20fa8ec1ee25e733227133b3b78e51d603115fab0f9509 != 0x8bfcfd33fda4385788b9c028f8025c35488b5187dfcd3901ac498a3ef0a6dbd0076e4d1f7b028c863e7e684713ff2521
  validator pubkey 3 mismatch: 0xb435167709d1793e5ed4a098968c51c5eb56a82abc9cf8c1b1078a617e24d73828819e77e211fee61914d8b410f96beb != 0x89e5207d07509abe027003c9adcc88649d072620e2583b212b2c1284d0a14aaf072b72e463997b39ca60bddeffa04896
  validator pubkey 4 mismatch: 0xa2ba209c53c8970f3661d0fad7a55a40dffe668b74f9f186255f4a0a607610f17690e0b3b9feab1b044351ea97a5a14c != 0x89d6cf68072d6a93aab7b4101d2c38cb514c2971460dd1430ae4a900969491b9927b5368d0c967bc0dc23b25798cde4c
  validator pubkey 5 mismatch: 0xb89ac729ca4dd05b95c3cda2f5f9a8c2f61c6fdaa8187363aed2f9b098e1f9ac7b024daa6b31af7aa309defdddc848c0 != 0x9861ce59afa1623bccee64b0caa6a195bb48ff60c932a0b355cc08f3ee6c3ab2a2dda4d7da04fe8c6ff07cfcf06c3081
  validator pubkey 6 mismatch: 0xac1f600fb8b5d056e474f8190bdbb1991db218ef412d007a583e1117ca86d5332fe33a2d69eb27360c36eb1f2e86e6bf != 0xa9d49d74114bba6059528831ff053a9024e11f98a3eb3c5c73607ad78d7ca2d7379424a9ff0cc020523fdfed6cb3e6c3
  validator pubkey 7 mismatch: 0x928494ed221c753fdfa71b9dc66ac975413b4ca860105895b6ec0f0f46bede8ddbc670bac79e8f60819f0404b8059267 != 0x8f47915127f9b9692812f8bcd9b630b8766c9baac92540f222745fb2112e4c4ad5d72fd5462f5724a0faa550ba795f23
  validator pubkey 8 mismatch: 0xb4b7f288287422152f76c3a3249d73825322dce59e8b230897486758f363cf315dba63cee4290d1cec26a53de1331142 != 0x97e8fafd9233f72a3da52805311bece0f405b64e80d0c831b5c8a2bb978b0a026f460e66789338a3e8057db6f5eece68
  validator pubkey 9 mismatch: 0xadda15cf824caf4db472ce7c5814bc88242ed8d074bdd938814ab3ea2772e0c265f60c8aadb04327147a1a1f5db2fcfa != 0x8f0eb2ed68556fd0ee84c0b1fcf107617f88f4a9a390963b3b8a242a64ffcf481cd9424e74e6d2bb05caf40d3c16774f

Works fine on a machine with proper AVX instructions.
Ideally the library should not return invalid results as it did before v1.34.1 :)

Testing on i9-14900K, with AVX instructions disabled via BIOS.

@jtraglia
Copy link

I think the problem might be in mcl, specifically the upgrade from v1.86 to v1.88 (herumi/mcl@v1.86.0...v1.88). It looks like this is the primary change in v1.34.1 of this package. Nothing in that diff particularly stands out to me though.

@pk910
Copy link
Author

pk910 commented Aug 30, 2024

Disabling the AVX instructions via bios actually disables quite a few cpuid features:

model name	: Intel(R) Core(TM) i9-14900K
microcode	: 0x129

# AVX enabled
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi vnmi umip pku ospke waitpkg gfni vaes vpclmulqdq tme rdpid movdiri movdir64b fsrm md_clear serialize pconfig arch_lbr ibt flush_l1d arch_capabilities

# AVX disabled
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg cx16 xtpr pdcm sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave rdrand lahf_lm 3dnowprefetch cpuid_fault ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust smep erms invpcid rdseed smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi vnmi umip pku ospke waitpkg gfni tme rdpid movdiri movdir64b fsrm md_clear serialize pconfig arch_lbr ibt flush_l1d arch_capabilities

Features missing after disabling AVX: fma, avx, f16c, abm, bmi1, avx2, bmi2, adx, avx_vnni, vaes, vpclmulqdq

The problem is consistently reproducible after turning AVX on or off (works when enabled, gives the same invalid keys when disabled).
All versions after v1.34.1 consistently produce the same invalid keys with these features disabled.

@herumi
Copy link
Owner

herumi commented Aug 30, 2024

Thank you for the report.
I have confirmed that it is fixed in the latest version of mcl. Please wait a little while as I update it.
Unintentionally, the AVX code automatically generated by the compiler was mixed up before CPU determination.

@herumi
Copy link
Owner

herumi commented Sep 3, 2024

It appears to be a problem with binaries created by GitHub Action.
I used an emulator SDE.

>git reset --hard v1.34.1
>go build examples/sample.go
>./sample|grep verify
verify=true # on Xeon w9-3495X
>sde -nhm -- ./sample|grep verify
verify=false # emulate Nehalem

To test it in a local environment,

>gcc -v
gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04)
>make clean
>make -j
>rm sample
>go build examples/sample.go
>sde -nhm -- ./sample|grep verify
verify=true

I will look into it some more.

@herumi
Copy link
Owner

herumi commented Sep 3, 2024

Using gcc instead of clang seems to work fine.

@herumi
Copy link
Owner

herumi commented Sep 3, 2024

Could you try the latest version https://github.com/herumi/bls-eth-go-binary/releases/tag/v1.36.1 ?
It seems okay by SDE.

% go build examples/sample.go
% sde -nhm -- ./sample
sample1
verify=true
...

@pk910
Copy link
Author

pk910 commented Sep 9, 2024

yea, can confirm the latest v1.36.1 works fine again with AVX disabled.

(just for completeness: v1.36.0 dies with "signal: illegal instruction")

@jclapis
Copy link

jclapis commented Sep 18, 2024

Just noting that I ran into this problem earlier today, and updating to v1.36.1 worked for me as well.

@herumi herumi closed this as completed Sep 18, 2024
gsora added a commit to ObolNetwork/charon that referenced this issue Oct 23, 2024
Recent DKG issues may be due to an issue in
bls-eth-go-binary, caused by an upstream bug in their
dependencies.

Update to v1.36.1 which solves the issue.

Reference: herumi/bls-eth-go-binary#63
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants