Extract sapling_generators Rust rendering
This commit is contained in:
parent
7e37b8cc24
commit
9f4a41dcf3
|
@ -1,9 +1,8 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from binascii import hexlify
|
|
||||||
from pyblake2 import blake2s
|
from pyblake2 import blake2s
|
||||||
|
|
||||||
from sapling_jubjub import Point, JUBJUB_COFACTOR
|
from sapling_jubjub import Point, JUBJUB_COFACTOR
|
||||||
from tv_output import chunk
|
from tv_output import tv_rust
|
||||||
|
|
||||||
# First 64 bytes of the BLAKE2s input during group hash.
|
# First 64 bytes of the BLAKE2s input during group hash.
|
||||||
# This is chosen to be some random string that we couldn't have
|
# This is chosen to be some random string that we couldn't have
|
||||||
|
@ -51,44 +50,25 @@ VALUE_COMMITMENT_RANDOMNESS_BASE = find_group_hash(b'Zcash_cv', b'r')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print('''
|
tv_rust(
|
||||||
struct SaplingGenerators {
|
'sapling_generators',
|
||||||
skb: [u8; 32],
|
(
|
||||||
pkb: [u8; 32],
|
('skb', '[u8; 32]'),
|
||||||
npb: [u8; 32],
|
('pkb', '[u8; 32]'),
|
||||||
wprb: [u8; 32],
|
('npb', '[u8; 32]'),
|
||||||
vcvb: [u8; 32],
|
('wprb', '[u8; 32]'),
|
||||||
vcrb: [u8; 32],
|
('vcvb', '[u8; 32]'),
|
||||||
};
|
('vcrb', '[u8; 32]'),
|
||||||
|
),
|
||||||
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/sapling_generators.py
|
{
|
||||||
let sapling_generators = SaplingGenerators {
|
'skb': bytes(SPENDING_KEY_BASE),
|
||||||
skb: [
|
'pkb': bytes(PROVING_KEY_BASE),
|
||||||
%s
|
'npb': bytes(NOTE_POSITION_BASE),
|
||||||
],
|
'wprb': bytes(WINDOWED_PEDERSEN_RANDOMNESS_BASE),
|
||||||
pkb: [
|
'vcvb': bytes(VALUE_COMMITMENT_VALUE_BASE),
|
||||||
%s
|
'vcrb': bytes(VALUE_COMMITMENT_RANDOMNESS_BASE),
|
||||||
],
|
},
|
||||||
npb: [
|
)
|
||||||
%s
|
|
||||||
],
|
|
||||||
wprb: [
|
|
||||||
%s
|
|
||||||
],
|
|
||||||
vcvb: [
|
|
||||||
%s
|
|
||||||
],
|
|
||||||
vcrb: [
|
|
||||||
%s
|
|
||||||
],
|
|
||||||
};''' % (
|
|
||||||
chunk(hexlify(bytes(SPENDING_KEY_BASE))),
|
|
||||||
chunk(hexlify(bytes(PROVING_KEY_BASE))),
|
|
||||||
chunk(hexlify(bytes(NOTE_POSITION_BASE))),
|
|
||||||
chunk(hexlify(bytes(WINDOWED_PEDERSEN_RANDOMNESS_BASE))),
|
|
||||||
chunk(hexlify(bytes(VALUE_COMMITMENT_VALUE_BASE))),
|
|
||||||
chunk(hexlify(bytes(VALUE_COMMITMENT_RANDOMNESS_BASE))),
|
|
||||||
))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
26
tv_output.py
26
tv_output.py
|
@ -1,3 +1,29 @@
|
||||||
|
from binascii import hexlify
|
||||||
|
|
||||||
|
|
||||||
def chunk(h):
|
def chunk(h):
|
||||||
h = str(h, 'utf-8')
|
h = str(h, 'utf-8')
|
||||||
return '0x' + ', 0x'.join([h[i:i+2] for i in range(0, len(h), 2)])
|
return '0x' + ', 0x'.join([h[i:i+2] for i in range(0, len(h), 2)])
|
||||||
|
|
||||||
|
def tv_part_rust(name, value):
|
||||||
|
print(''' %s: [
|
||||||
|
%s
|
||||||
|
],''' % (
|
||||||
|
name,
|
||||||
|
chunk(hexlify(value))
|
||||||
|
))
|
||||||
|
|
||||||
|
def tv_rust(filename, parts, vectors):
|
||||||
|
print(' struct TestVector {')
|
||||||
|
[print(' %s: %s,' % p) for p in parts]
|
||||||
|
print(''' };
|
||||||
|
|
||||||
|
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/%s.py''' % (
|
||||||
|
filename,
|
||||||
|
))
|
||||||
|
if type(vectors) == type({}):
|
||||||
|
print(' let test_vector = TestVector {')
|
||||||
|
[tv_part_rust(p[0], vectors[p[0]]) for p in parts]
|
||||||
|
print(' };')
|
||||||
|
else:
|
||||||
|
raise ValueError('Invalid type(vectors)')
|
||||||
|
|
Loading…
Reference in New Issue