verifyGuestCommitment.ts 1.5 KB

1234567891011121314151617181920212223242526272829
  1. export default (msg, min_excess_fee, max_excess_fee, num_components) => {
  2. # validate a PlayerCommit message; return the parsed InitialCommitments
  3. check(len(msg.initial_commitments) == num_components, "wrong number of component commitments")
  4. check(len(msg.blind_sig_requests) == num_components, "wrong number of blind sig requests")
  5. check(min_excess_fee <= msg.excess_fee <= max_excess_fee, "bad excess fee")
  6. check(len(msg.random_number_commitment) == 32, "bad random commit")
  7. check(len(msg.pedersen_total_nonce) == 32, "bad nonce")
  8. check(all(len(r) == 32 for r in msg.blind_sig_requests), "bad blind sig request")
  9. commit_messages = []
  10. for cblob in msg.initial_commitments:
  11. cmsg = proto_strict_parse(pb.InitialCommitment(), cblob)
  12. check(len(cmsg.salted_component_hash) == 32, "bad salted hash")
  13. P = cmsg.amount_commitment
  14. check(len(P) == 65 and P[0] == 4, "bad commitment point")
  15. check(len(cmsg.communication_key) == 33 and cmsg.communication_key[0] in (2,3), "bad communication key")
  16. commit_messages.append(cmsg)
  17. # Verify pedersen commitment
  18. try:
  19. pointsum = pedersen.add_points([m.amount_commitment for m in commit_messages])
  20. claimed_commit = Protocol.PEDERSEN.commit(msg.excess_fee, int.from_bytes(msg.pedersen_total_nonce,'big'))
  21. except Exception as e:
  22. raise ValidationError("pedersen commitment verification error")
  23. check(pointsum == claimed_commit.P_uncompressed, "pedersen commitment mismatch")
  24. return commit_messages
  25. }