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

SPV support with configurable backend #436

Merged
merged 4 commits into from Mar 14, 2019
Merged

SPV support with configurable backend #436

merged 4 commits into from Mar 14, 2019

Conversation

sirlensalot
Copy link
Contributor

Adds builtin verify-spv which utilizes supplied backend to operate on an Object payload, and return an object with the proof payload upon success.

Copy link
Member

@emilypi emilypi left a comment

Choose a reason for hiding this comment

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

Looks good! Only a few small comments

spv :: MVar (LibState) -> Text -> Object Name -> IO (Either Text (Object Name))
spv mv ty _ = readMVar mv >>= \LibState{..} -> case M.lookup ty _rlsMockSPV of
Nothing -> return $ Left $ "Unsupported SPV proof type: " <> ty
Just o -> return $ Right o
Copy link
Member

Choose a reason for hiding this comment

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

Why pass Object Name if it's never used? I'm assuming this is for future SPV work. If so, could we document what needs to be passed in there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This supports mock-spv -- we're not going to have actual SPV proofs in Pact or pact -s anytime soon, and I didn't want to build a cadillac mocker that is arg-dependent, so in repl scripts you just specify a response for a particular type and it will return that regardless of argument.

The larger question is whether the API itself is too lawless, ie string -> object -> object. There's nothing SPV-y about it, it's almost a general computation backend on untyped objects. The intent is to read something from the message payload which will be desz'd into the SPV proof object, and get back the desz'd payload of that proof, with support for "types", ie "TXIN" ("did my transaction go in?") and "TXOUT" ("did my transaction run and have this exact output?"). So I can't really think of a better shape, but thought I'd ask.

Copy link
Member

Choose a reason for hiding this comment

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

That's fair.

Unfortunately without "actually" calling out to SPV, i don't think you can do much besides mocking trivial SPV. That is, unless you want to come up with a way of storing merkle roots for a series of transactions and having the input object be verified as one of the inputs to a sort of "current merkle root" state in in the repl state, I don't how it could be lawful. For mocking, I guess this is fine, though, I do think it would be pretty cool to have SPV be tracked as part of the repl state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mocking on both arguments now as discussed

toJSON . _erOutput <$>
evalExec (setupEvalEnv dbEnv entity t (initMsgData (initialHashTx H.Blake2b_512))
refStore freeGasEnv permissiveNamespacePolicy noSPVSupport)
pc

benchKeySet :: KeySet
benchKeySet = KeySet [PublicKey "benchadmin"] (Name ">" def)
Copy link
Member

Choose a reason for hiding this comment

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

These pc's are a small legibility wibble. Maybe we should where on the evalExec so those <$>'s aren't line breaking on their arguments?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

@emilypi emilypi left a comment

Choose a reason for hiding this comment

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

Very slick 👍

@sirlensalot sirlensalot merged commit 81e41e0 into master Mar 14, 2019
@sirlensalot sirlensalot deleted the feat/spv branch March 14, 2019 22:36
@LindaOrtega LindaOrtega added the Pact 3.0 Features for next major Pact release label May 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pact 3.0 Features for next major Pact release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants