-
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
Conversation
@@ -642,16 +642,21 @@ contract Attestations is IAttestations, Ownable, Initializable, UsingRegistry, R | |||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to call into the Validators
smart contract for this, or can this contract call the precompile directly?
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.
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 comment
The 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 comment
The 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 TestAttestations
contract that inherits from Attestations
and mocks out the call to the precompile
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.
Consider defining a UsingPrecompiles
contract, e.g. https://github.com/celo-org/celo-monorepo/pull/1292/files#diff-0cffec14a25e6876b387a826c4b4946d
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.
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
Codecov Report
@@ Coverage Diff @@
## master #1248 +/- ##
======================================
Coverage 67.1% 67.1%
======================================
Files 266 266
Lines 7776 7776
Branches 512 512
======================================
Hits 5218 5218
Misses 2456 2456
Partials 102 102
Continue to review full report at Codecov.
|
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 some small nits
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this in MockValidators
?
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.
Same as the IValidators issue below.
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.
Remove it?
@@ -5,4 +5,6 @@ interface IValidators { | |||
function isVoting(address) external view returns (bool); | |||
function isValidating(address) external view returns (bool); | |||
function getValidators() external view returns (address[] memory); | |||
function validatorAddressFromCurrentSet(uint256) external view returns (address); |
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?
* couldn't test `request` with the current ganache local testnet. | ||
*/ | ||
contract TestAttestations is Attestations { | ||
address[] private __testValidators; |
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.
Why __
prefix? One underscore would be more consistent with what we do elsewhere
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.
That was precisely my reasoning - since we use _
sometimes, since this is a mock function that should never collide with an actual function, __
would avoid such potential collisions. Of course we don't want to fall down the rabbit hole of ___
, ____
, ..., in the future, but I can't imagine us needing to go down another level.
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 expect collisions? I feel like a single _
is fine
c4d6c2c
to
ce76b44
Compare
* master: (37 commits) [Wallet] Add support for social wallet (Safeguards) import (#1414) [Wallet] Implement new backup flows including social backup (#1399) Use validator set precompiles in Attestations (#1248) E2E Attestations test + various e2e improvements (#1417) Update Footer (#1331) [Wallet] New camera permission flow (#1398) [Wallet] Enable push notifications on iOS (#1389) [Wallet] Add Celo Lite toggle (UI only, zeroSync on/off in other PR) (#1369) Document npm inter-repo dependencies instructions (#1370) [wallet]Add more documentation on ZeroSync mode (#1367) [wallet]Add documentation for jndcrash (#1364) Point end-to-end tests back to master (#1372) Alfajores changes & comment on unlocking accounts (#1297) Reconfigure terraform local configuration during init to allow multiple envs (#773) Implement proof-of-stake changes (#1177) [Celotool] Update blockchain-api deploy script to automatically update faucet address (#1347) Allow most recently reporting oracle to report again (#1288) [wallet]Add documentation for ZeroSync mode (#1361) Fix Metadata registration during contract deploy (#1346) [Wallet] Enable firebase on iOS (#1344) ...
* master: (128 commits) [Wallet] Add support for social wallet (Safeguards) import (#1414) [Wallet] Implement new backup flows including social backup (#1399) Use validator set precompiles in Attestations (#1248) E2E Attestations test + various e2e improvements (#1417) Update Footer (#1331) [Wallet] New camera permission flow (#1398) [Wallet] Enable push notifications on iOS (#1389) [Wallet] Add Celo Lite toggle (UI only, zeroSync on/off in other PR) (#1369) Document npm inter-repo dependencies instructions (#1370) [wallet]Add more documentation on ZeroSync mode (#1367) [wallet]Add documentation for jndcrash (#1364) Point end-to-end tests back to master (#1372) Alfajores changes & comment on unlocking accounts (#1297) Reconfigure terraform local configuration during init to allow multiple envs (#773) Implement proof-of-stake changes (#1177) [Celotool] Update blockchain-api deploy script to automatically update faucet address (#1347) Allow most recently reporting oracle to report again (#1288) [wallet]Add documentation for ZeroSync mode (#1361) Fix Metadata registration during contract deploy (#1346) [Wallet] Enable firebase on iOS (#1344) ...
* master: (37 commits) [Wallet] Add support for social wallet (Safeguards) import (#1414) [Wallet] Implement new backup flows including social backup (#1399) Use validator set precompiles in Attestations (#1248) E2E Attestations test + various e2e improvements (#1417) Update Footer (#1331) [Wallet] New camera permission flow (#1398) [Wallet] Enable push notifications on iOS (#1389) [Wallet] Add Celo Lite toggle (UI only, zeroSync on/off in other PR) (#1369) Document npm inter-repo dependencies instructions (#1370) [wallet]Add more documentation on ZeroSync mode (#1367) [wallet]Add documentation for jndcrash (#1364) Point end-to-end tests back to master (#1372) Alfajores changes & comment on unlocking accounts (#1297) Reconfigure terraform local configuration during init to allow multiple envs (#773) Implement proof-of-stake changes (#1177) [Celotool] Update blockchain-api deploy script to automatically update faucet address (#1347) Allow most recently reporting oracle to report again (#1288) [wallet]Add documentation for ZeroSync mode (#1361) Fix Metadata registration during contract deploy (#1346) [Wallet] Enable firebase on iOS (#1344) ...
Description
We recently added precompiles to access the validator set on-chain, allowing for constant time access to a validator's address at a particular index in the set. We can use this to correctly and efficiently implement attestation requests.
Tested
Unit tests still pass after adding new mock functions to MockValidators.
Related issues