1
0

validateProofInternal.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * """ Validate a proof as far as we can without checking blockchain.
  3. Returns the deserialized InputComponent for further checking, if it was an
  4. input. """
  5. */
  6. export default (proofblob, commitment, all_components, bad_components, component_feerate) => {
  7. msg = proto_strict_parse(pb.Proof(), proofblob)
  8. try:
  9. componentblob = all_components[msg.component_idx]
  10. except IndexError:
  11. raise ValidationError("component index out of range")
  12. check(msg.component_idx not in bad_components, "component in bad list")
  13. # these deserializations should always succeed since we've already done them before.
  14. comp = pb.Component()
  15. comp.ParseFromString(componentblob)
  16. assert comp.IsInitialized()
  17. check(len(msg.salt) == 32, "salt wrong length")
  18. check(sha256(msg.salt) == comp.salt_commitment, "salt commitment mismatch")
  19. check(sha256(msg.salt + componentblob) == commitment.salted_component_hash, "salted component hash mismatch")
  20. contrib = component_contrib(comp, component_feerate)
  21. P_committed = commitment.amount_commitment
  22. claimed_commit = Protocol.PEDERSEN.commit(contrib, int.from_bytes(msg.pedersen_nonce,'big'))
  23. check(P_committed == claimed_commit.P_uncompressed, "pedersen commitment mismatch")
  24. if comp.WhichOneof('component') == 'input':
  25. return comp.input
  26. else:
  27. return None
  28. }