-
Notifications
You must be signed in to change notification settings - Fork 146
Swappable BLS backend #746
Comments
Inspired by the pattern used in the spec. In option 2 we can override the global variable bls with a decorator, which works well even the bls is buried in a deep call. from eth2._utils.bls import (
TrueBackend as bls,
ChiaBackend,
)
MSG = b'\x56' * 32
INVALID_SIG = b'\x56' * 96
INVALID_PUB = b'\x56' * 48
DOMAIN = 5
def decorate_chia(fn):
def entry(*args, **kwargs):
fn.__globals__['bls'] = ChiaBackend
output = fn(*args, **kwargs)
return output
return entry
def foo(msg, public_key, signature):
return bls.verify(msg, public_key, signature, DOMAIN)
@decorate_chia
def foo_decorated(msg, public_key, signature):
return bls.verify(msg, public_key, signature, DOMAIN)
def child_function_needs_bls(msg, public_key, signature):
return foo(msg, public_key, signature)
@decorate_chia
def bury_bls_so_deep(msg, public_key, signature):
return child_function_needs_bls(msg, public_key, signature)
if __name__ == '__main__':
assert foo(MSG, INVALID_PUB, INVALID_SIG)
assert not foo_decorated(MSG, INVALID_PUB, INVALID_SIG)
assert not bury_bls_so_deep(MSG, INVALID_PUB, INVALID_SIG) |
In general I prefer Option 1 where we properly defer to a passed-in backend. Btw |
I would recommend looking at In fact, it's not out of the question to bake this into the |
Also quoting here: #808 (review)
|
can we close this issue? we have moved ahead w/ a "swappable" backend implementation for the BLS routines... it seems like there is some support to (eventually) move the BLS crypto into |
For the moving to |
What is wrong?
After #708 we have a fast BLS API based on Chia's implementation. But we might want the freedom to switch between different implementation for different use cases.
For example,
How can it be fixed
Option 1: Pass as an argument to functions that need BLS methods
For example,
This makes inserting the desired backend to production code and testing code very easy. The downside is the diffs will bubble up to lots of functions and we need to reason that ultimately which class should hold these backends as their property (Chain, StateMachine, or StateTransition?).
Option 2: Import and mock in test
For example,
This is more like the current status. The pros and cons are opposite to option 1. Need inputs from @pipermerriam @cburgdorf @hwwhww
The text was updated successfully, but these errors were encountered: