Skip to content

Finalize integration of Adjudicator to new Worker/Staker model#1093

Merged
KPrasch merged 27 commits intonucypher:alhambra-verdefrom
cygnusv:identity-crisis
Jul 1, 2019
Merged

Finalize integration of Adjudicator to new Worker/Staker model#1093
KPrasch merged 27 commits intonucypher:alhambra-verdefrom
cygnusv:identity-crisis

Conversation

@cygnusv
Copy link
Member

@cygnusv cygnusv commented Jun 18, 2019

This PR completes the integration of Adjudicator to the worker/staker separation. It closes the loop initiated in #259 with the format for re-encryption metadata, by integrating the worker's identity evidence from the creation of WorkOrder to the slashing of the staker in the Adjudicator contract, and everything in between.

It also tackles #931, by creating the agent and actor for Adjudicator, namely, AdjudicatorAgent and Investigator

In principle, it should be the last PR of alhambra-verde before considering it for review.

@codecov
Copy link

codecov bot commented Jun 19, 2019

Codecov Report

Merging #1093 into alhambra-verde will decrease coverage by 2.49%.
The diff coverage is 81.37%.

Impacted file tree graph

@@                Coverage Diff                @@
##           alhambra-verde    #1093     +/-   ##
=================================================
- Coverage           82.93%   80.44%   -2.5%     
=================================================
  Files                  69       69             
  Lines                9109     9179     +70     
=================================================
- Hits                 7555     7384    -171     
- Misses               1554     1795    +241
Impacted Files Coverage Δ
nucypher/characters/lawful.py 81.75% <ø> (-8.06%) ⬇️
nucypher/network/nodes.py 80.12% <ø> (-1.39%) ⬇️
nucypher/network/server.py 85.18% <ø> (-0.93%) ⬇️
nucypher/crypto/powers.py 91.05% <0%> (-2.44%) ⬇️
nucypher/crypto/api.py 91.11% <100%> (-6.45%) ⬇️
nucypher/blockchain/economics.py 100% <100%> (ø) ⬆️
nucypher/policy/models.py 89.38% <100%> (-2.22%) ⬇️
nucypher/utilities/sandbox/ursula.py 88.46% <33.33%> (-11.54%) ⬇️
nucypher/blockchain/eth/actors.py 78.23% <68.75%> (+1.4%) ⬆️
nucypher/blockchain/eth/deployers.py 91.24% <80%> (-0.16%) ⬇️
... and 17 more

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 93e9cf3...109a160. Read the comment docs.

@jMyles
Copy link
Contributor

jMyles commented Jun 24, 2019

Do I understand that we are having to roll out own EIP-191 logic in solidity? This seems counter-intuitive to me. For it not to have landed in python yet is to be expected, but why are we going down a path of maintaining a persistent script for an accepted EIP?

@cygnusv
Copy link
Member Author

cygnusv commented Jun 24, 2019

@jMyles We currently are using the geth's personal_sign method for signing, also called version E in EIP191. This is not a new decision: it was done in #1031, which was part of the hawksbeard EPIC.

The on-chain verification of EIP191 signatures is necessary since we have to verify these signatures in the Adjudicator contract. I must say that I don't necessarily think we should use version 0 signatures, since specifying the validator's address may prove to be complex in our setting, where contracts are upgradable. So perhaps version E signatures is enough.

Let's hear what @KPrasch thinks too, as author of #1031.

@cygnusv cygnusv changed the title [WIP] Identity crisis Finalize integration of Adjudicator to new Worker/Staker model Jun 24, 2019
@cygnusv cygnusv marked this pull request as ready for review June 24, 2019 13:20
emit CFragEvaluated(evaluationHash, msg.sender, cFragIsCorrect);
if (cFragIsCorrect) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

If we remove this than may be such situation: investigator has correct CFrag but broken signatures and as a result - failed tx, and gas wasting (and investigator can do it again). From contract perspective we have two steps - CFrag correctness and evidence correctness. So if CFrag is correct -> there is no such thing like evedence of incorrect CFrag and next checking of signatures is not neccesery (from blockchain perspective)

Copy link
Member Author

Choose a reason for hiding this comment

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

This check is not removed, just postponed until we check the signatures too (see line 166). I don't think that, in case of incorrect supporting evidence for the evaluation (e.g. bad signatures), we should (1) mark the CFrag as evaluated, and (2) emit an evaluation event, considering that the investigator already checks this off-chain before submitting (assuming she uses our nucypher code).

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, but if signatures are wrong than investigator will get just failed tx and CFrag evaluation will not be saved in storage. Checking this signatures don't change any step in algorithm if CFrag is correct: if cignatures are ok -> just check signatures, check balance of staker (require(stakerValue > 0, "Staker has no tokens");`) and do nothing - no any changes in storage state (except CFrag evaluation). if cignatures are broken -> same checks and failed tx. Why need fail tx in that situation?
Also from contract we can't be sure in anything outside of blockchain and can't be sure that investigator did everything properly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Before my changes, if CFrag was correct but signatures were wrong there was change in the state of the contract. This doesn't make sense, since it's not valid data. It may even be the case that the CFrag isn't coming from an Ursula: anyone can generate valid CFrags (e.g., using pyUmbral) with invalid signatures (since valid signatures involve participation of a real Ursula of the NuCypher network). Again, unless there's valid signatures, which imply real participation of an Ursula, we shouldn't change state.

Copy link
Member

Choose a reason for hiding this comment

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

Can't agree that don't need to save correct CFrag when investigators sent wrong signatures: because investigator already paid and data are still valid for contract state. But I don't want be a blocker with that so I'm ok with your point

return wrapped


def cache_transaction(actor_method):
Copy link
Member

Choose a reason for hiding this comment

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

👍 Very cool - What about the name @save_receipt?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. For consistency, then self._transaction_cache should change to self._saved_receipts. Is that OK?

Copy link
Contributor

Choose a reason for hiding this comment

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

True, those are not "transactions" (which one could cache for a rebroadcast, for example), but indeed receipts. Where do we use those saved receipts and when do we clean them?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, they are not used, and they are not persisted anywhere, so they are cleaned once the actor object disappears. But I can imagine how they can be used to improve UX (e.g, in the CLI or some other GUI-based client).

adjudicator_deployer.deploy(secret_hash=os.urandom(DispatcherDeployer.DISPATCHER_SECRET_LENGTH))
adjudicator_agent = adjudicator_deployer.make_agent() # 4

# TODO: Perhaps we should get rid of returning these agents here.
Copy link
Member

Choose a reason for hiding this comment

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

Totally agree here.

In my local tree I have started doing staking_agent = Agency.get_agent(StakingEscrowAgent).

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm just doing StakingEscrowAgent(). Shouldn't that return the singleton?

cygnusv added 20 commits June 28, 2019 14:31
return period

@only_me
@save_receipt
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

@KPrasch KPrasch merged commit cfcbc2b into nucypher:alhambra-verde Jul 1, 2019
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.

6 participants