mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-02-20 14:28:22 +00:00
BLS on/off deco
This commit is contained in:
parent
ca22c195e0
commit
904e2e9c0c
@ -13,7 +13,7 @@ from typing import (
|
||||
Tuple,
|
||||
)
|
||||
from eth2spec.utils.minimal_ssz import *
|
||||
from eth2spec.utils.bls_stub import *
|
||||
from eth2spec.utils.bls import *
|
||||
|
||||
""")
|
||||
for i in (1, 2, 3, 4, 8, 32, 48, 96):
|
||||
|
@ -1,4 +1,5 @@
|
||||
from eth2spec.phase0 import spec
|
||||
from eth2spec.utils import bls
|
||||
|
||||
from .helpers import create_genesis_state
|
||||
|
||||
@ -10,7 +11,7 @@ with_state = with_args(lambda: [create_genesis_state(spec.SLOTS_PER_EPOCH * 8, l
|
||||
|
||||
# shorthand for decorating @with_state @spectest()
|
||||
def spec_state_test(fn):
|
||||
return with_state(spectest()(fn))
|
||||
return with_state(bls_switch(spectest()(fn)))
|
||||
|
||||
|
||||
def expect_assertion_error(fn):
|
||||
@ -25,3 +26,27 @@ def expect_assertion_error(fn):
|
||||
pass
|
||||
if bad:
|
||||
raise AssertionError('expected an assertion error, but got none.')
|
||||
|
||||
|
||||
def always_bls(fn):
|
||||
"""
|
||||
Decorator to apply on ``bls_switch`` decorator to force BLS activation. Useful to mark tests as BLS-dependent.
|
||||
"""
|
||||
def entry(*args, **kw):
|
||||
# override bls setting
|
||||
kw['bls_active'] = True
|
||||
fn(*args, **kw)
|
||||
return entry
|
||||
|
||||
|
||||
def bls_switch(fn):
|
||||
"""
|
||||
Decorator to make a function execute with BLS ON, or BLS off.
|
||||
Based on an optional bool argument ``bls_active``, passed to the function at runtime.
|
||||
"""
|
||||
def entry(*args, **kw):
|
||||
old_state = bls.bls_active
|
||||
bls.bls_active = kw.pop('bls_active', False)
|
||||
fn(*args, **kw)
|
||||
bls.bls_active = old_state
|
||||
return entry
|
||||
|
@ -1,4 +1,5 @@
|
||||
from eth2spec.debug.encode import encode
|
||||
from eth2spec.utils import bls
|
||||
|
||||
|
||||
def spectest(description: str = None):
|
||||
@ -18,6 +19,9 @@ def spectest(description: str = None):
|
||||
else:
|
||||
# description can be explicit
|
||||
out['description'] = description
|
||||
# If BLS is not active, mark the test as BLS-ignorant.
|
||||
if not bls.bls_active:
|
||||
out['stub_bls'] = True
|
||||
# put all generated data into a dict.
|
||||
for data in fn(*args, **kw):
|
||||
# If there is a type argument, encode it as that type.
|
||||
|
25
test_libs/pyspec/eth2spec/utils/bls.py
Normal file
25
test_libs/pyspec/eth2spec/utils/bls.py
Normal file
@ -0,0 +1,25 @@
|
||||
from py_ecc import bls
|
||||
|
||||
# Flag to make BLS active or not. Used for testing, do not ignore BLS in production unless you know what you are doing.
|
||||
bls_active = True
|
||||
|
||||
|
||||
def bls_verify(pubkey, message_hash, signature, domain):
|
||||
if bls_active:
|
||||
return bls.verify(message_hash=message_hash, pubkey=pubkey, signature=signature, domain=domain)
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def bls_verify_multiple(pubkeys, message_hashes, signature, domain):
|
||||
if bls_active:
|
||||
return bls.verify_multiple(pubkeys, message_hashes, signature, domain)
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def bls_aggregate_pubkeys(pubkeys):
|
||||
if bls_active:
|
||||
return bls.aggregate_pubkeys(pubkeys)
|
||||
else:
|
||||
return b'\x42' * 96
|
@ -1,12 +0,0 @@
|
||||
|
||||
|
||||
def bls_verify(pubkey, message_hash, signature, domain):
|
||||
return True
|
||||
|
||||
|
||||
def bls_verify_multiple(pubkeys, message_hashes, signature, domain):
|
||||
return True
|
||||
|
||||
|
||||
def bls_aggregate_pubkeys(pubkeys):
|
||||
return b'\x42' * 96
|
Loading…
x
Reference in New Issue
Block a user