Miller loop loaded on appimage via an .so C module.
This commit is contained in:
parent
f5558965e5
commit
a34121d3c6
4 changed files with 64 additions and 12 deletions
|
|
@ -19,16 +19,6 @@ from py_ecc.optimized_bls12_381.optimized_curve import FQ, FQ2
|
||||||
from core.errors.logger import logger
|
from core.errors.logger import logger
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
# for the (optional) validity tests:
|
|
||||||
try:
|
|
||||||
from core.services.crypto.cython.bls12_381_pairing import pairing
|
|
||||||
logger.info("Imported Cython pairings")
|
|
||||||
except ImportError:
|
|
||||||
# Fallback to py_ecc if not compiled
|
|
||||||
from py_ecc.optimized_bls12_381 import pairing
|
|
||||||
logger.error("FAILED to import cython pairings, used python py_ecc")
|
|
||||||
|
|
||||||
|
|
||||||
class TicketCustomer:
|
class TicketCustomer:
|
||||||
"""
|
"""
|
||||||
This class is the basis for all the crypto operations,
|
This class is the basis for all the crypto operations,
|
||||||
|
|
@ -37,6 +27,10 @@ class TicketCustomer:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
# lazy load of millers from so file:
|
||||||
|
from core.services.helpers.load_packages import load_millers_pairing
|
||||||
|
self.pairing = load_millers_pairing()
|
||||||
|
|
||||||
self.blinded_data = None
|
self.blinded_data = None
|
||||||
self.signature = None
|
self.signature = None
|
||||||
|
|
||||||
|
|
@ -223,7 +217,7 @@ class TicketCustomer:
|
||||||
# All of that was to prep the values for this pairing equation,
|
# All of that was to prep the values for this pairing equation,
|
||||||
# Which now uses Cython
|
# Which now uses Cython
|
||||||
try:
|
try:
|
||||||
if pairing(blinded_signature, G1) == pairing(
|
if self.pairing(blinded_signature, G1) == self.pairing(
|
||||||
blinded_commitment, projective_public_key
|
blinded_commitment, projective_public_key
|
||||||
):
|
):
|
||||||
return {"valid": True, "message": "It worked."}
|
return {"valid": True, "message": "It worked."}
|
||||||
|
|
|
||||||
57
core/services/helpers/load_packages.py
Normal file
57
core/services/helpers/load_packages.py
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
|
||||||
|
from core.errors.logger import logger
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import importlib.util
|
||||||
|
import os
|
||||||
|
|
||||||
|
def is_this_an_appimage():
|
||||||
|
if "APPIMAGE" in os.environ:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def load_millers_pairing():
|
||||||
|
|
||||||
|
if is_this_an_appimage():
|
||||||
|
# 1. Get the path to the python binary currently running
|
||||||
|
# This will be something like /tmp/.mount_myapp-EpCCLd/usr/bin/python3
|
||||||
|
exe_path = sys.executable
|
||||||
|
|
||||||
|
# 2. Find the AppImage mount root.
|
||||||
|
# We climb up from /usr/bin/python3 until we hit the root of the mount.
|
||||||
|
# In most AppImages, the root is 2 or 3 levels above the binary.
|
||||||
|
# A safer way is to look for the 'src' folder relative to the binary.
|
||||||
|
app_root = os.path.dirname(os.path.dirname(os.path.dirname(exe_path)))
|
||||||
|
|
||||||
|
# 3. Now build the absolute path using the root from step 2 + the relative path:
|
||||||
|
relative_path = "src/sp-hydra-veil-core/core/services/crypto/cython/bls12_381_pairing.cpython-312-x86_64-linux-gnu.so"
|
||||||
|
full_path = os.path.join(app_root, relative_path)
|
||||||
|
|
||||||
|
print(f"AppImage's Correct absolute path: {full_path}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
spec = importlib.util.spec_from_file_location("bls12_381_pairing", full_path)
|
||||||
|
my_module = importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(my_module)
|
||||||
|
print("Successfully loaded the so!")
|
||||||
|
return pairing
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"AppImage Failed to import cython pairings, used python py_ecc. {str(e)}")
|
||||||
|
# Fallback to py_ecc if not compiled
|
||||||
|
from py_ecc.optimized_bls12_381 import pairing
|
||||||
|
return pairing
|
||||||
|
|
||||||
|
# NOT an appimage:
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
from core.services.crypto.cython.bls12_381_pairing import pairing
|
||||||
|
logger.info("Imported Cython pairings")
|
||||||
|
return pairing
|
||||||
|
|
||||||
|
except ImportError as e:
|
||||||
|
# Fallback to py_ecc if not compiled
|
||||||
|
from py_ecc.optimized_bls12_381 import pairing
|
||||||
|
logger.error(f"Non-Appimage Failed to import cython pairings, used python py_ecc. {str(e)}")
|
||||||
|
return pairing
|
||||||
|
|
@ -146,7 +146,6 @@ def run_generic_command(
|
||||||
|
|
||||||
try:
|
try:
|
||||||
returncode, stdout = _run_command_via_terminal(command, timeout)
|
returncode, stdout = _run_command_via_terminal(command, timeout)
|
||||||
print("got output")
|
|
||||||
|
|
||||||
# output_data = stdout
|
# output_data = stdout
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ dependencies = [
|
||||||
"charset-normalizer==3.4.7",
|
"charset-normalizer==3.4.7",
|
||||||
"click==8.3.3",
|
"click==8.3.3",
|
||||||
"cytoolz==1.1.0",
|
"cytoolz==1.1.0",
|
||||||
|
"Cython==3.3.0",
|
||||||
"eth-hash==0.8.0",
|
"eth-hash==0.8.0",
|
||||||
"eth-typing==6.0.0",
|
"eth-typing==6.0.0",
|
||||||
"eth-utils==6.0.0",
|
"eth-utils==6.0.0",
|
||||||
|
|
@ -41,6 +42,7 @@ dependencies = [
|
||||||
"pydeps==3.0.6",
|
"pydeps==3.0.6",
|
||||||
"pytokens==0.4.1",
|
"pytokens==0.4.1",
|
||||||
"PyYAML==6.0.3",
|
"PyYAML==6.0.3",
|
||||||
|
"setuptools==84.0.0",
|
||||||
"stdlib-list==0.12.0",
|
"stdlib-list==0.12.0",
|
||||||
"SQLAlchemy==2.0.51",
|
"SQLAlchemy==2.0.51",
|
||||||
"toolz==1.1.0",
|
"toolz==1.1.0",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue