-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Coordinator aware of transcript size #334
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
588b9a5
Add calldata cost when calculating gas reimbursements
cygnusv c11dfc0
Validate transcript size when posting
cygnusv 94ec0df
Adapt tests to transcript size validation
cygnusv bd41a0f
Test bad transcript size
cygnusv 6231be4
Upgrade Lynx coordinator
cygnusv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import os | ||
from enum import IntEnum | ||
|
||
import ape | ||
import pytest | ||
|
@@ -8,41 +7,13 @@ | |
from hexbytes import HexBytes | ||
from web3 import Web3 | ||
|
||
from tests.conftest import ONE_DAY, gen_public_key, generate_transcript, RitualState | ||
|
||
TIMEOUT = 1000 | ||
MAX_DKG_SIZE = 31 | ||
FEE_RATE = 42 | ||
ERC20_SUPPLY = 10**24 | ||
DURATION = 48 * 60 * 60 | ||
ONE_DAY = 24 * 60 * 60 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for this cleanup. We were repeating the RitualState enum and fixtures in a number of places. |
||
|
||
RitualState = IntEnum( | ||
"RitualState", | ||
[ | ||
"NON_INITIATED", | ||
"DKG_AWAITING_TRANSCRIPTS", | ||
"DKG_AWAITING_AGGREGATIONS", | ||
"DKG_TIMEOUT", | ||
"DKG_INVALID", | ||
"ACTIVE", | ||
"EXPIRED", | ||
], | ||
start=0, | ||
) | ||
|
||
|
||
# This formula returns an approximated size | ||
# To have a representative size, create transcripts with `nucypher-core` | ||
def transcript_size(shares, threshold): | ||
return int(424 + 240 * (shares / 2) + 50 * (threshold)) | ||
|
||
|
||
def gen_public_key(): | ||
return (os.urandom(32), os.urandom(32), os.urandom(32)) | ||
|
||
|
||
def access_control_error_message(address, role=None): | ||
role = role or b"\x00" * 32 | ||
return f"account={address}, neededRole={role}" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
|
@@ -275,7 +246,9 @@ def test_post_transcript(coordinator, nodes, initiator, erc20, fee_model, global | |
nodes=nodes, | ||
allow_logic=global_allow_list, | ||
) | ||
transcript = os.urandom(transcript_size(len(nodes), len(nodes))) | ||
size = len(nodes) | ||
threshold = coordinator.getThresholdForRitualSize(size) | ||
transcript = generate_transcript(size, threshold) | ||
|
||
for node in nodes: | ||
assert coordinator.getRitualState(0) == RitualState.DKG_AWAITING_TRANSCRIPTS | ||
|
@@ -309,7 +282,10 @@ def test_post_transcript_but_not_part_of_ritual( | |
allow_logic=global_allow_list, | ||
) | ||
|
||
transcript = os.urandom(transcript_size(len(nodes), len(nodes))) | ||
size = len(nodes) | ||
threshold = coordinator.getThresholdForRitualSize(size) | ||
transcript = generate_transcript(size, threshold) | ||
|
||
with ape.reverts("Participant not part of ritual"): | ||
coordinator.postTranscript(0, transcript, sender=initiator) | ||
|
||
|
@@ -325,12 +301,40 @@ def test_post_transcript_but_already_posted_transcript( | |
nodes=nodes, | ||
allow_logic=global_allow_list, | ||
) | ||
transcript = os.urandom(transcript_size(len(nodes), len(nodes))) | ||
|
||
size = len(nodes) | ||
threshold = coordinator.getThresholdForRitualSize(size) | ||
transcript = generate_transcript(size, threshold) | ||
|
||
coordinator.postTranscript(0, transcript, sender=nodes[0]) | ||
with ape.reverts("Node already posted transcript"): | ||
coordinator.postTranscript(0, transcript, sender=nodes[0]) | ||
|
||
|
||
def test_post_transcript_but_wrong_size( | ||
coordinator, nodes, initiator, erc20, fee_model, global_allow_list | ||
): | ||
initiate_ritual( | ||
coordinator=coordinator, | ||
fee_model=fee_model, | ||
erc20=erc20, | ||
authority=initiator, | ||
nodes=nodes, | ||
allow_logic=global_allow_list, | ||
) | ||
|
||
size = len(nodes) | ||
threshold = coordinator.getThresholdForRitualSize(size) | ||
bad_transcript = generate_transcript(size, threshold + 1) | ||
|
||
with ape.reverts("Invalid transcript size"): | ||
coordinator.postTranscript(0, bad_transcript, sender=nodes[0]) | ||
|
||
bad_transcript = b"" | ||
with ape.reverts("Invalid transcript size"): | ||
coordinator.postTranscript(0, bad_transcript, sender=nodes[0]) | ||
|
||
|
||
def test_post_transcript_but_not_waiting_for_transcripts( | ||
coordinator, nodes, initiator, erc20, fee_model, global_allow_list | ||
): | ||
|
@@ -342,7 +346,11 @@ def test_post_transcript_but_not_waiting_for_transcripts( | |
nodes=nodes, | ||
allow_logic=global_allow_list, | ||
) | ||
transcript = os.urandom(transcript_size(len(nodes), len(nodes))) | ||
|
||
size = len(nodes) | ||
threshold = coordinator.getThresholdForRitualSize(size) | ||
transcript = generate_transcript(size, threshold) | ||
|
||
for node in nodes: | ||
coordinator.postTranscript(0, transcript, sender=node) | ||
|
||
|
@@ -359,7 +367,10 @@ def test_get_participants(coordinator, nodes, initiator, erc20, fee_model, globa | |
nodes=nodes, | ||
allow_logic=global_allow_list, | ||
) | ||
transcript = os.urandom(transcript_size(len(nodes), len(nodes))) | ||
|
||
size = len(nodes) | ||
threshold = coordinator.getThresholdForRitualSize(size) | ||
transcript = generate_transcript(size, threshold) | ||
|
||
for node in nodes: | ||
_ = coordinator.postTranscript(0, transcript, sender=node) | ||
|
@@ -413,7 +424,10 @@ def test_get_participant(nodes, coordinator, initiator, erc20, fee_model, global | |
nodes=nodes, | ||
allow_logic=global_allow_list, | ||
) | ||
transcript = os.urandom(transcript_size(len(nodes), len(nodes))) | ||
|
||
size = len(nodes) | ||
threshold = coordinator.getThresholdForRitualSize(size) | ||
transcript = generate_transcript(size, threshold) | ||
|
||
for node in nodes: | ||
_ = coordinator.postTranscript(0, transcript, sender=node) | ||
|
@@ -462,8 +476,12 @@ def test_post_aggregation( | |
nodes=nodes, | ||
allow_logic=global_allow_list, | ||
) | ||
|
||
ritualID = 0 | ||
transcript = os.urandom(transcript_size(len(nodes), len(nodes))) | ||
size = len(nodes) | ||
threshold = coordinator.getThresholdForRitualSize(size) | ||
transcript = generate_transcript(size, threshold) | ||
|
||
for node in nodes: | ||
coordinator.postTranscript(ritualID, transcript, sender=node) | ||
|
||
|
@@ -520,8 +538,12 @@ def test_post_aggregation_fails( | |
nodes=nodes, | ||
allow_logic=global_allow_list, | ||
) | ||
|
||
ritualID = 0 | ||
transcript = os.urandom(transcript_size(len(nodes), len(nodes))) | ||
size = len(nodes) | ||
threshold = coordinator.getThresholdForRitualSize(size) | ||
transcript = generate_transcript(size, threshold) | ||
|
||
for node in nodes: | ||
coordinator.postTranscript(ritualID, transcript, sender=node) | ||
|
||
|
@@ -535,7 +557,7 @@ def test_post_aggregation_fails( | |
) | ||
|
||
# Second node screws up everything | ||
bad_aggregated = os.urandom(transcript_size(len(nodes), len(nodes))) | ||
bad_aggregated = generate_transcript(size, threshold) | ||
tx = coordinator.postAggregation( | ||
ritualID, bad_aggregated, dkg_public_key, decryption_request_static_keys[1], sender=nodes[1] | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a nitpick but
40
is the only unnamed component of this calculation. Perhaps it can be assigned to a constant similar to the BLS point sizes?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, but the thing is that I don't understand well enough where that 40 comes from. I mean, it's a fixed overhead that comes from rust serialization but I don't have a full explanation for it. I'll update this when I have more info.