-
Notifications
You must be signed in to change notification settings - Fork 375
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
Use validator set precompiles in Attestations #1248
Changes from 2 commits
5c204df
ee13557
d3da2f0
b8e9211
fb9aba1
8701010
ec08cdd
535b8e1
ce76b44
31905d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,14 @@ contract MockValidators is IValidators { | |
return validators; | ||
} | ||
|
||
function numberValidatorsInCurrentSet() external view returns (uint256) { | ||
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. Why do we need this in 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. Same as the IValidators issue below. 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. Remove it? |
||
return validators.length; | ||
} | ||
|
||
function validatorAddressFromCurrentSet(uint256 index) external view returns (address) { | ||
return validators[index]; | ||
} | ||
|
||
function setValidating(address account) external { | ||
_isValidating[account] = true; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -757,17 +757,23 @@ contract Attestations is | |
internal | ||
{ | ||
IRandom random = IRandom(registry.getAddressForOrDie(RANDOM_REGISTRY_ID)); | ||
IValidators validators = IValidators( | ||
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. Do we need to call into the 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. We could. I was imagining having Validators expose a wrapper around the precompile to minimize complexity (with assembly in other contracts), though this does increase gas costs. 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. Agree with wanting to cut gas costs, but there is also a small technical problem I just ran into, that the current solution kind of nicely circumvents. If we use the precompile directly, we can't do ganache tests if we don't modify ethereumjs-vm to handle this precompile (which is not trivial since ganache has no concept of a validator set). By calling into the precompile wrapper in Validators, we can mock Validators and still test this function. 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. As we discussed offline, I think it's probably best to call the precompile directly in a privaet function, and to have a 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. Consider defining a 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. It would be nice to add some support for this to ganache. If not, we can't call any part of core contracts that use validators. Maybe define a list of addresses to serve as validators when launching it |
||
registry.getAddressForOrDie(VALIDATORS_REGISTRY_ID) | ||
); | ||
|
||
bytes32 seed = random.random(); | ||
address[] memory validators = getValidators(); | ||
uint256 numberValidators = validators.numberValidatorsInCurrentSet(); | ||
|
||
uint256 currentIndex = 0; | ||
address validator; | ||
address issuer; | ||
|
||
while (currentIndex < n) { | ||
seed = keccak256(abi.encodePacked(seed)); | ||
validator = validators[uint256(seed) % validators.length]; | ||
validator = validators.validatorAddressFromCurrentSet( | ||
m-chrzan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
uint256(seed) % numberValidators | ||
); | ||
|
||
issuer = getAccountFromValidator(validator); | ||
Attestation storage attestations = | ||
state.issuedAttestations[issuer]; | ||
|
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.
Do we need this in the IValidators interface?
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.
Leftover from before moving the precompile into Attestations.
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.
So remove it?