Skip to content

core: add Ethereum-compatible BLS12-381 serializators and operations to CryptoLib#4050

Open
Turalchik wants to merge 1 commit intomasterfrom
bls12-eth-aliases
Open

core: add Ethereum-compatible BLS12-381 serializators and operations to CryptoLib#4050
Turalchik wants to merge 1 commit intomasterfrom
bls12-eth-aliases

Conversation

@Turalchik
Copy link
Copy Markdown
Contributor

Close #4041.

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 27, 2025

Codecov Report

❌ Patch coverage is 90.22005% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.49%. Comparing base (86a7038) to head (09d273a).
⚠️ Report is 78 commits behind head on master.

Files with missing lines Patch % Lines
pkg/core/native/crypto.go 91.84% 25 Missing and 2 partials ⚠️
pkg/core/native/crypto_blspoints.go 83.33% 9 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4050      +/-   ##
==========================================
+ Coverage   83.45%   83.49%   +0.04%     
==========================================
  Files         352      352              
  Lines       42754    43158     +404     
==========================================
+ Hits        35679    36036     +357     
- Misses       5323     5366      +43     
- Partials     1752     1756       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@roman-khimov
Copy link
Copy Markdown
Member

It's not about aliases now, it's just a new function.

Copy link
Copy Markdown
Member

@AnnaShaleva AnnaShaleva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Workflows are failing.

Also, need some time to check the main math logic.

Comment thread docs/node-configuration.md Outdated
Comment thread pkg/interop/native/crypto/crypto.go
Comment thread go.mod Outdated
google.golang.org/protobuf v1.36.9 // indirect
)

replace github.com/nspcc-dev/neo-go/pkg/interop => ./pkg/interop No newline at end of file
Copy link
Copy Markdown
Member

@AnnaShaleva AnnaShaleva Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove it once PR is finilized.

Comment thread pkg/core/native/native_test/cryptolib_test.go Outdated
Comment thread pkg/core/native/native_test/management_test.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
@AnnaShaleva AnnaShaleva added the blocked Can't be done because of something label Nov 6, 2025
@Turalchik Turalchik force-pushed the bls12-eth-aliases branch 6 times, most recently from 0d9946b to 531864f Compare December 8, 2025 20:06
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
@Turalchik Turalchik force-pushed the bls12-eth-aliases branch 10 times, most recently from 008e092 to db38756 Compare December 11, 2025 13:56
@AnnaShaleva AnnaShaleva removed the blocked Can't be done because of something label Dec 11, 2025
@Turalchik Turalchik force-pushed the bls12-eth-aliases branch 3 times, most recently from 3aabc28 to 40f06e3 Compare December 12, 2025 08:14
@Turalchik Turalchik force-pushed the bls12-eth-aliases branch 5 times, most recently from 14c0d14 to 22bdc25 Compare December 12, 2025 18:00
Comment thread pkg/core/native/crypto.go Outdated
@Turalchik Turalchik force-pushed the bls12-eth-aliases branch 2 times, most recently from 444f75c to 84e7b36 Compare December 15, 2025 10:13
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go
Comment thread pkg/core/native/crypto_blspoints.go Outdated
Comment thread pkg/core/native/crypto.go Outdated
Comment thread pkg/core/native/crypto.go
@AnnaShaleva AnnaShaleva changed the title core: add Ethereum-compatible aliases for BLS12-381 core: add Ethereum-compatible serializators and operations for BLS12-381 to CryptoLib Dec 15, 2025
@AnnaShaleva AnnaShaleva changed the title core: add Ethereum-compatible serializators and operations for BLS12-381 to CryptoLib core: add Ethereum-compatible BLS12-381 serializators and operations to CryptoLib Dec 15, 2025
@Turalchik Turalchik force-pushed the bls12-eth-aliases branch 4 times, most recently from e438231 to f99c5a9 Compare December 17, 2025 15:08

func (p *blsPoint) FromBytesEth(buf []byte) error {
switch l := len(buf); l {
case bls12G1EncodedLength:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add default case, return an appropriate error.

}
}

func (p blsPoint) BytesEth() []byte {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exported method needs a comment.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto everywhere.

Close #4041.

Signed-off-by: Tural Devrishev <tural@nspcc.ru>
@AnnaShaleva
Copy link
Copy Markdown
Member

@txhsl could you please review the implementation one more time? This CryptoLib API is the final suggestion from our side. Our primary concern was neo-project/neo#4186 (comment), so we believe it's solved in this PR.

Copy link
Copy Markdown

@txhsl txhsl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our primary concern was neo-project/neo#4186 (comment), so we believe it's solved in this PR.

Yes, I see the difference you've made, and the implementation is quite clear to me.

Maybe it's time for @Jim8y to have a look on this, he's a bit confused about the idea at the beginning.

Comment thread pkg/core/native/crypto.go
res = append(res, p.BytesEth()...)
scalarBE := scalar.Bytes()
scalarBytes := make([]byte, bls12ScalarLength)
copy(scalarBytes[bls12ScalarLength-len(scalarBE):], scalarBE)
Copy link
Copy Markdown

@txhsl txhsl Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a length/border check first?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will panic with slice bounds out of range if scalarBE doesn't fit into bls12ScalarLength.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will panic with slice bounds out of range if scalarBE doesn't fit into bls12ScalarLength.

Oh, yes.

const (
g1Hex = "97f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb"
g2Hex = "93e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8"
ethG1MultiExpSingleInputHex = "0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e10000000000000000000000000000000000000000000000000000000000000011"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can have more EVM test cases for operations other than MultiExp, although IMO they have already provided enough guarantees.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, at least we need to add:

  1. Compatibility tests for bls12381PairingList with some hex-encoded raw data that may be ported to C#.
  2. Bi-directional serializators tests for all added APIs: ensure that result of serialize(deserialize(input)) matches the input exactly.

Comment thread pkg/core/native/crypto.go
return stackitem.NewByteArray(res)
}

func (c *Crypto) bls12381SerializeEthList(_ *interop.Context, args []stackitem.Item) stackitem.Item {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every introduced method needs a comment explaining which type of conversion it's performing, like it's done for bls12381SerializeList.

Comment thread pkg/core/native/crypto.go
res = append(res, p.BytesEth()...)
scalarBE := scalar.Bytes()
scalarBytes := make([]byte, bls12ScalarLength)
copy(scalarBytes[bls12ScalarLength-len(scalarBE):], scalarBE)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will panic with slice bounds out of range if scalarBE doesn't fit into bls12ScalarLength.

const (
g1Hex = "97f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb"
g2Hex = "93e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8"
ethG1MultiExpSingleInputHex = "0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e10000000000000000000000000000000000000000000000000000000000000011"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, at least we need to add:

  1. Compatibility tests for bls12381PairingList with some hex-encoded raw data that may be ported to C#.
  2. Bi-directional serializators tests for all added APIs: ensure that result of serialize(deserialize(input)) matches the input exactly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocked Can't be done because of something

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BLS12-381 multi exponentiation

4 participants