Ethereum: `pairing` function in `py_ecc.bn128` results in `RecursionError`

Ethereum mating feature PY_ECC_BN128 determines Recursionerror

The Ethereum pair feature is widely used for safe inspection of key exchange and digital signature. However, when implementing the couple’s function, users often face a common problem with PY_ECC_BN128.

Question

The problem arises from how the PY_ECC_BN128 handles the exhibition in its mating function. Specifically, it uses a technique called the Exponenance Squaring to effectively calculate the couple’s result.

When we try to multiply two points in G1 and G2 using G1 * G2, py_ecc_bn128 call yourself recursively to calculate the intermediate disposition results in square. However, in some cases, this recursive call can cause a pile of overflow or other unexpected behavior.

Solution

To solve this problem, we need to modify the couple’s function to avoid recursively when the intermediate result exceeds a certain threshold. Here’s the updated code:

`Python

from py_ecc.bn128 import g1, g2, pores, multiply

Def Porling_G1G2 (G1, G2):

“” “

Calculates a two -point pair using a square exhibit.

Args:

G1 (G1): First point.

G2 (G2): The second point.

Return:

Result: The calculated mating result.

“” “

Calculate the pores

p1 = mating (G1, G2)

Q1 = G2.p

Multiply pores to get the end result

A = multiply (p1, q1)

return a

`

In this updated installation, we define a new function Porling_G1G2, which accepts two points as an input and returns the result of their mating. We calculate the pores using the exhibit, dividing and multiplying them to get the final result.

Example of use

To show how to use a modified mating feature, let’s create two copies of G1 and G2 objects and perform a couple’s operation:

`Python

Create G1 and G2 specimens

G1 = g1.from_pem (“Your private key”)

G2 = g2.from_pem (“Your public key”)

Calculate the pores

p1 = mating (G1, G2)

Q1 = G2.p

Multiply pores to get the end result

A = multiply (p1, q1)

Print (a)

output: calculated mating result

`

By modifying the couple’s function in this way, using PY_ECC_BN128 to ensure safe exchange and digital signature to check, you should not face the Recursionerror.

ETHEREUM HAVE BITCOIN

error: Website is protected !!