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

Guard against non-expected parties during init observation. #295

Merged
merged 10 commits into from
Apr 6, 2022

Conversation

KtorZ
Copy link
Collaborator

@KtorZ KtorZ commented Apr 5, 2022

  • 📍 Add mutation on initial output address Pass list of PKH to on-chain state and verify PTs minting using that #243

  • 📍 Add pub key hashes to list of parties in on-chain head parameters.

  • 📍 Verify PTs match their respective pubkey hashes in head parameters.

  • 📍 Revert "Verify PTs match their respective pubkey hashes in head parameters."
    & Revert "Add pub key hashes to list of parties in on-chain head parameters.".

    After discussing the next steps, we realized that passing the pub key
    hashes on-chain and checking the PTs does not actually provide any
    extra security guarantees and only makes the on-chain code more
    complicated.

    In the end, this is something we can only truly handle off-chain,
    durign the observation of an init transaction. It is the observer who
    knows the configuration it is expecting, and that can decide whether
    some observation is valid or not.

    On-chain, there isn't much we can do since, anyone crafting the init
    transaction may also change the redeemer, parameters or anything
    really. The participants of a head are BY DEFINITION the keys
    identified by the PT. Now, those participants may or may not reflect a
    known configuration of a node, but this is decided off-chain
    exclusively.

  • 📍 Extract observe init mutations from init mutations.

  • 📍 Define new mutation properties for testing off-chain code observation.
    Use it for catching errors on an ill-formed init tx.

  • 📍 Fix output selection for init mutation: make tests fail for the right reason.
    Whoopsie...

  • 📍 Add Cardano credentials verification during init observation.

  • 📍 Tweak observe-init mutation to mutate minted values instead of outputs.
    Indeed... mutating outputs isn't caught by our guard because we only
    check minted values. Which is this however sufficient?

    (a) The ledger rules ensure that any minted value is actually properly
    distributed in outputs (transaction ins and outs must balance each
    other)

    (b) Our on-chain validator does ensure that the right number of assets
    are minted, in the right quantity, and that assets are distributed
    across the right number of outputs.

abailly-iohk and others added 9 commits April 5, 2022 12:12
…eters."

  & Revert "Add pub key hashes to list of parties in on-chain head parameters.".

  After discussing the next steps, we realized that passing the pub key
  hashes on-chain and checking the PTs does not actually provide any
  extra security guarantees and only makes the on-chain code more
  complicated.

  In the end, this is something we can only truly handle off-chain,
  durign the observation of an init transaction. It is the observer who
  knows the configuration it is expecting, and that can decide whether
  some observation is valid or not.

  On-chain, there isn't much we can do since, anyone crafting the init
  transaction may also change the redeemer, parameters or anything
  really. The participants of a head are BY DEFINITION the keys
  identified by the PT. Now, those participants may or may not reflect a
  known configuration of a node, but this is decided off-chain
  exclusively.
  Use it for catching errors on an illed-formed init tx.
  Indeed... mutating outputs isn't caught by our guard because we only
  check minted values. Which is this however sufficient?

  (a) The ledger rules ensure that any minted value is actually properly
  distributed in outputs (transaction ins and outs must balance each
  other)

  (b) Our on-chain validator does ensure that the right number of assets
  are minted, in the right quantity, and that assets are distributed
  across the right number of outputs.
@KtorZ KtorZ requested a review from a team April 5, 2022 15:57
@KtorZ KtorZ self-assigned this Apr 5, 2022
Copy link
Contributor

@abailly-iohk abailly-iohk left a comment

Choose a reason for hiding this comment

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

Minor comments

hydra-cardano-api/src/Hydra/Cardano/Api/Value.hs Outdated Show resolved Hide resolved
@@ -158,6 +159,7 @@ withDirectChain tracer networkId iocp socketPath keyPair party cardanoKeys callb
SomeOnChainHeadState $
idleOnChainHeadState
networkId
(cardanoKeys \\ [verificationKey wallet])
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Perhaps worthwhile to detail the comment on line 151 so that this line makes more within the context?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or just pass only peers' keys?

(event, observation) <- observeInitTx networkId ownParty tx
observeTx tx OnChainHeadState{networkId, peerVerificationKeys, ownParty, ownVerificationKey} = do
let allVerificationKeys = ownVerificationKey : peerVerificationKeys
(event, observation) <- observeInitTx networkId allVerificationKeys ownParty tx
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like we are not very consistent in what we store or pass as arguments to functions: Sometimes we pass all keys including ours, sometimes only our peers'...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, but this is very much context dependent... I started with all keys in the State, but, since the state also stored the ownVerificationKey, there was redundancy in the state which is room for hazards.

Within the observation function however, we care not about this distinction and all keys can be treated the same.. Not very consistent but,... I don't know, still preferable?

hydra-node/test/Hydra/Chain/Direct/Contract/Init.hs Outdated Show resolved Hide resolved
hydra-node/test/Hydra/Chain/Direct/Contract/Init.hs Outdated Show resolved Hide resolved
@github-actions
Copy link

github-actions bot commented Apr 5, 2022

Unit Test Results

    5 files  ±0    71 suites  ±0   7m 16s ⏱️ -18s
192 tests +1  190 ✔️ +1  2 💤 ±0  0 ±0 

Results for commit 7814721. ± Comparison against base commit 51546e9.

This pull request removes 1 and adds 2 tests. Note that renamed tests count towards both.
Hydra.Chain.Direct.Contract/Init ‑ does not survive random adversarial mutations
Hydra.Chain.Direct.Contract/Init ‑ does not survive random adversarial mutations (off-chain)
Hydra.Chain.Direct.Contract/Init ‑ does not survive random adversarial mutations (on-chain)

♻️ This comment has been updated with latest results.

@KtorZ KtorZ changed the title Guard against non-expected parties during init observation.c Guard against non-expected parties during init observation. Apr 6, 2022
@KtorZ KtorZ merged commit ef0bb53 into master Apr 6, 2022
@KtorZ KtorZ deleted the ensemble/check-pts-match-parties branch April 6, 2022 09:05
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.

2 participants