Skip to content

Conversation

@Jim8y
Copy link
Contributor

@Jim8y Jim8y commented Sep 22, 2025

This is requested and needed by NeoX.

Description

Adds Ethereum-compatible aliases for the BLS12-381 native contract methods (bls12_*) while
retaining the existing bls12381* surface. This keeps Neo and EVM tooling interoperable without
schema changes. Updated tests cover both naming schemes, and the expected genesis manifest now
includes the new ABI entries.

Fixes # (issue)

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • dotnet test tests/Neo.UnitTests/Neo.UnitTests.csproj --filter CryptoLib

Test Configuration:

  • .NET SDK 9.0.301
  • Default protocol settings via test harness

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@Jim8y Jim8y force-pushed the feature/bls12-eth-aliases branch from a157ce3 to 1a443fe Compare September 22, 2025 04:32
};
}

[ContractMethod(Hardfork.HF_Gorgon, CpuFee = 1 << 19, Name = "bls12_g1add")]
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it be HF_Faun

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it should be Faun

Copy link
Member

@vncoelho vncoelho left a comment

Choose a reason for hiding this comment

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

Looks good, it can be in the next release

Copy link
Contributor

@roman-khimov roman-khimov left a comment

Choose a reason for hiding this comment

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

What's preventing contracts from using the already existing names?


[ContractMethod(Hardfork.HF_Gorgon, CpuFee = 1 << 19, Name = "bls12_g1add")]
public static InteropInterface Bls12G1Add(InteropInterface x, InteropInterface y)
=> Bls12381Add(x, y);
Copy link
Member

Choose a reason for hiding this comment

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

Adds Ethereum-compatible aliases

CryptoLib calls won't be compatible with Ethereum anyway, so I don't think this PR can be accepted. It adds an ambiguity to the CryptoLib interface.

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, the same thing (if we really care about specific names which is questionable to me since it's about N3 contracts, they're different from EVM/Solidity contracts anyway) can be provided by devpack without contract modifications (and code/manifest bloat).

Copy link
Member

@shargon shargon left a comment

Choose a reason for hiding this comment

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

It only change the name?

Wi1l-B0t
Wi1l-B0t previously approved these changes Sep 26, 2025
Copy link
Contributor

@Wi1l-B0t Wi1l-B0t left a comment

Choose a reason for hiding this comment

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

It seems to be just for compatibility.

@Jim8y
Copy link
Contributor Author

Jim8y commented Sep 26, 2025

What's preventing contracts from using the already existing names?

hi roman @roman-khimov , this is a requested change for neox, i am not sure the detail, but i guess its related to eip standards, you or anna should know it better than me.

Copy link
Contributor

@roman-khimov roman-khimov left a comment

Choose a reason for hiding this comment

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

Aliases are not needed. We need to add compatibility with https://eips.ethereum.org/EIPS/eip-2537 and the only thing that can be incompatible now is bls12381MultiExp. So there is some functional extension we need here rather than aliases.

@txhsl
Copy link

txhsl commented Sep 26, 2025

We need to add compatibility with https://eips.ethereum.org/EIPS/eip-2537 and the only thing that can be incompatible now is bls12381MultiExp.

Yes, the EIP-2537 has been updated several times since Feb 2024, but now it gets finalized. The history can be referred https://github.com/ethereum/EIPs/commits/master/EIPS/eip-2537.md.

@erikzhang
Copy link
Member

@neo-project/ngd-shanghai Need testing.

/// </summary>
/// <param name="pairs">Array of [point, scalar] pairs.</param>
/// <returns>The accumulated point.</returns>
[ContractMethod(Hardfork.HF_Gorgon, CpuFee = 1 << 23)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Faun

{
var scalar = ParseScalar(pair[1]);
if (!scalar.IsZero)
g1Accumulator += new G1Projective(g1Affine) * scalar;
Copy link

@txhsl txhsl Oct 20, 2025

Choose a reason for hiding this comment

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

We need to make sure that subgroup check is executed before any multiplication operation. This was fixed in Ethereum through ethereum/EIPs#8456.

Briefly speaking, we need:

  1. "IsOnCurve" check after G1 point decoding and G2 point decoding, e.g. https://github.com/ethereum/go-ethereum/blob/v1.16.5/core/vm/contracts.go#L1212;
  2. "IsInSubGroup" check before multiply and pairing computation, e.g. https://github.com/ethereum/go-ethereum/blob/v1.16.5/core/vm/contracts.go#L1005 and https://github.com/ethereum/go-ethereum/blob/v1.16.5/core/vm/contracts.go#L1173.

About the detailed implementation of these checks, please ref https://github.com/Consensys/gnark-crypto/blob/v0.19.0/ecc/bls12-381/g1.go#L193-L218 and https://github.com/Consensys/gnark-crypto/blob/v0.19.0/ecc/bls12-381/g2.go#L200-L223.

/// <param name="pairs">Array of [point, scalar] pairs.</param>
/// <returns>The accumulated point.</returns>
[ContractMethod(Hardfork.HF_Faun, CpuFee = 1 << 23)]
public static InteropInterface Bls12381MultiExp(Array pairs)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we need to check the length, a max is required or it could deny the service with 1024 pairs

@cschuchardt88
Copy link
Member

the right way to execute a test by filters is

 dotnet test tests/Neo.UnitTests/Neo.UnitTests.csproj -- --filter CryptoLib

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants