Skip to content
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

Merged
merged 10 commits into from
Oct 22, 2019

Conversation

m-chrzan
Copy link
Contributor

@m-chrzan m-chrzan commented Oct 8, 2019

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

@@ -642,16 +642,21 @@ contract Attestations is IAttestations, Ownable, Initializable, UsingRegistry, R
internal
{
IRandom random = IRandom(registry.getAddressForOrDie(RANDOM_REGISTRY_ID));
IValidators validators = IValidators(
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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

packages/protocol/contracts/identity/Attestations.sol Outdated Show resolved Hide resolved
@asaj asaj assigned m-chrzan and unassigned asaj Oct 8, 2019
@nambrot nambrot removed their assignment Oct 10, 2019
@codecov
Copy link

codecov bot commented Oct 14, 2019

Codecov Report

Merging #1248 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          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
Flag Coverage Δ
#mobile 67.1% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 21f8cdc...31905d2. Read the comment docs.

@asaj asaj removed their assignment Oct 14, 2019
@mcortesi mcortesi self-requested a review October 15, 2019 09:16
@mcortesi mcortesi removed their assignment Oct 15, 2019
@m-chrzan m-chrzan assigned nambrot, mcortesi and asaj and unassigned m-chrzan Oct 16, 2019
@mcortesi
Copy link
Contributor

@m-chrzan I think there's a conflict with @asaj PR about PoS. Since the second one, add a UsingPrecompiles contract which seems to achieve the same we want here.

Copy link
Contributor

@asaj asaj left a 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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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;
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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

@asaj asaj assigned m-chrzan and unassigned asaj Oct 16, 2019
@nambrot nambrot force-pushed the m-chrzan/use-validator-precompile branch from c4d6c2c to ce76b44 Compare October 17, 2019 20:15
@nambrot nambrot assigned asaj and unassigned nambrot Oct 17, 2019
@asaj asaj assigned nambrot and unassigned asaj Oct 17, 2019
@m-chrzan m-chrzan merged commit 273fc82 into master Oct 22, 2019
aaronmgdr added a commit that referenced this pull request Oct 23, 2019
* 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)
  ...
aaronmgdr added a commit that referenced this pull request Oct 23, 2019
* 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)
  ...
aaronmgdr added a commit that referenced this pull request Oct 23, 2019
* 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)
  ...
@cmcewen cmcewen deleted the m-chrzan/use-validator-precompile branch December 2, 2019 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Attestation Users SBAT use the new precompile
5 participants