From 43de24d88c87706366bd26d124cc6859366f336d Mon Sep 17 00:00:00 2001 From: therealyingtong Date: Thu, 22 Apr 2021 13:29:28 +0800 Subject: [PATCH] Add Orchard generators --- orchard_generators.py | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 orchard_generators.py diff --git a/orchard_generators.py b/orchard_generators.py new file mode 100644 index 0000000..1737108 --- /dev/null +++ b/orchard_generators.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +import sys; assert sys.version_info[0] >= 3, "Python 3 required." + +from pyblake2 import blake2s + +from tv_output import render_args, render_tv +from orchard_group_hash import group_hash +from orchard_sinsemilla import sinsemilla_hash_to_point + +# https://zips.z.cash/protocol/nu5.pdf#concretespendauthsig +SPENDING_KEY_BASE = group_hash(b'z.cash:Orchard', b'G') + +# https://zips.z.cash/protocol/nu5.pdf#commitmentsandnullifiers +NULLIFIER_K_BASE = group_hash(b'z.cash:Orchard', b'K') + +# https://zips.z.cash/protocol/nu5.pdf#concretehomomorphiccommit +VALUE_COMMITMENT_VALUE_BASE = group_hash(b'z.cash:Orchard-cv', b'v') +VALUE_COMMITMENT_RANDOMNESS_BASE = group_hash(b'z.cash:Orchard-cv', b'r') + +# Used in SinsemillaCommit (https://zips.z.cash/protocol/nu5.pdf#sinsemillacommitments) +NOTE_COMMITMENT_BASE = group_hash(b'z.cash:Orchard-NoteCommit-r', b'') +NOTE_COMMITMENT_Q = group_hash(b'z.cash:Orchard-NoteCommit-M', b'') + +# Used in SinsemillaShortCommit (https://zips.z.cash/protocol/nu5.pdf#sinsemillacommitments) +IVK_COMMITMENT_BASE = group_hash(b'z.cash:Orchard-CommitIvk-r', b'') +IVK_COMMITMENT_Q = group_hash(b'z.cash:Orchard-CommitIvk-M', b'') + +# Used in SinsemillaHash (https://zips.z.cash/protocol/nu5.pdf#orchardmerklecrh) +MERKLE_CRH_Q = group_hash(b'z.cash:Orchard-MerkleCRH', b'') + +def main(): + render_tv( + render_args(), + 'orchard_generators', + ( + ('skb', '[u8; 32]'), + ('nkb', '[u8; 32]'), + ('vcvb', '[u8; 32]'), + ('vcrb', '[u8; 32]'), + ('cmb', '[u8; 32]'), + ('cmq', '[u8; 32]'), + ('ivkb', '[u8; 32]'), + ('ivkq', '[u8; 32]'), + ('mcq', '[u8; 32]'), + ), + { + 'skb': bytes(SPENDING_KEY_BASE), + 'nkb': bytes(NULLIFIER_K_BASE), + 'vcvb': bytes(VALUE_COMMITMENT_VALUE_BASE), + 'vcrb': bytes(VALUE_COMMITMENT_RANDOMNESS_BASE), + 'cmb': bytes(NOTE_COMMITMENT_BASE), + 'cmq': bytes(NOTE_COMMITMENT_Q), + 'ivkb': bytes(IVK_COMMITMENT_BASE), + 'ivkq': bytes(IVK_COMMITMENT_Q), + 'mcq': bytes(MERKLE_CRH_Q), + }, + ) + + +if __name__ == '__main__': + main()