You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.9 KiB

6 years ago
6 years ago
  1. # ADR 026: General Merkle Proof
  2. ## Context
  3. We are using raw `[]byte` for merkle proofs in `abci.ResponseQuery`. It makes hard to handle multilayer merkle proofs and general cases. Here, new interface `ProofOperator` is defined. The users can defines their own Merkle proof format and layer them easily.
  4. Goals:
  5. - Layer Merkle proofs without decoding/reencoding
  6. - Provide general way to chain proofs
  7. - Make the proof format extensible, allowing thirdparty proof types
  8. ## Decision
  9. ### ProofOperator
  10. `type ProofOperator` is an interface for Merkle proofs. The definition is:
  11. ```go
  12. type ProofOperator interface {
  13. Run([][]byte) ([][]byte, error)
  14. GetKey() []byte
  15. ProofOp() ProofOp
  16. }
  17. ```
  18. Since a proof can treat various data type, `Run()` takes `[][]byte` as the argument, not `[]byte`. For example, a range proof's `Run()` can take multiple key-values as its argument. It will then return the root of the tree for the further process, calculated with the input value.
  19. `ProofOperator` does not have to be a Merkle proof - it can be a function that transforms the argument for intermediate process e.g. prepending the length to the `[]byte`.
  20. ### ProofOp
  21. `type ProofOp` is a protobuf message which is a triple of `Type string`, `Key []byte`, and `Data []byte`. `ProofOperator` and `ProofOp`are interconvertible, using `ProofOperator.ProofOp()` and `OpDecoder()`, where `OpDecoder` is a function that each proof type can register for their own encoding scheme. For example, we can add an byte for encoding scheme before the serialized proof, supporting JSON decoding.
  22. ## Status
  23. Implemented
  24. ## Consequences
  25. ### Positive
  26. - Layering becomes easier (no encoding/decoding at each step)
  27. - Thirdparty proof format is available
  28. ### Negative
  29. - Larger size for abci.ResponseQuery
  30. - Unintuitive proof chaining(it is not clear what `Run()` is doing)
  31. - Additional codes for registering `OpDecoder`s