-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Lots of work in the now-extinct #65. * Composer tests shows memory issue * NOT working; TwoGates too trivial. * Zero out univariate accumulator (hack). * Init relation works. * Add failure tests. * Added Sage notebook. *Cleanup.
- Loading branch information
1 parent
41187fe
commit b5528ab
Showing
27 changed files
with
849 additions
and
338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,279 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "b1c5160a", | ||
"metadata": {}, | ||
"source": [ | ||
"# Barretenberg Notebook\n", | ||
"\n", | ||
"This is a start on a Sage notebook for checking one's work. I think we shouldn't build this out systematically, but periodically update it as we find the need to build some new functionality." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "0a1dead8-3d16-4175-a17b-217249302996", | ||
"metadata": {}, | ||
"source": [ | ||
"# General Utilities" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "1510ae41-d51c-4230-bbe5-24f3a5556b85", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"'{0x6c7301b49d85a46c, 0x44311531e39c64f6, 0xb13d66d8d6c1a24c, 0x04410c360230a295}'" | ||
] | ||
}, | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"# Convert a 256-bit hex string. Outputs four 64-bit limbs that can be used to construct a native field element.\n", | ||
"# Idea: s == barretenberg::fr(hex_to_field(s)).to_montgomery_form() is true as hex strings if s was in Montgomery form.\n", | ||
"def hex_to_field(s):\n", | ||
" s = s[2:] # slice off leading 0x\n", | ||
" data = [s[48:64], s[32:48], s[16:32], s[0:16]]\n", | ||
" data = [\"0x\" + d for d in data]\n", | ||
" out = ', '.join(data)\n", | ||
" return \"{\" + out + \"}\"\n", | ||
"\n", | ||
"hex_to_field('0x04410c360230a295b13d66d8d6c1a24c44311531e39c64f66c7301b49d85a46c')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "2bf8f9d7-8b17-4711-a52d-3da21337bfd4", | ||
"metadata": {}, | ||
"source": [ | ||
"# Basic Structures" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "1785930b", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Order of BN254 is: 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001\n", | ||
"21888242871839275222246405745257275088548364400416034343698204186575808495615\n", | ||
"X^2 + 21888242871839275222246405745257275088548364400416034343698204186575808495616\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# The BN254 prime.\n", | ||
"prime_r = 21888242871839275222246405745257275088548364400416034343698204186575808495617\n", | ||
"Fr = GF(prime_r)\n", | ||
"Polys.<X> = PolynomialRing(Fr)\n", | ||
"print(\"Order of BN254 is: \", hex(prime_r))\n", | ||
"print(Fr(-2))\n", | ||
"print((X + 1) * (X - 1))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "c28762ec", | ||
"metadata": {}, | ||
"source": [ | ||
"# Sumcheck Utilities\n", | ||
"Here we generate generate a two-gate example of a sumcheck calculation. The output of `get_values` is the expected `Univariate` produced after the first round." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "796ab188", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def get_values(poly):\n", | ||
" return [poly(i) for i in range(4)]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"id": "335dbb65-d2e3-4003-a8e9-576bd131a148", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def convert_to_polys(edge_list):\n", | ||
" return [edge[0] * (1-X) + edge[1] * X for edge in edge_list]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"id": "1dfb5ac7-bcdf-4341-87e6-6377ac1ba176", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"['0x0',\n", | ||
" '0x0',\n", | ||
" '0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593efffffff',\n", | ||
" '0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593effffffb']" | ||
] | ||
}, | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"edge_list = [[0, 1], [0, 1], [0, 2], [0, 0], [1, 1], [0, 1], [0, -1], [0, 0]]\n", | ||
"w_l, w_r, w_o, q_m, q_l, q_r, q_o, q_c = convert_to_polys(edge_list)\n", | ||
"[hex(val) for val in get_values(q_m * w_l * w_r + q_l * w_l + q_r * w_r + q_o * w_o + q_c)]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"id": "715f394b-e9f6-4311-8960-c13826070d08", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# edge_list = [[0,0] for _ in range(8)]\n", | ||
"# w_l, w_r, w_o, q_m, q_l, q_r, q_o, q_c = convert_to_polys(edge_list)\n", | ||
"# get_values(q_m * w_l * w_r + q_l * w_l + q_r * w_r + q_o * w_o + q_c)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"id": "810f52e0-6f5e-4f91-b0b8-e8f6878dfe66", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"u_2 = 0x2cb413b29041834eb4c859d50a771208a5e3dec2cd9bb2a1a13e5a57c6160691" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"id": "6fb88b21-efb7-447b-93b9-50627286965d", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[[20219933756566846493536316042331920548925056837893251409966172577112016684689, 0], [20219933756566846493536316042331920548925056837893251409966172577112016684689, 0], [18551624641294417764826226339406566009301749275370468476234140967648224873761, 0], [0, 0], [1, 0], [20219933756566846493536316042331920548925056837893251409966172577112016684689, 0], [1668309115272428728710089702925354539623307562522782933732031609463791810928, 0], [0, 0]]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"folded = [[poly(u_2), 0] for poly in [w_l, w_r, w_o, q_m, q_l, q_r, q_o, q_c]]\n", | ||
"print(folded)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"id": "40667a20-c063-4d51-b35b-5f62ea7d8890", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"True" | ||
] | ||
}, | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"folded == [[u_2, 0], [u_2, 0], [2*u_2, 0], [0, 0], [1, 0], [u_2, 0], [-u_2, 0], [0, 0]]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"id": "ecd54ffa-b3b4-4f5b-81c4-de1c3250a595", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"['0x2cb413b29041834eb4c859d50a771208a5e3dec2cd9bb2a1a13e5a57c6160691',\n", | ||
" '0x2cb413b29041834eb4c859d50a771208a5e3dec2cd9bb2a1a13e5a57c6160691',\n", | ||
" '0x2903d8f23f516673b1406df3936ccbb42393d53d217df4b1fe9abf1b9c2c0d21',\n", | ||
" '0x0',\n", | ||
" '0x1',\n", | ||
" '0x2cb413b29041834eb4c859d50a771208a5e3dec2cd9bb2a1a13e5a57c6160691',\n", | ||
" '0x3b03ac050f01cdb0387ebe1770a465482500985ac1dbdefa2a39b3c29e9f970',\n", | ||
" '0x0']" | ||
] | ||
}, | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"[hex(Fr(first)) for [first, second] in folded]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"id": "8e00fb7f-0085-45e0-af29-79ee9784842e", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"['0x18ea803098b5a8b9d02047be7a4f24cf4db4c25696323b82b34625f98827c179',\n", | ||
" '0x0',\n", | ||
" '0x18ea803098b5a8b9d02047be7a4f24cf4db4c25696323b82b34625f98827c179',\n", | ||
" '0x2e163dca0736293cfe0938ce639e282e66b38c965560ce84554acbe409f05e2']" | ||
] | ||
}, | ||
"execution_count": 11, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"w_l, w_r, w_o, q_m, q_l, q_r, q_o, q_c = convert_to_polys(folded)\n", | ||
"[hex(val) for val in get_values(q_m * w_l * w_r + q_l * w_l + q_r * w_r + q_o * w_o + q_c)]" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "SageMath 9.7", | ||
"language": "sage", | ||
"name": "sagemath" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.8" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.