diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a76513d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,37 @@ +name: ci +on: + push: + pull_request: +jobs: + lean: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install elan + run: | + curl https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -sSf | sh -s -- -y --default-toolchain none + echo "$HOME/.elan/bin" >> "$GITHUB_PATH" + - name: Fetch Mathlib cache + run: lake exe cache get + - name: Build + run: lake build + - name: Build tests + run: lake build RandTest + - name: Axiom audit + run: scripts/audit.sh + generated: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Rust 1.98.1 + run: rustup toolchain install 1.98.1 --profile minimal + - name: Cache exporter build + uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + exporter/target + key: exporter-${{ runner.os }}-${{ hashFiles('exporter/Cargo.lock', 'exporter/Cargo.toml', 'SOURCES.toml') }} + - name: Regenerate and diff Rand/Generated + run: scripts/check-generated.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1e57bff --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.lake/ +build/ +third_party/ +exporter/target/ diff --git a/ASSUMPTIONS.md b/ASSUMPTIONS.md new file mode 100644 index 0000000..8ea1c03 --- /dev/null +++ b/ASSUMPTIONS.md @@ -0,0 +1,31 @@ +# Assumptions + +Every assumption below matches a named Lean hypothesis (a `structure` field or +a theorem argument, never an `axiom`). The list is the initial one and grows +with the proofs. + +- **Known gap: the Poseidon2 round constants are a development seed + (`research/src/poseidon2_constants.rs`, listed in `research/AGENTS.md`), not + the published constants. Replacing them changes every chain hash and needs a + chain cut, which is outside this project; publication does not wait on it.** +- STARK/FRI soundness with the deployed parameters (RV32: blowup 3, 80 + queries, 20 PoW bits; rVM: blowup 4 per rate ¼, 92 queries, 24 PoW bits), + and LogUp/permutation bus soundness ⇒ multiset equality. +- Poseidon2, BLAKE3, Keccak-f, SHA-256 behave as their bus contracts say. +- Dilithium2 EUF-CMA; validator signatures unforgeable. +- The Rust compiler, Plonky3 prover/verifier code, the RV32 guest toolchain, + and the RV32→rVM constraint emitter are trusted. +- Honest replicas persist safety state before voting; < 1/3 Byzantine stake + per epoch; epoch hand-off. +- The RV32 lookup contracts (`Rand.rv32Contract`: RANGE8, POW2, AND4, OR4, + XOR4) are justified by the fixed tables' contents plus bus soundness: the + exporter prints the range and nibble chips' `preprocessed_trace`s into + `Rand/Generated/RV32/Tables.lean`, and `RandTest/Contracts.lean` checks each + contract against those rows by `decide`. The table chips' own AIRs (that the + provided multiplicities are the only entries on those buses) are not yet + proved; M2 proves them. +- The exporter (`exporter/`, `air2lean`) is trusted to translate Plonky3's + symbolic constraint DAG faithfully. It fails on any leaf, bus or interaction + kind it does not translate; `scripts/check-generated.sh` (CI job + `generated`) regenerates `Rand/Generated/` from the pinned circuits commit + and fails on any difference. diff --git a/Audit.lean b/Audit.lean new file mode 100644 index 0000000..e94360c --- /dev/null +++ b/Audit.lean @@ -0,0 +1,28 @@ +import Lean +import Rand + +/-! +# Axiom audit + +Every theorem in `published` may depend only on `propext`, `Classical.choice` +and `Quot.sound`. `scripts/audit.sh` runs this file and fails on any other axiom +(which also catches `native_decide`, via `Lean.ofReduceBool`). +-/ + +open Lean Elab Command + +/-- The published theorems (listed in `PROVEN.md`). Empty until Task 5 onward. -/ +def published : List Name := [] + +def allowedAxioms : List Name := [`propext, `Classical.choice, `Quot.sound] + +run_cmd do + let mut bad := false + for n in published do + let axs ← liftCoreM <| collectAxioms n + let extra := axs.filter (fun a => !allowedAxioms.contains a) + logInfo m!"{n}: {axs.toList}" + if !extra.isEmpty then + bad := true + logError m!"{n} depends on disallowed axioms: {extra.toList}" + if !bad then logInfo m!"audit ok: {published.length} theorem(s)" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f288702 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/PROVEN.md b/PROVEN.md new file mode 100644 index 0000000..df0b9a6 --- /dev/null +++ b/PROVEN.md @@ -0,0 +1,17 @@ +# Proven + +| Theorem | Plain statement | Lean name | Models | Assumptions | +|---|---|---|---|---| + +## Scope + +Statements are about the Rand chain-21 genesis configuration and the circuits +commit pinned in [`SOURCES.toml`](SOURCES.toml). Source anchors +(`-- models: /: @`) are a review prompt: a CI script +reports which anchored Rust bodies changed when a new pin is proposed. They are +not a proof that the Lean model corresponds to the Rust code. + +CI runs `#print axioms`-style checks (`scripts/audit.sh`) on every published +theorem and fails unless the result is within `propext`, `Classical.choice`, +`Quot.sound`. See [`ASSUMPTIONS.md`](ASSUMPTIONS.md) for what the theorems take +on trust. diff --git a/README.md b/README.md new file mode 100644 index 0000000..630eca8 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# Rand: Lean 4 formal verification + +Public Lean 4 / Mathlib formalization of parts of the Rand blockchain full node +and its zero-knowledge circuits. Constraints of the Plonky3 AIRs are exported +from the Rust source and soundness is proved against them; the first target is +the RV32 ALU chip. + +- [`PROVEN.md`](PROVEN.md): each published theorem, in plain English, with its Lean name, the Rust it models and the assumptions it takes. +- [`ASSUMPTIONS.md`](ASSUMPTIONS.md): everything taken on trust, including a known Poseidon2 constants gap. +- [`SOURCES.toml`](SOURCES.toml): the exact fullnode and circuits commits the model was checked against. + +## Build + +Requires [elan](https://github.com/leanprover/elan). The toolchain is pinned in `lean-toolchain`. + +``` +lake exe cache get # prebuilt Mathlib; do not build Mathlib from source +lake build +lake build RandTest +scripts/audit.sh # no sorry/admit/axiom/native_decide; published theorems use only propext, Classical.choice, Quot.sound +``` + +`Rand/Generated/` is printed by the Rust exporter in `exporter/` (`air2lean`, Rust +1.98.1) from the circuits commit pinned in `SOURCES.toml`; never edit it by hand. +`scripts/check-generated.sh` fetches that commit, regenerates and diffs +(`RAND_SOURCES_LOCAL_CIRCUITS=/path` fetches from a local clone). + +The field is Goldilocks, `p = 2^64 - 2^32 + 1`, modelled as `ZMod p` (`Rand/Field.lean`). + +## License + +GPL-3.0, see `LICENSE`. diff --git a/Rand.lean b/Rand.lean new file mode 100644 index 0000000..5b706e6 --- /dev/null +++ b/Rand.lean @@ -0,0 +1,9 @@ +import Rand.Field +import Rand.Bus +import Rand.RV32.Contracts +import Rand.RV32.AluSpec +import Rand.Generated.RV32.AluVectors +import Rand.Generated.RV32.Alu +import Rand.Generated.RV32.AluHonest +import Rand.Generated.RV32.Tables +import Rand.RV32.Alu.Basic diff --git a/Rand/Bus.lean b/Rand/Bus.lean new file mode 100644 index 0000000..04d7548 --- /dev/null +++ b/Rand/Bus.lean @@ -0,0 +1,23 @@ +import Rand.Field + +namespace Rand + +/-- Interaction kinds on a bus. `lookup` consumes a table entry; `provide` is the +table side; `send`/`receive` are the two halves of a permutation bus. -/ +inductive Kind | lookup | provide | send | receive + deriving DecidableEq + +/-- One bus interaction of an AIR row: a tuple on a named bus with a multiplicity. -/ +structure Interaction where + bus : String + kind : Kind + tuple : List F + count : F + +/-- Bus soundness assumption, in usable form: every *lookup* whose count is +nonzero hits a tuple satisfying the bus contract. A gated-off lookup +(count `0`) and non-lookup kinds are not constrained. -/ +def lookupsHold (contract : String → List F → Prop) (is : List Interaction) : Prop := + ∀ i ∈ is, i.kind = .lookup → i.count ≠ 0 → contract i.bus i.tuple + +end Rand diff --git a/Rand/Field.lean b/Rand/Field.lean new file mode 100644 index 0000000..d4d91a0 --- /dev/null +++ b/Rand/Field.lean @@ -0,0 +1,119 @@ +import Mathlib.Data.ZMod.Basic +import Mathlib.Tactic.NormNum.Prime +import Mathlib.Tactic.NormNum.PowMod +import Mathlib.Tactic.ReduceModChar +import Mathlib.NumberTheory.LucasPrimality + +/-! +# The Goldilocks field + +`p = 2^64 - 2^32 + 1`, the base field of the Plonky3 AIRs, modelled as `ZMod p`. +Hand-written; models the field used by `rand_zkvm` (circuits pin in `SOURCES.toml`). +-/ + +namespace Rand + +namespace Goldilocks + +/-- The Goldilocks prime `2^64 - 2^32 + 1`. -/ +def p : ℕ := 18446744069414584321 + +theorem p_eq : p = 2 ^ 64 - 2 ^ 32 + 1 := by norm_num [p] + +end Goldilocks + +open Goldilocks + +/-- Lucas certificate part 1: `7^(p-1) = 1` in `ZMod p`, with `p` as a literal. -/ +private theorem seven_pow_top : (7 : ZMod 18446744069414584321) ^ 18446744069414584320 = 1 := by + reduce_mod_char + +private theorem seven_pow_div_2 : (7 : ZMod 18446744069414584321) ^ 9223372034707292160 ≠ 1 := by + reduce_mod_char + decide + +private theorem seven_pow_div_3 : (7 : ZMod 18446744069414584321) ^ 6148914689804861440 ≠ 1 := by + reduce_mod_char + decide + +private theorem seven_pow_div_5 : (7 : ZMod 18446744069414584321) ^ 3689348813882916864 ≠ 1 := by + reduce_mod_char + decide + +private theorem seven_pow_div_17 : (7 : ZMod 18446744069414584321) ^ 1085102592318504960 ≠ 1 := by + reduce_mod_char + decide + +private theorem seven_pow_div_257 : (7 : ZMod 18446744069414584321) ^ 71777214277877760 ≠ 1 := by + reduce_mod_char + decide + +private theorem seven_pow_div_65537 : (7 : ZMod 18446744069414584321) ^ 281470681743360 ≠ 1 := by + reduce_mod_char + decide + +/-- Primality of `p` by a Lucas certificate: `7` has order `p - 1`, and +`p - 1 = 2^32 * 3 * 5 * 17 * 257 * 65537`. (`norm_num` alone would trial-divide.) +The modular powers are evaluated by `reduce_mod_char` (square-and-multiply). -/ +theorem p_prime : p.Prime := by + have hfac : p - 1 = 2 ^ 32 * 3 * 5 * 17 * 257 * 65537 := by norm_num [p] + refine lucas_primality p 7 ?_ ?_ + · have h : p - 1 = 18446744069414584320 := by norm_num [p] + rw [h] + exact seven_pow_top + · intro q hq hdvd + rw [hfac] at hdvd + have e : ∀ r : ℕ, r.Prime → q ∣ r → q = r := fun r hr h => + (Nat.prime_dvd_prime_iff_eq hq hr).1 h + have key : q = 2 ∨ q = 3 ∨ q = 5 ∨ q = 17 ∨ q = 257 ∨ q = 65537 := by + rcases (Nat.Prime.dvd_mul hq).1 hdvd with h | h + · rcases (Nat.Prime.dvd_mul hq).1 h with h | h + · rcases (Nat.Prime.dvd_mul hq).1 h with h | h + · rcases (Nat.Prime.dvd_mul hq).1 h with h | h + · rcases (Nat.Prime.dvd_mul hq).1 h with h | h + · exact Or.inl (e 2 Nat.prime_two (hq.dvd_of_dvd_pow h)) + · exact Or.inr (Or.inl (e 3 (by norm_num) h)) + · exact Or.inr (Or.inr (Or.inl (e 5 (by norm_num) h))) + · exact Or.inr (Or.inr (Or.inr (Or.inl (e 17 (by norm_num) h)))) + · exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inl (e 257 (by norm_num) h))))) + · exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (e 65537 (by norm_num) h))))) + have hp : p - 1 = 18446744069414584320 := by norm_num [p] + rw [hp] + rcases key with rfl | rfl | rfl | rfl | rfl | rfl + · have h : (18446744069414584320 : ℕ) / 2 = 9223372034707292160 := by norm_num + rw [h] + exact seven_pow_div_2 + · have h : (18446744069414584320 : ℕ) / 3 = 6148914689804861440 := by norm_num + rw [h] + exact seven_pow_div_3 + · have h : (18446744069414584320 : ℕ) / 5 = 3689348813882916864 := by norm_num + rw [h] + exact seven_pow_div_5 + · have h : (18446744069414584320 : ℕ) / 17 = 1085102592318504960 := by norm_num + rw [h] + exact seven_pow_div_17 + · have h : (18446744069414584320 : ℕ) / 257 = 71777214277877760 := by norm_num + rw [h] + exact seven_pow_div_257 + · have h : (18446744069414584320 : ℕ) / 65537 = 281470681743360 := by norm_num + rw [h] + exact seven_pow_div_65537 + +instance : Fact p.Prime := ⟨p_prime⟩ + +/-- The Goldilocks field. -/ +abbrev F := ZMod p + +/-- No wrap-around: the canonical value of a sum, given an explicit bound. -/ +theorem val_add_of_lt {a b : F} (h : a.val + b.val < p) : (a + b).val = a.val + b.val := by + rw [ZMod.val_add, Nat.mod_eq_of_lt h] + +/-- No wrap-around: the canonical value of a product, given an explicit bound. -/ +theorem val_mul_of_lt {a b : F} (h : a.val * b.val < p) : (a * b).val = a.val * b.val := by + rw [ZMod.val_mul, Nat.mod_eq_of_lt h] + +/-- Casting a small natural number into `F` and back is the identity. -/ +theorem val_natCast_of_lt {n : ℕ} (h : n < p) : (n : F).val = n := by + rw [ZMod.val_natCast, Nat.mod_eq_of_lt h] + +end Rand diff --git a/Rand/Generated/RV32/Alu.lean b/Rand/Generated/RV32/Alu.lean new file mode 100644 index 0000000..2fe2ed3 --- /dev/null +++ b/Rand/Generated/RV32/Alu.lean @@ -0,0 +1,218 @@ +-- GENERATED by exporter from zkp-circuits @b3e21d9ea16225452bcd03a94317cb61e1705979. Do not edit. +import Rand.Bus + +/-! The `alu` chip's base constraints and bus interactions, read off its `Air::eval` +through Plonky3's symbolic builder: 72 constraints, 77 interactions. -/ + +namespace Rand.Generated.RV32.Alu + +open Rand + +/-- Main trace width. -/ +def width : ℕ := 64 + +/-- Every base constraint, in `eval` order; a row is accepted iff all are `0`. -/ +def constraints (m : Fin 64 → F) : List F := + let x0 := (m ⟨0, by decide⟩ + m ⟨1, by decide⟩) + let x1 := (m ⟨8, by decide⟩ + m ⟨9, by decide⟩) + let x2 := (m ⟨46, by decide⟩ + m ⟨47, by decide⟩) + let x3 := ((m ⟨46, by decide⟩ * m ⟨47, by decide⟩) * (2 : F)) + let x4 := ((m ⟨34, by decide⟩ + (m ⟨35, by decide⟩ * (256 : F))) + (m ⟨36, by decide⟩ * (65536 : F))) + let x5 := (m ⟨37, by decide⟩ * (16777216 : F)) + let x6 := ((m ⟨38, by decide⟩ + (m ⟨39, by decide⟩ * (256 : F))) + (m ⟨40, by decide⟩ * (65536 : F))) + let x7 := (m ⟨41, by decide⟩ * (16777216 : F)) + let x8 := ((m ⟨11, by decide⟩ + m ⟨12, by decide⟩) + m ⟨13, by decide⟩) + let x9 := ((256 : F) * m ⟨23, by decide⟩) + let x10 := ((256 : F) * m ⟨27, by decide⟩) + let x11 := ((256 : F) * m ⟨29, by decide⟩) + let x12 := ((256 : F) * m ⟨25, by decide⟩) + let x13 := (m ⟨34, by decide⟩ + ((65536 : F) * m ⟨35, by decide⟩)) + let x14 := ((4294967296 : F) * m ⟨37, by decide⟩) + let x15 := ((m ⟨15, by decide⟩ + m ⟨16, by decide⟩) + m ⟨17, by decide⟩) + let x16 := (x15 + m ⟨18, by decide⟩) + let x17 := ((1 : F) - m ⟨60, by decide⟩) + let x18 := ((m ⟨34, by decide⟩ + (m ⟨35, by decide⟩ * (256 : F))) + (m ⟨36, by decide⟩ * (65536 : F))) + let x19 := (m ⟨37, by decide⟩ * (16777216 : F)) + let x20 := (m ⟨47, by decide⟩ * ((4294967296 : F) - ((2 : F) * m ⟨20, by decide⟩))) + let x21 := ((m ⟨38, by decide⟩ + (m ⟨39, by decide⟩ * (256 : F))) + (m ⟨40, by decide⟩ * (65536 : F))) + let x22 := (m ⟨41, by decide⟩ * (16777216 : F)) + let x23 := ((m ⟨15, by decide⟩ + m ⟨16, by decide⟩) * (x18 + x19)) + let x24 := ((m ⟨17, by decide⟩ + m ⟨18, by decide⟩) * (x21 + x22)) + [ (m ⟨55, by decide⟩ * (m ⟨55, by decide⟩ - (1 : F))) + , (((1 : F) - m ⟨55, by decide⟩) * m ⟨56, by decide⟩) + , (m ⟨0, by decide⟩ * (m ⟨0, by decide⟩ - (1 : F))) + , (m ⟨1, by decide⟩ * (m ⟨1, by decide⟩ - (1 : F))) + , (m ⟨2, by decide⟩ * (m ⟨2, by decide⟩ - (1 : F))) + , (m ⟨3, by decide⟩ * (m ⟨3, by decide⟩ - (1 : F))) + , (m ⟨4, by decide⟩ * (m ⟨4, by decide⟩ - (1 : F))) + , (m ⟨5, by decide⟩ * (m ⟨5, by decide⟩ - (1 : F))) + , (m ⟨6, by decide⟩ * (m ⟨6, by decide⟩ - (1 : F))) + , (m ⟨7, by decide⟩ * (m ⟨7, by decide⟩ - (1 : F))) + , (m ⟨8, by decide⟩ * (m ⟨8, by decide⟩ - (1 : F))) + , (m ⟨9, by decide⟩ * (m ⟨9, by decide⟩ - (1 : F))) + , (m ⟨10, by decide⟩ * (m ⟨10, by decide⟩ - (1 : F))) + , (m ⟨11, by decide⟩ * (m ⟨11, by decide⟩ - (1 : F))) + , (m ⟨12, by decide⟩ * (m ⟨12, by decide⟩ - (1 : F))) + , (m ⟨13, by decide⟩ * (m ⟨13, by decide⟩ - (1 : F))) + , (m ⟨14, by decide⟩ * (m ⟨14, by decide⟩ - (1 : F))) + , (m ⟨15, by decide⟩ * (m ⟨15, by decide⟩ - (1 : F))) + , (m ⟨16, by decide⟩ * (m ⟨16, by decide⟩ - (1 : F))) + , (m ⟨17, by decide⟩ * (m ⟨17, by decide⟩ - (1 : F))) + , (m ⟨18, by decide⟩ * (m ⟨18, by decide⟩ - (1 : F))) + , (((((((((((((((((((m ⟨0, by decide⟩ + m ⟨1, by decide⟩) + m ⟨2, by decide⟩) + m ⟨3, by decide⟩) + m ⟨4, by decide⟩) + m ⟨5, by decide⟩) + m ⟨6, by decide⟩) + m ⟨7, by decide⟩) + m ⟨8, by decide⟩) + m ⟨9, by decide⟩) + m ⟨10, by decide⟩) + m ⟨11, by decide⟩) + m ⟨12, by decide⟩) + m ⟨13, by decide⟩) + m ⟨14, by decide⟩) + m ⟨15, by decide⟩) + m ⟨16, by decide⟩) + m ⟨17, by decide⟩) + m ⟨18, by decide⟩) - m ⟨55, by decide⟩) + , ((((m ⟨22, by decide⟩ + (m ⟨23, by decide⟩ * (256 : F))) + (m ⟨24, by decide⟩ * (65536 : F))) + (m ⟨25, by decide⟩ * (16777216 : F))) - m ⟨19, by decide⟩) + , ((((m ⟨26, by decide⟩ + (m ⟨27, by decide⟩ * (256 : F))) + (m ⟨28, by decide⟩ * (65536 : F))) + (m ⟨29, by decide⟩ * (16777216 : F))) - m ⟨20, by decide⟩) + , ((((m ⟨30, by decide⟩ + (m ⟨31, by decide⟩ * (256 : F))) + (m ⟨32, by decide⟩ * (65536 : F))) + (m ⟨33, by decide⟩ * (16777216 : F))) - m ⟨21, by decide⟩) + , (m ⟨50, by decide⟩ * (m ⟨50, by decide⟩ - (1 : F))) + , (((1 : F) - (x0 + x1)) * m ⟨50, by decide⟩) + , ((((((m ⟨0, by decide⟩ * m ⟨22, by decide⟩) + (m ⟨1, by decide⟩ * m ⟨26, by decide⟩)) + ((m ⟨8, by decide⟩ + m ⟨9, by decide⟩) * m ⟨26, by decide⟩)) + (((m ⟨0, by decide⟩ * m ⟨26, by decide⟩) + (m ⟨1, by decide⟩ * m ⟨30, by decide⟩)) + ((m ⟨8, by decide⟩ + m ⟨9, by decide⟩) * m ⟨38, by decide⟩))) - ((m ⟨0, by decide⟩ * m ⟨30, by decide⟩) + ((m ⟨1, by decide⟩ + (m ⟨8, by decide⟩ + m ⟨9, by decide⟩)) * m ⟨22, by decide⟩))) - (m ⟨50, by decide⟩ * (256 : F))) + , (m ⟨51, by decide⟩ * (m ⟨51, by decide⟩ - (1 : F))) + , (((1 : F) - (x0 + x1)) * m ⟨51, by decide⟩) + , (((((((m ⟨0, by decide⟩ * m ⟨23, by decide⟩) + (m ⟨1, by decide⟩ * m ⟨27, by decide⟩)) + ((m ⟨8, by decide⟩ + m ⟨9, by decide⟩) * m ⟨27, by decide⟩)) + (((m ⟨0, by decide⟩ * m ⟨27, by decide⟩) + (m ⟨1, by decide⟩ * m ⟨31, by decide⟩)) + ((m ⟨8, by decide⟩ + m ⟨9, by decide⟩) * m ⟨39, by decide⟩))) + m ⟨50, by decide⟩) - ((m ⟨0, by decide⟩ * m ⟨31, by decide⟩) + ((m ⟨1, by decide⟩ + (m ⟨8, by decide⟩ + m ⟨9, by decide⟩)) * m ⟨23, by decide⟩))) - (m ⟨51, by decide⟩ * (256 : F))) + , (m ⟨52, by decide⟩ * (m ⟨52, by decide⟩ - (1 : F))) + , (((1 : F) - (x0 + x1)) * m ⟨52, by decide⟩) + , (((((((m ⟨0, by decide⟩ * m ⟨24, by decide⟩) + (m ⟨1, by decide⟩ * m ⟨28, by decide⟩)) + ((m ⟨8, by decide⟩ + m ⟨9, by decide⟩) * m ⟨28, by decide⟩)) + (((m ⟨0, by decide⟩ * m ⟨28, by decide⟩) + (m ⟨1, by decide⟩ * m ⟨32, by decide⟩)) + ((m ⟨8, by decide⟩ + m ⟨9, by decide⟩) * m ⟨40, by decide⟩))) + m ⟨51, by decide⟩) - ((m ⟨0, by decide⟩ * m ⟨32, by decide⟩) + ((m ⟨1, by decide⟩ + (m ⟨8, by decide⟩ + m ⟨9, by decide⟩)) * m ⟨24, by decide⟩))) - (m ⟨52, by decide⟩ * (256 : F))) + , (m ⟨53, by decide⟩ * (m ⟨53, by decide⟩ - (1 : F))) + , (((1 : F) - (x0 + x1)) * m ⟨53, by decide⟩) + , (((((((m ⟨0, by decide⟩ * m ⟨25, by decide⟩) + (m ⟨1, by decide⟩ * m ⟨29, by decide⟩)) + ((m ⟨8, by decide⟩ + m ⟨9, by decide⟩) * m ⟨29, by decide⟩)) + (((m ⟨0, by decide⟩ * m ⟨29, by decide⟩) + (m ⟨1, by decide⟩ * m ⟨33, by decide⟩)) + ((m ⟨8, by decide⟩ + m ⟨9, by decide⟩) * m ⟨41, by decide⟩))) + m ⟨52, by decide⟩) - ((m ⟨0, by decide⟩ * m ⟨33, by decide⟩) + ((m ⟨1, by decide⟩ + (m ⟨8, by decide⟩ + m ⟨9, by decide⟩)) * m ⟨25, by decide⟩))) - (m ⟨53, by decide⟩ * (256 : F))) + , (m ⟨46, by decide⟩ * (m ⟨46, by decide⟩ - (1 : F))) + , (m ⟨47, by decide⟩ * (m ⟨47, by decide⟩ - (1 : F))) + , (m ⟨6, by decide⟩ * m ⟨46, by decide⟩) + , ((((m ⟨8, by decide⟩ + m ⟨9, by decide⟩) + m ⟨10, by decide⟩) * m ⟨21, by decide⟩) * (m ⟨21, by decide⟩ - (1 : F))) + , (m ⟨9, by decide⟩ * (m ⟨21, by decide⟩ - m ⟨53, by decide⟩)) + , (m ⟨8, by decide⟩ * ((m ⟨21, by decide⟩ - (((1 : F) - (x2 - x3)) * m ⟨53, by decide⟩)) - ((x2 - x3) * m ⟨46, by decide⟩))) + , (m ⟨10, by decide⟩ * ((((m ⟨19, by decide⟩ - m ⟨20, by decide⟩) * m ⟨54, by decide⟩) + m ⟨21, by decide⟩) - (1 : F))) + , ((m ⟨10, by decide⟩ * m ⟨21, by decide⟩) * (m ⟨19, by decide⟩ - m ⟨20, by decide⟩)) + , (m ⟨5, by decide⟩ * (((m ⟨19, by decide⟩ * m ⟨49, by decide⟩) - ((x4 + x5) * (4294967296 : F))) - m ⟨21, by decide⟩)) + , ((m ⟨6, by decide⟩ + m ⟨7, by decide⟩) * ((((((m ⟨22, by decide⟩ + (m ⟨46, by decide⟩ * ((255 : F) - (m ⟨22, by decide⟩ * (2 : F))))) + ((m ⟨23, by decide⟩ + (m ⟨46, by decide⟩ * ((255 : F) - (m ⟨23, by decide⟩ * (2 : F))))) * (256 : F))) + ((m ⟨24, by decide⟩ + (m ⟨46, by decide⟩ * ((255 : F) - (m ⟨24, by decide⟩ * (2 : F))))) * (65536 : F))) + ((m ⟨25, by decide⟩ + (m ⟨46, by decide⟩ * ((255 : F) - (m ⟨25, by decide⟩ * (2 : F))))) * (16777216 : F))) - ((x4 + x5) * m ⟨49, by decide⟩)) - (x6 + x7))) + , ((m ⟨6, by decide⟩ + m ⟨7, by decide⟩) * (((m ⟨49, by decide⟩ - (1 : F)) - (x6 + x7)) - (((m ⟨42, by decide⟩ + (m ⟨43, by decide⟩ * (256 : F))) + (m ⟨44, by decide⟩ * (65536 : F))) + (m ⟨45, by decide⟩ * (16777216 : F))))) + , ((m ⟨6, by decide⟩ + m ⟨7, by decide⟩) * (m ⟨30, by decide⟩ - (m ⟨34, by decide⟩ + (m ⟨46, by decide⟩ * ((255 : F) - (m ⟨34, by decide⟩ * (2 : F))))))) + , ((m ⟨6, by decide⟩ + m ⟨7, by decide⟩) * (m ⟨31, by decide⟩ - (m ⟨35, by decide⟩ + (m ⟨46, by decide⟩ * ((255 : F) - (m ⟨35, by decide⟩ * (2 : F))))))) + , ((m ⟨6, by decide⟩ + m ⟨7, by decide⟩) * (m ⟨32, by decide⟩ - (m ⟨36, by decide⟩ + (m ⟨46, by decide⟩ * ((255 : F) - (m ⟨36, by decide⟩ * (2 : F))))))) + , ((m ⟨6, by decide⟩ + m ⟨7, by decide⟩) * (m ⟨33, by decide⟩ - (m ⟨37, by decide⟩ + (m ⟨46, by decide⟩ * ((255 : F) - (m ⟨37, by decide⟩ * (2 : F))))))) + , ((x8 + m ⟨14, by decide⟩) * (m ⟨34, by decide⟩ - ((m ⟨22, by decide⟩ + x9) * (m ⟨26, by decide⟩ + x10)))) + , ((x8 + m ⟨14, by decide⟩) * (m ⟨35, by decide⟩ - (((m ⟨22, by decide⟩ + x9) * (m ⟨28, by decide⟩ + x11)) + ((m ⟨24, by decide⟩ + x12) * (m ⟨26, by decide⟩ + x10))))) + , ((x8 + m ⟨14, by decide⟩) * (m ⟨36, by decide⟩ - ((m ⟨24, by decide⟩ + x12) * (m ⟨28, by decide⟩ + x11)))) + , ((x8 + m ⟨14, by decide⟩) * (m ⟨37, by decide⟩ - ((m ⟨39, by decide⟩ + ((256 : F) * m ⟨40, by decide⟩)) + ((65536 : F) * m ⟨41, by decide⟩)))) + , ((x8 + m ⟨14, by decide⟩) * ((((m ⟨42, by decide⟩ + (m ⟨43, by decide⟩ * (256 : F))) + (m ⟨44, by decide⟩ * (65536 : F))) + (m ⟨45, by decide⟩ * (16777216 : F))) - (x13 - x14))) + , (((m ⟨12, by decide⟩ + m ⟨14, by decide⟩) * m ⟨38, by decide⟩) * (m ⟨38, by decide⟩ - (1 : F))) + , (m ⟨11, by decide⟩ * (m ⟨21, by decide⟩ - (x13 - x14))) + , (m ⟨13, by decide⟩ * (m ⟨21, by decide⟩ - (m ⟨36, by decide⟩ + m ⟨37, by decide⟩))) + , ((m ⟨12, by decide⟩ + m ⟨14, by decide⟩) * (m ⟨21, by decide⟩ - ((((m ⟨36, by decide⟩ + m ⟨37, by decide⟩) - (m ⟨46, by decide⟩ * m ⟨20, by decide⟩)) - ((m ⟨12, by decide⟩ * m ⟨47, by decide⟩) * m ⟨19, by decide⟩)) + (m ⟨38, by decide⟩ * (4294967296 : F))))) + , (m ⟨60, by decide⟩ * (m ⟨60, by decide⟩ - (1 : F))) + , ((x15 + m ⟨18, by decide⟩) * ((m ⟨20, by decide⟩ * m ⟨61, by decide⟩) - ((1 : F) - m ⟨60, by decide⟩))) + , (((x15 + m ⟨18, by decide⟩) * m ⟨60, by decide⟩) * m ⟨20, by decide⟩) + , ((x16 * x17) * (((m ⟨19, by decide⟩ + (m ⟨46, by decide⟩ * ((4294967296 : F) - ((2 : F) * m ⟨19, by decide⟩)))) - ((x18 + x19) * (m ⟨20, by decide⟩ + x20))) - (x21 + x22))) + , ((x16 * x17) * ((((m ⟨20, by decide⟩ + x20) - (x21 + x22)) - (1 : F)) - (((m ⟨48, by decide⟩ + ((256 : F) * m ⟨49, by decide⟩)) + ((65536 : F) * m ⟨62, by decide⟩)) + ((16777216 : F) * m ⟨63, by decide⟩)))) + , ((x16 * x17) * (((x23 + x24) * m ⟨54, by decide⟩) - ((1 : F) - m ⟨59, by decide⟩))) + , (((x16 * x17) * m ⟨59, by decide⟩) * (x23 + x24)) + , ((x16 * x17) * (m ⟨21, by decide⟩ - ((x23 + x24) + ((((m ⟨15, by decide⟩ * ((m ⟨46, by decide⟩ + m ⟨47, by decide⟩) - (((2 : F) * m ⟨46, by decide⟩) * m ⟨47, by decide⟩))) + (m ⟨17, by decide⟩ * m ⟨46, by decide⟩)) * ((1 : F) - m ⟨59, by decide⟩)) * ((4294967296 : F) - ((2 : F) * (x23 + x24))))))) + , ((m ⟨60, by decide⟩ * (m ⟨15, by decide⟩ + m ⟨16, by decide⟩)) * (m ⟨21, by decide⟩ - (4294967295 : F))) + , ((m ⟨60, by decide⟩ * (m ⟨17, by decide⟩ + m ⟨18, by decide⟩)) * (m ⟨21, by decide⟩ - m ⟨19, by decide⟩)) + , ((m ⟨16, by decide⟩ + m ⟨18, by decide⟩) * (m ⟨46, by decide⟩ + m ⟨47, by decide⟩)) + ] + +/-- Every bus interaction, in push order (global, then exclusive branches). -/ +def interactions (m : Fin 64 → F) : List Interaction := + let x0 := ((m ⟨55, by decide⟩ - m ⟨2, by decide⟩) - m ⟨3, by decide⟩) + let x1 := (((x0 - m ⟨4, by decide⟩) - m ⟨8, by decide⟩) - m ⟨9, by decide⟩) + let x2 := (m ⟨6, by decide⟩ + m ⟨7, by decide⟩) + let x3 := ((((m ⟨8, by decide⟩ + m ⟨7, by decide⟩) + m ⟨12, by decide⟩) + m ⟨14, by decide⟩) + m ⟨15, by decide⟩) + let x4 := ((m ⟨8, by decide⟩ + m ⟨12, by decide⟩) + m ⟨15, by decide⟩) + let x5 := (m ⟨22, by decide⟩ - m ⟨34, by decide⟩) + let x6 := (m ⟨26, by decide⟩ - m ⟨38, by decide⟩) + let x7 := (m ⟨30, by decide⟩ - m ⟨42, by decide⟩) + let x8 := (m ⟨23, by decide⟩ - m ⟨35, by decide⟩) + let x9 := (m ⟨27, by decide⟩ - m ⟨39, by decide⟩) + let x10 := (m ⟨31, by decide⟩ - m ⟨43, by decide⟩) + let x11 := (m ⟨24, by decide⟩ - m ⟨36, by decide⟩) + let x12 := (m ⟨28, by decide⟩ - m ⟨40, by decide⟩) + let x13 := (m ⟨32, by decide⟩ - m ⟨44, by decide⟩) + let x14 := (m ⟨25, by decide⟩ - m ⟨37, by decide⟩) + let x15 := (m ⟨29, by decide⟩ - m ⟨41, by decide⟩) + let x16 := (m ⟨33, by decide⟩ - m ⟨45, by decide⟩) + let x17 := ((16 : F) * m ⟨58, by decide⟩) + let x18 := ((m ⟨11, by decide⟩ + m ⟨12, by decide⟩) + m ⟨13, by decide⟩) + let x19 := ((m ⟨15, by decide⟩ + m ⟨16, by decide⟩) + m ⟨17, by decide⟩) + let x20 := (x19 + m ⟨18, by decide⟩) + let x21 := ((1 : F) - m ⟨60, by decide⟩) + [ { bus := "RANGE8", kind := .lookup, tuple := [m ⟨22, by decide⟩], count := (x0 - m ⟨4, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨26, by decide⟩], count := (x0 - m ⟨4, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨30, by decide⟩], count := (x1 - m ⟨10, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨23, by decide⟩], count := (x0 - m ⟨4, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨27, by decide⟩], count := (x0 - m ⟨4, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨31, by decide⟩], count := (x1 - m ⟨10, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨24, by decide⟩], count := (x0 - m ⟨4, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨28, by decide⟩], count := (x0 - m ⟨4, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨32, by decide⟩], count := (x1 - m ⟨10, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨25, by decide⟩], count := (x0 - m ⟨4, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨29, by decide⟩], count := (x0 - m ⟨4, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨33, by decide⟩], count := (x1 - m ⟨10, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨38, by decide⟩], count := ((m ⟨8, by decide⟩ + m ⟨9, by decide⟩) + (m ⟨6, by decide⟩ + m ⟨7, by decide⟩)) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨42, by decide⟩], count := (m ⟨6, by decide⟩ + m ⟨7, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨34, by decide⟩], count := (m ⟨5, by decide⟩ + x2) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨39, by decide⟩], count := ((m ⟨8, by decide⟩ + m ⟨9, by decide⟩) + (m ⟨6, by decide⟩ + m ⟨7, by decide⟩)) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨43, by decide⟩], count := (m ⟨6, by decide⟩ + m ⟨7, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨35, by decide⟩], count := (m ⟨5, by decide⟩ + x2) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨40, by decide⟩], count := ((m ⟨8, by decide⟩ + m ⟨9, by decide⟩) + (m ⟨6, by decide⟩ + m ⟨7, by decide⟩)) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨44, by decide⟩], count := (m ⟨6, by decide⟩ + m ⟨7, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨36, by decide⟩], count := (m ⟨5, by decide⟩ + x2) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨41, by decide⟩], count := ((m ⟨8, by decide⟩ + m ⟨9, by decide⟩) + (m ⟨6, by decide⟩ + m ⟨7, by decide⟩)) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨45, by decide⟩], count := (m ⟨6, by decide⟩ + m ⟨7, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨37, by decide⟩], count := (m ⟨5, by decide⟩ + x2) } + , { bus := "AND4", kind := .lookup, tuple := [(m ⟨25, by decide⟩ - ((16 : F) * m ⟨57, by decide⟩)), (0 : F), (0 : F)], count := (x3 + m ⟨17, by decide⟩) } + , { bus := "AND4", kind := .lookup, tuple := [m ⟨57, by decide⟩, (8 : F), (m ⟨46, by decide⟩ * (8 : F))], count := (x3 + m ⟨17, by decide⟩) } + , { bus := "AND4", kind := .lookup, tuple := [(m ⟨29, by decide⟩ - ((16 : F) * m ⟨58, by decide⟩)), (0 : F), (0 : F)], count := (x4 + m ⟨17, by decide⟩) } + , { bus := "AND4", kind := .lookup, tuple := [m ⟨58, by decide⟩, (8 : F), (m ⟨47, by decide⟩ * (8 : F))], count := (x4 + m ⟨17, by decide⟩) } + , { bus := "AND4", kind := .lookup, tuple := [m ⟨34, by decide⟩, m ⟨38, by decide⟩, m ⟨42, by decide⟩], count := m ⟨2, by decide⟩ } + , { bus := "AND4", kind := .lookup, tuple := [(x5 * (17293822565076172801 : F)), (x6 * (17293822565076172801 : F)), (x7 * (17293822565076172801 : F))], count := m ⟨2, by decide⟩ } + , { bus := "OR4", kind := .lookup, tuple := [m ⟨34, by decide⟩, m ⟨38, by decide⟩, m ⟨42, by decide⟩], count := m ⟨3, by decide⟩ } + , { bus := "OR4", kind := .lookup, tuple := [(x5 * (17293822565076172801 : F)), (x6 * (17293822565076172801 : F)), (x7 * (17293822565076172801 : F))], count := m ⟨3, by decide⟩ } + , { bus := "XOR4", kind := .lookup, tuple := [m ⟨34, by decide⟩, m ⟨38, by decide⟩, m ⟨42, by decide⟩], count := m ⟨4, by decide⟩ } + , { bus := "XOR4", kind := .lookup, tuple := [(x5 * (17293822565076172801 : F)), (x6 * (17293822565076172801 : F)), (x7 * (17293822565076172801 : F))], count := m ⟨4, by decide⟩ } + , { bus := "AND4", kind := .lookup, tuple := [m ⟨35, by decide⟩, m ⟨39, by decide⟩, m ⟨43, by decide⟩], count := m ⟨2, by decide⟩ } + , { bus := "AND4", kind := .lookup, tuple := [(x8 * (17293822565076172801 : F)), (x9 * (17293822565076172801 : F)), (x10 * (17293822565076172801 : F))], count := m ⟨2, by decide⟩ } + , { bus := "OR4", kind := .lookup, tuple := [m ⟨35, by decide⟩, m ⟨39, by decide⟩, m ⟨43, by decide⟩], count := m ⟨3, by decide⟩ } + , { bus := "OR4", kind := .lookup, tuple := [(x8 * (17293822565076172801 : F)), (x9 * (17293822565076172801 : F)), (x10 * (17293822565076172801 : F))], count := m ⟨3, by decide⟩ } + , { bus := "XOR4", kind := .lookup, tuple := [m ⟨35, by decide⟩, m ⟨39, by decide⟩, m ⟨43, by decide⟩], count := m ⟨4, by decide⟩ } + , { bus := "XOR4", kind := .lookup, tuple := [(x8 * (17293822565076172801 : F)), (x9 * (17293822565076172801 : F)), (x10 * (17293822565076172801 : F))], count := m ⟨4, by decide⟩ } + , { bus := "AND4", kind := .lookup, tuple := [m ⟨36, by decide⟩, m ⟨40, by decide⟩, m ⟨44, by decide⟩], count := m ⟨2, by decide⟩ } + , { bus := "AND4", kind := .lookup, tuple := [(x11 * (17293822565076172801 : F)), (x12 * (17293822565076172801 : F)), (x13 * (17293822565076172801 : F))], count := m ⟨2, by decide⟩ } + , { bus := "OR4", kind := .lookup, tuple := [m ⟨36, by decide⟩, m ⟨40, by decide⟩, m ⟨44, by decide⟩], count := m ⟨3, by decide⟩ } + , { bus := "OR4", kind := .lookup, tuple := [(x11 * (17293822565076172801 : F)), (x12 * (17293822565076172801 : F)), (x13 * (17293822565076172801 : F))], count := m ⟨3, by decide⟩ } + , { bus := "XOR4", kind := .lookup, tuple := [m ⟨36, by decide⟩, m ⟨40, by decide⟩, m ⟨44, by decide⟩], count := m ⟨4, by decide⟩ } + , { bus := "XOR4", kind := .lookup, tuple := [(x11 * (17293822565076172801 : F)), (x12 * (17293822565076172801 : F)), (x13 * (17293822565076172801 : F))], count := m ⟨4, by decide⟩ } + , { bus := "AND4", kind := .lookup, tuple := [m ⟨37, by decide⟩, m ⟨41, by decide⟩, m ⟨45, by decide⟩], count := m ⟨2, by decide⟩ } + , { bus := "AND4", kind := .lookup, tuple := [(x14 * (17293822565076172801 : F)), (x15 * (17293822565076172801 : F)), (x16 * (17293822565076172801 : F))], count := m ⟨2, by decide⟩ } + , { bus := "OR4", kind := .lookup, tuple := [m ⟨37, by decide⟩, m ⟨41, by decide⟩, m ⟨45, by decide⟩], count := m ⟨3, by decide⟩ } + , { bus := "OR4", kind := .lookup, tuple := [(x14 * (17293822565076172801 : F)), (x15 * (17293822565076172801 : F)), (x16 * (17293822565076172801 : F))], count := m ⟨3, by decide⟩ } + , { bus := "XOR4", kind := .lookup, tuple := [m ⟨37, by decide⟩, m ⟨41, by decide⟩, m ⟨45, by decide⟩], count := m ⟨4, by decide⟩ } + , { bus := "XOR4", kind := .lookup, tuple := [(x14 * (17293822565076172801 : F)), (x15 * (17293822565076172801 : F)), (x16 * (17293822565076172801 : F))], count := m ⟨4, by decide⟩ } + , { bus := "AND4", kind := .lookup, tuple := [(m ⟨26, by decide⟩ - x17), (0 : F), (0 : F)], count := (m ⟨5, by decide⟩ + x2) } + , { bus := "AND4", kind := .lookup, tuple := [m ⟨58, by decide⟩, (1 : F), m ⟨48, by decide⟩], count := (m ⟨5, by decide⟩ + x2) } + , { bus := "POW2", kind := .lookup, tuple := [((m ⟨26, by decide⟩ - x17) + ((16 : F) * m ⟨48, by decide⟩)), m ⟨49, by decide⟩], count := (m ⟨5, by decide⟩ + x2) } + , { bus := "AND4", kind := .lookup, tuple := [(m ⟨37, by decide⟩ - ((16 : F) * m ⟨59, by decide⟩)), (0 : F), (0 : F)], count := m ⟨5, by decide⟩ } + , { bus := "AND4", kind := .lookup, tuple := [m ⟨59, by decide⟩, (8 : F), (0 : F)], count := m ⟨5, by decide⟩ } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨39, by decide⟩], count := (x18 + m ⟨14, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨40, by decide⟩], count := (x18 + m ⟨14, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨41, by decide⟩], count := (x18 + m ⟨14, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨42, by decide⟩], count := (x18 + m ⟨14, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨43, by decide⟩], count := (x18 + m ⟨14, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨44, by decide⟩], count := (x18 + m ⟨14, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨45, by decide⟩], count := (x18 + m ⟨14, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨34, by decide⟩], count := (x19 + m ⟨18, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨38, by decide⟩], count := (x19 + m ⟨18, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨35, by decide⟩], count := (x19 + m ⟨18, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨39, by decide⟩], count := (x19 + m ⟨18, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨36, by decide⟩], count := (x19 + m ⟨18, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨40, by decide⟩], count := (x19 + m ⟨18, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨37, by decide⟩], count := (x19 + m ⟨18, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨41, by decide⟩], count := (x19 + m ⟨18, by decide⟩) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨48, by decide⟩], count := (x20 * x21) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨49, by decide⟩], count := (x20 * x21) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨62, by decide⟩], count := (x20 * x21) } + , { bus := "RANGE8", kind := .lookup, tuple := [m ⟨63, by decide⟩], count := (x20 * x21) } + , { bus := "ALU", kind := .provide, tuple := [(((((((((((((((((m ⟨1, by decide⟩ + (m ⟨2, by decide⟩ * (2 : F))) + (m ⟨3, by decide⟩ * (3 : F))) + (m ⟨4, by decide⟩ * (4 : F))) + (m ⟨5, by decide⟩ * (5 : F))) + (m ⟨6, by decide⟩ * (6 : F))) + (m ⟨7, by decide⟩ * (7 : F))) + (m ⟨8, by decide⟩ * (8 : F))) + (m ⟨9, by decide⟩ * (9 : F))) + (m ⟨10, by decide⟩ * (10 : F))) + (m ⟨11, by decide⟩ * (11 : F))) + (m ⟨12, by decide⟩ * (12 : F))) + (m ⟨13, by decide⟩ * (13 : F))) + (m ⟨14, by decide⟩ * (14 : F))) + (m ⟨15, by decide⟩ * (15 : F))) + (m ⟨16, by decide⟩ * (16 : F))) + (m ⟨17, by decide⟩ * (17 : F))) + (m ⟨18, by decide⟩ * (18 : F))), m ⟨19, by decide⟩, m ⟨20, by decide⟩, m ⟨21, by decide⟩], count := m ⟨56, by decide⟩ } + ] + +end Rand.Generated.RV32.Alu diff --git a/Rand/Generated/RV32/AluHonest.lean b/Rand/Generated/RV32/AluHonest.lean new file mode 100644 index 0000000..c31cfcf --- /dev/null +++ b/Rand/Generated/RV32/AluHonest.lean @@ -0,0 +1,60 @@ +-- GENERATED by exporter from zkp-circuits @b3e21d9ea16225452bcd03a94317cb61e1705979. Do not edit. +import Rand.Field + +/-! Rows of the real `alu_trace` on a small guest running all 19 ALU ops (every distinct +real row in trace order, then one padding row): 42 rows. -/ + +namespace Rand.Generated.RV32.Alu + +open Rand + +/-- A row from its 64 cells as canonical values. -/ +def row (l : List ℕ) : Fin 64 → F := fun i => (l.getD i.val 0 : F) + +/-- Honest rows produced by the Rust trace generator. -/ +def honestRows : List (Fin 64 → F) := + [ row [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 305418240, 1656, 305419896, 0, 80, 52, 18, 120, 6, 0, 0, 120, 86, 52, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4294967289, 4294967289, 0, 0, 0, 0, 249, 255, 255, 255, 249, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 305419896, 4294967289, 305419889, 120, 86, 52, 18, 249, 255, 255, 255, 113, 86, 52, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 305419896, 4294967289, 305419903, 120, 86, 52, 18, 249, 255, 255, 255, 127, 86, 52, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 305419896, 4294967289, 305419896, 120, 86, 52, 18, 249, 255, 255, 255, 120, 86, 52, 18, 8, 6, 4, 2, 9, 15, 15, 15, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 305419896, 4294967289, 4294967289, 120, 86, 52, 18, 249, 255, 255, 255, 249, 255, 255, 255, 8, 6, 4, 2, 9, 15, 15, 15, 9, 15, 15, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 305419896, 4294967289, 3989547393, 120, 86, 52, 18, 249, 255, 255, 255, 129, 169, 203, 237, 8, 6, 4, 2, 9, 15, 15, 15, 1, 9, 11, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 305419896, 4294967289, 4026531840, 120, 86, 52, 18, 249, 255, 255, 255, 0, 0, 0, 240, 172, 104, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 33554432, 0, 0, 0, 0, 0, 1, 1, 0, 15, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 305419896, 4294967289, 9, 120, 86, 52, 18, 249, 255, 255, 255, 9, 0, 0, 0, 9, 0, 0, 0, 120, 86, 52, 0, 135, 169, 203, 1, 0, 0, 1, 33554432, 0, 0, 0, 0, 0, 1, 1, 0, 15, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 305419896, 4294967289, 9, 120, 86, 52, 18, 249, 255, 255, 255, 9, 0, 0, 0, 9, 0, 0, 0, 120, 86, 52, 0, 135, 169, 203, 1, 0, 0, 1, 33554432, 0, 0, 0, 0, 0, 1, 1, 1, 15, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 305419896, 4294967289, 0, 120, 86, 52, 18, 249, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 127, 86, 52, 18, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 15, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 305419896, 4294967289, 1, 120, 86, 52, 18, 249, 255, 255, 255, 1, 0, 0, 0, 0, 0, 0, 0, 127, 86, 52, 18, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 305419896, 4294967289, 2157028024, 120, 86, 52, 18, 249, 255, 255, 255, 184, 162, 145, 128, 1450549944, 1756047900, 305393100, 26795, 0, 171, 104, 0, 184, 162, 145, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 305419896, 4294967289, 4294967295, 120, 86, 52, 18, 249, 255, 255, 255, 255, 255, 255, 255, 1450549944, 1756047900, 305393100, 26795, 1, 171, 104, 0, 184, 162, 145, 128, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 15, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 305419896, 4294967289, 305419895, 120, 86, 52, 18, 249, 255, 255, 255, 119, 86, 52, 18, 1450549944, 1756047900, 305393100, 26795, 0, 171, 104, 0, 184, 162, 145, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 305419896, 4294967289, 305419895, 120, 86, 52, 18, 249, 255, 255, 255, 119, 86, 52, 18, 1450549944, 1756047900, 305393100, 26795, 0, 171, 104, 0, 184, 162, 145, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 305419896, 4294967289, 4251335883, 120, 86, 52, 18, 249, 255, 255, 255, 203, 60, 102, 253, 53, 195, 153, 2, 5, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 5544592909374452085, 1, 1, 1, 15, 0, 0, 10295857154922210614, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 305419896, 4294967289, 0, 120, 86, 52, 18, 249, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 120, 86, 52, 18, 0, 0, 0, 0, 0, 0, 128, 169, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 10295857154922210614, 203, 237] + , row [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 305419896, 4294967289, 5, 120, 86, 52, 18, 249, 255, 255, 255, 5, 0, 0, 0, 53, 195, 153, 2, 5, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 14757395255531667457, 1, 1, 1, 15, 0, 0, 10295857154922210614, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 305419896, 4294967289, 305419896, 120, 86, 52, 18, 249, 255, 255, 255, 120, 86, 52, 18, 0, 0, 0, 0, 120, 86, 52, 18, 0, 0, 0, 0, 0, 0, 128, 169, 0, 0, 0, 0, 4905480685480067893, 1, 1, 0, 0, 0, 0, 10295857154922210614, 203, 237] + , row [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4294967289, 0, 4294967289, 249, 255, 255, 255, 0, 0, 0, 0, 249, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4294967289, 0, 4294967289, 249, 255, 255, 255, 0, 0, 0, 0, 249, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4294967289, 0, 0, 249, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 9, 15, 15, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4294967289, 0, 4294967289, 249, 255, 255, 255, 0, 0, 0, 0, 249, 255, 255, 255, 9, 15, 15, 15, 0, 0, 0, 0, 9, 15, 15, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4294967289, 0, 4294967289, 249, 255, 255, 255, 0, 0, 0, 0, 249, 255, 255, 255, 9, 15, 15, 15, 0, 0, 0, 0, 9, 15, 15, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4294967289, 0, 4294967289, 249, 255, 255, 255, 0, 0, 0, 0, 249, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4294967289, 0, 4294967289, 249, 255, 255, 255, 0, 0, 0, 0, 249, 255, 255, 255, 249, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4294967289, 0, 4294967289, 249, 255, 255, 255, 0, 0, 0, 0, 249, 255, 255, 255, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 15, 0, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4294967289, 0, 1, 249, 255, 255, 255, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 249, 255, 255, 255, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 15, 0, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4294967289, 0, 0, 249, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 249, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 4294967289, 0, 0, 249, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 4294967289, 0, 0, 249, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 15, 0, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 4294967289, 0, 0, 249, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 4294967289, 0, 0, 249, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 15, 0, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 4294967289, 0, 4294967295, 249, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 15, 0, 0, 1, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 4294967289, 0, 4294967295, 249, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 4294967289, 0, 4294967289, 249, 255, 255, 255, 0, 0, 0, 0, 249, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 15, 0, 0, 1, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4294967289, 0, 4294967289, 249, 255, 255, 255, 0, 0, 0, 0, 249, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 4294967289, 4294967289, 1, 249, 255, 255, 255, 249, 255, 255, 255, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 164, 4, 168, 164, 0, 0, 0, 4, 0, 0, 0, 168, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0] + , row [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + ] + +end Rand.Generated.RV32.Alu diff --git a/Rand/Generated/RV32/AluVectors.lean b/Rand/Generated/RV32/AluVectors.lean new file mode 100644 index 0000000..a11fbe0 --- /dev/null +++ b/Rand/Generated/RV32/AluVectors.lean @@ -0,0 +1,2848 @@ +-- GENERATED by exporter from zkp-circuits @b3e21d9ea16225452bcd03a94317cb61e1705979. Do not edit. +import Mathlib.Data.Nat.Notation + +/-! `AluOp::eval` of `rand_zkvm::isa`, run by the exporter on 145 operand pairs (the edge set +{0, 1, 2, 31, 32, 0x7fffffff, 0x80000000, 0xfffffffe, 0xffffffff}², then 64 seeded-random pairs) +for each of the 19 ops: 2755 vectors `(code, a, b, result)`. -/ + +namespace Rand.Generated.RV32.AluVectors + +-- One list per op: a single 2755-element literal exceeds the elaborator's recursion limit. +set_option maxRecDepth 8000 + +/-- `Add` (code 0): `(code, a, b, AluOp::eval(a, b))` for each pair. -/ +def vectors0 : List (ℕ × ℕ × ℕ × ℕ) := + [ (0, 0, 0, 0) + , (0, 0, 1, 1) + , (0, 0, 2, 2) + , (0, 0, 31, 31) + , (0, 0, 32, 32) + , (0, 0, 2147483647, 2147483647) + , (0, 0, 2147483648, 2147483648) + , (0, 0, 4294967294, 4294967294) + , (0, 0, 4294967295, 4294967295) + , (0, 1, 0, 1) + , (0, 1, 1, 2) + , (0, 1, 2, 3) + , (0, 1, 31, 32) + , (0, 1, 32, 33) + , (0, 1, 2147483647, 2147483648) + , (0, 1, 2147483648, 2147483649) + , (0, 1, 4294967294, 4294967295) + , (0, 1, 4294967295, 0) + , (0, 2, 0, 2) + , (0, 2, 1, 3) + , (0, 2, 2, 4) + , (0, 2, 31, 33) + , (0, 2, 32, 34) + , (0, 2, 2147483647, 2147483649) + , (0, 2, 2147483648, 2147483650) + , (0, 2, 4294967294, 0) + , (0, 2, 4294967295, 1) + , (0, 31, 0, 31) + , (0, 31, 1, 32) + , (0, 31, 2, 33) + , (0, 31, 31, 62) + , (0, 31, 32, 63) + , (0, 31, 2147483647, 2147483678) + , (0, 31, 2147483648, 2147483679) + , (0, 31, 4294967294, 29) + , (0, 31, 4294967295, 30) + , (0, 32, 0, 32) + , (0, 32, 1, 33) + , (0, 32, 2, 34) + , (0, 32, 31, 63) + , (0, 32, 32, 64) + , (0, 32, 2147483647, 2147483679) + , (0, 32, 2147483648, 2147483680) + , (0, 32, 4294967294, 30) + , (0, 32, 4294967295, 31) + , (0, 2147483647, 0, 2147483647) + , (0, 2147483647, 1, 2147483648) + , (0, 2147483647, 2, 2147483649) + , (0, 2147483647, 31, 2147483678) + , (0, 2147483647, 32, 2147483679) + , (0, 2147483647, 2147483647, 4294967294) + , (0, 2147483647, 2147483648, 4294967295) + , (0, 2147483647, 4294967294, 2147483645) + , (0, 2147483647, 4294967295, 2147483646) + , (0, 2147483648, 0, 2147483648) + , (0, 2147483648, 1, 2147483649) + , (0, 2147483648, 2, 2147483650) + , (0, 2147483648, 31, 2147483679) + , (0, 2147483648, 32, 2147483680) + , (0, 2147483648, 2147483647, 4294967295) + , (0, 2147483648, 2147483648, 0) + , (0, 2147483648, 4294967294, 2147483646) + , (0, 2147483648, 4294967295, 2147483647) + , (0, 4294967294, 0, 4294967294) + , (0, 4294967294, 1, 4294967295) + , (0, 4294967294, 2, 0) + , (0, 4294967294, 31, 29) + , (0, 4294967294, 32, 30) + , (0, 4294967294, 2147483647, 2147483645) + , (0, 4294967294, 2147483648, 2147483646) + , (0, 4294967294, 4294967294, 4294967292) + , (0, 4294967294, 4294967295, 4294967293) + , (0, 4294967295, 0, 4294967295) + , (0, 4294967295, 1, 0) + , (0, 4294967295, 2, 1) + , (0, 4294967295, 31, 30) + , (0, 4294967295, 32, 31) + , (0, 4294967295, 2147483647, 2147483646) + , (0, 4294967295, 2147483648, 2147483647) + , (0, 4294967295, 4294967294, 4294967293) + , (0, 4294967295, 4294967295, 4294967294) + , (0, 4222272340, 3018856485, 2946161529) + , (0, 379515872, 178533105, 558048977) + , (0, 707510791, 2591788913, 3299299704) + , (0, 3933066539, 659350380, 297449623) + , (0, 2333640804, 3487620568, 1526294076) + , (0, 1765341752, 3405633948, 876008404) + , (0, 3236348377, 1431584459, 372965540) + , (0, 2478600280, 3249560273, 1433193257) + , (0, 2460645879, 149137941, 2609783820) + , (0, 3433877109, 1271316163, 410225976) + , (0, 3723453251, 2182014576, 1610500531) + , (0, 2769503457, 1018057816, 3787561273) + , (0, 3260756530, 4124728163, 3090517397) + , (0, 3438460860, 669438262, 4107899122) + , (0, 1826033185, 1148320962, 2974354147) + , (0, 2095817777, 125410707, 2221228484) + , (0, 164472764, 1173487102, 1337959866) + , (0, 1816836761, 1648241983, 3465078744) + , (0, 1856018840, 343361865, 2199380705) + , (0, 2288712981, 1947234856, 4235947837) + , (0, 3015231039, 969299767, 3984530806) + , (0, 3158443250, 758246939, 3916690189) + , (0, 3150010492, 1684333854, 539377050) + , (0, 4239251582, 3186512646, 3130796932) + , (0, 2236034112, 1248349535, 3484383647) + , (0, 2253431469, 1837736069, 4091167538) + , (0, 3581590838, 3346653714, 2633277256) + , (0, 1351433231, 1149939738, 2501372969) + , (0, 3395186067, 1158888304, 259107075) + , (0, 3290394050, 1573886483, 569313237) + , (0, 1296804427, 3587281360, 589118491) + , (0, 453833330, 1665922652, 2119755982) + , (0, 2475109104, 2911185365, 1091327173) + , (0, 755740888, 1167230839, 1922971727) + , (0, 4192557824, 3532097471, 3429687999) + , (0, 1524723696, 1053814038, 2578537734) + , (0, 1609670288, 426029171, 2035699459) + , (0, 3701505454, 317959263, 4019464717) + , (0, 3954083790, 1972473457, 1631589951) + , (0, 2583541165, 3975072409, 2263646278) + , (0, 563224588, 3812216621, 80473913) + , (0, 1030500844, 2967456744, 3997957588) + , (0, 2373900222, 2102548527, 181481453) + , (0, 2992286323, 2682139598, 1379458625) + , (0, 3720596378, 3946355560, 3371984642) + , (0, 1016409648, 1140208456, 2156618104) + , (0, 82580043, 17156065, 99736108) + , (0, 3818267397, 3081334409, 2604634510) + , (0, 3465194745, 4292146700, 3462374149) + , (0, 3725224097, 3684892669, 3115149470) + , (0, 527877525, 256409499, 784287024) + , (0, 2592462716, 2990664910, 1288160330) + , (0, 1925553553, 3927762823, 1558349080) + , (0, 1390245551, 2521092483, 3911338034) + , (0, 521880022, 2481597211, 3003477233) + , (0, 1860304388, 598127922, 2458432310) + , (0, 945207741, 1771423344, 2716631085) + , (0, 3417966451, 2785685302, 1908684457) + , (0, 511205855, 4079302086, 295540645) + , (0, 2289434543, 2323379776, 317847023) + , (0, 3246274374, 3812191436, 2763498514) + , (0, 2356553023, 2513710439, 575296166) + , (0, 3338856311, 4079201695, 3123090710) + , (0, 1501407491, 4267822174, 1474262369) + ] + +/-- `Sub` (code 1): `(code, a, b, AluOp::eval(a, b))` for each pair. -/ +def vectors1 : List (ℕ × ℕ × ℕ × ℕ) := + [ (1, 0, 0, 0) + , (1, 0, 1, 4294967295) + , (1, 0, 2, 4294967294) + , (1, 0, 31, 4294967265) + , (1, 0, 32, 4294967264) + , (1, 0, 2147483647, 2147483649) + , (1, 0, 2147483648, 2147483648) + , (1, 0, 4294967294, 2) + , (1, 0, 4294967295, 1) + , (1, 1, 0, 1) + , (1, 1, 1, 0) + , (1, 1, 2, 4294967295) + , (1, 1, 31, 4294967266) + , (1, 1, 32, 4294967265) + , (1, 1, 2147483647, 2147483650) + , (1, 1, 2147483648, 2147483649) + , (1, 1, 4294967294, 3) + , (1, 1, 4294967295, 2) + , (1, 2, 0, 2) + , (1, 2, 1, 1) + , (1, 2, 2, 0) + , (1, 2, 31, 4294967267) + , (1, 2, 32, 4294967266) + , (1, 2, 2147483647, 2147483651) + , (1, 2, 2147483648, 2147483650) + , (1, 2, 4294967294, 4) + , (1, 2, 4294967295, 3) + , (1, 31, 0, 31) + , (1, 31, 1, 30) + , (1, 31, 2, 29) + , (1, 31, 31, 0) + , (1, 31, 32, 4294967295) + , (1, 31, 2147483647, 2147483680) + , (1, 31, 2147483648, 2147483679) + , (1, 31, 4294967294, 33) + , (1, 31, 4294967295, 32) + , (1, 32, 0, 32) + , (1, 32, 1, 31) + , (1, 32, 2, 30) + , (1, 32, 31, 1) + , (1, 32, 32, 0) + , (1, 32, 2147483647, 2147483681) + , (1, 32, 2147483648, 2147483680) + , (1, 32, 4294967294, 34) + , (1, 32, 4294967295, 33) + , (1, 2147483647, 0, 2147483647) + , (1, 2147483647, 1, 2147483646) + , (1, 2147483647, 2, 2147483645) + , (1, 2147483647, 31, 2147483616) + , (1, 2147483647, 32, 2147483615) + , (1, 2147483647, 2147483647, 0) + , (1, 2147483647, 2147483648, 4294967295) + , (1, 2147483647, 4294967294, 2147483649) + , (1, 2147483647, 4294967295, 2147483648) + , (1, 2147483648, 0, 2147483648) + , (1, 2147483648, 1, 2147483647) + , (1, 2147483648, 2, 2147483646) + , (1, 2147483648, 31, 2147483617) + , (1, 2147483648, 32, 2147483616) + , (1, 2147483648, 2147483647, 1) + , (1, 2147483648, 2147483648, 0) + , (1, 2147483648, 4294967294, 2147483650) + , (1, 2147483648, 4294967295, 2147483649) + , (1, 4294967294, 0, 4294967294) + , (1, 4294967294, 1, 4294967293) + , (1, 4294967294, 2, 4294967292) + , (1, 4294967294, 31, 4294967263) + , (1, 4294967294, 32, 4294967262) + , (1, 4294967294, 2147483647, 2147483647) + , (1, 4294967294, 2147483648, 2147483646) + , (1, 4294967294, 4294967294, 0) + , (1, 4294967294, 4294967295, 4294967295) + , (1, 4294967295, 0, 4294967295) + , (1, 4294967295, 1, 4294967294) + , (1, 4294967295, 2, 4294967293) + , (1, 4294967295, 31, 4294967264) + , (1, 4294967295, 32, 4294967263) + , (1, 4294967295, 2147483647, 2147483648) + , (1, 4294967295, 2147483648, 2147483647) + , (1, 4294967295, 4294967294, 1) + , (1, 4294967295, 4294967295, 0) + , (1, 4222272340, 3018856485, 1203415855) + , (1, 379515872, 178533105, 200982767) + , (1, 707510791, 2591788913, 2410689174) + , (1, 3933066539, 659350380, 3273716159) + , (1, 2333640804, 3487620568, 3140987532) + , (1, 1765341752, 3405633948, 2654675100) + , (1, 3236348377, 1431584459, 1804763918) + , (1, 2478600280, 3249560273, 3524007303) + , (1, 2460645879, 149137941, 2311507938) + , (1, 3433877109, 1271316163, 2162560946) + , (1, 3723453251, 2182014576, 1541438675) + , (1, 2769503457, 1018057816, 1751445641) + , (1, 3260756530, 4124728163, 3430995663) + , (1, 3438460860, 669438262, 2769022598) + , (1, 1826033185, 1148320962, 677712223) + , (1, 2095817777, 125410707, 1970407070) + , (1, 164472764, 1173487102, 3285952958) + , (1, 1816836761, 1648241983, 168594778) + , (1, 1856018840, 343361865, 1512656975) + , (1, 2288712981, 1947234856, 341478125) + , (1, 3015231039, 969299767, 2045931272) + , (1, 3158443250, 758246939, 2400196311) + , (1, 3150010492, 1684333854, 1465676638) + , (1, 4239251582, 3186512646, 1052738936) + , (1, 2236034112, 1248349535, 987684577) + , (1, 2253431469, 1837736069, 415695400) + , (1, 3581590838, 3346653714, 234937124) + , (1, 1351433231, 1149939738, 201493493) + , (1, 3395186067, 1158888304, 2236297763) + , (1, 3290394050, 1573886483, 1716507567) + , (1, 1296804427, 3587281360, 2004490363) + , (1, 453833330, 1665922652, 3082877974) + , (1, 2475109104, 2911185365, 3858891035) + , (1, 755740888, 1167230839, 3883477345) + , (1, 4192557824, 3532097471, 660460353) + , (1, 1524723696, 1053814038, 470909658) + , (1, 1609670288, 426029171, 1183641117) + , (1, 3701505454, 317959263, 3383546191) + , (1, 3954083790, 1972473457, 1981610333) + , (1, 2583541165, 3975072409, 2903436052) + , (1, 563224588, 3812216621, 1045975263) + , (1, 1030500844, 2967456744, 2358011396) + , (1, 2373900222, 2102548527, 271351695) + , (1, 2992286323, 2682139598, 310146725) + , (1, 3720596378, 3946355560, 4069208114) + , (1, 1016409648, 1140208456, 4171168488) + , (1, 82580043, 17156065, 65423978) + , (1, 3818267397, 3081334409, 736932988) + , (1, 3465194745, 4292146700, 3468015341) + , (1, 3725224097, 3684892669, 40331428) + , (1, 527877525, 256409499, 271468026) + , (1, 2592462716, 2990664910, 3896765102) + , (1, 1925553553, 3927762823, 2292758026) + , (1, 1390245551, 2521092483, 3164120364) + , (1, 521880022, 2481597211, 2335250107) + , (1, 1860304388, 598127922, 1262176466) + , (1, 945207741, 1771423344, 3468751693) + , (1, 3417966451, 2785685302, 632281149) + , (1, 511205855, 4079302086, 726871065) + , (1, 2289434543, 2323379776, 4261022063) + , (1, 3246274374, 3812191436, 3729050234) + , (1, 2356553023, 2513710439, 4137809880) + , (1, 3338856311, 4079201695, 3554621912) + , (1, 1501407491, 4267822174, 1528552613) + ] + +/-- `And` (code 2): `(code, a, b, AluOp::eval(a, b))` for each pair. -/ +def vectors2 : List (ℕ × ℕ × ℕ × ℕ) := + [ (2, 0, 0, 0) + , (2, 0, 1, 0) + , (2, 0, 2, 0) + , (2, 0, 31, 0) + , (2, 0, 32, 0) + , (2, 0, 2147483647, 0) + , (2, 0, 2147483648, 0) + , (2, 0, 4294967294, 0) + , (2, 0, 4294967295, 0) + , (2, 1, 0, 0) + , (2, 1, 1, 1) + , (2, 1, 2, 0) + , (2, 1, 31, 1) + , (2, 1, 32, 0) + , (2, 1, 2147483647, 1) + , (2, 1, 2147483648, 0) + , (2, 1, 4294967294, 0) + , (2, 1, 4294967295, 1) + , (2, 2, 0, 0) + , (2, 2, 1, 0) + , (2, 2, 2, 2) + , (2, 2, 31, 2) + , (2, 2, 32, 0) + , (2, 2, 2147483647, 2) + , (2, 2, 2147483648, 0) + , (2, 2, 4294967294, 2) + , (2, 2, 4294967295, 2) + , (2, 31, 0, 0) + , (2, 31, 1, 1) + , (2, 31, 2, 2) + , (2, 31, 31, 31) + , (2, 31, 32, 0) + , (2, 31, 2147483647, 31) + , (2, 31, 2147483648, 0) + , (2, 31, 4294967294, 30) + , (2, 31, 4294967295, 31) + , (2, 32, 0, 0) + , (2, 32, 1, 0) + , (2, 32, 2, 0) + , (2, 32, 31, 0) + , (2, 32, 32, 32) + , (2, 32, 2147483647, 32) + , (2, 32, 2147483648, 0) + , (2, 32, 4294967294, 32) + , (2, 32, 4294967295, 32) + , (2, 2147483647, 0, 0) + , (2, 2147483647, 1, 1) + , (2, 2147483647, 2, 2) + , (2, 2147483647, 31, 31) + , (2, 2147483647, 32, 32) + , (2, 2147483647, 2147483647, 2147483647) + , (2, 2147483647, 2147483648, 0) + , (2, 2147483647, 4294967294, 2147483646) + , (2, 2147483647, 4294967295, 2147483647) + , (2, 2147483648, 0, 0) + , (2, 2147483648, 1, 0) + , (2, 2147483648, 2, 0) + , (2, 2147483648, 31, 0) + , (2, 2147483648, 32, 0) + , (2, 2147483648, 2147483647, 0) + , (2, 2147483648, 2147483648, 2147483648) + , (2, 2147483648, 4294967294, 2147483648) + , (2, 2147483648, 4294967295, 2147483648) + , (2, 4294967294, 0, 0) + , (2, 4294967294, 1, 0) + , (2, 4294967294, 2, 2) + , (2, 4294967294, 31, 30) + , (2, 4294967294, 32, 32) + , (2, 4294967294, 2147483647, 2147483646) + , (2, 4294967294, 2147483648, 2147483648) + , (2, 4294967294, 4294967294, 4294967294) + , (2, 4294967294, 4294967295, 4294967294) + , (2, 4294967295, 0, 0) + , (2, 4294967295, 1, 1) + , (2, 4294967295, 2, 2) + , (2, 4294967295, 31, 31) + , (2, 4294967295, 32, 32) + , (2, 4294967295, 2147483647, 2147483647) + , (2, 4294967295, 2147483648, 2147483648) + , (2, 4294967295, 4294967294, 4294967294) + , (2, 4294967295, 4294967295, 4294967295) + , (2, 4222272340, 3018856485, 3013607428) + , (2, 379515872, 178533105, 42218208) + , (2, 707510791, 2591788913, 170623489) + , (2, 3933066539, 659350380, 575455528) + , (2, 2333640804, 3487620568, 2332067904) + , (2, 1765341752, 3405633948, 1211684888) + , (2, 3236348377, 1431584459, 1078198473) + , (2, 2478600280, 3249560273, 2175815760) + , (2, 2460645879, 149137941, 10627093) + , (2, 3433877109, 1271316163, 1216646721) + , (2, 3723453251, 2182014576, 2148426304) + , (2, 2769503457, 1018057816, 604128320) + , (2, 3260756530, 4124728163, 3227128354) + , (2, 3438460860, 669438262, 81957172) + , (2, 1826033185, 1148320962, 1146162176) + , (2, 2095817777, 125410707, 74023953) + , (2, 164472764, 1173487102, 29468092) + , (2, 1816836761, 1648241983, 1611278361) + , (2, 1856018840, 343361865, 69208328) + , (2, 2288712981, 1947234856, 28672) + , (2, 3015231039, 969299767, 830490167) + , (2, 3158443250, 758246939, 738198546) + , (2, 3150010492, 1684333854, 541081628) + , (2, 4239251582, 3186512646, 3165409286) + , (2, 2236034112, 1248349535, 4197440) + , (2, 2253431469, 1837736069, 67149957) + , (2, 3581590838, 3346653714, 3313016850) + , (2, 1351433231, 1149939738, 1082667018) + , (2, 3395186067, 1158888304, 1074931984) + , (2, 3290394050, 1573886483, 1141835778) + , (2, 1296804427, 3587281360, 1161920576) + , (2, 453833330, 1665922652, 50917968) + , (2, 2475109104, 2911185365, 2172987600) + , (2, 755740888, 1167230839, 84050000) + , (2, 4192557824, 3532097471, 3498377984) + , (2, 1524723696, 1053814038, 448883984) + , (2, 1609670288, 426029171, 425758736) + , (2, 3701505454, 317959263, 278932494) + , (2, 3954083790, 1972473457, 1635812928) + , (2, 2583541165, 3975072409, 2297200777) + , (2, 563224588, 3812216621, 554696716) + , (2, 1030500844, 2967456744, 810287592) + , (2, 2373900222, 2102548527, 223498286) + , (2, 2992286323, 2682139598, 2455380546) + , (2, 3720596378, 3946355560, 3372256008) + , (2, 1016409648, 1140208456, 9708032) + , (2, 82580043, 17156065, 262721) + , (2, 3818267397, 3081334409, 2743083521) + , (2, 3465194745, 4292146700, 3464537096) + , (2, 3725224097, 3684892669, 3657590945) + , (2, 527877525, 256409499, 255870353) + , (2, 2592462716, 2990664910, 2449589324) + , (2, 1925553553, 3927762823, 1644463489) + , (2, 1390245551, 2521092483, 306466947) + , (2, 521880022, 2481597211, 319422738) + , (2, 1860304388, 598127922, 580957184) + , (2, 945207741, 1771423344, 672432176) + , (2, 3417966451, 2785685302, 2181695282) + , (2, 511205855, 4079302086, 304095686) + , (2, 2289434543, 2323379776, 2289169920) + , (2, 3246274374, 3812191436, 3241681988) + , (2, 2356553023, 2513710439, 2220107047) + , (2, 3338856311, 4079201695, 3271730455) + , (2, 1501407491, 4267822174, 1482786818) + ] + +/-- `Or` (code 3): `(code, a, b, AluOp::eval(a, b))` for each pair. -/ +def vectors3 : List (ℕ × ℕ × ℕ × ℕ) := + [ (3, 0, 0, 0) + , (3, 0, 1, 1) + , (3, 0, 2, 2) + , (3, 0, 31, 31) + , (3, 0, 32, 32) + , (3, 0, 2147483647, 2147483647) + , (3, 0, 2147483648, 2147483648) + , (3, 0, 4294967294, 4294967294) + , (3, 0, 4294967295, 4294967295) + , (3, 1, 0, 1) + , (3, 1, 1, 1) + , (3, 1, 2, 3) + , (3, 1, 31, 31) + , (3, 1, 32, 33) + , (3, 1, 2147483647, 2147483647) + , (3, 1, 2147483648, 2147483649) + , (3, 1, 4294967294, 4294967295) + , (3, 1, 4294967295, 4294967295) + , (3, 2, 0, 2) + , (3, 2, 1, 3) + , (3, 2, 2, 2) + , (3, 2, 31, 31) + , (3, 2, 32, 34) + , (3, 2, 2147483647, 2147483647) + , (3, 2, 2147483648, 2147483650) + , (3, 2, 4294967294, 4294967294) + , (3, 2, 4294967295, 4294967295) + , (3, 31, 0, 31) + , (3, 31, 1, 31) + , (3, 31, 2, 31) + , (3, 31, 31, 31) + , (3, 31, 32, 63) + , (3, 31, 2147483647, 2147483647) + , (3, 31, 2147483648, 2147483679) + , (3, 31, 4294967294, 4294967295) + , (3, 31, 4294967295, 4294967295) + , (3, 32, 0, 32) + , (3, 32, 1, 33) + , (3, 32, 2, 34) + , (3, 32, 31, 63) + , (3, 32, 32, 32) + , (3, 32, 2147483647, 2147483647) + , (3, 32, 2147483648, 2147483680) + , (3, 32, 4294967294, 4294967294) + , (3, 32, 4294967295, 4294967295) + , (3, 2147483647, 0, 2147483647) + , (3, 2147483647, 1, 2147483647) + , (3, 2147483647, 2, 2147483647) + , (3, 2147483647, 31, 2147483647) + , (3, 2147483647, 32, 2147483647) + , (3, 2147483647, 2147483647, 2147483647) + , (3, 2147483647, 2147483648, 4294967295) + , (3, 2147483647, 4294967294, 4294967295) + , (3, 2147483647, 4294967295, 4294967295) + , (3, 2147483648, 0, 2147483648) + , (3, 2147483648, 1, 2147483649) + , (3, 2147483648, 2, 2147483650) + , (3, 2147483648, 31, 2147483679) + , (3, 2147483648, 32, 2147483680) + , (3, 2147483648, 2147483647, 4294967295) + , (3, 2147483648, 2147483648, 2147483648) + , (3, 2147483648, 4294967294, 4294967294) + , (3, 2147483648, 4294967295, 4294967295) + , (3, 4294967294, 0, 4294967294) + , (3, 4294967294, 1, 4294967295) + , (3, 4294967294, 2, 4294967294) + , (3, 4294967294, 31, 4294967295) + , (3, 4294967294, 32, 4294967294) + , (3, 4294967294, 2147483647, 4294967295) + , (3, 4294967294, 2147483648, 4294967294) + , (3, 4294967294, 4294967294, 4294967294) + , (3, 4294967294, 4294967295, 4294967295) + , (3, 4294967295, 0, 4294967295) + , (3, 4294967295, 1, 4294967295) + , (3, 4294967295, 2, 4294967295) + , (3, 4294967295, 31, 4294967295) + , (3, 4294967295, 32, 4294967295) + , (3, 4294967295, 2147483647, 4294967295) + , (3, 4294967295, 2147483648, 4294967295) + , (3, 4294967295, 4294967294, 4294967295) + , (3, 4294967295, 4294967295, 4294967295) + , (3, 4222272340, 3018856485, 4227521397) + , (3, 379515872, 178533105, 515830769) + , (3, 707510791, 2591788913, 3128676215) + , (3, 3933066539, 659350380, 4016961391) + , (3, 2333640804, 3487620568, 3489193468) + , (3, 1765341752, 3405633948, 3959290812) + , (3, 3236348377, 1431584459, 3589734363) + , (3, 2478600280, 3249560273, 3552344793) + , (3, 2460645879, 149137941, 2599156727) + , (3, 3433877109, 1271316163, 3488546551) + , (3, 3723453251, 2182014576, 3757041523) + , (3, 2769503457, 1018057816, 3183432953) + , (3, 3260756530, 4124728163, 4158356339) + , (3, 3438460860, 669438262, 4025941950) + , (3, 1826033185, 1148320962, 1828191971) + , (3, 2095817777, 125410707, 2147204531) + , (3, 164472764, 1173487102, 1308491774) + , (3, 1816836761, 1648241983, 1853800383) + , (3, 1856018840, 343361865, 2130172377) + , (3, 2288712981, 1947234856, 4235919165) + , (3, 3015231039, 969299767, 3154040639) + , (3, 3158443250, 758246939, 3178491643) + , (3, 3150010492, 1684333854, 4293262718) + , (3, 4239251582, 3186512646, 4260354942) + , (3, 2236034112, 1248349535, 3480186207) + , (3, 2253431469, 1837736069, 4024017581) + , (3, 3581590838, 3346653714, 3615227702) + , (3, 1351433231, 1149939738, 1418705951) + , (3, 3395186067, 1158888304, 3479142387) + , (3, 3290394050, 1573886483, 3722444755) + , (3, 1296804427, 3587281360, 3722165211) + , (3, 453833330, 1665922652, 2068838014) + , (3, 2475109104, 2911185365, 3213306869) + , (3, 755740888, 1167230839, 1838921727) + , (3, 4192557824, 3532097471, 4226277311) + , (3, 1524723696, 1053814038, 2129653750) + , (3, 1609670288, 426029171, 1609940723) + , (3, 3701505454, 317959263, 3740532223) + , (3, 3954083790, 1972473457, 4290744319) + , (3, 2583541165, 3975072409, 4261412797) + , (3, 563224588, 3812216621, 3820744493) + , (3, 1030500844, 2967456744, 3187669996) + , (3, 2373900222, 2102548527, 4252950463) + , (3, 2992286323, 2682139598, 3219045375) + , (3, 3720596378, 3946355560, 4294695930) + , (3, 1016409648, 1140208456, 2146910072) + , (3, 82580043, 17156065, 99473387) + , (3, 3818267397, 3081334409, 4156518285) + , (3, 3465194745, 4292146700, 4292804349) + , (3, 3725224097, 3684892669, 3752525821) + , (3, 527877525, 256409499, 528416671) + , (3, 2592462716, 2990664910, 3133538302) + , (3, 1925553553, 3927762823, 4208852887) + , (3, 1390245551, 2521092483, 3604871087) + , (3, 521880022, 2481597211, 2684054495) + , (3, 1860304388, 598127922, 1877475126) + , (3, 945207741, 1771423344, 2044198909) + , (3, 3417966451, 2785685302, 4021956471) + , (3, 511205855, 4079302086, 4286412255) + , (3, 2289434543, 2323379776, 2323644399) + , (3, 3246274374, 3812191436, 3816783822) + , (3, 2356553023, 2513710439, 2650156415) + , (3, 3338856311, 4079201695, 4146327551) + , (3, 1501407491, 4267822174, 4286442847) + ] + +/-- `Xor` (code 4): `(code, a, b, AluOp::eval(a, b))` for each pair. -/ +def vectors4 : List (ℕ × ℕ × ℕ × ℕ) := + [ (4, 0, 0, 0) + , (4, 0, 1, 1) + , (4, 0, 2, 2) + , (4, 0, 31, 31) + , (4, 0, 32, 32) + , (4, 0, 2147483647, 2147483647) + , (4, 0, 2147483648, 2147483648) + , (4, 0, 4294967294, 4294967294) + , (4, 0, 4294967295, 4294967295) + , (4, 1, 0, 1) + , (4, 1, 1, 0) + , (4, 1, 2, 3) + , (4, 1, 31, 30) + , (4, 1, 32, 33) + , (4, 1, 2147483647, 2147483646) + , (4, 1, 2147483648, 2147483649) + , (4, 1, 4294967294, 4294967295) + , (4, 1, 4294967295, 4294967294) + , (4, 2, 0, 2) + , (4, 2, 1, 3) + , (4, 2, 2, 0) + , (4, 2, 31, 29) + , (4, 2, 32, 34) + , (4, 2, 2147483647, 2147483645) + , (4, 2, 2147483648, 2147483650) + , (4, 2, 4294967294, 4294967292) + , (4, 2, 4294967295, 4294967293) + , (4, 31, 0, 31) + , (4, 31, 1, 30) + , (4, 31, 2, 29) + , (4, 31, 31, 0) + , (4, 31, 32, 63) + , (4, 31, 2147483647, 2147483616) + , (4, 31, 2147483648, 2147483679) + , (4, 31, 4294967294, 4294967265) + , (4, 31, 4294967295, 4294967264) + , (4, 32, 0, 32) + , (4, 32, 1, 33) + , (4, 32, 2, 34) + , (4, 32, 31, 63) + , (4, 32, 32, 0) + , (4, 32, 2147483647, 2147483615) + , (4, 32, 2147483648, 2147483680) + , (4, 32, 4294967294, 4294967262) + , (4, 32, 4294967295, 4294967263) + , (4, 2147483647, 0, 2147483647) + , (4, 2147483647, 1, 2147483646) + , (4, 2147483647, 2, 2147483645) + , (4, 2147483647, 31, 2147483616) + , (4, 2147483647, 32, 2147483615) + , (4, 2147483647, 2147483647, 0) + , (4, 2147483647, 2147483648, 4294967295) + , (4, 2147483647, 4294967294, 2147483649) + , (4, 2147483647, 4294967295, 2147483648) + , (4, 2147483648, 0, 2147483648) + , (4, 2147483648, 1, 2147483649) + , (4, 2147483648, 2, 2147483650) + , (4, 2147483648, 31, 2147483679) + , (4, 2147483648, 32, 2147483680) + , (4, 2147483648, 2147483647, 4294967295) + , (4, 2147483648, 2147483648, 0) + , (4, 2147483648, 4294967294, 2147483646) + , (4, 2147483648, 4294967295, 2147483647) + , (4, 4294967294, 0, 4294967294) + , (4, 4294967294, 1, 4294967295) + , (4, 4294967294, 2, 4294967292) + , (4, 4294967294, 31, 4294967265) + , (4, 4294967294, 32, 4294967262) + , (4, 4294967294, 2147483647, 2147483649) + , (4, 4294967294, 2147483648, 2147483646) + , (4, 4294967294, 4294967294, 0) + , (4, 4294967294, 4294967295, 1) + , (4, 4294967295, 0, 4294967295) + , (4, 4294967295, 1, 4294967294) + , (4, 4294967295, 2, 4294967293) + , (4, 4294967295, 31, 4294967264) + , (4, 4294967295, 32, 4294967263) + , (4, 4294967295, 2147483647, 2147483648) + , (4, 4294967295, 2147483648, 2147483647) + , (4, 4294967295, 4294967294, 1) + , (4, 4294967295, 4294967295, 0) + , (4, 4222272340, 3018856485, 1213913969) + , (4, 379515872, 178533105, 473612561) + , (4, 707510791, 2591788913, 2958052726) + , (4, 3933066539, 659350380, 3441505863) + , (4, 2333640804, 3487620568, 1157125564) + , (4, 1765341752, 3405633948, 2747605924) + , (4, 3236348377, 1431584459, 2511535890) + , (4, 2478600280, 3249560273, 1376529033) + , (4, 2460645879, 149137941, 2588529634) + , (4, 3433877109, 1271316163, 2271899830) + , (4, 3723453251, 2182014576, 1608615219) + , (4, 2769503457, 1018057816, 2579304633) + , (4, 3260756530, 4124728163, 931227985) + , (4, 3438460860, 669438262, 3943984778) + , (4, 1826033185, 1148320962, 682029795) + , (4, 2095817777, 125410707, 2073180578) + , (4, 164472764, 1173487102, 1279023682) + , (4, 1816836761, 1648241983, 242522022) + , (4, 1856018840, 343361865, 2060964049) + , (4, 2288712981, 1947234856, 4235890493) + , (4, 3015231039, 969299767, 2323550472) + , (4, 3158443250, 758246939, 2440293097) + , (4, 3150010492, 1684333854, 3752181090) + , (4, 4239251582, 3186512646, 1094945656) + , (4, 2236034112, 1248349535, 3475988767) + , (4, 2253431469, 1837736069, 3956867624) + , (4, 3581590838, 3346653714, 302210852) + , (4, 1351433231, 1149939738, 336038933) + , (4, 3395186067, 1158888304, 2404210403) + , (4, 3290394050, 1573886483, 2580608977) + , (4, 1296804427, 3587281360, 2560244635) + , (4, 453833330, 1665922652, 2017920046) + , (4, 2475109104, 2911185365, 1040319269) + , (4, 755740888, 1167230839, 1754871727) + , (4, 4192557824, 3532097471, 727899327) + , (4, 1524723696, 1053814038, 1680769766) + , (4, 1609670288, 426029171, 1184181987) + , (4, 3701505454, 317959263, 3461599729) + , (4, 3954083790, 1972473457, 2654931391) + , (4, 2583541165, 3975072409, 1964212020) + , (4, 563224588, 3812216621, 3266047777) + , (4, 1030500844, 2967456744, 2377382404) + , (4, 2373900222, 2102548527, 4029452177) + , (4, 2992286323, 2682139598, 763664829) + , (4, 3720596378, 3946355560, 922439922) + , (4, 1016409648, 1140208456, 2137202040) + , (4, 82580043, 17156065, 99210666) + , (4, 3818267397, 3081334409, 1413434764) + , (4, 3465194745, 4292146700, 828267253) + , (4, 3725224097, 3684892669, 94934876) + , (4, 527877525, 256409499, 272546318) + , (4, 2592462716, 2990664910, 683948978) + , (4, 1925553553, 3927762823, 2564389398) + , (4, 1390245551, 2521092483, 3298404140) + , (4, 521880022, 2481597211, 2364631757) + , (4, 1860304388, 598127922, 1296517942) + , (4, 945207741, 1771423344, 1371766733) + , (4, 3417966451, 2785685302, 1840261189) + , (4, 511205855, 4079302086, 3982316569) + , (4, 2289434543, 2323379776, 34474479) + , (4, 3246274374, 3812191436, 575101834) + , (4, 2356553023, 2513710439, 430049368) + , (4, 3338856311, 4079201695, 874597096) + , (4, 1501407491, 4267822174, 2803656029) + ] + +/-- `Sll` (code 5): `(code, a, b, AluOp::eval(a, b))` for each pair. -/ +def vectors5 : List (ℕ × ℕ × ℕ × ℕ) := + [ (5, 0, 0, 0) + , (5, 0, 1, 0) + , (5, 0, 2, 0) + , (5, 0, 31, 0) + , (5, 0, 32, 0) + , (5, 0, 2147483647, 0) + , (5, 0, 2147483648, 0) + , (5, 0, 4294967294, 0) + , (5, 0, 4294967295, 0) + , (5, 1, 0, 1) + , (5, 1, 1, 2) + , (5, 1, 2, 4) + , (5, 1, 31, 2147483648) + , (5, 1, 32, 1) + , (5, 1, 2147483647, 2147483648) + , (5, 1, 2147483648, 1) + , (5, 1, 4294967294, 1073741824) + , (5, 1, 4294967295, 2147483648) + , (5, 2, 0, 2) + , (5, 2, 1, 4) + , (5, 2, 2, 8) + , (5, 2, 31, 0) + , (5, 2, 32, 2) + , (5, 2, 2147483647, 0) + , (5, 2, 2147483648, 2) + , (5, 2, 4294967294, 2147483648) + , (5, 2, 4294967295, 0) + , (5, 31, 0, 31) + , (5, 31, 1, 62) + , (5, 31, 2, 124) + , (5, 31, 31, 2147483648) + , (5, 31, 32, 31) + , (5, 31, 2147483647, 2147483648) + , (5, 31, 2147483648, 31) + , (5, 31, 4294967294, 3221225472) + , (5, 31, 4294967295, 2147483648) + , (5, 32, 0, 32) + , (5, 32, 1, 64) + , (5, 32, 2, 128) + , (5, 32, 31, 0) + , (5, 32, 32, 32) + , (5, 32, 2147483647, 0) + , (5, 32, 2147483648, 32) + , (5, 32, 4294967294, 0) + , (5, 32, 4294967295, 0) + , (5, 2147483647, 0, 2147483647) + , (5, 2147483647, 1, 4294967294) + , (5, 2147483647, 2, 4294967292) + , (5, 2147483647, 31, 2147483648) + , (5, 2147483647, 32, 2147483647) + , (5, 2147483647, 2147483647, 2147483648) + , (5, 2147483647, 2147483648, 2147483647) + , (5, 2147483647, 4294967294, 3221225472) + , (5, 2147483647, 4294967295, 2147483648) + , (5, 2147483648, 0, 2147483648) + , (5, 2147483648, 1, 0) + , (5, 2147483648, 2, 0) + , (5, 2147483648, 31, 0) + , (5, 2147483648, 32, 2147483648) + , (5, 2147483648, 2147483647, 0) + , (5, 2147483648, 2147483648, 2147483648) + , (5, 2147483648, 4294967294, 0) + , (5, 2147483648, 4294967295, 0) + , (5, 4294967294, 0, 4294967294) + , (5, 4294967294, 1, 4294967292) + , (5, 4294967294, 2, 4294967288) + , (5, 4294967294, 31, 0) + , (5, 4294967294, 32, 4294967294) + , (5, 4294967294, 2147483647, 0) + , (5, 4294967294, 2147483648, 4294967294) + , (5, 4294967294, 4294967294, 2147483648) + , (5, 4294967294, 4294967295, 0) + , (5, 4294967295, 0, 4294967295) + , (5, 4294967295, 1, 4294967294) + , (5, 4294967295, 2, 4294967292) + , (5, 4294967295, 31, 2147483648) + , (5, 4294967295, 32, 4294967295) + , (5, 4294967295, 2147483647, 2147483648) + , (5, 4294967295, 2147483648, 4294967295) + , (5, 4294967295, 4294967294, 3221225472) + , (5, 4294967295, 4294967295, 2147483648) + , (5, 4222272340, 3018856485, 1968728704) + , (5, 379515872, 178533105, 3888119808) + , (5, 707510791, 2591788913, 2215510016) + , (5, 3933066539, 659350380, 3713183744) + , (5, 2333640804, 3487620568, 1677721600) + , (5, 1765341752, 3405633948, 2147483648) + , (5, 3236348377, 1431584459, 906938368) + , (5, 2478600280, 3249560273, 3769630720) + , (5, 2460645879, 149137941, 1054867456) + , (5, 3433877109, 1271316163, 1701213096) + , (5, 3723453251, 2182014576, 1665335296) + , (5, 2769503457, 1018057816, 3774873600) + , (5, 3260756530, 4124728163, 316248464) + , (5, 3438460860, 669438262, 4009754624) + , (5, 1826033185, 1148320962, 3009165444) + , (5, 2095817777, 125410707, 562561024) + , (5, 164472764, 1173487102, 0) + , (5, 1816836761, 1648241983, 2147483648) + , (5, 1856018840, 343361865, 1093873664) + , (5, 2288712981, 1947234856, 1794970880) + , (5, 3015231039, 969299767, 528482304) + , (5, 3158443250, 758246939, 2415919104) + , (5, 3150010492, 1684333854, 0) + , (5, 4239251582, 3186512646, 729161600) + , (5, 2236034112, 1248349535, 0) + , (5, 2253431469, 1837736069, 3390330272) + , (5, 3581590838, 3346653714, 4107796480) + , (5, 1351433231, 1149939738, 1006632960) + , (5, 3395186067, 1158888304, 1838350336) + , (5, 3290394050, 1573886483, 1846542336) + , (5, 1296804427, 3587281360, 2857041920) + , (5, 453833330, 1665922652, 536870912) + , (5, 2475109104, 2911185365, 1577058304) + , (5, 755740888, 1167230839, 1811939328) + , (5, 4192557824, 3532097471, 0) + , (5, 1524723696, 1053814038, 4227858432) + , (5, 1609670288, 426029171, 4102029312) + , (5, 3701505454, 317959263, 0) + , (5, 3954083790, 1972473457, 261881856) + , (5, 2583541165, 3975072409, 1509949440) + , (5, 563224588, 3812216621, 1140948992) + , (5, 1030500844, 2967456744, 1815211008) + , (5, 2373900222, 2102548527, 1809776640) + , (5, 2992286323, 2682139598, 2862399488) + , (5, 3720596378, 3946355560, 3284900352) + , (5, 1016409648, 1140208456, 2502832128) + , (5, 82580043, 17156065, 165160086) + , (5, 3818267397, 3081334409, 742787584) + , (5, 3465194745, 4292146700, 2865729536) + , (5, 3725224097, 3684892669, 536870912) + , (5, 527877525, 256409499, 2818572288) + , (5, 2592462716, 2990664910, 1977548800) + , (5, 1925553553, 3927762823, 1657718912) + , (5, 1390245551, 2521092483, 2532029816) + , (5, 521880022, 2481597211, 2952790016) + , (5, 1860304388, 598127922, 4161798144) + , (5, 945207741, 1771423344, 3116171264) + , (5, 3417966451, 2785685302, 3703570432) + , (5, 511205855, 4079302086, 2652403648) + , (5, 2289434543, 2323379776, 2289434543) + , (5, 3246274374, 3812191436, 3816054784) + , (5, 2356553023, 2513710439, 991076224) + , (5, 3338856311, 4079201695, 2147483648) + , (5, 1501407491, 4267822174, 3221225472) + ] + +/-- `Srl` (code 6): `(code, a, b, AluOp::eval(a, b))` for each pair. -/ +def vectors6 : List (ℕ × ℕ × ℕ × ℕ) := + [ (6, 0, 0, 0) + , (6, 0, 1, 0) + , (6, 0, 2, 0) + , (6, 0, 31, 0) + , (6, 0, 32, 0) + , (6, 0, 2147483647, 0) + , (6, 0, 2147483648, 0) + , (6, 0, 4294967294, 0) + , (6, 0, 4294967295, 0) + , (6, 1, 0, 1) + , (6, 1, 1, 0) + , (6, 1, 2, 0) + , (6, 1, 31, 0) + , (6, 1, 32, 1) + , (6, 1, 2147483647, 0) + , (6, 1, 2147483648, 1) + , (6, 1, 4294967294, 0) + , (6, 1, 4294967295, 0) + , (6, 2, 0, 2) + , (6, 2, 1, 1) + , (6, 2, 2, 0) + , (6, 2, 31, 0) + , (6, 2, 32, 2) + , (6, 2, 2147483647, 0) + , (6, 2, 2147483648, 2) + , (6, 2, 4294967294, 0) + , (6, 2, 4294967295, 0) + , (6, 31, 0, 31) + , (6, 31, 1, 15) + , (6, 31, 2, 7) + , (6, 31, 31, 0) + , (6, 31, 32, 31) + , (6, 31, 2147483647, 0) + , (6, 31, 2147483648, 31) + , (6, 31, 4294967294, 0) + , (6, 31, 4294967295, 0) + , (6, 32, 0, 32) + , (6, 32, 1, 16) + , (6, 32, 2, 8) + , (6, 32, 31, 0) + , (6, 32, 32, 32) + , (6, 32, 2147483647, 0) + , (6, 32, 2147483648, 32) + , (6, 32, 4294967294, 0) + , (6, 32, 4294967295, 0) + , (6, 2147483647, 0, 2147483647) + , (6, 2147483647, 1, 1073741823) + , (6, 2147483647, 2, 536870911) + , (6, 2147483647, 31, 0) + , (6, 2147483647, 32, 2147483647) + , (6, 2147483647, 2147483647, 0) + , (6, 2147483647, 2147483648, 2147483647) + , (6, 2147483647, 4294967294, 1) + , (6, 2147483647, 4294967295, 0) + , (6, 2147483648, 0, 2147483648) + , (6, 2147483648, 1, 1073741824) + , (6, 2147483648, 2, 536870912) + , (6, 2147483648, 31, 1) + , (6, 2147483648, 32, 2147483648) + , (6, 2147483648, 2147483647, 1) + , (6, 2147483648, 2147483648, 2147483648) + , (6, 2147483648, 4294967294, 2) + , (6, 2147483648, 4294967295, 1) + , (6, 4294967294, 0, 4294967294) + , (6, 4294967294, 1, 2147483647) + , (6, 4294967294, 2, 1073741823) + , (6, 4294967294, 31, 1) + , (6, 4294967294, 32, 4294967294) + , (6, 4294967294, 2147483647, 1) + , (6, 4294967294, 2147483648, 4294967294) + , (6, 4294967294, 4294967294, 3) + , (6, 4294967294, 4294967295, 1) + , (6, 4294967295, 0, 4294967295) + , (6, 4294967295, 1, 2147483647) + , (6, 4294967295, 2, 1073741823) + , (6, 4294967295, 31, 1) + , (6, 4294967295, 32, 4294967295) + , (6, 4294967295, 2147483647, 1) + , (6, 4294967295, 2147483648, 4294967295) + , (6, 4294967295, 4294967294, 3) + , (6, 4294967295, 4294967295, 1) + , (6, 4222272340, 3018856485, 131946010) + , (6, 379515872, 178533105, 2895) + , (6, 707510791, 2591788913, 5397) + , (6, 3933066539, 659350380, 960221) + , (6, 2333640804, 3487620568, 139) + , (6, 1765341752, 3405633948, 6) + , (6, 3236348377, 1431584459, 1580248) + , (6, 2478600280, 3249560273, 18910) + , (6, 2460645879, 149137941, 1173) + , (6, 3433877109, 1271316163, 429234638) + , (6, 3723453251, 2182014576, 56815) + , (6, 2769503457, 1018057816, 165) + , (6, 3260756530, 4124728163, 407594566) + , (6, 3438460860, 669438262, 819) + , (6, 1826033185, 1148320962, 456508296) + , (6, 2095817777, 125410707, 3997) + , (6, 164472764, 1173487102, 0) + , (6, 1816836761, 1648241983, 0) + , (6, 1856018840, 343361865, 3625036) + , (6, 2288712981, 1947234856, 8940285) + , (6, 3015231039, 969299767, 359) + , (6, 3158443250, 758246939, 23) + , (6, 3150010492, 1684333854, 2) + , (6, 4239251582, 3186512646, 66238305) + , (6, 2236034112, 1248349535, 1) + , (6, 2253431469, 1837736069, 70419733) + , (6, 3581590838, 3346653714, 13662) + , (6, 1351433231, 1149939738, 20) + , (6, 3395186067, 1158888304, 51806) + , (6, 3290394050, 1573886483, 6275) + , (6, 1296804427, 3587281360, 19787) + , (6, 453833330, 1665922652, 1) + , (6, 2475109104, 2911185365, 1180) + , (6, 755740888, 1167230839, 90) + , (6, 4192557824, 3532097471, 1) + , (6, 1524723696, 1053814038, 363) + , (6, 1609670288, 426029171, 3070) + , (6, 3701505454, 317959263, 1) + , (6, 3954083790, 1972473457, 30167) + , (6, 2583541165, 3975072409, 76) + , (6, 563224588, 3812216621, 68753) + , (6, 1030500844, 2967456744, 4025393) + , (6, 2373900222, 2102548527, 72445) + , (6, 2992286323, 2682139598, 182634) + , (6, 3720596378, 3946355560, 14533579) + , (6, 1016409648, 1140208456, 3970350) + , (6, 82580043, 17156065, 41290021) + , (6, 3818267397, 3081334409, 7457553) + , (6, 3465194745, 4292146700, 845994) + , (6, 3725224097, 3684892669, 6) + , (6, 527877525, 256409499, 3) + , (6, 2592462716, 2990664910, 158231) + , (6, 1925553553, 3927762823, 15043387) + , (6, 1390245551, 2521092483, 173780693) + , (6, 521880022, 2481597211, 3) + , (6, 1860304388, 598127922, 7096) + , (6, 945207741, 1771423344, 14422) + , (6, 3417966451, 2785685302, 814) + , (6, 511205855, 4079302086, 7987591) + , (6, 2289434543, 2323379776, 2289434543) + , (6, 3246274374, 3812191436, 792547) + , (6, 2356553023, 2513710439, 18410570) + , (6, 3338856311, 4079201695, 1) + , (6, 1501407491, 4267822174, 1) + ] + +/-- `Sra` (code 7): `(code, a, b, AluOp::eval(a, b))` for each pair. -/ +def vectors7 : List (ℕ × ℕ × ℕ × ℕ) := + [ (7, 0, 0, 0) + , (7, 0, 1, 0) + , (7, 0, 2, 0) + , (7, 0, 31, 0) + , (7, 0, 32, 0) + , (7, 0, 2147483647, 0) + , (7, 0, 2147483648, 0) + , (7, 0, 4294967294, 0) + , (7, 0, 4294967295, 0) + , (7, 1, 0, 1) + , (7, 1, 1, 0) + , (7, 1, 2, 0) + , (7, 1, 31, 0) + , (7, 1, 32, 1) + , (7, 1, 2147483647, 0) + , (7, 1, 2147483648, 1) + , (7, 1, 4294967294, 0) + , (7, 1, 4294967295, 0) + , (7, 2, 0, 2) + , (7, 2, 1, 1) + , (7, 2, 2, 0) + , (7, 2, 31, 0) + , (7, 2, 32, 2) + , (7, 2, 2147483647, 0) + , (7, 2, 2147483648, 2) + , (7, 2, 4294967294, 0) + , (7, 2, 4294967295, 0) + , (7, 31, 0, 31) + , (7, 31, 1, 15) + , (7, 31, 2, 7) + , (7, 31, 31, 0) + , (7, 31, 32, 31) + , (7, 31, 2147483647, 0) + , (7, 31, 2147483648, 31) + , (7, 31, 4294967294, 0) + , (7, 31, 4294967295, 0) + , (7, 32, 0, 32) + , (7, 32, 1, 16) + , (7, 32, 2, 8) + , (7, 32, 31, 0) + , (7, 32, 32, 32) + , (7, 32, 2147483647, 0) + , (7, 32, 2147483648, 32) + , (7, 32, 4294967294, 0) + , (7, 32, 4294967295, 0) + , (7, 2147483647, 0, 2147483647) + , (7, 2147483647, 1, 1073741823) + , (7, 2147483647, 2, 536870911) + , (7, 2147483647, 31, 0) + , (7, 2147483647, 32, 2147483647) + , (7, 2147483647, 2147483647, 0) + , (7, 2147483647, 2147483648, 2147483647) + , (7, 2147483647, 4294967294, 1) + , (7, 2147483647, 4294967295, 0) + , (7, 2147483648, 0, 2147483648) + , (7, 2147483648, 1, 3221225472) + , (7, 2147483648, 2, 3758096384) + , (7, 2147483648, 31, 4294967295) + , (7, 2147483648, 32, 2147483648) + , (7, 2147483648, 2147483647, 4294967295) + , (7, 2147483648, 2147483648, 2147483648) + , (7, 2147483648, 4294967294, 4294967294) + , (7, 2147483648, 4294967295, 4294967295) + , (7, 4294967294, 0, 4294967294) + , (7, 4294967294, 1, 4294967295) + , (7, 4294967294, 2, 4294967295) + , (7, 4294967294, 31, 4294967295) + , (7, 4294967294, 32, 4294967294) + , (7, 4294967294, 2147483647, 4294967295) + , (7, 4294967294, 2147483648, 4294967294) + , (7, 4294967294, 4294967294, 4294967295) + , (7, 4294967294, 4294967295, 4294967295) + , (7, 4294967295, 0, 4294967295) + , (7, 4294967295, 1, 4294967295) + , (7, 4294967295, 2, 4294967295) + , (7, 4294967295, 31, 4294967295) + , (7, 4294967295, 32, 4294967295) + , (7, 4294967295, 2147483647, 4294967295) + , (7, 4294967295, 2147483648, 4294967295) + , (7, 4294967295, 4294967294, 4294967295) + , (7, 4294967295, 4294967295, 4294967295) + , (7, 4222272340, 3018856485, 4292695578) + , (7, 379515872, 178533105, 2895) + , (7, 707510791, 2591788913, 5397) + , (7, 3933066539, 659350380, 4294878941) + , (7, 2333640804, 3487620568, 4294967179) + , (7, 1765341752, 3405633948, 6) + , (7, 3236348377, 1431584459, 4294450392) + , (7, 2478600280, 3249560273, 4294953438) + , (7, 2460645879, 149137941, 4294966421) + , (7, 3433877109, 1271316163, 4187331022) + , (7, 3723453251, 2182014576, 4294958575) + , (7, 2769503457, 1018057816, 4294967205) + , (7, 3260756530, 4124728163, 4165690950) + , (7, 3438460860, 669438262, 4294967091) + , (7, 1826033185, 1148320962, 456508296) + , (7, 2095817777, 125410707, 3997) + , (7, 164472764, 1173487102, 0) + , (7, 1816836761, 1648241983, 0) + , (7, 1856018840, 343361865, 3625036) + , (7, 2288712981, 1947234856, 4287130365) + , (7, 3015231039, 969299767, 4294967143) + , (7, 3158443250, 758246939, 4294967287) + , (7, 3150010492, 1684333854, 4294967294) + , (7, 4239251582, 3186512646, 4294096737) + , (7, 2236034112, 1248349535, 4294967295) + , (7, 2253431469, 1837736069, 4231169301) + , (7, 3581590838, 3346653714, 4294964574) + , (7, 1351433231, 1149939738, 20) + , (7, 3395186067, 1158888304, 4294953566) + , (7, 3290394050, 1573886483, 4294965379) + , (7, 1296804427, 3587281360, 19787) + , (7, 453833330, 1665922652, 1) + , (7, 2475109104, 2911185365, 4294966428) + , (7, 755740888, 1167230839, 90) + , (7, 4192557824, 3532097471, 4294967295) + , (7, 1524723696, 1053814038, 363) + , (7, 1609670288, 426029171, 3070) + , (7, 3701505454, 317959263, 4294967295) + , (7, 3954083790, 1972473457, 4294964695) + , (7, 2583541165, 3975072409, 4294967244) + , (7, 563224588, 3812216621, 68753) + , (7, 1030500844, 2967456744, 4025393) + , (7, 2373900222, 2102548527, 4294908669) + , (7, 2992286323, 2682139598, 4294887786) + , (7, 3720596378, 3946355560, 4292723659) + , (7, 1016409648, 1140208456, 3970350) + , (7, 82580043, 17156065, 41290021) + , (7, 3818267397, 3081334409, 4294036241) + , (7, 3465194745, 4292146700, 4294764714) + , (7, 3725224097, 3684892669, 4294967294) + , (7, 527877525, 256409499, 3) + , (7, 2592462716, 2990664910, 4294863383) + , (7, 1925553553, 3927762823, 15043387) + , (7, 1390245551, 2521092483, 173780693) + , (7, 521880022, 2481597211, 3) + , (7, 1860304388, 598127922, 7096) + , (7, 945207741, 1771423344, 14422) + , (7, 3417966451, 2785685302, 4294967086) + , (7, 511205855, 4079302086, 7987591) + , (7, 2289434543, 2323379776, 2289434543) + , (7, 3246274374, 3812191436, 4294711267) + , (7, 2356553023, 2513710439, 4279823434) + , (7, 3338856311, 4079201695, 4294967295) + , (7, 1501407491, 4267822174, 1) + ] + +/-- `Slt` (code 8): `(code, a, b, AluOp::eval(a, b))` for each pair. -/ +def vectors8 : List (ℕ × ℕ × ℕ × ℕ) := + [ (8, 0, 0, 0) + , (8, 0, 1, 1) + , (8, 0, 2, 1) + , (8, 0, 31, 1) + , (8, 0, 32, 1) + , (8, 0, 2147483647, 1) + , (8, 0, 2147483648, 0) + , (8, 0, 4294967294, 0) + , (8, 0, 4294967295, 0) + , (8, 1, 0, 0) + , (8, 1, 1, 0) + , (8, 1, 2, 1) + , (8, 1, 31, 1) + , (8, 1, 32, 1) + , (8, 1, 2147483647, 1) + , (8, 1, 2147483648, 0) + , (8, 1, 4294967294, 0) + , (8, 1, 4294967295, 0) + , (8, 2, 0, 0) + , (8, 2, 1, 0) + , (8, 2, 2, 0) + , (8, 2, 31, 1) + , (8, 2, 32, 1) + , (8, 2, 2147483647, 1) + , (8, 2, 2147483648, 0) + , (8, 2, 4294967294, 0) + , (8, 2, 4294967295, 0) + , (8, 31, 0, 0) + , (8, 31, 1, 0) + , (8, 31, 2, 0) + , (8, 31, 31, 0) + , (8, 31, 32, 1) + , (8, 31, 2147483647, 1) + , (8, 31, 2147483648, 0) + , (8, 31, 4294967294, 0) + , (8, 31, 4294967295, 0) + , (8, 32, 0, 0) + , (8, 32, 1, 0) + , (8, 32, 2, 0) + , (8, 32, 31, 0) + , (8, 32, 32, 0) + , (8, 32, 2147483647, 1) + , (8, 32, 2147483648, 0) + , (8, 32, 4294967294, 0) + , (8, 32, 4294967295, 0) + , (8, 2147483647, 0, 0) + , (8, 2147483647, 1, 0) + , (8, 2147483647, 2, 0) + , (8, 2147483647, 31, 0) + , (8, 2147483647, 32, 0) + , (8, 2147483647, 2147483647, 0) + , (8, 2147483647, 2147483648, 0) + , (8, 2147483647, 4294967294, 0) + , (8, 2147483647, 4294967295, 0) + , (8, 2147483648, 0, 1) + , (8, 2147483648, 1, 1) + , (8, 2147483648, 2, 1) + , (8, 2147483648, 31, 1) + , (8, 2147483648, 32, 1) + , (8, 2147483648, 2147483647, 1) + , (8, 2147483648, 2147483648, 0) + , (8, 2147483648, 4294967294, 1) + , (8, 2147483648, 4294967295, 1) + , (8, 4294967294, 0, 1) + , (8, 4294967294, 1, 1) + , (8, 4294967294, 2, 1) + , (8, 4294967294, 31, 1) + , (8, 4294967294, 32, 1) + , (8, 4294967294, 2147483647, 1) + , (8, 4294967294, 2147483648, 0) + , (8, 4294967294, 4294967294, 0) + , (8, 4294967294, 4294967295, 1) + , (8, 4294967295, 0, 1) + , (8, 4294967295, 1, 1) + , (8, 4294967295, 2, 1) + , (8, 4294967295, 31, 1) + , (8, 4294967295, 32, 1) + , (8, 4294967295, 2147483647, 1) + , (8, 4294967295, 2147483648, 0) + , (8, 4294967295, 4294967294, 0) + , (8, 4294967295, 4294967295, 0) + , (8, 4222272340, 3018856485, 0) + , (8, 379515872, 178533105, 0) + , (8, 707510791, 2591788913, 0) + , (8, 3933066539, 659350380, 1) + , (8, 2333640804, 3487620568, 1) + , (8, 1765341752, 3405633948, 0) + , (8, 3236348377, 1431584459, 1) + , (8, 2478600280, 3249560273, 1) + , (8, 2460645879, 149137941, 1) + , (8, 3433877109, 1271316163, 1) + , (8, 3723453251, 2182014576, 0) + , (8, 2769503457, 1018057816, 1) + , (8, 3260756530, 4124728163, 1) + , (8, 3438460860, 669438262, 1) + , (8, 1826033185, 1148320962, 0) + , (8, 2095817777, 125410707, 0) + , (8, 164472764, 1173487102, 1) + , (8, 1816836761, 1648241983, 0) + , (8, 1856018840, 343361865, 0) + , (8, 2288712981, 1947234856, 1) + , (8, 3015231039, 969299767, 1) + , (8, 3158443250, 758246939, 1) + , (8, 3150010492, 1684333854, 1) + , (8, 4239251582, 3186512646, 0) + , (8, 2236034112, 1248349535, 1) + , (8, 2253431469, 1837736069, 1) + , (8, 3581590838, 3346653714, 0) + , (8, 1351433231, 1149939738, 0) + , (8, 3395186067, 1158888304, 1) + , (8, 3290394050, 1573886483, 1) + , (8, 1296804427, 3587281360, 0) + , (8, 453833330, 1665922652, 1) + , (8, 2475109104, 2911185365, 1) + , (8, 755740888, 1167230839, 1) + , (8, 4192557824, 3532097471, 0) + , (8, 1524723696, 1053814038, 0) + , (8, 1609670288, 426029171, 0) + , (8, 3701505454, 317959263, 1) + , (8, 3954083790, 1972473457, 1) + , (8, 2583541165, 3975072409, 1) + , (8, 563224588, 3812216621, 0) + , (8, 1030500844, 2967456744, 0) + , (8, 2373900222, 2102548527, 1) + , (8, 2992286323, 2682139598, 0) + , (8, 3720596378, 3946355560, 1) + , (8, 1016409648, 1140208456, 1) + , (8, 82580043, 17156065, 0) + , (8, 3818267397, 3081334409, 0) + , (8, 3465194745, 4292146700, 1) + , (8, 3725224097, 3684892669, 0) + , (8, 527877525, 256409499, 0) + , (8, 2592462716, 2990664910, 1) + , (8, 1925553553, 3927762823, 0) + , (8, 1390245551, 2521092483, 0) + , (8, 521880022, 2481597211, 0) + , (8, 1860304388, 598127922, 0) + , (8, 945207741, 1771423344, 1) + , (8, 3417966451, 2785685302, 0) + , (8, 511205855, 4079302086, 0) + , (8, 2289434543, 2323379776, 1) + , (8, 3246274374, 3812191436, 1) + , (8, 2356553023, 2513710439, 1) + , (8, 3338856311, 4079201695, 1) + , (8, 1501407491, 4267822174, 0) + ] + +/-- `Sltu` (code 9): `(code, a, b, AluOp::eval(a, b))` for each pair. -/ +def vectors9 : List (ℕ × ℕ × ℕ × ℕ) := + [ (9, 0, 0, 0) + , (9, 0, 1, 1) + , (9, 0, 2, 1) + , (9, 0, 31, 1) + , (9, 0, 32, 1) + , (9, 0, 2147483647, 1) + , (9, 0, 2147483648, 1) + , (9, 0, 4294967294, 1) + , (9, 0, 4294967295, 1) + , (9, 1, 0, 0) + , (9, 1, 1, 0) + , (9, 1, 2, 1) + , (9, 1, 31, 1) + , (9, 1, 32, 1) + , (9, 1, 2147483647, 1) + , (9, 1, 2147483648, 1) + , (9, 1, 4294967294, 1) + , (9, 1, 4294967295, 1) + , (9, 2, 0, 0) + , (9, 2, 1, 0) + , (9, 2, 2, 0) + , (9, 2, 31, 1) + , (9, 2, 32, 1) + , (9, 2, 2147483647, 1) + , (9, 2, 2147483648, 1) + , (9, 2, 4294967294, 1) + , (9, 2, 4294967295, 1) + , (9, 31, 0, 0) + , (9, 31, 1, 0) + , (9, 31, 2, 0) + , (9, 31, 31, 0) + , (9, 31, 32, 1) + , (9, 31, 2147483647, 1) + , (9, 31, 2147483648, 1) + , (9, 31, 4294967294, 1) + , (9, 31, 4294967295, 1) + , (9, 32, 0, 0) + , (9, 32, 1, 0) + , (9, 32, 2, 0) + , (9, 32, 31, 0) + , (9, 32, 32, 0) + , (9, 32, 2147483647, 1) + , (9, 32, 2147483648, 1) + , (9, 32, 4294967294, 1) + , (9, 32, 4294967295, 1) + , (9, 2147483647, 0, 0) + , (9, 2147483647, 1, 0) + , (9, 2147483647, 2, 0) + , (9, 2147483647, 31, 0) + , (9, 2147483647, 32, 0) + , (9, 2147483647, 2147483647, 0) + , (9, 2147483647, 2147483648, 1) + , (9, 2147483647, 4294967294, 1) + , (9, 2147483647, 4294967295, 1) + , (9, 2147483648, 0, 0) + , (9, 2147483648, 1, 0) + , (9, 2147483648, 2, 0) + , (9, 2147483648, 31, 0) + , (9, 2147483648, 32, 0) + , (9, 2147483648, 2147483647, 0) + , (9, 2147483648, 2147483648, 0) + , (9, 2147483648, 4294967294, 1) + , (9, 2147483648, 4294967295, 1) + , (9, 4294967294, 0, 0) + , (9, 4294967294, 1, 0) + , (9, 4294967294, 2, 0) + , (9, 4294967294, 31, 0) + , (9, 4294967294, 32, 0) + , (9, 4294967294, 2147483647, 0) + , (9, 4294967294, 2147483648, 0) + , (9, 4294967294, 4294967294, 0) + , (9, 4294967294, 4294967295, 1) + , (9, 4294967295, 0, 0) + , (9, 4294967295, 1, 0) + , (9, 4294967295, 2, 0) + , (9, 4294967295, 31, 0) + , (9, 4294967295, 32, 0) + , (9, 4294967295, 2147483647, 0) + , (9, 4294967295, 2147483648, 0) + , (9, 4294967295, 4294967294, 0) + , (9, 4294967295, 4294967295, 0) + , (9, 4222272340, 3018856485, 0) + , (9, 379515872, 178533105, 0) + , (9, 707510791, 2591788913, 1) + , (9, 3933066539, 659350380, 0) + , (9, 2333640804, 3487620568, 1) + , (9, 1765341752, 3405633948, 1) + , (9, 3236348377, 1431584459, 0) + , (9, 2478600280, 3249560273, 1) + , (9, 2460645879, 149137941, 0) + , (9, 3433877109, 1271316163, 0) + , (9, 3723453251, 2182014576, 0) + , (9, 2769503457, 1018057816, 0) + , (9, 3260756530, 4124728163, 1) + , (9, 3438460860, 669438262, 0) + , (9, 1826033185, 1148320962, 0) + , (9, 2095817777, 125410707, 0) + , (9, 164472764, 1173487102, 1) + , (9, 1816836761, 1648241983, 0) + , (9, 1856018840, 343361865, 0) + , (9, 2288712981, 1947234856, 0) + , (9, 3015231039, 969299767, 0) + , (9, 3158443250, 758246939, 0) + , (9, 3150010492, 1684333854, 0) + , (9, 4239251582, 3186512646, 0) + , (9, 2236034112, 1248349535, 0) + , (9, 2253431469, 1837736069, 0) + , (9, 3581590838, 3346653714, 0) + , (9, 1351433231, 1149939738, 0) + , (9, 3395186067, 1158888304, 0) + , (9, 3290394050, 1573886483, 0) + , (9, 1296804427, 3587281360, 1) + , (9, 453833330, 1665922652, 1) + , (9, 2475109104, 2911185365, 1) + , (9, 755740888, 1167230839, 1) + , (9, 4192557824, 3532097471, 0) + , (9, 1524723696, 1053814038, 0) + , (9, 1609670288, 426029171, 0) + , (9, 3701505454, 317959263, 0) + , (9, 3954083790, 1972473457, 0) + , (9, 2583541165, 3975072409, 1) + , (9, 563224588, 3812216621, 1) + , (9, 1030500844, 2967456744, 1) + , (9, 2373900222, 2102548527, 0) + , (9, 2992286323, 2682139598, 0) + , (9, 3720596378, 3946355560, 1) + , (9, 1016409648, 1140208456, 1) + , (9, 82580043, 17156065, 0) + , (9, 3818267397, 3081334409, 0) + , (9, 3465194745, 4292146700, 1) + , (9, 3725224097, 3684892669, 0) + , (9, 527877525, 256409499, 0) + , (9, 2592462716, 2990664910, 1) + , (9, 1925553553, 3927762823, 1) + , (9, 1390245551, 2521092483, 1) + , (9, 521880022, 2481597211, 1) + , (9, 1860304388, 598127922, 0) + , (9, 945207741, 1771423344, 1) + , (9, 3417966451, 2785685302, 0) + , (9, 511205855, 4079302086, 1) + , (9, 2289434543, 2323379776, 1) + , (9, 3246274374, 3812191436, 1) + , (9, 2356553023, 2513710439, 1) + , (9, 3338856311, 4079201695, 1) + , (9, 1501407491, 4267822174, 1) + ] + +/-- `Eq` (code 10): `(code, a, b, AluOp::eval(a, b))` for each pair. -/ +def vectors10 : List (ℕ × ℕ × ℕ × ℕ) := + [ (10, 0, 0, 1) + , (10, 0, 1, 0) + , (10, 0, 2, 0) + , (10, 0, 31, 0) + , (10, 0, 32, 0) + , (10, 0, 2147483647, 0) + , (10, 0, 2147483648, 0) + , (10, 0, 4294967294, 0) + , (10, 0, 4294967295, 0) + , (10, 1, 0, 0) + , (10, 1, 1, 1) + , (10, 1, 2, 0) + , (10, 1, 31, 0) + , (10, 1, 32, 0) + , (10, 1, 2147483647, 0) + , (10, 1, 2147483648, 0) + , (10, 1, 4294967294, 0) + , (10, 1, 4294967295, 0) + , (10, 2, 0, 0) + , (10, 2, 1, 0) + , (10, 2, 2, 1) + , (10, 2, 31, 0) + , (10, 2, 32, 0) + , (10, 2, 2147483647, 0) + , (10, 2, 2147483648, 0) + , (10, 2, 4294967294, 0) + , (10, 2, 4294967295, 0) + , (10, 31, 0, 0) + , (10, 31, 1, 0) + , (10, 31, 2, 0) + , (10, 31, 31, 1) + , (10, 31, 32, 0) + , (10, 31, 2147483647, 0) + , (10, 31, 2147483648, 0) + , (10, 31, 4294967294, 0) + , (10, 31, 4294967295, 0) + , (10, 32, 0, 0) + , (10, 32, 1, 0) + , (10, 32, 2, 0) + , (10, 32, 31, 0) + , (10, 32, 32, 1) + , (10, 32, 2147483647, 0) + , (10, 32, 2147483648, 0) + , (10, 32, 4294967294, 0) + , (10, 32, 4294967295, 0) + , (10, 2147483647, 0, 0) + , (10, 2147483647, 1, 0) + , (10, 2147483647, 2, 0) + , (10, 2147483647, 31, 0) + , (10, 2147483647, 32, 0) + , (10, 2147483647, 2147483647, 1) + , (10, 2147483647, 2147483648, 0) + , (10, 2147483647, 4294967294, 0) + , (10, 2147483647, 4294967295, 0) + , (10, 2147483648, 0, 0) + , (10, 2147483648, 1, 0) + , (10, 2147483648, 2, 0) + , (10, 2147483648, 31, 0) + , (10, 2147483648, 32, 0) + , (10, 2147483648, 2147483647, 0) + , (10, 2147483648, 2147483648, 1) + , (10, 2147483648, 4294967294, 0) + , (10, 2147483648, 4294967295, 0) + , (10, 4294967294, 0, 0) + , (10, 4294967294, 1, 0) + , (10, 4294967294, 2, 0) + , (10, 4294967294, 31, 0) + , (10, 4294967294, 32, 0) + , (10, 4294967294, 2147483647, 0) + , (10, 4294967294, 2147483648, 0) + , (10, 4294967294, 4294967294, 1) + , (10, 4294967294, 4294967295, 0) + , (10, 4294967295, 0, 0) + , (10, 4294967295, 1, 0) + , (10, 4294967295, 2, 0) + , (10, 4294967295, 31, 0) + , (10, 4294967295, 32, 0) + , (10, 4294967295, 2147483647, 0) + , (10, 4294967295, 2147483648, 0) + , (10, 4294967295, 4294967294, 0) + , (10, 4294967295, 4294967295, 1) + , (10, 4222272340, 3018856485, 0) + , (10, 379515872, 178533105, 0) + , (10, 707510791, 2591788913, 0) + , (10, 3933066539, 659350380, 0) + , (10, 2333640804, 3487620568, 0) + , (10, 1765341752, 3405633948, 0) + , (10, 3236348377, 1431584459, 0) + , (10, 2478600280, 3249560273, 0) + , (10, 2460645879, 149137941, 0) + , (10, 3433877109, 1271316163, 0) + , (10, 3723453251, 2182014576, 0) + , (10, 2769503457, 1018057816, 0) + , (10, 3260756530, 4124728163, 0) + , (10, 3438460860, 669438262, 0) + , (10, 1826033185, 1148320962, 0) + , (10, 2095817777, 125410707, 0) + , (10, 164472764, 1173487102, 0) + , (10, 1816836761, 1648241983, 0) + , (10, 1856018840, 343361865, 0) + , (10, 2288712981, 1947234856, 0) + , (10, 3015231039, 969299767, 0) + , (10, 3158443250, 758246939, 0) + , (10, 3150010492, 1684333854, 0) + , (10, 4239251582, 3186512646, 0) + , (10, 2236034112, 1248349535, 0) + , (10, 2253431469, 1837736069, 0) + , (10, 3581590838, 3346653714, 0) + , (10, 1351433231, 1149939738, 0) + , (10, 3395186067, 1158888304, 0) + , (10, 3290394050, 1573886483, 0) + , (10, 1296804427, 3587281360, 0) + , (10, 453833330, 1665922652, 0) + , (10, 2475109104, 2911185365, 0) + , (10, 755740888, 1167230839, 0) + , (10, 4192557824, 3532097471, 0) + , (10, 1524723696, 1053814038, 0) + , (10, 1609670288, 426029171, 0) + , (10, 3701505454, 317959263, 0) + , (10, 3954083790, 1972473457, 0) + , (10, 2583541165, 3975072409, 0) + , (10, 563224588, 3812216621, 0) + , (10, 1030500844, 2967456744, 0) + , (10, 2373900222, 2102548527, 0) + , (10, 2992286323, 2682139598, 0) + , (10, 3720596378, 3946355560, 0) + , (10, 1016409648, 1140208456, 0) + , (10, 82580043, 17156065, 0) + , (10, 3818267397, 3081334409, 0) + , (10, 3465194745, 4292146700, 0) + , (10, 3725224097, 3684892669, 0) + , (10, 527877525, 256409499, 0) + , (10, 2592462716, 2990664910, 0) + , (10, 1925553553, 3927762823, 0) + , (10, 1390245551, 2521092483, 0) + , (10, 521880022, 2481597211, 0) + , (10, 1860304388, 598127922, 0) + , (10, 945207741, 1771423344, 0) + , (10, 3417966451, 2785685302, 0) + , (10, 511205855, 4079302086, 0) + , (10, 2289434543, 2323379776, 0) + , (10, 3246274374, 3812191436, 0) + , (10, 2356553023, 2513710439, 0) + , (10, 3338856311, 4079201695, 0) + , (10, 1501407491, 4267822174, 0) + ] + +/-- `Mul` (code 11): `(code, a, b, AluOp::eval(a, b))` for each pair. -/ +def vectors11 : List (ℕ × ℕ × ℕ × ℕ) := + [ (11, 0, 0, 0) + , (11, 0, 1, 0) + , (11, 0, 2, 0) + , (11, 0, 31, 0) + , (11, 0, 32, 0) + , (11, 0, 2147483647, 0) + , (11, 0, 2147483648, 0) + , (11, 0, 4294967294, 0) + , (11, 0, 4294967295, 0) + , (11, 1, 0, 0) + , (11, 1, 1, 1) + , (11, 1, 2, 2) + , (11, 1, 31, 31) + , (11, 1, 32, 32) + , (11, 1, 2147483647, 2147483647) + , (11, 1, 2147483648, 2147483648) + , (11, 1, 4294967294, 4294967294) + , (11, 1, 4294967295, 4294967295) + , (11, 2, 0, 0) + , (11, 2, 1, 2) + , (11, 2, 2, 4) + , (11, 2, 31, 62) + , (11, 2, 32, 64) + , (11, 2, 2147483647, 4294967294) + , (11, 2, 2147483648, 0) + , (11, 2, 4294967294, 4294967292) + , (11, 2, 4294967295, 4294967294) + , (11, 31, 0, 0) + , (11, 31, 1, 31) + , (11, 31, 2, 62) + , (11, 31, 31, 961) + , (11, 31, 32, 992) + , (11, 31, 2147483647, 2147483617) + , (11, 31, 2147483648, 2147483648) + , (11, 31, 4294967294, 4294967234) + , (11, 31, 4294967295, 4294967265) + , (11, 32, 0, 0) + , (11, 32, 1, 32) + , (11, 32, 2, 64) + , (11, 32, 31, 992) + , (11, 32, 32, 1024) + , (11, 32, 2147483647, 4294967264) + , (11, 32, 2147483648, 0) + , (11, 32, 4294967294, 4294967232) + , (11, 32, 4294967295, 4294967264) + , (11, 2147483647, 0, 0) + , (11, 2147483647, 1, 2147483647) + , (11, 2147483647, 2, 4294967294) + , (11, 2147483647, 31, 2147483617) + , (11, 2147483647, 32, 4294967264) + , (11, 2147483647, 2147483647, 1) + , (11, 2147483647, 2147483648, 2147483648) + , (11, 2147483647, 4294967294, 2) + , (11, 2147483647, 4294967295, 2147483649) + , (11, 2147483648, 0, 0) + , (11, 2147483648, 1, 2147483648) + , (11, 2147483648, 2, 0) + , (11, 2147483648, 31, 2147483648) + , (11, 2147483648, 32, 0) + , (11, 2147483648, 2147483647, 2147483648) + , (11, 2147483648, 2147483648, 0) + , (11, 2147483648, 4294967294, 0) + , (11, 2147483648, 4294967295, 2147483648) + , (11, 4294967294, 0, 0) + , (11, 4294967294, 1, 4294967294) + , (11, 4294967294, 2, 4294967292) + , (11, 4294967294, 31, 4294967234) + , (11, 4294967294, 32, 4294967232) + , (11, 4294967294, 2147483647, 2) + , (11, 4294967294, 2147483648, 0) + , (11, 4294967294, 4294967294, 4) + , (11, 4294967294, 4294967295, 2) + , (11, 4294967295, 0, 0) + , (11, 4294967295, 1, 4294967295) + , (11, 4294967295, 2, 4294967294) + , (11, 4294967295, 31, 4294967265) + , (11, 4294967295, 32, 4294967264) + , (11, 4294967295, 2147483647, 2147483649) + , (11, 4294967295, 2147483648, 2147483648) + , (11, 4294967295, 4294967294, 2) + , (11, 4294967295, 4294967295, 1) + , (11, 4222272340, 3018856485, 1019091748) + , (11, 379515872, 178533105, 1388664288) + , (11, 707510791, 2591788913, 2114948631) + , (11, 3933066539, 659350380, 538906404) + , (11, 2333640804, 3487620568, 3186714720) + , (11, 1765341752, 3405633948, 3827954208) + , (11, 3236348377, 1431584459, 2183283987) + , (11, 2478600280, 3249560273, 1893115864) + , (11, 2460645879, 149137941, 452921155) + , (11, 3433877109, 1271316163, 509221151) + , (11, 3723453251, 2182014576, 2677251920) + , (11, 2769503457, 1018057816, 2653389144) + , (11, 3260756530, 4124728163, 749743958) + , (11, 3438460860, 669438262, 1352986024) + , (11, 1826033185, 1148320962, 762458370) + , (11, 2095817777, 125410707, 824857891) + , (11, 164472764, 1173487102, 2362259592) + , (11, 1816836761, 1648241983, 2352926887) + , (11, 1856018840, 343361865, 2638226520) + , (11, 2288712981, 1947234856, 1253762376) + , (11, 3015231039, 969299767, 3284926601) + , (11, 3158443250, 758246939, 3085009286) + , (11, 3150010492, 1684333854, 4114565768) + , (11, 4239251582, 3186512646, 2489838836) + , (11, 2236034112, 1248349535, 1471720384) + , (11, 2253431469, 1837736069, 3844449249) + , (11, 3581590838, 3346653714, 3325098444) + , (11, 1351433231, 1149939738, 2746771846) + , (11, 3395186067, 1158888304, 226087248) + , (11, 3290394050, 1573886483, 2956581222) + , (11, 1296804427, 3587281360, 388618224) + , (11, 453833330, 1665922652, 1191619832) + , (11, 2475109104, 2911185365, 3825674672) + , (11, 755740888, 1167230839, 769727592) + , (11, 4192557824, 3532097471, 1645995264) + , (11, 1524723696, 1053814038, 655412896) + , (11, 1609670288, 426029171, 919419568) + , (11, 3701505454, 317959263, 1009355666) + , (11, 3954083790, 1972473457, 3909891566) + , (11, 2583541165, 3975072409, 2631013989) + , (11, 563224588, 3812216621, 3578091036) + , (11, 1030500844, 2967456744, 842490336) + , (11, 2373900222, 2102548527, 1968106466) + , (11, 2992286323, 2682139598, 3517190538) + , (11, 3720596378, 3946355560, 2340484240) + , (11, 1016409648, 1140208456, 3024653696) + , (11, 82580043, 17156065, 2083217643) + , (11, 3818267397, 3081334409, 4289848237) + , (11, 3465194745, 4292146700, 904618412) + , (11, 3725224097, 3684892669, 3210987037) + , (11, 527877525, 256409499, 1171688503) + , (11, 2592462716, 2990664910, 2832577992) + , (11, 1925553553, 3927762823, 2638212727) + , (11, 1390245551, 2521092483, 1169463949) + , (11, 521880022, 2481597211, 3951747986) + , (11, 1860304388, 598127922, 3008655560) + , (11, 945207741, 1771423344, 1503293616) + , (11, 3417966451, 2785685302, 4246318914) + , (11, 511205855, 4079302086, 1335483770) + , (11, 2289434543, 2323379776, 2957448640) + , (11, 3246274374, 3812191436, 3497759688) + , (11, 2356553023, 2513710439, 3410038617) + , (11, 3338856311, 4079201695, 729689577) + , (11, 1501407491, 4267822174, 49640218) + ] + +/-- `Mulh` (code 12): `(code, a, b, AluOp::eval(a, b))` for each pair. -/ +def vectors12 : List (ℕ × ℕ × ℕ × ℕ) := + [ (12, 0, 0, 0) + , (12, 0, 1, 0) + , (12, 0, 2, 0) + , (12, 0, 31, 0) + , (12, 0, 32, 0) + , (12, 0, 2147483647, 0) + , (12, 0, 2147483648, 0) + , (12, 0, 4294967294, 0) + , (12, 0, 4294967295, 0) + , (12, 1, 0, 0) + , (12, 1, 1, 0) + , (12, 1, 2, 0) + , (12, 1, 31, 0) + , (12, 1, 32, 0) + , (12, 1, 2147483647, 0) + , (12, 1, 2147483648, 4294967295) + , (12, 1, 4294967294, 4294967295) + , (12, 1, 4294967295, 4294967295) + , (12, 2, 0, 0) + , (12, 2, 1, 0) + , (12, 2, 2, 0) + , (12, 2, 31, 0) + , (12, 2, 32, 0) + , (12, 2, 2147483647, 0) + , (12, 2, 2147483648, 4294967295) + , (12, 2, 4294967294, 4294967295) + , (12, 2, 4294967295, 4294967295) + , (12, 31, 0, 0) + , (12, 31, 1, 0) + , (12, 31, 2, 0) + , (12, 31, 31, 0) + , (12, 31, 32, 0) + , (12, 31, 2147483647, 15) + , (12, 31, 2147483648, 4294967280) + , (12, 31, 4294967294, 4294967295) + , (12, 31, 4294967295, 4294967295) + , (12, 32, 0, 0) + , (12, 32, 1, 0) + , (12, 32, 2, 0) + , (12, 32, 31, 0) + , (12, 32, 32, 0) + , (12, 32, 2147483647, 15) + , (12, 32, 2147483648, 4294967280) + , (12, 32, 4294967294, 4294967295) + , (12, 32, 4294967295, 4294967295) + , (12, 2147483647, 0, 0) + , (12, 2147483647, 1, 0) + , (12, 2147483647, 2, 0) + , (12, 2147483647, 31, 15) + , (12, 2147483647, 32, 15) + , (12, 2147483647, 2147483647, 1073741823) + , (12, 2147483647, 2147483648, 3221225472) + , (12, 2147483647, 4294967294, 4294967295) + , (12, 2147483647, 4294967295, 4294967295) + , (12, 2147483648, 0, 0) + , (12, 2147483648, 1, 4294967295) + , (12, 2147483648, 2, 4294967295) + , (12, 2147483648, 31, 4294967280) + , (12, 2147483648, 32, 4294967280) + , (12, 2147483648, 2147483647, 3221225472) + , (12, 2147483648, 2147483648, 1073741824) + , (12, 2147483648, 4294967294, 1) + , (12, 2147483648, 4294967295, 0) + , (12, 4294967294, 0, 0) + , (12, 4294967294, 1, 4294967295) + , (12, 4294967294, 2, 4294967295) + , (12, 4294967294, 31, 4294967295) + , (12, 4294967294, 32, 4294967295) + , (12, 4294967294, 2147483647, 4294967295) + , (12, 4294967294, 2147483648, 1) + , (12, 4294967294, 4294967294, 0) + , (12, 4294967294, 4294967295, 0) + , (12, 4294967295, 0, 0) + , (12, 4294967295, 1, 4294967295) + , (12, 4294967295, 2, 4294967295) + , (12, 4294967295, 31, 4294967295) + , (12, 4294967295, 32, 4294967295) + , (12, 4294967295, 2147483647, 4294967295) + , (12, 4294967295, 2147483648, 0) + , (12, 4294967295, 4294967294, 0) + , (12, 4294967295, 4294967295, 0) + , (12, 4222272340, 3018856485, 21598958) + , (12, 379515872, 178533105, 15775707) + , (12, 707510791, 2591788913, 4014402392) + , (12, 3933066539, 659350380, 4239409387) + , (12, 2333640804, 3487620568, 368680461) + , (12, 1765341752, 3405633948, 3929428472) + , (12, 3236348377, 1431584459, 3942111898) + , (12, 2478600280, 3249560273, 442108799) + , (12, 2460645879, 149137941, 4231272534) + , (12, 3433877109, 1271316163, 4040083429) + , (12, 3723453251, 2182014576, 281162130) + , (12, 2769503457, 1018057816, 3933378888) + , (12, 3260756530, 4124728163, 40992895) + , (12, 3438460860, 669438262, 4161467285) + , (12, 1826033185, 1148320962, 488216100) + , (12, 2095817777, 125410707, 61196738) + , (12, 164472764, 1173487102, 44937866) + , (12, 1816836761, 1648241983, 697231531) + , (12, 1856018840, 343361865, 148379730) + , (12, 2288712981, 1947234856, 3385379850) + , (12, 3015231039, 969299767, 4006152976) + , (12, 3158443250, 758246939, 4094321791) + , (12, 3150010492, 1684333854, 3845955842) + , (12, 4239251582, 3186512646, 14379234) + , (12, 2236034112, 1248349535, 3696530077) + , (12, 2253431469, 1837736069, 3421432349) + , (12, 3581590838, 3346653714, 157510997) + , (12, 1351433231, 1149939738, 361834367) + , (12, 3395186067, 1158888304, 4052184087) + , (12, 3290394050, 1573886483, 3926842431) + , (12, 1296804427, 3587281360, 4081291570) + , (12, 453833330, 1665922652, 176031893) + , (12, 2475109104, 2911185365, 586334355) + , (12, 755740888, 1167230839, 205385515) + , (12, 4192557824, 3532097471, 18189916) + , (12, 1524723696, 1053814038, 374106512) + , (12, 1609670288, 426029171, 159667455) + , (12, 3701505454, 317959263, 4251032924) + , (12, 3954083790, 1972473457, 4138415773) + , (12, 2583541165, 3975072409, 127469298) + , (12, 563224588, 3812216621, 4231661330) + , (12, 1030500844, 2967456744, 3976454802) + , (12, 2373900222, 2102548527, 3354532487) + , (12, 2992286323, 2682139598, 489177171) + , (12, 3720596378, 3946355560, 46620248) + , (12, 1016409648, 1140208456, 269831827) + , (12, 82580043, 17156065, 329862) + , (12, 3818267397, 3081334409, 134701531) + , (12, 3465194745, 4292146700, 544929) + , (12, 3725224097, 3684892669, 80928641) + , (12, 527877525, 256409499, 31514282) + , (12, 2592462716, 2990664910, 517019253) + , (12, 1925553553, 3927762823, 4130339295) + , (12, 1390245551, 2521092483, 3720778624) + , (12, 521880022, 2481597211, 4074625310) + , (12, 1860304388, 598127922, 259070656) + , (12, 945207741, 1771423344, 389843028) + , (12, 3417966451, 2785685302, 308184321) + , (12, 511205855, 4079302086, 4269297876) + , (12, 2289434543, 2323379776, 920631770) + , (12, 3246274374, 3812191436, 117878342) + , (12, 2356553023, 2513710439, 803920839) + , (12, 3338856311, 4079201695, 48031998) + , (12, 1501407491, 4267822174, 4285478076) + ] + +/-- `Mulhu` (code 13): `(code, a, b, AluOp::eval(a, b))` for each pair. -/ +def vectors13 : List (ℕ × ℕ × ℕ × ℕ) := + [ (13, 0, 0, 0) + , (13, 0, 1, 0) + , (13, 0, 2, 0) + , (13, 0, 31, 0) + , (13, 0, 32, 0) + , (13, 0, 2147483647, 0) + , (13, 0, 2147483648, 0) + , (13, 0, 4294967294, 0) + , (13, 0, 4294967295, 0) + , (13, 1, 0, 0) + , (13, 1, 1, 0) + , (13, 1, 2, 0) + , (13, 1, 31, 0) + , (13, 1, 32, 0) + , (13, 1, 2147483647, 0) + , (13, 1, 2147483648, 0) + , (13, 1, 4294967294, 0) + , (13, 1, 4294967295, 0) + , (13, 2, 0, 0) + , (13, 2, 1, 0) + , (13, 2, 2, 0) + , (13, 2, 31, 0) + , (13, 2, 32, 0) + , (13, 2, 2147483647, 0) + , (13, 2, 2147483648, 1) + , (13, 2, 4294967294, 1) + , (13, 2, 4294967295, 1) + , (13, 31, 0, 0) + , (13, 31, 1, 0) + , (13, 31, 2, 0) + , (13, 31, 31, 0) + , (13, 31, 32, 0) + , (13, 31, 2147483647, 15) + , (13, 31, 2147483648, 15) + , (13, 31, 4294967294, 30) + , (13, 31, 4294967295, 30) + , (13, 32, 0, 0) + , (13, 32, 1, 0) + , (13, 32, 2, 0) + , (13, 32, 31, 0) + , (13, 32, 32, 0) + , (13, 32, 2147483647, 15) + , (13, 32, 2147483648, 16) + , (13, 32, 4294967294, 31) + , (13, 32, 4294967295, 31) + , (13, 2147483647, 0, 0) + , (13, 2147483647, 1, 0) + , (13, 2147483647, 2, 0) + , (13, 2147483647, 31, 15) + , (13, 2147483647, 32, 15) + , (13, 2147483647, 2147483647, 1073741823) + , (13, 2147483647, 2147483648, 1073741823) + , (13, 2147483647, 4294967294, 2147483646) + , (13, 2147483647, 4294967295, 2147483646) + , (13, 2147483648, 0, 0) + , (13, 2147483648, 1, 0) + , (13, 2147483648, 2, 1) + , (13, 2147483648, 31, 15) + , (13, 2147483648, 32, 16) + , (13, 2147483648, 2147483647, 1073741823) + , (13, 2147483648, 2147483648, 1073741824) + , (13, 2147483648, 4294967294, 2147483647) + , (13, 2147483648, 4294967295, 2147483647) + , (13, 4294967294, 0, 0) + , (13, 4294967294, 1, 0) + , (13, 4294967294, 2, 1) + , (13, 4294967294, 31, 30) + , (13, 4294967294, 32, 31) + , (13, 4294967294, 2147483647, 2147483646) + , (13, 4294967294, 2147483648, 2147483647) + , (13, 4294967294, 4294967294, 4294967292) + , (13, 4294967294, 4294967295, 4294967293) + , (13, 4294967295, 0, 0) + , (13, 4294967295, 1, 0) + , (13, 4294967295, 2, 1) + , (13, 4294967295, 31, 30) + , (13, 4294967295, 32, 31) + , (13, 4294967295, 2147483647, 2147483646) + , (13, 4294967295, 2147483648, 2147483647) + , (13, 4294967295, 4294967294, 4294967293) + , (13, 4294967295, 4294967295, 4294967294) + , (13, 4222272340, 3018856485, 2967760487) + , (13, 379515872, 178533105, 15775707) + , (13, 707510791, 2591788913, 426945887) + , (13, 3933066539, 659350380, 603792471) + , (13, 2333640804, 3487620568, 1894974537) + , (13, 1765341752, 3405633948, 1399802928) + , (13, 3236348377, 1431584459, 1078729061) + , (13, 2478600280, 3249560273, 1875302056) + , (13, 2460645879, 149137941, 85443179) + , (13, 3433877109, 1271316163, 1016432296) + , (13, 3723453251, 2182014576, 1891662661) + , (13, 2769503457, 1018057816, 656469408) + , (13, 3260756530, 4124728163, 3131510292) + , (13, 3438460860, 669438262, 535938251) + , (13, 1826033185, 1148320962, 488216100) + , (13, 2095817777, 125410707, 61196738) + , (13, 164472764, 1173487102, 44937866) + , (13, 1816836761, 1648241983, 697231531) + , (13, 1856018840, 343361865, 148379730) + , (13, 2288712981, 1947234856, 1037647410) + , (13, 3015231039, 969299767, 680485447) + , (13, 3158443250, 758246939, 557601434) + , (13, 3150010492, 1684333854, 1235322400) + , (13, 4239251582, 3186512646, 3145176166) + , (13, 2236034112, 1248349535, 649912316) + , (13, 2253431469, 1837736069, 964201122) + , (13, 3581590838, 3346653714, 2790788253) + , (13, 1351433231, 1149939738, 361834367) + , (13, 3395186067, 1158888304, 916105095) + , (13, 3290394050, 1573886483, 1205761618) + , (13, 1296804427, 3587281360, 1083128701) + , (13, 453833330, 1665922652, 176031893) + , (13, 2475109104, 2911185365, 1677661528) + , (13, 755740888, 1167230839, 205385515) + , (13, 4192557824, 3532097471, 3447877915) + , (13, 1524723696, 1053814038, 374106512) + , (13, 1609670288, 426029171, 159667455) + , (13, 3701505454, 317959263, 274024891) + , (13, 3954083790, 1972473457, 1815921934) + , (13, 2583541165, 3975072409, 2391115576) + , (13, 563224588, 3812216621, 499918622) + , (13, 1030500844, 2967456744, 711988350) + , (13, 2373900222, 2102548527, 1162113718) + , (13, 2992286323, 2682139598, 1868635796) + , (13, 3720596378, 3946355560, 3418604890) + , (13, 1016409648, 1140208456, 269831827) + , (13, 82580043, 17156065, 329862) + , (13, 3818267397, 3081334409, 2739336041) + , (13, 3465194745, 4292146700, 3462919078) + , (13, 3725224097, 3684892669, 3196078111) + , (13, 527877525, 256409499, 31514282) + , (13, 2592462716, 2990664910, 1805179583) + , (13, 1925553553, 3927762823, 1760925552) + , (13, 1390245551, 2521092483, 816056879) + , (13, 521880022, 2481597211, 301538036) + , (13, 1860304388, 598127922, 259070656) + , (13, 945207741, 1771423344, 389843028) + , (13, 3417966451, 2785685302, 2216868778) + , (13, 511205855, 4079302086, 485536435) + , (13, 2289434543, 2323379776, 1238478793) + , (13, 3246274374, 3812191436, 2881376856) + , (13, 2356553023, 2513710439, 1379217005) + , (13, 3338856311, 4079201695, 3171122708) + , (13, 1501407491, 4267822174, 1491918271) + ] + +/-- `Mulhsu` (code 14): `(code, a, b, AluOp::eval(a, b))` for each pair. -/ +def vectors14 : List (ℕ × ℕ × ℕ × ℕ) := + [ (14, 0, 0, 0) + , (14, 0, 1, 0) + , (14, 0, 2, 0) + , (14, 0, 31, 0) + , (14, 0, 32, 0) + , (14, 0, 2147483647, 0) + , (14, 0, 2147483648, 0) + , (14, 0, 4294967294, 0) + , (14, 0, 4294967295, 0) + , (14, 1, 0, 0) + , (14, 1, 1, 0) + , (14, 1, 2, 0) + , (14, 1, 31, 0) + , (14, 1, 32, 0) + , (14, 1, 2147483647, 0) + , (14, 1, 2147483648, 0) + , (14, 1, 4294967294, 0) + , (14, 1, 4294967295, 0) + , (14, 2, 0, 0) + , (14, 2, 1, 0) + , (14, 2, 2, 0) + , (14, 2, 31, 0) + , (14, 2, 32, 0) + , (14, 2, 2147483647, 0) + , (14, 2, 2147483648, 1) + , (14, 2, 4294967294, 1) + , (14, 2, 4294967295, 1) + , (14, 31, 0, 0) + , (14, 31, 1, 0) + , (14, 31, 2, 0) + , (14, 31, 31, 0) + , (14, 31, 32, 0) + , (14, 31, 2147483647, 15) + , (14, 31, 2147483648, 15) + , (14, 31, 4294967294, 30) + , (14, 31, 4294967295, 30) + , (14, 32, 0, 0) + , (14, 32, 1, 0) + , (14, 32, 2, 0) + , (14, 32, 31, 0) + , (14, 32, 32, 0) + , (14, 32, 2147483647, 15) + , (14, 32, 2147483648, 16) + , (14, 32, 4294967294, 31) + , (14, 32, 4294967295, 31) + , (14, 2147483647, 0, 0) + , (14, 2147483647, 1, 0) + , (14, 2147483647, 2, 0) + , (14, 2147483647, 31, 15) + , (14, 2147483647, 32, 15) + , (14, 2147483647, 2147483647, 1073741823) + , (14, 2147483647, 2147483648, 1073741823) + , (14, 2147483647, 4294967294, 2147483646) + , (14, 2147483647, 4294967295, 2147483646) + , (14, 2147483648, 0, 0) + , (14, 2147483648, 1, 4294967295) + , (14, 2147483648, 2, 4294967295) + , (14, 2147483648, 31, 4294967280) + , (14, 2147483648, 32, 4294967280) + , (14, 2147483648, 2147483647, 3221225472) + , (14, 2147483648, 2147483648, 3221225472) + , (14, 2147483648, 4294967294, 2147483649) + , (14, 2147483648, 4294967295, 2147483648) + , (14, 4294967294, 0, 0) + , (14, 4294967294, 1, 4294967295) + , (14, 4294967294, 2, 4294967295) + , (14, 4294967294, 31, 4294967295) + , (14, 4294967294, 32, 4294967295) + , (14, 4294967294, 2147483647, 4294967295) + , (14, 4294967294, 2147483648, 4294967295) + , (14, 4294967294, 4294967294, 4294967294) + , (14, 4294967294, 4294967295, 4294967294) + , (14, 4294967295, 0, 0) + , (14, 4294967295, 1, 4294967295) + , (14, 4294967295, 2, 4294967295) + , (14, 4294967295, 31, 4294967295) + , (14, 4294967295, 32, 4294967295) + , (14, 4294967295, 2147483647, 4294967295) + , (14, 4294967295, 2147483648, 4294967295) + , (14, 4294967295, 4294967294, 4294967295) + , (14, 4294967295, 4294967295, 4294967295) + , (14, 4222272340, 3018856485, 4243871298) + , (14, 379515872, 178533105, 15775707) + , (14, 707510791, 2591788913, 426945887) + , (14, 3933066539, 659350380, 4239409387) + , (14, 2333640804, 3487620568, 2702321265) + , (14, 1765341752, 3405633948, 1399802928) + , (14, 3236348377, 1431584459, 3942111898) + , (14, 2478600280, 3249560273, 2920709079) + , (14, 2460645879, 149137941, 4231272534) + , (14, 3433877109, 1271316163, 4040083429) + , (14, 3723453251, 2182014576, 4004615381) + , (14, 2769503457, 1018057816, 3933378888) + , (14, 3260756530, 4124728163, 3301749425) + , (14, 3438460860, 669438262, 4161467285) + , (14, 1826033185, 1148320962, 488216100) + , (14, 2095817777, 125410707, 61196738) + , (14, 164472764, 1173487102, 44937866) + , (14, 1816836761, 1648241983, 697231531) + , (14, 1856018840, 343361865, 148379730) + , (14, 2288712981, 1947234856, 3385379850) + , (14, 3015231039, 969299767, 4006152976) + , (14, 3158443250, 758246939, 4094321791) + , (14, 3150010492, 1684333854, 3845955842) + , (14, 4239251582, 3186512646, 4253630816) + , (14, 2236034112, 1248349535, 3696530077) + , (14, 2253431469, 1837736069, 3421432349) + , (14, 3581590838, 3346653714, 3739101835) + , (14, 1351433231, 1149939738, 361834367) + , (14, 3395186067, 1158888304, 4052184087) + , (14, 3290394050, 1573886483, 3926842431) + , (14, 1296804427, 3587281360, 1083128701) + , (14, 453833330, 1665922652, 176031893) + , (14, 2475109104, 2911185365, 3061443459) + , (14, 755740888, 1167230839, 205385515) + , (14, 4192557824, 3532097471, 4210747740) + , (14, 1524723696, 1053814038, 374106512) + , (14, 1609670288, 426029171, 159667455) + , (14, 3701505454, 317959263, 4251032924) + , (14, 3954083790, 1972473457, 4138415773) + , (14, 2583541165, 3975072409, 2711010463) + , (14, 563224588, 3812216621, 499918622) + , (14, 1030500844, 2967456744, 711988350) + , (14, 2373900222, 2102548527, 3354532487) + , (14, 2992286323, 2682139598, 3481463494) + , (14, 3720596378, 3946355560, 3767216626) + , (14, 1016409648, 1140208456, 269831827) + , (14, 82580043, 17156065, 329862) + , (14, 3818267397, 3081334409, 3952968928) + , (14, 3465194745, 4292146700, 3465739674) + , (14, 3725224097, 3684892669, 3806152738) + , (14, 527877525, 256409499, 31514282) + , (14, 2592462716, 2990664910, 3109481969) + , (14, 1925553553, 3927762823, 1760925552) + , (14, 1390245551, 2521092483, 816056879) + , (14, 521880022, 2481597211, 301538036) + , (14, 1860304388, 598127922, 259070656) + , (14, 945207741, 1771423344, 389843028) + , (14, 3417966451, 2785685302, 3726150772) + , (14, 511205855, 4079302086, 485536435) + , (14, 2289434543, 2323379776, 3210066313) + , (14, 3246274374, 3812191436, 3364152716) + , (14, 2356553023, 2513710439, 3160473862) + , (14, 3338856311, 4079201695, 3386888309) + , (14, 1501407491, 4267822174, 1491918271) + ] + +/-- `Div` (code 15): `(code, a, b, AluOp::eval(a, b))` for each pair. -/ +def vectors15 : List (ℕ × ℕ × ℕ × ℕ) := + [ (15, 0, 0, 4294967295) + , (15, 0, 1, 0) + , (15, 0, 2, 0) + , (15, 0, 31, 0) + , (15, 0, 32, 0) + , (15, 0, 2147483647, 0) + , (15, 0, 2147483648, 0) + , (15, 0, 4294967294, 0) + , (15, 0, 4294967295, 0) + , (15, 1, 0, 4294967295) + , (15, 1, 1, 1) + , (15, 1, 2, 0) + , (15, 1, 31, 0) + , (15, 1, 32, 0) + , (15, 1, 2147483647, 0) + , (15, 1, 2147483648, 0) + , (15, 1, 4294967294, 0) + , (15, 1, 4294967295, 4294967295) + , (15, 2, 0, 4294967295) + , (15, 2, 1, 2) + , (15, 2, 2, 1) + , (15, 2, 31, 0) + , (15, 2, 32, 0) + , (15, 2, 2147483647, 0) + , (15, 2, 2147483648, 0) + , (15, 2, 4294967294, 4294967295) + , (15, 2, 4294967295, 4294967294) + , (15, 31, 0, 4294967295) + , (15, 31, 1, 31) + , (15, 31, 2, 15) + , (15, 31, 31, 1) + , (15, 31, 32, 0) + , (15, 31, 2147483647, 0) + , (15, 31, 2147483648, 0) + , (15, 31, 4294967294, 4294967281) + , (15, 31, 4294967295, 4294967265) + , (15, 32, 0, 4294967295) + , (15, 32, 1, 32) + , (15, 32, 2, 16) + , (15, 32, 31, 1) + , (15, 32, 32, 1) + , (15, 32, 2147483647, 0) + , (15, 32, 2147483648, 0) + , (15, 32, 4294967294, 4294967280) + , (15, 32, 4294967295, 4294967264) + , (15, 2147483647, 0, 4294967295) + , (15, 2147483647, 1, 2147483647) + , (15, 2147483647, 2, 1073741823) + , (15, 2147483647, 31, 69273666) + , (15, 2147483647, 32, 67108863) + , (15, 2147483647, 2147483647, 1) + , (15, 2147483647, 2147483648, 0) + , (15, 2147483647, 4294967294, 3221225473) + , (15, 2147483647, 4294967295, 2147483649) + , (15, 2147483648, 0, 4294967295) + , (15, 2147483648, 1, 2147483648) + , (15, 2147483648, 2, 3221225472) + , (15, 2147483648, 31, 4225693630) + , (15, 2147483648, 32, 4227858432) + , (15, 2147483648, 2147483647, 4294967295) + , (15, 2147483648, 2147483648, 1) + , (15, 2147483648, 4294967294, 1073741824) + , (15, 2147483648, 4294967295, 2147483648) + , (15, 4294967294, 0, 4294967295) + , (15, 4294967294, 1, 4294967294) + , (15, 4294967294, 2, 4294967295) + , (15, 4294967294, 31, 0) + , (15, 4294967294, 32, 0) + , (15, 4294967294, 2147483647, 0) + , (15, 4294967294, 2147483648, 0) + , (15, 4294967294, 4294967294, 1) + , (15, 4294967294, 4294967295, 2) + , (15, 4294967295, 0, 4294967295) + , (15, 4294967295, 1, 4294967295) + , (15, 4294967295, 2, 0) + , (15, 4294967295, 31, 0) + , (15, 4294967295, 32, 0) + , (15, 4294967295, 2147483647, 0) + , (15, 4294967295, 2147483648, 0) + , (15, 4294967295, 4294967294, 0) + , (15, 4294967295, 4294967295, 1) + , (15, 4222272340, 3018856485, 0) + , (15, 379515872, 178533105, 2) + , (15, 707510791, 2591788913, 0) + , (15, 3933066539, 659350380, 0) + , (15, 2333640804, 3487620568, 2) + , (15, 1765341752, 3405633948, 4294967295) + , (15, 3236348377, 1431584459, 0) + , (15, 2478600280, 3249560273, 1) + , (15, 2460645879, 149137941, 4294967284) + , (15, 3433877109, 1271316163, 0) + , (15, 3723453251, 2182014576, 0) + , (15, 2769503457, 1018057816, 4294967295) + , (15, 3260756530, 4124728163, 6) + , (15, 3438460860, 669438262, 4294967295) + , (15, 1826033185, 1148320962, 1) + , (15, 2095817777, 125410707, 16) + , (15, 164472764, 1173487102, 0) + , (15, 1816836761, 1648241983, 1) + , (15, 1856018840, 343361865, 5) + , (15, 2288712981, 1947234856, 4294967295) + , (15, 3015231039, 969299767, 4294967295) + , (15, 3158443250, 758246939, 4294967295) + , (15, 3150010492, 1684333854, 0) + , (15, 4239251582, 3186512646, 0) + , (15, 2236034112, 1248349535, 4294967295) + , (15, 2253431469, 1837736069, 4294967295) + , (15, 3581590838, 3346653714, 0) + , (15, 1351433231, 1149939738, 1) + , (15, 3395186067, 1158888304, 0) + , (15, 3290394050, 1573886483, 0) + , (15, 1296804427, 3587281360, 4294967295) + , (15, 453833330, 1665922652, 0) + , (15, 2475109104, 2911185365, 1) + , (15, 755740888, 1167230839, 0) + , (15, 4192557824, 3532097471, 0) + , (15, 1524723696, 1053814038, 1) + , (15, 1609670288, 426029171, 3) + , (15, 3701505454, 317959263, 4294967295) + , (15, 3954083790, 1972473457, 0) + , (15, 2583541165, 3975072409, 5) + , (15, 563224588, 3812216621, 4294967295) + , (15, 1030500844, 2967456744, 0) + , (15, 2373900222, 2102548527, 0) + , (15, 2992286323, 2682139598, 0) + , (15, 3720596378, 3946355560, 1) + , (15, 1016409648, 1140208456, 0) + , (15, 82580043, 17156065, 4) + , (15, 3818267397, 3081334409, 0) + , (15, 3465194745, 4292146700, 294) + , (15, 3725224097, 3684892669, 0) + , (15, 527877525, 256409499, 2) + , (15, 2592462716, 2990664910, 1) + , (15, 1925553553, 3927762823, 4294967291) + , (15, 1390245551, 2521092483, 0) + , (15, 521880022, 2481597211, 0) + , (15, 1860304388, 598127922, 3) + , (15, 945207741, 1771423344, 0) + , (15, 3417966451, 2785685302, 0) + , (15, 511205855, 4079302086, 4294967294) + , (15, 2289434543, 2323379776, 1) + , (15, 3246274374, 3812191436, 2) + , (15, 2356553023, 2513710439, 1) + , (15, 3338856311, 4079201695, 4) + , (15, 1501407491, 4267822174, 4294967241) + ] + +/-- `Divu` (code 16): `(code, a, b, AluOp::eval(a, b))` for each pair. -/ +def vectors16 : List (ℕ × ℕ × ℕ × ℕ) := + [ (16, 0, 0, 4294967295) + , (16, 0, 1, 0) + , (16, 0, 2, 0) + , (16, 0, 31, 0) + , (16, 0, 32, 0) + , (16, 0, 2147483647, 0) + , (16, 0, 2147483648, 0) + , (16, 0, 4294967294, 0) + , (16, 0, 4294967295, 0) + , (16, 1, 0, 4294967295) + , (16, 1, 1, 1) + , (16, 1, 2, 0) + , (16, 1, 31, 0) + , (16, 1, 32, 0) + , (16, 1, 2147483647, 0) + , (16, 1, 2147483648, 0) + , (16, 1, 4294967294, 0) + , (16, 1, 4294967295, 0) + , (16, 2, 0, 4294967295) + , (16, 2, 1, 2) + , (16, 2, 2, 1) + , (16, 2, 31, 0) + , (16, 2, 32, 0) + , (16, 2, 2147483647, 0) + , (16, 2, 2147483648, 0) + , (16, 2, 4294967294, 0) + , (16, 2, 4294967295, 0) + , (16, 31, 0, 4294967295) + , (16, 31, 1, 31) + , (16, 31, 2, 15) + , (16, 31, 31, 1) + , (16, 31, 32, 0) + , (16, 31, 2147483647, 0) + , (16, 31, 2147483648, 0) + , (16, 31, 4294967294, 0) + , (16, 31, 4294967295, 0) + , (16, 32, 0, 4294967295) + , (16, 32, 1, 32) + , (16, 32, 2, 16) + , (16, 32, 31, 1) + , (16, 32, 32, 1) + , (16, 32, 2147483647, 0) + , (16, 32, 2147483648, 0) + , (16, 32, 4294967294, 0) + , (16, 32, 4294967295, 0) + , (16, 2147483647, 0, 4294967295) + , (16, 2147483647, 1, 2147483647) + , (16, 2147483647, 2, 1073741823) + , (16, 2147483647, 31, 69273666) + , (16, 2147483647, 32, 67108863) + , (16, 2147483647, 2147483647, 1) + , (16, 2147483647, 2147483648, 0) + , (16, 2147483647, 4294967294, 0) + , (16, 2147483647, 4294967295, 0) + , (16, 2147483648, 0, 4294967295) + , (16, 2147483648, 1, 2147483648) + , (16, 2147483648, 2, 1073741824) + , (16, 2147483648, 31, 69273666) + , (16, 2147483648, 32, 67108864) + , (16, 2147483648, 2147483647, 1) + , (16, 2147483648, 2147483648, 1) + , (16, 2147483648, 4294967294, 0) + , (16, 2147483648, 4294967295, 0) + , (16, 4294967294, 0, 4294967295) + , (16, 4294967294, 1, 4294967294) + , (16, 4294967294, 2, 2147483647) + , (16, 4294967294, 31, 138547332) + , (16, 4294967294, 32, 134217727) + , (16, 4294967294, 2147483647, 2) + , (16, 4294967294, 2147483648, 1) + , (16, 4294967294, 4294967294, 1) + , (16, 4294967294, 4294967295, 0) + , (16, 4294967295, 0, 4294967295) + , (16, 4294967295, 1, 4294967295) + , (16, 4294967295, 2, 2147483647) + , (16, 4294967295, 31, 138547332) + , (16, 4294967295, 32, 134217727) + , (16, 4294967295, 2147483647, 2) + , (16, 4294967295, 2147483648, 1) + , (16, 4294967295, 4294967294, 1) + , (16, 4294967295, 4294967295, 1) + , (16, 4222272340, 3018856485, 1) + , (16, 379515872, 178533105, 2) + , (16, 707510791, 2591788913, 0) + , (16, 3933066539, 659350380, 5) + , (16, 2333640804, 3487620568, 0) + , (16, 1765341752, 3405633948, 0) + , (16, 3236348377, 1431584459, 2) + , (16, 2478600280, 3249560273, 0) + , (16, 2460645879, 149137941, 16) + , (16, 3433877109, 1271316163, 2) + , (16, 3723453251, 2182014576, 1) + , (16, 2769503457, 1018057816, 2) + , (16, 3260756530, 4124728163, 0) + , (16, 3438460860, 669438262, 5) + , (16, 1826033185, 1148320962, 1) + , (16, 2095817777, 125410707, 16) + , (16, 164472764, 1173487102, 0) + , (16, 1816836761, 1648241983, 1) + , (16, 1856018840, 343361865, 5) + , (16, 2288712981, 1947234856, 1) + , (16, 3015231039, 969299767, 3) + , (16, 3158443250, 758246939, 4) + , (16, 3150010492, 1684333854, 1) + , (16, 4239251582, 3186512646, 1) + , (16, 2236034112, 1248349535, 1) + , (16, 2253431469, 1837736069, 1) + , (16, 3581590838, 3346653714, 1) + , (16, 1351433231, 1149939738, 1) + , (16, 3395186067, 1158888304, 2) + , (16, 3290394050, 1573886483, 2) + , (16, 1296804427, 3587281360, 0) + , (16, 453833330, 1665922652, 0) + , (16, 2475109104, 2911185365, 0) + , (16, 755740888, 1167230839, 0) + , (16, 4192557824, 3532097471, 1) + , (16, 1524723696, 1053814038, 1) + , (16, 1609670288, 426029171, 3) + , (16, 3701505454, 317959263, 11) + , (16, 3954083790, 1972473457, 2) + , (16, 2583541165, 3975072409, 0) + , (16, 563224588, 3812216621, 0) + , (16, 1030500844, 2967456744, 0) + , (16, 2373900222, 2102548527, 1) + , (16, 2992286323, 2682139598, 1) + , (16, 3720596378, 3946355560, 0) + , (16, 1016409648, 1140208456, 0) + , (16, 82580043, 17156065, 4) + , (16, 3818267397, 3081334409, 1) + , (16, 3465194745, 4292146700, 0) + , (16, 3725224097, 3684892669, 1) + , (16, 527877525, 256409499, 2) + , (16, 2592462716, 2990664910, 0) + , (16, 1925553553, 3927762823, 0) + , (16, 1390245551, 2521092483, 0) + , (16, 521880022, 2481597211, 0) + , (16, 1860304388, 598127922, 3) + , (16, 945207741, 1771423344, 0) + , (16, 3417966451, 2785685302, 1) + , (16, 511205855, 4079302086, 0) + , (16, 2289434543, 2323379776, 0) + , (16, 3246274374, 3812191436, 0) + , (16, 2356553023, 2513710439, 0) + , (16, 3338856311, 4079201695, 0) + , (16, 1501407491, 4267822174, 0) + ] + +/-- `Rem` (code 17): `(code, a, b, AluOp::eval(a, b))` for each pair. -/ +def vectors17 : List (ℕ × ℕ × ℕ × ℕ) := + [ (17, 0, 0, 0) + , (17, 0, 1, 0) + , (17, 0, 2, 0) + , (17, 0, 31, 0) + , (17, 0, 32, 0) + , (17, 0, 2147483647, 0) + , (17, 0, 2147483648, 0) + , (17, 0, 4294967294, 0) + , (17, 0, 4294967295, 0) + , (17, 1, 0, 1) + , (17, 1, 1, 0) + , (17, 1, 2, 1) + , (17, 1, 31, 1) + , (17, 1, 32, 1) + , (17, 1, 2147483647, 1) + , (17, 1, 2147483648, 1) + , (17, 1, 4294967294, 1) + , (17, 1, 4294967295, 0) + , (17, 2, 0, 2) + , (17, 2, 1, 0) + , (17, 2, 2, 0) + , (17, 2, 31, 2) + , (17, 2, 32, 2) + , (17, 2, 2147483647, 2) + , (17, 2, 2147483648, 2) + , (17, 2, 4294967294, 0) + , (17, 2, 4294967295, 0) + , (17, 31, 0, 31) + , (17, 31, 1, 0) + , (17, 31, 2, 1) + , (17, 31, 31, 0) + , (17, 31, 32, 31) + , (17, 31, 2147483647, 31) + , (17, 31, 2147483648, 31) + , (17, 31, 4294967294, 1) + , (17, 31, 4294967295, 0) + , (17, 32, 0, 32) + , (17, 32, 1, 0) + , (17, 32, 2, 0) + , (17, 32, 31, 1) + , (17, 32, 32, 0) + , (17, 32, 2147483647, 32) + , (17, 32, 2147483648, 32) + , (17, 32, 4294967294, 0) + , (17, 32, 4294967295, 0) + , (17, 2147483647, 0, 2147483647) + , (17, 2147483647, 1, 0) + , (17, 2147483647, 2, 1) + , (17, 2147483647, 31, 1) + , (17, 2147483647, 32, 31) + , (17, 2147483647, 2147483647, 0) + , (17, 2147483647, 2147483648, 2147483647) + , (17, 2147483647, 4294967294, 1) + , (17, 2147483647, 4294967295, 0) + , (17, 2147483648, 0, 2147483648) + , (17, 2147483648, 1, 0) + , (17, 2147483648, 2, 0) + , (17, 2147483648, 31, 4294967294) + , (17, 2147483648, 32, 0) + , (17, 2147483648, 2147483647, 4294967295) + , (17, 2147483648, 2147483648, 0) + , (17, 2147483648, 4294967294, 0) + , (17, 2147483648, 4294967295, 0) + , (17, 4294967294, 0, 4294967294) + , (17, 4294967294, 1, 0) + , (17, 4294967294, 2, 0) + , (17, 4294967294, 31, 4294967294) + , (17, 4294967294, 32, 4294967294) + , (17, 4294967294, 2147483647, 4294967294) + , (17, 4294967294, 2147483648, 4294967294) + , (17, 4294967294, 4294967294, 0) + , (17, 4294967294, 4294967295, 0) + , (17, 4294967295, 0, 4294967295) + , (17, 4294967295, 1, 0) + , (17, 4294967295, 2, 4294967295) + , (17, 4294967295, 31, 4294967295) + , (17, 4294967295, 32, 4294967295) + , (17, 4294967295, 2147483647, 4294967295) + , (17, 4294967295, 2147483648, 4294967295) + , (17, 4294967295, 4294967294, 4294967295) + , (17, 4294967295, 4294967295, 0) + , (17, 4222272340, 3018856485, 4222272340) + , (17, 379515872, 178533105, 22449662) + , (17, 707510791, 2591788913, 707510791) + , (17, 3933066539, 659350380, 3933066539) + , (17, 2333640804, 3487620568, 3948334260) + , (17, 1765341752, 3405633948, 876008404) + , (17, 3236348377, 1431584459, 3236348377) + , (17, 2478600280, 3249560273, 3524007303) + , (17, 2460645879, 149137941, 4250301171) + , (17, 3433877109, 1271316163, 3433877109) + , (17, 3723453251, 2182014576, 3723453251) + , (17, 2769503457, 1018057816, 3787561273) + , (17, 3260756530, 4124728163, 4282191328) + , (17, 3438460860, 669438262, 4107899122) + , (17, 1826033185, 1148320962, 677712223) + , (17, 2095817777, 125410707, 89246465) + , (17, 164472764, 1173487102, 164472764) + , (17, 1816836761, 1648241983, 168594778) + , (17, 1856018840, 343361865, 139209515) + , (17, 2288712981, 1947234856, 4235947837) + , (17, 3015231039, 969299767, 3984530806) + , (17, 3158443250, 758246939, 3916690189) + , (17, 3150010492, 1684333854, 3150010492) + , (17, 4239251582, 3186512646, 4239251582) + , (17, 2236034112, 1248349535, 3484383647) + , (17, 2253431469, 1837736069, 4091167538) + , (17, 3581590838, 3346653714, 3581590838) + , (17, 1351433231, 1149939738, 201493493) + , (17, 3395186067, 1158888304, 3395186067) + , (17, 3290394050, 1573886483, 3290394050) + , (17, 1296804427, 3587281360, 589118491) + , (17, 453833330, 1665922652, 453833330) + , (17, 2475109104, 2911185365, 3858891035) + , (17, 755740888, 1167230839, 755740888) + , (17, 4192557824, 3532097471, 4192557824) + , (17, 1524723696, 1053814038, 470909658) + , (17, 1609670288, 426029171, 331582775) + , (17, 3701505454, 317959263, 4019464717) + , (17, 3954083790, 1972473457, 3954083790) + , (17, 2583541165, 3975072409, 4183015600) + , (17, 563224588, 3812216621, 80473913) + , (17, 1030500844, 2967456744, 1030500844) + , (17, 2373900222, 2102548527, 2373900222) + , (17, 2992286323, 2682139598, 2992286323) + , (17, 3720596378, 3946355560, 4069208114) + , (17, 1016409648, 1140208456, 1016409648) + , (17, 82580043, 17156065, 13955783) + , (17, 3818267397, 3081334409, 3818267397) + , (17, 3465194745, 4292146700, 4294449969) + , (17, 3725224097, 3684892669, 3725224097) + , (17, 527877525, 256409499, 15058527) + , (17, 2592462716, 2990664910, 3896765102) + , (17, 1925553553, 3927762823, 89531188) + , (17, 1390245551, 2521092483, 1390245551) + , (17, 521880022, 2481597211, 521880022) + , (17, 1860304388, 598127922, 65920622) + , (17, 945207741, 1771423344, 945207741) + , (17, 3417966451, 2785685302, 3417966451) + , (17, 511205855, 4079302086, 79875435) + , (17, 2289434543, 2323379776, 4261022063) + , (17, 3246274374, 3812191436, 4211826094) + , (17, 2356553023, 2513710439, 4137809880) + , (17, 3338856311, 4079201695, 4201918715) + , (17, 1501407491, 4267822174, 8425781) + ] + +/-- `Remu` (code 18): `(code, a, b, AluOp::eval(a, b))` for each pair. -/ +def vectors18 : List (ℕ × ℕ × ℕ × ℕ) := + [ (18, 0, 0, 0) + , (18, 0, 1, 0) + , (18, 0, 2, 0) + , (18, 0, 31, 0) + , (18, 0, 32, 0) + , (18, 0, 2147483647, 0) + , (18, 0, 2147483648, 0) + , (18, 0, 4294967294, 0) + , (18, 0, 4294967295, 0) + , (18, 1, 0, 1) + , (18, 1, 1, 0) + , (18, 1, 2, 1) + , (18, 1, 31, 1) + , (18, 1, 32, 1) + , (18, 1, 2147483647, 1) + , (18, 1, 2147483648, 1) + , (18, 1, 4294967294, 1) + , (18, 1, 4294967295, 1) + , (18, 2, 0, 2) + , (18, 2, 1, 0) + , (18, 2, 2, 0) + , (18, 2, 31, 2) + , (18, 2, 32, 2) + , (18, 2, 2147483647, 2) + , (18, 2, 2147483648, 2) + , (18, 2, 4294967294, 2) + , (18, 2, 4294967295, 2) + , (18, 31, 0, 31) + , (18, 31, 1, 0) + , (18, 31, 2, 1) + , (18, 31, 31, 0) + , (18, 31, 32, 31) + , (18, 31, 2147483647, 31) + , (18, 31, 2147483648, 31) + , (18, 31, 4294967294, 31) + , (18, 31, 4294967295, 31) + , (18, 32, 0, 32) + , (18, 32, 1, 0) + , (18, 32, 2, 0) + , (18, 32, 31, 1) + , (18, 32, 32, 0) + , (18, 32, 2147483647, 32) + , (18, 32, 2147483648, 32) + , (18, 32, 4294967294, 32) + , (18, 32, 4294967295, 32) + , (18, 2147483647, 0, 2147483647) + , (18, 2147483647, 1, 0) + , (18, 2147483647, 2, 1) + , (18, 2147483647, 31, 1) + , (18, 2147483647, 32, 31) + , (18, 2147483647, 2147483647, 0) + , (18, 2147483647, 2147483648, 2147483647) + , (18, 2147483647, 4294967294, 2147483647) + , (18, 2147483647, 4294967295, 2147483647) + , (18, 2147483648, 0, 2147483648) + , (18, 2147483648, 1, 0) + , (18, 2147483648, 2, 0) + , (18, 2147483648, 31, 2) + , (18, 2147483648, 32, 0) + , (18, 2147483648, 2147483647, 1) + , (18, 2147483648, 2147483648, 0) + , (18, 2147483648, 4294967294, 2147483648) + , (18, 2147483648, 4294967295, 2147483648) + , (18, 4294967294, 0, 4294967294) + , (18, 4294967294, 1, 0) + , (18, 4294967294, 2, 0) + , (18, 4294967294, 31, 2) + , (18, 4294967294, 32, 30) + , (18, 4294967294, 2147483647, 0) + , (18, 4294967294, 2147483648, 2147483646) + , (18, 4294967294, 4294967294, 0) + , (18, 4294967294, 4294967295, 4294967294) + , (18, 4294967295, 0, 4294967295) + , (18, 4294967295, 1, 0) + , (18, 4294967295, 2, 1) + , (18, 4294967295, 31, 3) + , (18, 4294967295, 32, 31) + , (18, 4294967295, 2147483647, 1) + , (18, 4294967295, 2147483648, 2147483647) + , (18, 4294967295, 4294967294, 1) + , (18, 4294967295, 4294967295, 0) + , (18, 4222272340, 3018856485, 1203415855) + , (18, 379515872, 178533105, 22449662) + , (18, 707510791, 2591788913, 707510791) + , (18, 3933066539, 659350380, 636314639) + , (18, 2333640804, 3487620568, 2333640804) + , (18, 1765341752, 3405633948, 1765341752) + , (18, 3236348377, 1431584459, 373179459) + , (18, 2478600280, 3249560273, 2478600280) + , (18, 2460645879, 149137941, 74438823) + , (18, 3433877109, 1271316163, 891244783) + , (18, 3723453251, 2182014576, 1541438675) + , (18, 2769503457, 1018057816, 733387825) + , (18, 3260756530, 4124728163, 3260756530) + , (18, 3438460860, 669438262, 91269550) + , (18, 1826033185, 1148320962, 677712223) + , (18, 2095817777, 125410707, 89246465) + , (18, 164472764, 1173487102, 164472764) + , (18, 1816836761, 1648241983, 168594778) + , (18, 1856018840, 343361865, 139209515) + , (18, 2288712981, 1947234856, 341478125) + , (18, 3015231039, 969299767, 107331738) + , (18, 3158443250, 758246939, 125455494) + , (18, 3150010492, 1684333854, 1465676638) + , (18, 4239251582, 3186512646, 1052738936) + , (18, 2236034112, 1248349535, 987684577) + , (18, 2253431469, 1837736069, 415695400) + , (18, 3581590838, 3346653714, 234937124) + , (18, 1351433231, 1149939738, 201493493) + , (18, 3395186067, 1158888304, 1077409459) + , (18, 3290394050, 1573886483, 142621084) + , (18, 1296804427, 3587281360, 1296804427) + , (18, 453833330, 1665922652, 453833330) + , (18, 2475109104, 2911185365, 2475109104) + , (18, 755740888, 1167230839, 755740888) + , (18, 4192557824, 3532097471, 660460353) + , (18, 1524723696, 1053814038, 470909658) + , (18, 1609670288, 426029171, 331582775) + , (18, 3701505454, 317959263, 203953561) + , (18, 3954083790, 1972473457, 9136876) + , (18, 2583541165, 3975072409, 2583541165) + , (18, 563224588, 3812216621, 563224588) + , (18, 1030500844, 2967456744, 1030500844) + , (18, 2373900222, 2102548527, 271351695) + , (18, 2992286323, 2682139598, 310146725) + , (18, 3720596378, 3946355560, 3720596378) + , (18, 1016409648, 1140208456, 1016409648) + , (18, 82580043, 17156065, 13955783) + , (18, 3818267397, 3081334409, 736932988) + , (18, 3465194745, 4292146700, 3465194745) + , (18, 3725224097, 3684892669, 40331428) + , (18, 527877525, 256409499, 15058527) + , (18, 2592462716, 2990664910, 2592462716) + , (18, 1925553553, 3927762823, 1925553553) + , (18, 1390245551, 2521092483, 1390245551) + , (18, 521880022, 2481597211, 521880022) + , (18, 1860304388, 598127922, 65920622) + , (18, 945207741, 1771423344, 945207741) + , (18, 3417966451, 2785685302, 632281149) + , (18, 511205855, 4079302086, 511205855) + , (18, 2289434543, 2323379776, 2289434543) + , (18, 3246274374, 3812191436, 3246274374) + , (18, 2356553023, 2513710439, 2356553023) + , (18, 3338856311, 4079201695, 3338856311) + , (18, 1501407491, 4267822174, 1501407491) + ] + +/-- All vectors, ops in code order. -/ +def aluVectors : List (ℕ × ℕ × ℕ × ℕ) := + vectors0 ++ vectors1 ++ vectors2 ++ vectors3 ++ vectors4 ++ vectors5 ++ vectors6 ++ vectors7 ++ vectors8 ++ vectors9 ++ vectors10 ++ vectors11 ++ vectors12 ++ vectors13 ++ vectors14 ++ vectors15 ++ vectors16 ++ vectors17 ++ vectors18 + +end Rand.Generated.RV32.AluVectors diff --git a/Rand/Generated/RV32/Tables.lean b/Rand/Generated/RV32/Tables.lean new file mode 100644 index 0000000..ed5f1df --- /dev/null +++ b/Rand/Generated/RV32/Tables.lean @@ -0,0 +1,528 @@ +-- GENERATED by exporter from zkp-circuits @b3e21d9ea16225452bcd03a94317cb61e1705979. Do not edit. +import Mathlib.Data.Nat.Notation + +/-! The fixed tables' `preprocessed_trace`s, as canonical values. -/ + +namespace Rand.Generated.RV32.Tables + +/-- `range.rs`: (A, POW2, IS_POW2) for each of the 256 rows. -/ +def range8Rows : List (ℕ × ℕ × ℕ) := + [ (0, 1, 1) + , (1, 2, 1) + , (2, 4, 1) + , (3, 8, 1) + , (4, 16, 1) + , (5, 32, 1) + , (6, 64, 1) + , (7, 128, 1) + , (8, 256, 1) + , (9, 512, 1) + , (10, 1024, 1) + , (11, 2048, 1) + , (12, 4096, 1) + , (13, 8192, 1) + , (14, 16384, 1) + , (15, 32768, 1) + , (16, 65536, 1) + , (17, 131072, 1) + , (18, 262144, 1) + , (19, 524288, 1) + , (20, 1048576, 1) + , (21, 2097152, 1) + , (22, 4194304, 1) + , (23, 8388608, 1) + , (24, 16777216, 1) + , (25, 33554432, 1) + , (26, 67108864, 1) + , (27, 134217728, 1) + , (28, 268435456, 1) + , (29, 536870912, 1) + , (30, 1073741824, 1) + , (31, 2147483648, 1) + , (32, 0, 0) + , (33, 0, 0) + , (34, 0, 0) + , (35, 0, 0) + , (36, 0, 0) + , (37, 0, 0) + , (38, 0, 0) + , (39, 0, 0) + , (40, 0, 0) + , (41, 0, 0) + , (42, 0, 0) + , (43, 0, 0) + , (44, 0, 0) + , (45, 0, 0) + , (46, 0, 0) + , (47, 0, 0) + , (48, 0, 0) + , (49, 0, 0) + , (50, 0, 0) + , (51, 0, 0) + , (52, 0, 0) + , (53, 0, 0) + , (54, 0, 0) + , (55, 0, 0) + , (56, 0, 0) + , (57, 0, 0) + , (58, 0, 0) + , (59, 0, 0) + , (60, 0, 0) + , (61, 0, 0) + , (62, 0, 0) + , (63, 0, 0) + , (64, 0, 0) + , (65, 0, 0) + , (66, 0, 0) + , (67, 0, 0) + , (68, 0, 0) + , (69, 0, 0) + , (70, 0, 0) + , (71, 0, 0) + , (72, 0, 0) + , (73, 0, 0) + , (74, 0, 0) + , (75, 0, 0) + , (76, 0, 0) + , (77, 0, 0) + , (78, 0, 0) + , (79, 0, 0) + , (80, 0, 0) + , (81, 0, 0) + , (82, 0, 0) + , (83, 0, 0) + , (84, 0, 0) + , (85, 0, 0) + , (86, 0, 0) + , (87, 0, 0) + , (88, 0, 0) + , (89, 0, 0) + , (90, 0, 0) + , (91, 0, 0) + , (92, 0, 0) + , (93, 0, 0) + , (94, 0, 0) + , (95, 0, 0) + , (96, 0, 0) + , (97, 0, 0) + , (98, 0, 0) + , (99, 0, 0) + , (100, 0, 0) + , (101, 0, 0) + , (102, 0, 0) + , (103, 0, 0) + , (104, 0, 0) + , (105, 0, 0) + , (106, 0, 0) + , (107, 0, 0) + , (108, 0, 0) + , (109, 0, 0) + , (110, 0, 0) + , (111, 0, 0) + , (112, 0, 0) + , (113, 0, 0) + , (114, 0, 0) + , (115, 0, 0) + , (116, 0, 0) + , (117, 0, 0) + , (118, 0, 0) + , (119, 0, 0) + , (120, 0, 0) + , (121, 0, 0) + , (122, 0, 0) + , (123, 0, 0) + , (124, 0, 0) + , (125, 0, 0) + , (126, 0, 0) + , (127, 0, 0) + , (128, 0, 0) + , (129, 0, 0) + , (130, 0, 0) + , (131, 0, 0) + , (132, 0, 0) + , (133, 0, 0) + , (134, 0, 0) + , (135, 0, 0) + , (136, 0, 0) + , (137, 0, 0) + , (138, 0, 0) + , (139, 0, 0) + , (140, 0, 0) + , (141, 0, 0) + , (142, 0, 0) + , (143, 0, 0) + , (144, 0, 0) + , (145, 0, 0) + , (146, 0, 0) + , (147, 0, 0) + , (148, 0, 0) + , (149, 0, 0) + , (150, 0, 0) + , (151, 0, 0) + , (152, 0, 0) + , (153, 0, 0) + , (154, 0, 0) + , (155, 0, 0) + , (156, 0, 0) + , (157, 0, 0) + , (158, 0, 0) + , (159, 0, 0) + , (160, 0, 0) + , (161, 0, 0) + , (162, 0, 0) + , (163, 0, 0) + , (164, 0, 0) + , (165, 0, 0) + , (166, 0, 0) + , (167, 0, 0) + , (168, 0, 0) + , (169, 0, 0) + , (170, 0, 0) + , (171, 0, 0) + , (172, 0, 0) + , (173, 0, 0) + , (174, 0, 0) + , (175, 0, 0) + , (176, 0, 0) + , (177, 0, 0) + , (178, 0, 0) + , (179, 0, 0) + , (180, 0, 0) + , (181, 0, 0) + , (182, 0, 0) + , (183, 0, 0) + , (184, 0, 0) + , (185, 0, 0) + , (186, 0, 0) + , (187, 0, 0) + , (188, 0, 0) + , (189, 0, 0) + , (190, 0, 0) + , (191, 0, 0) + , (192, 0, 0) + , (193, 0, 0) + , (194, 0, 0) + , (195, 0, 0) + , (196, 0, 0) + , (197, 0, 0) + , (198, 0, 0) + , (199, 0, 0) + , (200, 0, 0) + , (201, 0, 0) + , (202, 0, 0) + , (203, 0, 0) + , (204, 0, 0) + , (205, 0, 0) + , (206, 0, 0) + , (207, 0, 0) + , (208, 0, 0) + , (209, 0, 0) + , (210, 0, 0) + , (211, 0, 0) + , (212, 0, 0) + , (213, 0, 0) + , (214, 0, 0) + , (215, 0, 0) + , (216, 0, 0) + , (217, 0, 0) + , (218, 0, 0) + , (219, 0, 0) + , (220, 0, 0) + , (221, 0, 0) + , (222, 0, 0) + , (223, 0, 0) + , (224, 0, 0) + , (225, 0, 0) + , (226, 0, 0) + , (227, 0, 0) + , (228, 0, 0) + , (229, 0, 0) + , (230, 0, 0) + , (231, 0, 0) + , (232, 0, 0) + , (233, 0, 0) + , (234, 0, 0) + , (235, 0, 0) + , (236, 0, 0) + , (237, 0, 0) + , (238, 0, 0) + , (239, 0, 0) + , (240, 0, 0) + , (241, 0, 0) + , (242, 0, 0) + , (243, 0, 0) + , (244, 0, 0) + , (245, 0, 0) + , (246, 0, 0) + , (247, 0, 0) + , (248, 0, 0) + , (249, 0, 0) + , (250, 0, 0) + , (251, 0, 0) + , (252, 0, 0) + , (253, 0, 0) + , (254, 0, 0) + , (255, 0, 0) + ] + +/-- `nibble.rs`: (a, b, a AND b, a OR b, a XOR b) for each of the 256 rows. -/ +def nibbleRows : List (ℕ × ℕ × ℕ × ℕ × ℕ) := + [ (0, 0, 0, 0, 0) + , (0, 1, 0, 1, 1) + , (0, 2, 0, 2, 2) + , (0, 3, 0, 3, 3) + , (0, 4, 0, 4, 4) + , (0, 5, 0, 5, 5) + , (0, 6, 0, 6, 6) + , (0, 7, 0, 7, 7) + , (0, 8, 0, 8, 8) + , (0, 9, 0, 9, 9) + , (0, 10, 0, 10, 10) + , (0, 11, 0, 11, 11) + , (0, 12, 0, 12, 12) + , (0, 13, 0, 13, 13) + , (0, 14, 0, 14, 14) + , (0, 15, 0, 15, 15) + , (1, 0, 0, 1, 1) + , (1, 1, 1, 1, 0) + , (1, 2, 0, 3, 3) + , (1, 3, 1, 3, 2) + , (1, 4, 0, 5, 5) + , (1, 5, 1, 5, 4) + , (1, 6, 0, 7, 7) + , (1, 7, 1, 7, 6) + , (1, 8, 0, 9, 9) + , (1, 9, 1, 9, 8) + , (1, 10, 0, 11, 11) + , (1, 11, 1, 11, 10) + , (1, 12, 0, 13, 13) + , (1, 13, 1, 13, 12) + , (1, 14, 0, 15, 15) + , (1, 15, 1, 15, 14) + , (2, 0, 0, 2, 2) + , (2, 1, 0, 3, 3) + , (2, 2, 2, 2, 0) + , (2, 3, 2, 3, 1) + , (2, 4, 0, 6, 6) + , (2, 5, 0, 7, 7) + , (2, 6, 2, 6, 4) + , (2, 7, 2, 7, 5) + , (2, 8, 0, 10, 10) + , (2, 9, 0, 11, 11) + , (2, 10, 2, 10, 8) + , (2, 11, 2, 11, 9) + , (2, 12, 0, 14, 14) + , (2, 13, 0, 15, 15) + , (2, 14, 2, 14, 12) + , (2, 15, 2, 15, 13) + , (3, 0, 0, 3, 3) + , (3, 1, 1, 3, 2) + , (3, 2, 2, 3, 1) + , (3, 3, 3, 3, 0) + , (3, 4, 0, 7, 7) + , (3, 5, 1, 7, 6) + , (3, 6, 2, 7, 5) + , (3, 7, 3, 7, 4) + , (3, 8, 0, 11, 11) + , (3, 9, 1, 11, 10) + , (3, 10, 2, 11, 9) + , (3, 11, 3, 11, 8) + , (3, 12, 0, 15, 15) + , (3, 13, 1, 15, 14) + , (3, 14, 2, 15, 13) + , (3, 15, 3, 15, 12) + , (4, 0, 0, 4, 4) + , (4, 1, 0, 5, 5) + , (4, 2, 0, 6, 6) + , (4, 3, 0, 7, 7) + , (4, 4, 4, 4, 0) + , (4, 5, 4, 5, 1) + , (4, 6, 4, 6, 2) + , (4, 7, 4, 7, 3) + , (4, 8, 0, 12, 12) + , (4, 9, 0, 13, 13) + , (4, 10, 0, 14, 14) + , (4, 11, 0, 15, 15) + , (4, 12, 4, 12, 8) + , (4, 13, 4, 13, 9) + , (4, 14, 4, 14, 10) + , (4, 15, 4, 15, 11) + , (5, 0, 0, 5, 5) + , (5, 1, 1, 5, 4) + , (5, 2, 0, 7, 7) + , (5, 3, 1, 7, 6) + , (5, 4, 4, 5, 1) + , (5, 5, 5, 5, 0) + , (5, 6, 4, 7, 3) + , (5, 7, 5, 7, 2) + , (5, 8, 0, 13, 13) + , (5, 9, 1, 13, 12) + , (5, 10, 0, 15, 15) + , (5, 11, 1, 15, 14) + , (5, 12, 4, 13, 9) + , (5, 13, 5, 13, 8) + , (5, 14, 4, 15, 11) + , (5, 15, 5, 15, 10) + , (6, 0, 0, 6, 6) + , (6, 1, 0, 7, 7) + , (6, 2, 2, 6, 4) + , (6, 3, 2, 7, 5) + , (6, 4, 4, 6, 2) + , (6, 5, 4, 7, 3) + , (6, 6, 6, 6, 0) + , (6, 7, 6, 7, 1) + , (6, 8, 0, 14, 14) + , (6, 9, 0, 15, 15) + , (6, 10, 2, 14, 12) + , (6, 11, 2, 15, 13) + , (6, 12, 4, 14, 10) + , (6, 13, 4, 15, 11) + , (6, 14, 6, 14, 8) + , (6, 15, 6, 15, 9) + , (7, 0, 0, 7, 7) + , (7, 1, 1, 7, 6) + , (7, 2, 2, 7, 5) + , (7, 3, 3, 7, 4) + , (7, 4, 4, 7, 3) + , (7, 5, 5, 7, 2) + , (7, 6, 6, 7, 1) + , (7, 7, 7, 7, 0) + , (7, 8, 0, 15, 15) + , (7, 9, 1, 15, 14) + , (7, 10, 2, 15, 13) + , (7, 11, 3, 15, 12) + , (7, 12, 4, 15, 11) + , (7, 13, 5, 15, 10) + , (7, 14, 6, 15, 9) + , (7, 15, 7, 15, 8) + , (8, 0, 0, 8, 8) + , (8, 1, 0, 9, 9) + , (8, 2, 0, 10, 10) + , (8, 3, 0, 11, 11) + , (8, 4, 0, 12, 12) + , (8, 5, 0, 13, 13) + , (8, 6, 0, 14, 14) + , (8, 7, 0, 15, 15) + , (8, 8, 8, 8, 0) + , (8, 9, 8, 9, 1) + , (8, 10, 8, 10, 2) + , (8, 11, 8, 11, 3) + , (8, 12, 8, 12, 4) + , (8, 13, 8, 13, 5) + , (8, 14, 8, 14, 6) + , (8, 15, 8, 15, 7) + , (9, 0, 0, 9, 9) + , (9, 1, 1, 9, 8) + , (9, 2, 0, 11, 11) + , (9, 3, 1, 11, 10) + , (9, 4, 0, 13, 13) + , (9, 5, 1, 13, 12) + , (9, 6, 0, 15, 15) + , (9, 7, 1, 15, 14) + , (9, 8, 8, 9, 1) + , (9, 9, 9, 9, 0) + , (9, 10, 8, 11, 3) + , (9, 11, 9, 11, 2) + , (9, 12, 8, 13, 5) + , (9, 13, 9, 13, 4) + , (9, 14, 8, 15, 7) + , (9, 15, 9, 15, 6) + , (10, 0, 0, 10, 10) + , (10, 1, 0, 11, 11) + , (10, 2, 2, 10, 8) + , (10, 3, 2, 11, 9) + , (10, 4, 0, 14, 14) + , (10, 5, 0, 15, 15) + , (10, 6, 2, 14, 12) + , (10, 7, 2, 15, 13) + , (10, 8, 8, 10, 2) + , (10, 9, 8, 11, 3) + , (10, 10, 10, 10, 0) + , (10, 11, 10, 11, 1) + , (10, 12, 8, 14, 6) + , (10, 13, 8, 15, 7) + , (10, 14, 10, 14, 4) + , (10, 15, 10, 15, 5) + , (11, 0, 0, 11, 11) + , (11, 1, 1, 11, 10) + , (11, 2, 2, 11, 9) + , (11, 3, 3, 11, 8) + , (11, 4, 0, 15, 15) + , (11, 5, 1, 15, 14) + , (11, 6, 2, 15, 13) + , (11, 7, 3, 15, 12) + , (11, 8, 8, 11, 3) + , (11, 9, 9, 11, 2) + , (11, 10, 10, 11, 1) + , (11, 11, 11, 11, 0) + , (11, 12, 8, 15, 7) + , (11, 13, 9, 15, 6) + , (11, 14, 10, 15, 5) + , (11, 15, 11, 15, 4) + , (12, 0, 0, 12, 12) + , (12, 1, 0, 13, 13) + , (12, 2, 0, 14, 14) + , (12, 3, 0, 15, 15) + , (12, 4, 4, 12, 8) + , (12, 5, 4, 13, 9) + , (12, 6, 4, 14, 10) + , (12, 7, 4, 15, 11) + , (12, 8, 8, 12, 4) + , (12, 9, 8, 13, 5) + , (12, 10, 8, 14, 6) + , (12, 11, 8, 15, 7) + , (12, 12, 12, 12, 0) + , (12, 13, 12, 13, 1) + , (12, 14, 12, 14, 2) + , (12, 15, 12, 15, 3) + , (13, 0, 0, 13, 13) + , (13, 1, 1, 13, 12) + , (13, 2, 0, 15, 15) + , (13, 3, 1, 15, 14) + , (13, 4, 4, 13, 9) + , (13, 5, 5, 13, 8) + , (13, 6, 4, 15, 11) + , (13, 7, 5, 15, 10) + , (13, 8, 8, 13, 5) + , (13, 9, 9, 13, 4) + , (13, 10, 8, 15, 7) + , (13, 11, 9, 15, 6) + , (13, 12, 12, 13, 1) + , (13, 13, 13, 13, 0) + , (13, 14, 12, 15, 3) + , (13, 15, 13, 15, 2) + , (14, 0, 0, 14, 14) + , (14, 1, 0, 15, 15) + , (14, 2, 2, 14, 12) + , (14, 3, 2, 15, 13) + , (14, 4, 4, 14, 10) + , (14, 5, 4, 15, 11) + , (14, 6, 6, 14, 8) + , (14, 7, 6, 15, 9) + , (14, 8, 8, 14, 6) + , (14, 9, 8, 15, 7) + , (14, 10, 10, 14, 4) + , (14, 11, 10, 15, 5) + , (14, 12, 12, 14, 2) + , (14, 13, 12, 15, 3) + , (14, 14, 14, 14, 0) + , (14, 15, 14, 15, 1) + , (15, 0, 0, 15, 15) + , (15, 1, 1, 15, 14) + , (15, 2, 2, 15, 13) + , (15, 3, 3, 15, 12) + , (15, 4, 4, 15, 11) + , (15, 5, 5, 15, 10) + , (15, 6, 6, 15, 9) + , (15, 7, 7, 15, 8) + , (15, 8, 8, 15, 7) + , (15, 9, 9, 15, 6) + , (15, 10, 10, 15, 5) + , (15, 11, 11, 15, 4) + , (15, 12, 12, 15, 3) + , (15, 13, 13, 15, 2) + , (15, 14, 14, 15, 1) + , (15, 15, 15, 15, 0) + ] + +end Rand.Generated.RV32.Tables diff --git a/Rand/RV32/Alu/Basic.lean b/Rand/RV32/Alu/Basic.lean new file mode 100644 index 0000000..2a1835f --- /dev/null +++ b/Rand/RV32/Alu/Basic.lean @@ -0,0 +1,552 @@ +import Mathlib.Tactic.LinearCombination +import Mathlib.Tactic.IntervalCases +import Mathlib.Tactic.Linarith +import Mathlib.Algebra.BigOperators.Group.Finset.Basic +import Rand.RV32.Contracts +import Rand.RV32.AluSpec +import Rand.Generated.RV32.Alu + +/-! +# Shared infrastructure for the RV32 ALU soundness proofs + +* Column names of `research/src/tables/alu.rs` (`col`), as reducible `Fin 64` constants that + unfold to exactly the `⟨k, _⟩` literals the generated file uses, so `rw`/`simp`/`ring` see + `m A0` and the generated `m ⟨22, _⟩` as the same atom. +* `AluRowOk`: one row satisfying every generated constraint and every lookup contract. +* Extraction: `cons_at h.cons k as ck` puts the `k`-th generated constraint into context as + ` = 0`; `alu_look h k as lk` puts the `k`-th interaction in as + ` ≠ 0 → `. Both read the expression off the generated `List` literal + (no hand copy), and the proof term is checked against `(constraints m)[k]` by `defeq`, so + a regenerated file is picked up automatically. +* `alu_flags h hf`: from one flag equal to `1`, every flag and `IS_REAL` as concrete hypotheses. +* Field-to-`ℕ` lifting: `nat_eq_of_cast` and the `lift_eq` tactic; every `.val` of a sum or + product goes through an explicit `< p` bound. +* `flags_onehot`, `a_lt`, `b_lt`. +-/ + +namespace Rand.RV32.Alu + +open Rand Rand.Goldilocks Rand.Generated.RV32.Alu + +/-! ## Columns -/ + +-- models: zkp-circuits/research/src/tables/alu.rs:80 @b3e21d9 +abbrev FLAG0 : Fin 64 := ⟨0, by decide⟩ +-- models: zkp-circuits/research/src/tables/alu.rs:81 @b3e21d9 +abbrev A : Fin 64 := ⟨19, by decide⟩ +-- models: zkp-circuits/research/src/tables/alu.rs:81 @b3e21d9 +abbrev B : Fin 64 := ⟨20, by decide⟩ +-- models: zkp-circuits/research/src/tables/alu.rs:81 @b3e21d9 +abbrev C : Fin 64 := ⟨21, by decide⟩ +-- models: zkp-circuits/research/src/tables/alu.rs:82 @b3e21d9 (A0 + i) +abbrev A0 : Fin 64 := ⟨22, by decide⟩ +abbrev A1 : Fin 64 := ⟨23, by decide⟩ +abbrev A2 : Fin 64 := ⟨24, by decide⟩ +abbrev A3 : Fin 64 := ⟨25, by decide⟩ +-- models: zkp-circuits/research/src/tables/alu.rs:82 @b3e21d9 (B0 + i) +abbrev B0 : Fin 64 := ⟨26, by decide⟩ +abbrev B1 : Fin 64 := ⟨27, by decide⟩ +abbrev B2 : Fin 64 := ⟨28, by decide⟩ +abbrev B3 : Fin 64 := ⟨29, by decide⟩ +-- models: zkp-circuits/research/src/tables/alu.rs:82 @b3e21d9 (C0 + i) +abbrev C0 : Fin 64 := ⟨30, by decide⟩ +abbrev C1 : Fin 64 := ⟨31, by decide⟩ +abbrev C2 : Fin 64 := ⟨32, by decide⟩ +abbrev C3 : Fin 64 := ⟨33, by decide⟩ +-- models: zkp-circuits/research/src/tables/alu.rs:87 @b3e21d9 (Q0 + i) +abbrev Q0 : Fin 64 := ⟨34, by decide⟩ +abbrev Q1 : Fin 64 := ⟨35, by decide⟩ +abbrev Q2 : Fin 64 := ⟨36, by decide⟩ +abbrev Q3 : Fin 64 := ⟨37, by decide⟩ +-- models: zkp-circuits/research/src/tables/alu.rs:91 @b3e21d9 (S0 + i) +abbrev S0 : Fin 64 := ⟨38, by decide⟩ +abbrev S1 : Fin 64 := ⟨39, by decide⟩ +abbrev S2 : Fin 64 := ⟨40, by decide⟩ +abbrev S3 : Fin 64 := ⟨41, by decide⟩ +-- models: zkp-circuits/research/src/tables/alu.rs:98 @b3e21d9 (T0 + i) +abbrev T0 : Fin 64 := ⟨42, by decide⟩ +abbrev T1 : Fin 64 := ⟨43, by decide⟩ +abbrev T2 : Fin 64 := ⟨44, by decide⟩ +abbrev T3 : Fin 64 := ⟨45, by decide⟩ +-- models: zkp-circuits/research/src/tables/alu.rs:99 @b3e21d9 +abbrev SA : Fin 64 := ⟨46, by decide⟩ +abbrev SB : Fin 64 := ⟨47, by decide⟩ +abbrev SHH : Fin 64 := ⟨48, by decide⟩ +abbrev PW : Fin 64 := ⟨49, by decide⟩ +-- models: zkp-circuits/research/src/tables/alu.rs:102 @b3e21d9 (CARRY0 + i) +abbrev CARRY0 : Fin 64 := ⟨50, by decide⟩ +abbrev CARRY1 : Fin 64 := ⟨51, by decide⟩ +abbrev CARRY2 : Fin 64 := ⟨52, by decide⟩ +abbrev CARRY3 : Fin 64 := ⟨53, by decide⟩ +-- models: zkp-circuits/research/src/tables/alu.rs:103 @b3e21d9 +abbrev INV : Fin 64 := ⟨54, by decide⟩ +abbrev IS_REAL : Fin 64 := ⟨55, by decide⟩ +abbrev MULT : Fin 64 := ⟨56, by decide⟩ +-- models: zkp-circuits/research/src/tables/alu.rs:106 @b3e21d9 +abbrev AH3 : Fin 64 := ⟨57, by decide⟩ +-- models: zkp-circuits/research/src/tables/alu.rs:109 @b3e21d9 +abbrev BH_N : Fin 64 := ⟨58, by decide⟩ +-- models: zkp-circuits/research/src/tables/alu.rs:113 @b3e21d9 +abbrev QH3 : Fin 64 := ⟨59, by decide⟩ +-- models: zkp-circuits/research/src/tables/alu.rs:115 @b3e21d9 +abbrev DIVZ : Fin 64 := ⟨60, by decide⟩ +-- models: zkp-circuits/research/src/tables/alu.rs:118 @b3e21d9 +abbrev INVB : Fin 64 := ⟨61, by decide⟩ +-- models: zkp-circuits/research/src/tables/alu.rs:122 @b3e21d9 +abbrev DB2 : Fin 64 := ⟨62, by decide⟩ +abbrev DB3 : Fin 64 := ⟨63, by decide⟩ + +theorem AluOp.code_lt (o : AluOp) : o.code < 19 := by cases o <;> decide + +/-- The selector column of an operation: `FLAG0 + o.code`. -/ +-- models: zkp-circuits/research/src/tables/alu.rs:178 @b3e21d9 (`f(op) = v(FLAG0 + op.code())`) +def flag (o : AluOp) : Fin 64 := ⟨o.code, by have := AluOp.code_lt o; omega⟩ + +@[simp] theorem flag_add : flag .add = ⟨0, by decide⟩ := rfl +@[simp] theorem flag_sub : flag .sub = ⟨1, by decide⟩ := rfl +@[simp] theorem flag_and : flag .and = ⟨2, by decide⟩ := rfl +@[simp] theorem flag_or : flag .or = ⟨3, by decide⟩ := rfl +@[simp] theorem flag_xor : flag .xor = ⟨4, by decide⟩ := rfl +@[simp] theorem flag_sll : flag .sll = ⟨5, by decide⟩ := rfl +@[simp] theorem flag_srl : flag .srl = ⟨6, by decide⟩ := rfl +@[simp] theorem flag_sra : flag .sra = ⟨7, by decide⟩ := rfl +@[simp] theorem flag_slt : flag .slt = ⟨8, by decide⟩ := rfl +@[simp] theorem flag_sltu : flag .sltu = ⟨9, by decide⟩ := rfl +@[simp] theorem flag_eq : flag .eq = ⟨10, by decide⟩ := rfl +@[simp] theorem flag_mul : flag .mul = ⟨11, by decide⟩ := rfl +@[simp] theorem flag_mulh : flag .mulh = ⟨12, by decide⟩ := rfl +@[simp] theorem flag_mulhu : flag .mulhu = ⟨13, by decide⟩ := rfl +@[simp] theorem flag_mulhsu : flag .mulhsu = ⟨14, by decide⟩ := rfl +@[simp] theorem flag_div : flag .div = ⟨15, by decide⟩ := rfl +@[simp] theorem flag_divu : flag .divu = ⟨16, by decide⟩ := rfl +@[simp] theorem flag_rem : flag .rem = ⟨17, by decide⟩ := rfl +@[simp] theorem flag_remu : flag .remu = ⟨18, by decide⟩ := rfl + +/-- The opcode field the row provides on the `ALU` bus: `Σ flag(o) · code(o)`. -/ +-- models: zkp-circuits/research/src/tables/alu.rs:433 @b3e21d9 +def aluOpField (m : Fin 64 → F) : F := + (AluOp.all.map fun o => m (flag o) * (o.code : F)).sum + +/-- A little-endian word of four byte limbs, in the generated file's association order. -/ +-- models: zkp-circuits/research/src/tables/alu.rs:201 @b3e21d9 +abbrev word4 (x0 x1 x2 x3 : F) : F := x0 + x1 * 256 + x2 * 65536 + x3 * 16777216 + +/-- `word m base` = limbs `base .. base+3` of row `m` recomposed (`word(base)` in `alu.rs`). -/ +-- models: zkp-circuits/research/src/tables/alu.rs:201 @b3e21d9 +def word (m : Fin 64 → F) (base : ℕ) (hb : base + 3 < 64 := by decide) : F := + word4 (m ⟨base, by omega⟩) (m ⟨base + 1, by omega⟩) (m ⟨base + 2, by omega⟩) + (m ⟨base + 3, by omega⟩) + +/-- `alu_unfold` unfolds the column names to the generated `⟨k, _⟩` literals everywhere. +`omega` compares atoms syntactically, so hypotheses read off the generated file +(`m ⟨22, _⟩`) and statements written with names (`m A0`) must be put in one form first. -/ +macro "alu_unfold" : tactic => `(tactic| try simp only [FLAG0, A, B, C, A0, A1, A2, A3, B0, B1, B2, B3, C0, C1, C2, C3, Q0, Q1, Q2, Q3, S0, S1, S2, S3, T0, T1, T2, T3, SA, SB, SHH, PW, CARRY0, CARRY1, CARRY2, CARRY3, INV, IS_REAL, MULT, AH3, BH_N, QH3, DIVZ, INVB, DB2, DB3] at *) + +/-- `alu_omega`: `omega` after `alu_unfold`. `omega` uses every hypothesis in context and gets +slow on the long carry chains with all their byte bounds; prefer `alu_linarith` for linear +steps there and `omega` only after clearing (`clear * - …`). -/ +macro "alu_omega" : tactic => `(tactic| (alu_unfold; omega)) + +/-- `alu_linarith`: `linarith` after `alu_unfold`. -/ +macro "alu_linarith" : tactic => `(tactic| (alu_unfold; linarith)) + +/-! ## The row hypothesis -/ + +/-- One ALU row accepted by the chip: every generated base constraint vanishes and every +active lookup hits its table (`rv32Contract`). -/ +structure AluRowOk (m : Fin 64 → F) : Prop where + cons : ∀ c ∈ Generated.RV32.Alu.constraints m, c = 0 + look : lookupsHold rv32Contract (Generated.RV32.Alu.interactions m) + +/-! ## Extraction of one constraint / interaction from the generated lists -/ + +theorem cons_nth {L : List F} (h : ∀ c ∈ L, c = 0) (i : ℕ) (hi : i < L.length) : L[i] = 0 := + h _ (List.getElem_mem hi) + +theorem look_nth {c : String → List F → Prop} {L : List Interaction} (h : lookupsHold c L) + (i : ℕ) (hi : i < L.length) (hk : L[i].kind = .lookup) : + L[i].count ≠ 0 → c L[i].bus L[i].tuple := + h _ (List.getElem_mem hi) hk + +open Lean Meta Elab Tactic in +/-- The `i`-th element of a list term that reduces (by unfolding and `let`-zeta) to a literal. -/ +partial def listLitNth (l : Expr) (i : Nat) : MetaM Expr := do + let l ← whnfD l + match l.getAppFnArgs with + | (``List.cons, #[_, hd, tl]) => if i = 0 then return hd else listLitNth tl (i - 1) + | _ => throwError "listLitNth: not a list literal (or index out of range): {l}" + +open Lean Meta Elab Tactic in +/-- The list `L` of a hypothesis `∀ c ∈ L, _` or `lookupsHold _ L`. -/ +def listOfHyp (ty : Expr) : MetaM Expr := do + let ty ← instantiateMVars ty + if ty.isAppOfArity ``lookupsHold 2 then return ty.appArg! + forallTelescopeReducing ty fun xs _ => do + unless xs.size ≥ 2 do throwError "expected `∀ c ∈ L, _`, got {ty}" + let memTy ← inferType xs[1]! + unless memTy.isAppOfArity ``Membership.mem 5 do throwError "expected `∀ c ∈ L, _`, got {ty}" + return memTy.getAppArgs[3]! + +open Lean Meta Elab Tactic in +/-- `cons_at h k as ck`, for `h : ∀ c ∈ L, c = 0` with `L` a generated constraint list: adds +`ck : e = 0`, where `e` is the `k`-th element of `L` read off the generated literal (lets +inlined). The proof is `cons_nth h k _`, checked against `e = 0` by `defeq`. -/ +elab "cons_at " h:term:max k:num " as " n:ident : tactic => withMainContext do + let hE ← elabTerm h none + let L ← listOfHyp (← inferType hE) + let i := k.getNat + let e ← listLitNth L i + let hi ← mkDecideProof (← mkAppM ``LT.lt #[mkNatLit i, ← mkAppM ``List.length #[L]]) + let pf ← mkAppM ``cons_nth #[hE, mkNatLit i, hi] + let some (_, _, rhs) := (← inferType pf).eq? | throwError "cons_at: unexpected type" + let ty ← mkEq e rhs + unless ← isDefEq (← inferType pf) ty do throwError "cons_at: element {i} does not match" + liftMetaTactic fun g => do + let (_, g) ← (← g.assert n.getId ty pf).intro1P + return [g] + +open Lean Meta Elab Tactic in +/-- `look_at h k as lk`, for `h : lookupsHold c L`: adds `lk : count ≠ 0 → c bus tuple` for +the `k`-th interaction of `L` (which must be a lookup). -/ +elab "look_at " h:term:max k:num " as " n:ident : tactic => withMainContext do + let hE ← elabTerm h none + let L ← listOfHyp (← inferType hE) + let i := k.getNat + let e ← whnfD (← listLitNth L i) + unless e.isAppOfArity ``Interaction.mk 4 do throwError "look_at: not an interaction literal {e}" + let args := e.getAppArgs + let (bus, kind, tuple, count) := (args[0]!, args[1]!, args[2]!, args[3]!) + unless kind.isConstOf ``Kind.lookup do throwError "look_at: interaction {i} is not a lookup" + let hi ← mkDecideProof (← mkAppM ``LT.lt #[mkNatLit i, ← mkAppM ``List.length #[L]]) + let hk ← mkEqRefl (mkConst ``Kind.lookup) + let pf ← mkAppOptM ``look_nth #[none, none, hE, mkNatLit i, hi, hk] + let cE := (← instantiateMVars (← inferType hE)).appFn!.appArg! + let ty ← mkArrow (← mkAppM ``Ne #[count, ← mkAppOptM ``OfNat.ofNat + #[← inferType count, mkRawNatLit 0, none]]) (mkAppN cE #[bus, tuple]) + unless ← isDefEq (← inferType pf) ty do throwError "look_at: interaction {i} does not match" + liftMetaTactic fun g => do + let (_, g) ← (← g.assert n.getId ty pf).intro1P + return [g] + +/-- `alu_look h k as lk` for `h : AluRowOk m`: `look_at h.look k as lk` with the RV32 contract +unfolded (e.g. `lk : count ≠ 0 → (m ⟨22, _⟩).val < 256`). -/ +macro "alu_look " h:term:max k:num " as " n:ident : tactic => + `(tactic| (look_at ($h).look $k as $n; simp only [rv32Contract] at $n:ident)) + +/-! ## Field facts -/ + +theorem p_lit : p = 18446744069414584321 := rfl + +theorem val_lt_p (x : F) : x.val < 18446744069414584321 := ZMod.val_lt x + +/-- Injectivity of `ℕ → F` below `p`: the one way equalities leave the field. -/ +theorem nat_eq_of_cast {a b : ℕ} (ha : a < 18446744069414584321) (hb : b < 18446744069414584321) + (h : (a : F) = (b : F)) : a = b := by + rw [← val_natCast_of_lt ha, ← val_natCast_of_lt hb, h] + +/-- `lift_eq c₁ c₂ …` closes a `ℕ` goal `lhs = rhs` (in `.val`s of row cells) whose cast to `F` +follows linearly from the field hypotheses `cᵢ`; the two `< p` side goals go to `omega` +(with the `val_lt_p` bound as a fallback). -/ +syntax "lift_eq" (ppSpace colGt term:max)? : tactic +macro_rules + | `(tactic| lift_eq) => `(tactic| + (refine nat_eq_of_cast (by first | exact val_lt_p _ | alu_linarith) + (by first | exact val_lt_p _ | alu_linarith) ?_ + push_cast [ZMod.natCast_zmod_val] + ring)) + | `(tactic| lift_eq $c) => `(tactic| + (refine nat_eq_of_cast (by first | exact val_lt_p _ | alu_linarith) + (by first | exact val_lt_p _ | alu_linarith) ?_ + push_cast [ZMod.natCast_zmod_val] + first | linear_combination $c:term | linear_combination -$c:term)) + +theorem bool_cases {x : F} (h : x * (x - 1) = 0) : x = 0 ∨ x = 1 := by + rcases mul_eq_zero.1 h with h | h + · exact Or.inl h + · exact Or.inr (sub_eq_zero.1 h) + +instance : Fact (1 < p) := ⟨p_prime.one_lt⟩ + +theorem val_zero' : (0 : F).val = 0 := ZMod.val_zero +theorem val_one' : (1 : F).val = 1 := ZMod.val_one _ + +theorem val_le_one_of_bool {x : F} (h : x * (x - 1) = 0) : x.val ≤ 1 := by + rcases bool_cases h with rfl | rfl + · rw [val_zero']; omega + · rw [val_one'] + +/-- `16⁻¹` in Goldilocks, the constant `INV16` of `alu.rs`. -/ +theorem sixteen_mul_inv16 : (16 : F) * 17293822565076172801 = 1 := by decide + +/-- A byte from two looked-up nibbles: if `lo < 16` and the *derived* high nibble +`(byte - lo) * 16⁻¹` is `< 16`, then `byte < 256` (`bitwise_high_nibble` in `alu.rs`). -/ +-- models: zkp-circuits/research/src/tables/alu.rs:164 @b3e21d9 +theorem byte_lt_of_nibbles {byte lo : F} (hlo : lo.val < 16) + (hhi : ((byte - lo) * 17293822565076172801).val < 16) : + byte.val < 256 ∧ byte.val = lo.val + 16 * ((byte - lo) * 17293822565076172801).val := by + have e : byte.val = lo.val + 16 * ((byte - lo) * 17293822565076172801).val := by + lift_eq ((lo - byte) * sixteen_mul_inv16) + omega + +/-- Word recomposition does not wrap: `(word4 x₀ x₁ x₂ x₃).val = Σ xᵢ.val · 256^i`. -/ +theorem word4_val {x0 x1 x2 x3 : F} (h0 : x0.val < 256) (h1 : x1.val < 256) (h2 : x2.val < 256) + (h3 : x3.val < 256) : + (word4 x0 x1 x2 x3).val = x0.val + x1.val * 256 + x2.val * 65536 + x3.val * 16777216 := by + lift_eq + +theorem word_val (m : Fin 64 → F) (base : ℕ) (hb : base + 3 < 64) + (h : ∀ i : Fin 4, (m ⟨base + i, by omega⟩).val < 256) : + (word m base hb).val = ∑ i : Fin 4, (m ⟨base + i, by omega⟩).val * 256 ^ (i : ℕ) := by + have h0 : (m ⟨base, by omega⟩).val < 256 := h 0 + have h1 : (m ⟨base + 1, by omega⟩).val < 256 := h 1 + have h2 : (m ⟨base + 2, by omega⟩).val < 256 := h 2 + have h3 : (m ⟨base + 3, by omega⟩).val < 256 := h 3 + rw [word, word4_val h0 h1 h2 h3, Fin.sum_univ_four] + simp only [Fin.isValue, Fin.val_zero, Fin.val_one, Fin.val_two, Nat.add_zero, pow_zero, + mul_one, pow_one] + rfl + +/-! ## Flags -/ + +instance : Fintype AluOp := + ⟨⟨AluOp.all, by decide⟩, fun o => by cases o <;> decide⟩ + +theorem sum_univ_eq_all {M : Type*} [AddCommMonoid M] (f : AluOp → M) : + ∑ o, f o = (AluOp.all.map f).sum := rfl + +theorem constraints_length (m : Fin 64 → F) : (constraints m).length = 72 := rfl + +theorem interactions_length (m : Fin 64 → F) : (interactions m).length = 77 := rfl + +variable {m : Fin 64 → F} + +/-- `IS_REAL` is boolean (constraint 0). -/ +-- models: zkp-circuits/research/src/tables/alu.rs:185 @b3e21d9 +theorem real_bool (h : AluRowOk m) : m IS_REAL * (m IS_REAL - 1) = 0 := by + cons_at h.cons 0 as c + exact c + +/-- Every flag is boolean (constraints 2..20). -/ +-- models: zkp-circuits/research/src/tables/alu.rs:197 @b3e21d9 +theorem flag_bool (h : AluRowOk m) (o : AluOp) : m (flag o) * (m (flag o) - 1) = 0 := by + have c := cons_nth h.cons (o.code + 2) + (by rw [constraints_length]; have := AluOp.code_lt o; omega) + cases o <;> exact c + +/-- The flags sum to `IS_REAL` (constraint 21), read in `ℕ`. -/ +-- models: zkp-circuits/research/src/tables/alu.rs:198 @b3e21d9 +theorem flag_sum_cast (h : AluRowOk m) : ((∑ o, (m (flag o)).val : ℕ) : F) = m IS_REAL := by + cons_at h.cons 21 as c + rw [sum_univ_eq_all] + simp only [AluOp.all, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil, Nat.cast_add, + Nat.cast_zero, ZMod.natCast_zmod_val, flag_add, flag_sub, flag_and, flag_or, flag_xor, + flag_sll, flag_srl, flag_sra, flag_slt, flag_sltu, flag_eq, flag_mul, flag_mulh, flag_mulhu, + flag_mulhsu, flag_div, flag_divu, flag_rem, flag_remu] + linear_combination c + +theorem flag_val_le (h : AluRowOk m) (o : AluOp) : (m (flag o)).val ≤ 1 := + val_le_one_of_bool (flag_bool h o) + +theorem flag_sum_le (h : AluRowOk m) : ∑ o, (m (flag o)).val ≤ 19 := by + calc ∑ o, (m (flag o)).val ≤ ∑ _o : AluOp, 1 := Finset.sum_le_sum fun o _ => flag_val_le h o + _ = 19 := rfl + +theorem val_eq_one_iff {x : F} : x.val = 1 ↔ x = 1 := by + constructor + · intro hx; exact ZMod.val_injective _ (hx.trans val_one'.symm) + · rintro rfl; exact val_one' + +/-- One flag set forces a real row and every other flag off. -/ +theorem flag_others (h : AluRowOk m) {o : AluOp} (hf : m (flag o) = 1) : + m IS_REAL = 1 ∧ ∀ o' ≠ o, m (flag o') = 0 := by + have hS := flag_sum_cast h + have hle := flag_sum_le h + have hvo : (m (flag o)).val = 1 := val_eq_one_iff.2 hf + have hge : (m (flag o)).val ≤ ∑ o, (m (flag o)).val := + Finset.single_le_sum (f := fun o => (m (flag o)).val) (fun _ _ => Nat.zero_le _) + (Finset.mem_univ o) + have hreal : m IS_REAL = 1 := by + rcases bool_cases (real_bool h) with h0 | h1 + · exfalso + rw [h0] at hS + have : (∑ o, (m (flag o)).val) = 0 := nat_eq_of_cast (by omega) (by omega) (by rw [Nat.cast_zero]; exact hS) + omega + · exact h1 + refine ⟨hreal, fun o' hne => ?_⟩ + have hS1 : (∑ o, (m (flag o)).val) = 1 := + nat_eq_of_cast (by omega) (by omega) (by rw [hS, hreal, Nat.cast_one]) + have hpair : (m (flag o)).val + (m (flag o')).val ≤ ∑ o, (m (flag o)).val := by + rw [← Finset.sum_pair (f := fun o => (m (flag o)).val) hne.symm] + exact Finset.sum_le_sum_of_subset (Finset.subset_univ _) + have : (m (flag o')).val = 0 := by omega + exact (ZMod.val_eq_zero _).1 this + +/-- Every flag's value, given the one that is set. -/ +theorem flag_val (h : AluRowOk m) {o : AluOp} (hf : m (flag o) = 1) (o' : AluOp) : + m (flag o') = if o' = o then 1 else 0 := by + split_ifs with he + · rw [he]; exact hf + · exact (flag_others h hf).2 o' he + +/-- On a real row exactly one operation flag is set. -/ +theorem flags_onehot (h : AluRowOk m) (hr : m IS_REAL = 1) : + ∃! o : AluOp, m (flag o) = 1 ∧ ∀ o' ≠ o, m (flag o') = 0 := by + have hS := flag_sum_cast h + have hle := flag_sum_le h + have hS1 : (∑ o, (m (flag o)).val) = 1 := + nat_eq_of_cast (by omega) (by omega) (by rw [hS, hr, Nat.cast_one]) + obtain ⟨o, -, ho⟩ := Finset.exists_ne_zero_of_sum_ne_zero (s := Finset.univ) + (f := fun o => (m (flag o)).val) (by omega) + have hf : m (flag o) = 1 := val_eq_one_iff.1 (by have := flag_val_le h o; omega) + refine ⟨o, ⟨hf, (flag_others h hf).2⟩, fun o' ⟨hf', _⟩ => ?_⟩ + by_contra hne + have := (flag_others h hf).2 o' hne + rw [hf'] at this + exact one_ne_zero this + +set_option hygiene false in +/-- `alu_flags h hf` (with `h : AluRowOk m`, `hf : m (flag o) = 1` for a concrete `o`) adds +`hreal : m IS_REAL = 1` and `f0 … f18 : m ⟨k, _⟩ = 1 / 0`, the value of every flag column. -/ +macro "alu_flags " h:term:max hf:term:max : tactic => `(tactic| ( + have hreal := (flag_others $h $hf).1 + have f0 := flag_val $h $hf .add + have f1 := flag_val $h $hf .sub + have f2 := flag_val $h $hf .and + have f3 := flag_val $h $hf .or + have f4 := flag_val $h $hf .xor + have f5 := flag_val $h $hf .sll + have f6 := flag_val $h $hf .srl + have f7 := flag_val $h $hf .sra + have f8 := flag_val $h $hf .slt + have f9 := flag_val $h $hf .sltu + have f10 := flag_val $h $hf .eq + have f11 := flag_val $h $hf .mul + have f12 := flag_val $h $hf .mulh + have f13 := flag_val $h $hf .mulhu + have f14 := flag_val $h $hf .mulhsu + have f15 := flag_val $h $hf .div + have f16 := flag_val $h $hf .divu + have f17 := flag_val $h $hf .rem + have f18 := flag_val $h $hf .remu + simp only [flag_add, flag_sub, flag_and, flag_or, flag_xor, flag_sll, flag_srl, flag_sra, + flag_slt, flag_sltu, flag_eq, flag_mul, flag_mulh, flag_mulhu, flag_mulhsu, flag_div, + flag_divu, flag_rem, flag_remu, reduceCtorEq, ↓reduceIte] at f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18)) + +set_option hygiene false in +/-- `alu_simp at hs` rewrites the flag and `IS_REAL` columns (from `alu_flags`) in `hs`. -/ +macro "alu_simp" l:(Lean.Parser.Tactic.location)? : tactic => `(tactic| + simp only [f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, + hreal] $(l)?) + +/-- `alu_count` closes a lookup-count side goal `count ≠ 0` once `alu_flags` has run. -/ +macro "alu_count" : tactic => `(tactic| (alu_simp; norm_num)) + +/-! ## Arithmetic helpers -/ + +/-- A sum that overflows by `k · 2^32` reduces to its low word. -/ +theorem mod_of_carry {s c k : ℕ} (e : s = c + 2 ^ 32 * k) (hc : c < 2 ^ 32) : s % 2 ^ 32 = c := by + rw [e, Nat.add_mul_mod_self_left, Nat.mod_eq_of_lt hc] + +/-- `ofSigned32` of an integer congruent to a u32 `c` is `c`. -/ +theorem ofSigned32_of_carry {z : ℤ} {c : ℕ} (k : ℤ) (e : z = c + 2 ^ 32 * k) (hc : c < 2 ^ 32) : + ofSigned32 z = c := by + unfold ofSigned32 + rw [e, Int.add_mul_emod_self_left, Int.emod_eq_of_lt (by omega) (by omega)] + simp + +theorem val_eight : (8 : F).val = 8 := rfl + +theorem land_eight {x : ℕ} (hx : x < 16) : x &&& 8 = if 8 ≤ x then 8 else 0 := by + interval_cases x <;> rfl + +/-- Isolated sign-bit extraction (`a3_lo`/`AND4[hi, 8, s·8]` in `alu.rs`): with the dummy +low-nibble lookup `(byte - 16·hi) < 16`, the high-nibble lookup `hi < 16`, `s` boolean and +`(s·8) = hi &&& 8`, the byte is `< 256` and `s` is its top bit. -/ +-- models: zkp-circuits/research/src/tables/alu.rs:271 @b3e21d9 +theorem sign_bit {byte hi s : F} (hlo : (byte - 16 * hi).val < 16) (hhi : hi.val < 16) + (hs : s * (s - 1) = 0) (hand : (s * 8).val = hi.val &&& (8 : F).val) : + byte.val < 256 ∧ (s = 1 ∧ 128 ≤ byte.val ∨ s = 0 ∧ byte.val < 128) := by + have e : byte.val = (byte - 16 * hi).val + 16 * hi.val := by lift_eq + rw [val_eight, land_eight hhi] at hand + rcases bool_cases hs with rfl | rfl + · rw [zero_mul, val_zero'] at hand + have : hi.val < 8 := by split_ifs at hand; omega + exact ⟨by omega, Or.inr ⟨rfl, by omega⟩⟩ + · rw [one_mul, val_eight] at hand + have : 8 ≤ hi.val := by split_ifs at hand; omega + exact ⟨by omega, Or.inl ⟨rfl, by omega⟩⟩ + +/-! ## Operand ranges -/ + +/-- `A0..3` and `B0..3` are bytes on every real row: by RANGE8 when the row is not bitwise +(`g_ab = IS_REAL - and - or - xor ≠ 0`), by the two nibble lookups per limb otherwise. -/ +-- models: zkp-circuits/research/src/tables/alu.rs:230 @b3e21d9 +theorem ab_bytes (h : AluRowOk m) (hr : m IS_REAL = 1) : + (m A0).val < 256 ∧ (m A1).val < 256 ∧ (m A2).val < 256 ∧ (m A3).val < 256 ∧ + (m B0).val < 256 ∧ (m B1).val < 256 ∧ (m B2).val < 256 ∧ (m B3).val < 256 := by + rcases bool_cases (flag_bool h .and) with h2 | h2 + · rcases bool_cases (flag_bool h .or) with h3 | h3 + · rcases bool_cases (flag_bool h .xor) with h4 | h4 + · -- not bitwise: RANGE8, gate `IS_REAL - and - or - xor = 1` + simp only [flag_and, flag_or, flag_xor] at h2 h3 h4 + alu_look h 0 as l0; alu_look h 3 as l3; alu_look h 6 as l6; alu_look h 9 as l9 + alu_look h 1 as l1; alu_look h 4 as l4; alu_look h 7 as l7; alu_look h 10 as l10 + have hg : m IS_REAL - m ⟨2, by decide⟩ - m ⟨3, by decide⟩ - m ⟨4, by decide⟩ ≠ 0 := by + rw [hr, h2, h3, h4]; norm_num + exact ⟨l0 hg, l3 hg, l6 hg, l9 hg, l1 hg, l4 hg, l7 hg, l10 hg⟩ + · alu_flags h h4 + alu_look h 32 as a0; alu_look h 33 as b0; alu_look h 38 as a1; alu_look h 39 as b1 + alu_look h 44 as a2; alu_look h 45 as b2; alu_look h 50 as a3; alu_look h 51 as b3 + have g : m ⟨4, by decide⟩ ≠ 0 := by alu_count + exact ⟨(byte_lt_of_nibbles (a0 g).1 (b0 g).1).1, (byte_lt_of_nibbles (a1 g).1 (b1 g).1).1, + (byte_lt_of_nibbles (a2 g).1 (b2 g).1).1, (byte_lt_of_nibbles (a3 g).1 (b3 g).1).1, + (byte_lt_of_nibbles (a0 g).2.1 (b0 g).2.1).1, (byte_lt_of_nibbles (a1 g).2.1 (b1 g).2.1).1, + (byte_lt_of_nibbles (a2 g).2.1 (b2 g).2.1).1, (byte_lt_of_nibbles (a3 g).2.1 (b3 g).2.1).1⟩ + · alu_flags h h3 + alu_look h 30 as a0; alu_look h 31 as b0; alu_look h 36 as a1; alu_look h 37 as b1 + alu_look h 42 as a2; alu_look h 43 as b2; alu_look h 48 as a3; alu_look h 49 as b3 + have g : m ⟨3, by decide⟩ ≠ 0 := by alu_count + exact ⟨(byte_lt_of_nibbles (a0 g).1 (b0 g).1).1, (byte_lt_of_nibbles (a1 g).1 (b1 g).1).1, + (byte_lt_of_nibbles (a2 g).1 (b2 g).1).1, (byte_lt_of_nibbles (a3 g).1 (b3 g).1).1, + (byte_lt_of_nibbles (a0 g).2.1 (b0 g).2.1).1, (byte_lt_of_nibbles (a1 g).2.1 (b1 g).2.1).1, + (byte_lt_of_nibbles (a2 g).2.1 (b2 g).2.1).1, (byte_lt_of_nibbles (a3 g).2.1 (b3 g).2.1).1⟩ + · alu_flags h h2 + alu_look h 28 as a0; alu_look h 29 as b0; alu_look h 34 as a1; alu_look h 35 as b1 + alu_look h 40 as a2; alu_look h 41 as b2; alu_look h 46 as a3; alu_look h 47 as b3 + have g : m ⟨2, by decide⟩ ≠ 0 := by alu_count + exact ⟨(byte_lt_of_nibbles (a0 g).1 (b0 g).1).1, (byte_lt_of_nibbles (a1 g).1 (b1 g).1).1, + (byte_lt_of_nibbles (a2 g).1 (b2 g).1).1, (byte_lt_of_nibbles (a3 g).1 (b3 g).1).1, + (byte_lt_of_nibbles (a0 g).2.1 (b0 g).2.1).1, (byte_lt_of_nibbles (a1 g).2.1 (b1 g).2.1).1, + (byte_lt_of_nibbles (a2 g).2.1 (b2 g).2.1).1, (byte_lt_of_nibbles (a3 g).2.1 (b3 g).2.1).1⟩ + +/-- `A` recomposed from its limbs (constraint 22), in `ℕ`. -/ +-- models: zkp-circuits/research/src/tables/alu.rs:202 @b3e21d9 +theorem A_val (h : AluRowOk m) (hr : m IS_REAL = 1) : + (m A).val = (m A0).val + (m A1).val * 256 + (m A2).val * 65536 + (m A3).val * 16777216 := by + obtain ⟨h0, h1, h2, h3, -⟩ := ab_bytes h hr + cons_at h.cons 22 as c + lift_eq c + +/-- `B` recomposed from its limbs (constraint 23), in `ℕ`. -/ +-- models: zkp-circuits/research/src/tables/alu.rs:203 @b3e21d9 +theorem B_val (h : AluRowOk m) (hr : m IS_REAL = 1) : + (m B).val = (m B0).val + (m B1).val * 256 + (m B2).val * 65536 + (m B3).val * 16777216 := by + obtain ⟨-, -, -, -, h0, h1, h2, h3⟩ := ab_bytes h hr + cons_at h.cons 23 as c + lift_eq c + +/-- `A` is a u32 on every real row. -/ +-- models: zkp-circuits/research/src/tables/alu.rs:202 @b3e21d9 +theorem a_lt (h : AluRowOk m) (hr : m IS_REAL = 1) : (m A).val < 2 ^ 32 := by + have := A_val h hr + obtain ⟨h0, h1, h2, h3, -⟩ := ab_bytes h hr + omega + +/-- `B` is a u32 on every real row. -/ +-- models: zkp-circuits/research/src/tables/alu.rs:203 @b3e21d9 +theorem b_lt (h : AluRowOk m) (hr : m IS_REAL = 1) : (m B).val < 2 ^ 32 := by + have := B_val h hr + obtain ⟨-, -, -, -, h0, h1, h2, h3⟩ := ab_bytes h hr + omega + +end Rand.RV32.Alu diff --git a/Rand/RV32/AluSpec.lean b/Rand/RV32/AluSpec.lean new file mode 100644 index 0000000..4f9227a --- /dev/null +++ b/Rand/RV32/AluSpec.lean @@ -0,0 +1,129 @@ +import Mathlib.Tactic.Common +import Mathlib.Tactic.NormNum +import Mathlib.Data.Nat.Bitwise +import Mathlib.Data.Int.Bitwise + +/-! +# The RV32 ALU reference function + +`AluOp.eval` is the Lean transcription of `AluOp::eval` in `rand_zkvm::isa`: u32 values are +`ℕ` below `2^32`, signed operations go through the two's-complement helpers `toSigned32` and +`ofSigned32`. Later tasks prove that the ALU chip's constraints compute exactly this function; +`RandTest/AluVectors.lean` checks it against the Rust on exporter-generated vectors. +-/ + +namespace Rand + +/-- Two's-complement reading of a u32. -/ +def toSigned32 (n : ℕ) : ℤ := if n < 2 ^ 31 then (n : ℤ) else (n : ℤ) - 2 ^ 32 + +/-- Wrap an integer into a u32 (`as u32`). -/ +def ofSigned32 (z : ℤ) : ℕ := (z % 2 ^ 32).toNat + +theorem ofSigned32_lt (z : ℤ) : ofSigned32 z < 2 ^ 32 := by + have h0 : 0 ≤ z % 2 ^ 32 := Int.emod_nonneg _ (by norm_num) + have h1 : z % 2 ^ 32 < 2 ^ 32 := Int.emod_lt_of_pos _ (by norm_num) + unfold ofSigned32 + omega + +/-- The 19 ALU operations, in the Rust enum's order. -/ +inductive AluOp + | add | sub | and | or | xor | sll | srl | sra | slt | sltu | eq + | mul | mulh | mulhu | mulhsu | div | divu | rem | remu + deriving DecidableEq, Repr + +namespace AluOp + +/-- All operations in code order (`AluOp::ALL`). -/ +def all : List AluOp := + [add, sub, and, or, xor, sll, srl, sra, slt, sltu, eq, + mul, mulh, mulhu, mulhsu, div, divu, rem, remu] + +/-- The numeric code `0..18` (`AluOp::code`). -/ +def code : AluOp → ℕ + | add => 0 | sub => 1 | and => 2 | or => 3 | xor => 4 | sll => 5 | srl => 6 + | sra => 7 | slt => 8 | sltu => 9 | eq => 10 | mul => 11 | mulh => 12 + | mulhu => 13 | mulhsu => 14 | div => 15 | divu => 16 | rem => 17 | remu => 18 + +/-- Inverse of `code`; `none` outside `0..18` (Rust's `from_code` panics there). -/ +def ofCode? : ℕ → Option AluOp + | 0 => some add | 1 => some sub | 2 => some and | 3 => some or | 4 => some xor + | 5 => some sll | 6 => some srl | 7 => some sra | 8 => some slt | 9 => some sltu + | 10 => some eq | 11 => some mul | 12 => some mulh | 13 => some mulhu + | 14 => some mulhsu | 15 => some div | 16 => some divu | 17 => some rem + | 18 => some remu | _ => none + +/-- Reference semantics on u32 values. `s = b & 31` is the shift amount; division by zero +gives `0xffffffff` (`rem` gives `a`), and `MIN / -1` gives `MIN` (`MIN % -1` gives `0`). -/ +-- models: zkp-circuits/research/src/isa.rs:94 @b3e21d9 +def eval (o : AluOp) (a b : ℕ) : ℕ := + let s := b &&& 31 + match o with + | add => (a + b) % 2 ^ 32 + | sub => ofSigned32 ((a : ℤ) - b) + | and => a &&& b + | or => a ||| b + | xor => a ^^^ b + | sll => (a <<< s) % 2 ^ 32 + | srl => a >>> s + | sra => ofSigned32 (toSigned32 a >>> s) + | slt => if toSigned32 a < toSigned32 b then 1 else 0 + | sltu => if a < b then 1 else 0 + | eq => if a = b then 1 else 0 + | mul => (a * b) % 2 ^ 32 + | mulh => ofSigned32 ((toSigned32 a * toSigned32 b) >>> 32) + | mulhu => (a * b) >>> 32 + | mulhsu => ofSigned32 ((toSigned32 a * (b : ℤ)) >>> 32) + | div => + if b = 0 then 0xffffffff + else if a = 0x80000000 ∧ b = 0xffffffff then 0x80000000 + else ofSigned32 (Int.tdiv (toSigned32 a) (toSigned32 b)) + | divu => if b = 0 then 0xffffffff else a / b + | rem => + if b = 0 then a + else if a = 0x80000000 ∧ b = 0xffffffff then 0 + else ofSigned32 (Int.tmod (toSigned32 a) (toSigned32 b)) + | remu => if b = 0 then a else a % b + +/-- Every operation maps u32 values to a u32 value. -/ +theorem eval_lt (o : AluOp) {a b : ℕ} (ha : a < 2 ^ 32) (hb : b < 2 ^ 32) : + o.eval a b < 2 ^ 32 := by + cases o <;> simp only [eval] + · exact Nat.mod_lt _ (by norm_num) + · exact ofSigned32_lt _ + · exact Nat.and_lt_two_pow _ hb + · exact Nat.or_lt_two_pow ha hb + · exact Nat.xor_lt_two_pow ha hb + · exact Nat.mod_lt _ (by norm_num) + · rw [Nat.shiftRight_eq_div_pow] + exact lt_of_le_of_lt (Nat.div_le_self _ _) ha + · exact ofSigned32_lt _ + · split <;> norm_num + · split <;> norm_num + · split <;> norm_num + · exact Nat.mod_lt _ (by norm_num) + · exact ofSigned32_lt _ + · rw [Nat.shiftRight_eq_div_pow, Nat.div_lt_iff_lt_mul (by norm_num)] + calc a * b < 2 ^ 32 * 2 ^ 32 := Nat.mul_lt_mul'' ha hb + _ = 2 ^ 32 * 2 ^ 32 := rfl + · exact ofSigned32_lt _ + · split + · norm_num + · split + · norm_num + · exact ofSigned32_lt _ + · split + · norm_num + · exact lt_of_le_of_lt (Nat.div_le_self _ _) ha + · split + · exact ha + · split + · norm_num + · exact ofSigned32_lt _ + · split + · exact ha + · exact lt_of_le_of_lt (Nat.mod_le _ _) ha + +end AluOp + +end Rand diff --git a/Rand/RV32/Contracts.lean b/Rand/RV32/Contracts.lean new file mode 100644 index 0000000..3653d31 --- /dev/null +++ b/Rand/RV32/Contracts.lean @@ -0,0 +1,22 @@ +import Rand.Bus + +namespace Rand + +/-- What a successful lookup on each RV32 table bus guarantees. Each clause is the +content of the table's `preprocessed_trace`; bus names equal the +`LookupBus::new("…")` strings in `research/src/tables/mod.rs`. Other buses claim +nothing. -/ +def rv32Contract : String → List F → Prop + -- models: zkp-circuits/research/src/tables/range.rs:52 @b3e21d9 (rows A = 0..255) + | "RANGE8", [x] => x.val < 256 + -- models: zkp-circuits/research/src/tables/nibble.rs:64 @b3e21d9 (a, b < 16; AND = a & b) + | "AND4", [x, y, z] => x.val < 16 ∧ y.val < 16 ∧ z.val = x.val &&& y.val + -- models: zkp-circuits/research/src/tables/nibble.rs:65 @b3e21d9 + | "OR4", [x, y, z] => x.val < 16 ∧ y.val < 16 ∧ z.val = x.val ||| y.val + -- models: zkp-circuits/research/src/tables/nibble.rs:66 @b3e21d9 + | "XOR4", [x, y, z] => x.val < 16 ∧ y.val < 16 ∧ z.val = x.val ^^^ y.val + -- models: zkp-circuits/research/src/tables/range.rs:53 @b3e21d9 (POW2 = 2^A if A < 32 else 0, A < 256) + | "POW2", [s, w] => s.val < 256 ∧ w.val = if s.val < 32 then 2 ^ s.val else 0 + | _, _ => True + +end Rand diff --git a/RandTest.lean b/RandTest.lean new file mode 100644 index 0000000..e8480cb --- /dev/null +++ b/RandTest.lean @@ -0,0 +1,5 @@ +import RandTest.Field +import RandTest.Bus +import RandTest.GeneratedAlu +import RandTest.Contracts +import RandTest.AluVectors diff --git a/RandTest/AluVectors.lean b/RandTest/AluVectors.lean new file mode 100644 index 0000000..ffb071c --- /dev/null +++ b/RandTest/AluVectors.lean @@ -0,0 +1,31 @@ +import Rand.RV32.AluSpec +import Rand.Generated.RV32.AluVectors +import Rand.Generated.RV32.Alu + +/-! Review Focus 3: the Lean `AluOp.eval` agrees with the Rust `AluOp::eval` on every +exporter-generated vector (the 9x9 edge set, which includes division by zero, `MIN / -1`, +shifts by 32 and above, and the `mulhsu` sign cases, plus 64 seeded-random pairs per op). -/ + +open Rand Rand.Generated.RV32.AluVectors + +-- The 'Bool' form: `decide` on a `∀ x ∈ list` Prop can pick an instance enumerating a huge type. +set_option maxRecDepth 100000 +theorem aluVectors_agree : + aluVectors.all (fun (c, a, b, r) => (AluOp.ofCode? c).map (·.eval a b) == some r) = true := by + decide + +-- Not vacuous: every op is exercised, and a corrupted result is refused. +example : AluOp.all.length = 19 ∧ aluVectors.length = 19 * 145 := by decide +example : (aluVectors.filter (·.1 == 18)).length = 145 := by decide +example : ((15, 0x80000000, 0xffffffff, 0) :: aluVectors).all + (fun (c, a, b, r) => (AluOp.ofCode? c).map (·.eval a b) == some r) = false := by decide + +/-- `ofCode?` and `code` are inverse, and out-of-range codes are refused. -/ +example : AluOp.all.all (fun o => AluOp.ofCode? o.code == some o) = true := by decide +example : AluOp.ofCode? 19 = none := by decide + +/-- Bus-rename guard: every `.lookup` interaction of the ALU names a bus that `rv32Contract` +constrains (its fallback is `True`, so a renamed bus would make the lookup vacuous). -/ +example : ((Rand.Generated.RV32.Alu.interactions (fun _ => 0)).all fun i => + i.kind != .lookup || ["RANGE8", "AND4", "OR4", "XOR4", "POW2"].contains i.bus) = true := by + decide diff --git a/RandTest/Bus.lean b/RandTest/Bus.lean new file mode 100644 index 0000000..c96326c --- /dev/null +++ b/RandTest/Bus.lean @@ -0,0 +1,58 @@ +import Rand.Bus +import Rand.RV32.Contracts + +open Rand + +-- A gated-off lookup (count 0) with an out-of-table tuple is not binding. +example : lookupsHold rv32Contract [⟨"RANGE8", .lookup, [300], 0⟩] := by + intro i hi _ hc + simp at hi + subst hi + simp at hc + +-- A live lookup with an out-of-table tuple violates the contract. +example : ¬ lookupsHold rv32Contract [⟨"RANGE8", .lookup, [300], 1⟩] := by + intro h + have := h ⟨"RANGE8", .lookup, [300], 1⟩ (by simp) rfl (by simp) + simp [rv32Contract] at this + have h300 : ((300 : F)).val = 300 := val_natCast_of_lt (n := 300) (by norm_num [Goldilocks.p]) + omega + +-- send/receive are not constrained by lookupsHold. +example : lookupsHold rv32Contract [⟨"RANGE8", .send, [300], 1⟩] := by + intro i hi hk _ + simp at hi + subst hi + cases hk + +example : rv32Contract "POW2" [40, 0] := by + have h : ((40 : F)).val = 40 := val_natCast_of_lt (n := 40) (by norm_num [Goldilocks.p]) + simp [rv32Contract, h] + +example : rv32Contract "POW2" [5, 32] := by + have h : ((5 : F)).val = 5 := val_natCast_of_lt (n := 5) (by norm_num [Goldilocks.p]) + have h2 : ((32 : F)).val = 32 := val_natCast_of_lt (n := 32) (by norm_num [Goldilocks.p]) + simp [rv32Contract, h, h2] + +example : ¬ rv32Contract "POW2" [40, 2^40] := by + have h : ((40 : F)).val = 40 := val_natCast_of_lt (n := 40) (by norm_num [Goldilocks.p]) + have h2 : (((2^40 : ℕ) : F)).val = 2^40 := val_natCast_of_lt (by norm_num [Goldilocks.p]) + have e : ((2 : F)^40) = ((2^40 : ℕ) : F) := by push_cast; rfl + intro hc + have hc2 := hc.2 + rw [e, h2, h] at hc2 + norm_num at hc2 + +example : rv32Contract "AND4" [12, 10, 8] := by + have a : ((12 : F)).val = 12 := val_natCast_of_lt (n := 12) (by norm_num [Goldilocks.p]) + have b : ((10 : F)).val = 10 := val_natCast_of_lt (n := 10) (by norm_num [Goldilocks.p]) + have c : ((8 : F)).val = 8 := val_natCast_of_lt (n := 8) (by norm_num [Goldilocks.p]) + simp [rv32Contract, a, b, c] + +example : ¬ rv32Contract "XOR4" [12, 10, 8] := by + have a : ((12 : F)).val = 12 := val_natCast_of_lt (n := 12) (by norm_num [Goldilocks.p]) + have b : ((10 : F)).val = 10 := val_natCast_of_lt (n := 10) (by norm_num [Goldilocks.p]) + have c : ((8 : F)).val = 8 := val_natCast_of_lt (n := 8) (by norm_num [Goldilocks.p]) + simp [rv32Contract, a, b, c] + +example (t : List F) : rv32Contract "ALU" t := trivial diff --git a/RandTest/Contracts.lean b/RandTest/Contracts.lean new file mode 100644 index 0000000..0c359b0 --- /dev/null +++ b/RandTest/Contracts.lean @@ -0,0 +1,24 @@ +import Rand.Generated.RV32.Tables + +/-! Review Focus 2: the RV32 lookup contracts (`Rand.rv32Contract`) against the generated +contents of the fixed tables' `preprocessed_trace`s. -/ + +open Rand.Generated.RV32.Tables + +-- The 256-row lists nest deeper than the default recursion limit when `decide` unfolds them. +set_option maxRecDepth 8000 + +-- range.rs: rows A = 0..255 in order (the RANGE8 contract `x < 256`). +example : range8Rows.map (·.1) = List.range 256 := by decide + +-- range.rs: POW2 = 2^A for A < 32, else 0 (the POW2 contract), and IS_POW2 = [A < 32]. +example : ∀ r ∈ range8Rows, r.2.1 = if r.1 < 32 then 2 ^ r.1 else 0 := by decide +example : ∀ r ∈ range8Rows, r.2.2 = if r.1 < 32 then 1 else 0 := by decide + +-- nibble.rs: 256 rows, a, b < 16 and AND/OR/XOR columns are the bitwise ops (AND4/OR4/XOR4). +example : nibbleRows.length = 256 := by decide +example : ∀ r ∈ nibbleRows, r.1 < 16 ∧ r.2.1 < 16 ∧ r.2.2.1 = r.1 &&& r.2.1 ∧ + r.2.2.2.1 = r.1 ||| r.2.1 ∧ r.2.2.2.2 = r.1 ^^^ r.2.1 := by decide +-- … and every nibble pair occurs (the contracts claim no pair is missing a row). +example : nibbleRows.map (fun r => (r.1, r.2.1)) = + (List.range 16).flatMap (fun a => (List.range 16).map (fun b => (a, b))) := by decide diff --git a/RandTest/Field.lean b/RandTest/Field.lean new file mode 100644 index 0000000..f3d8143 --- /dev/null +++ b/RandTest/Field.lean @@ -0,0 +1,5 @@ +import Rand.Field + +example : Rand.Goldilocks.p = 2^64 - 2^32 + 1 := by norm_num [Rand.Goldilocks.p] +example : ((2^32 - 1 : ℕ) : Rand.F) * ((2^32 - 1 : ℕ) : Rand.F) = (((2^32-1)*(2^32-1) : ℕ) : Rand.F) := by push_cast; ring +example : ((2^32 - 1 : ℕ) : Rand.F).val = 2^32 - 1 := Rand.val_natCast_of_lt (by norm_num [Rand.Goldilocks.p]) diff --git a/RandTest/GeneratedAlu.lean b/RandTest/GeneratedAlu.lean new file mode 100644 index 0000000..d19724c --- /dev/null +++ b/RandTest/GeneratedAlu.lean @@ -0,0 +1,23 @@ +import Rand.Generated.RV32.Alu +import Rand.Generated.RV32.AluHonest + +open Rand Rand.Generated.RV32.Alu + +example : width = 64 := rfl + +/-- Every row the real Rust trace generator produced (`alu_trace`, through the exporter) +satisfies every exported constraint, evaluated in the kernel. -/ +theorem honestRows_accepted_bool : + (honestRows.all fun r => (constraints r).all (· == 0)) = true := by + decide + +-- The statement in `Prop` form. (`decide` on it directly is hopeless: instance search +-- picks `Fintype.decidableForallFintype` for `∀ c : F` and enumerates all of `ZMod p`.) +example : ∀ r ∈ honestRows, ∀ c ∈ constraints r, c = 0 := by + simpa [List.all_eq_true] using honestRows_accepted_bool + +-- Not vacuous: the first honest row with its output `C` (column 21) bumped by one is refused. +example : + (constraints (fun i => if i = ⟨21, by decide⟩ then honestRows.head! i + 1 + else honestRows.head! i)).all (· == 0) = false := by + decide diff --git a/SOURCES.toml b/SOURCES.toml new file mode 100644 index 0000000..b4a182d --- /dev/null +++ b/SOURCES.toml @@ -0,0 +1,6 @@ +[circuits] +repo = "https://github.com/randprotocol/zkp-circuits" +rev = "b3e21d9ea16225452bcd03a94317cb61e1705979" +[fullnode] +repo = "https://github.com/randprotocol/fullnode" +rev = "246cb5f97624e9f9d70a929941298b78511d5fe8" diff --git a/exporter/Cargo.lock b/exporter/Cargo.lock new file mode 100644 index 0000000..6aaeafa --- /dev/null +++ b/exporter/Cargo.lock @@ -0,0 +1,1034 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aead" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1973cfbc1a2daf9cf550e74e1f088c28e7f7d8c1e1418fb6c9dc5184b7e84c99" +dependencies = [ + "crypto-common", + "inout", +] + +[[package]] +name = "air2lean" +version = "0.1.0" +dependencies = [ + "p3-air", + "p3-field", + "p3-goldilocks", + "p3-lookup", + "p3-matrix", + "rand_zkvm", +] + +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + +[[package]] +name = "atomic-polyfill" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cf2bce30dfe09ef0bfaef228b9d414faaf7e563035494d7fe092dba54b300f4" +dependencies = [ + "critical-section", +] + +[[package]] +name = "autocfg" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" + +[[package]] +name = "base64ct" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" + +[[package]] +name = "block-buffer" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2f6c7dbe95a6ed67ad9f18e57daf93a2f034c524b99fd2b76d18fdfeb6660aa" +dependencies = [ + "hybrid-array", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "chacha20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", + "rand_core", +] + +[[package]] +name = "chacha20poly1305" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b89e1c441e926b9c82a8d023f6e1b7ae0adcfaa7d621814e4d60789bac751cb" +dependencies = [ + "aead", + "chacha20", + "cipher", + "poly1305", +] + +[[package]] +name = "cipher" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8cf2a2c93cd704877c0858356ed03480ff301ee950b43f1cbe4573b088bfa6c" +dependencies = [ + "block-buffer", + "crypto-common", + "inout", +] + +[[package]] +name = "cmov" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a" + +[[package]] +name = "cobs" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa961b519f0b462e3a3b4a34b64d119eeaca1d59af726fe450bbba07a9fc0a1" +dependencies = [ + "thiserror", +] + +[[package]] +name = "const-oid" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" + +[[package]] +name = "cpufeatures" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566" +dependencies = [ + "libc", +] + +[[package]] +name = "critical-section" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" + +[[package]] +name = "crunchy" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" + +[[package]] +name = "crypto-common" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" +dependencies = [ + "getrandom", + "hybrid-array", + "rand_core", +] + +[[package]] +name = "ctutils" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5515a3834141de9eafb9717ad39eea8247b5674e6066c404e8c4b365d2a29e" +dependencies = [ + "cmov", +] + +[[package]] +name = "der" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a878c850e9e421b20262e9b41f9c860e4785fa07541c266b62ff9d1ef998a80a" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "dilithium-core" +version = "0.1.0" + +[[package]] +name = "either" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "252afb9ae5eaa683babdc6a068b3f5726eb19e05070c731f9b2a23a7c3e8ed34" + +[[package]] +name = "embedded-io" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" + +[[package]] +name = "embedded-io" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "evm-core" +version = "0.1.0" + +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "rand_core", +] + +[[package]] +name = "hash32" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" +dependencies = [ + "byteorder", +] + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] + +[[package]] +name = "heapless" +version = "0.7.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f" +dependencies = [ + "atomic-polyfill", + "hash32", + "rustc_version", + "serde", + "spin 0.9.9", + "stable_deref_trait", +] + +[[package]] +name = "hybrid-array" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27f864f10dfb56725ce5ce5472bc52252c8f93a4ab86327122cebf62c5f59a17" +dependencies = [ + "ctutils", + "typenum", +] + +[[package]] +name = "inout" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4250ce6452e92010fdf7268ccc5d14faa80bb12fc741938534c58f16804e03c7" +dependencies = [ + "hybrid-array", +] + +[[package]] +name = "itertools" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b4baf93f58d4425749ca49a51c50ebab072c5df6994d08fed93541c331481dc" +dependencies = [ + "either", +] + +[[package]] +name = "keccak" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8f198d1db720e4940b5a493201d199d9f24f568f8f746bd13706243a2f71598" +dependencies = [ + "cfg-if", + "cpufeatures", +] + +[[package]] +name = "kem" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01737161ba802849cfd486b5bd209d38ba4943494c249a8126005170c7621edd" +dependencies = [ + "crypto-common", + "rand_core", +] + +[[package]] +name = "libc" +version = "0.2.189" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" + +[[package]] +name = "libm" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "ml-kem" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e15f3e5b957493873e396a66914e83e616b6afe335cdef7efe5c6e1216aba66" +dependencies = [ + "hybrid-array", + "kem", + "module-lattice", + "pkcs8", + "rand_core", + "sha3", +] + +[[package]] +name = "module-lattice" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c61b87c9683ab7cb1c6871d261ad5479b6b10ceb52c4352aaca3b5d35a8febe" +dependencies = [ + "ctutils", + "hybrid-array", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93e7820bc0a80a0238e650327316f929ba18d5be054b647490a3a6a339f3e7c0" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ce2d95d4b3734dc35aa2f45e1aa22cd416814592a4f9d9205e11affd5b8e10b" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "p3-air" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1de1da5a48410a5a68356cb0c43e2642b6fab1bb5906d77bd33e3e4c4d2a7785" +dependencies = [ + "p3-field", + "p3-matrix", + "serde", + "tracing", +] + +[[package]] +name = "p3-batch-stark" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d68b4d3ba163ef87fb27a61f1c47be9b9eb05e5320c410f9f8cf09503ae4f95" +dependencies = [ + "hashbrown", + "p3-air", + "p3-challenger", + "p3-commit", + "p3-field", + "p3-lookup", + "p3-matrix", + "p3-maybe-rayon", + "p3-uni-stark", + "p3-util", + "serde", + "thiserror", + "tracing", +] + +[[package]] +name = "p3-challenger" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d33cda6d6dadf1e541121a479589206b83877889d04a3e6a42610c834d348ed2" +dependencies = [ + "p3-field", + "p3-maybe-rayon", + "p3-symmetric", + "p3-util", + "tracing", +] + +[[package]] +name = "p3-commit" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06ff71ad9ca37959a576fe0a6dec2bb53a8d41e06e61707f6e6c301b338f50a" +dependencies = [ + "itertools", + "p3-dft", + "p3-field", + "p3-matrix", + "p3-multilinear-util", + "p3-util", + "serde", +] + +[[package]] +name = "p3-dft" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4344492a3a2981879411ef31b51b12fb364efeda59b9ac855d7d92559e7b46e8" +dependencies = [ + "itertools", + "p3-field", + "p3-matrix", + "p3-maybe-rayon", + "p3-util", + "spin 0.12.3", + "tracing", +] + +[[package]] +name = "p3-field" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f45f7364ae3aac1bd42e8dfec4aa76d1bc9087c4749649c893a671e386e96727" +dependencies = [ + "itertools", + "num-bigint", + "p3-maybe-rayon", + "p3-util", + "paste", + "rand", + "serde", + "tracing", +] + +[[package]] +name = "p3-fri" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52e1cb8b63f02a9e3e441b20c341856d9bce85ae3e3bee6d3ed0da9bea8779d1" +dependencies = [ + "itertools", + "p3-challenger", + "p3-commit", + "p3-dft", + "p3-field", + "p3-matrix", + "p3-maybe-rayon", + "p3-security", + "p3-util", + "rand", + "serde", + "spin 0.12.3", + "thiserror", + "tracing", +] + +[[package]] +name = "p3-goldilocks" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c62b44c110832ba3d3a5c11160f591205e23f81a08ceb8c7be1a3a71fc4c214" +dependencies = [ + "num-bigint", + "p3-dft", + "p3-field", + "p3-mds", + "p3-poseidon1", + "p3-poseidon2", + "p3-symmetric", + "p3-util", + "paste", + "rand", + "serde", + "spin 0.12.3", +] + +[[package]] +name = "p3-keccak" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc78b429da6c572d3d3764d5da86d711f75c0937c9821a8741dd0b4c2314819d" +dependencies = [ + "p3-symmetric", + "p3-util", + "tiny-keccak", +] + +[[package]] +name = "p3-lookup" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe175bcc36c74b4252d5e50bf188c0b2e0c58d3c537a579efeb1cae213e19bf" +dependencies = [ + "hashbrown", + "itertools", + "num-bigint", + "p3-air", + "p3-field", + "p3-matrix", + "p3-maybe-rayon", + "p3-uni-stark", + "serde", + "thiserror", + "tracing", +] + +[[package]] +name = "p3-matrix" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92f322bd7dded657d51f4c3adcc64bed27ffe4894dbd0f9c077d5670ce73217e" +dependencies = [ + "itertools", + "p3-field", + "p3-maybe-rayon", + "p3-util", + "rand", + "serde", + "tracing", +] + +[[package]] +name = "p3-maybe-rayon" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "486d6396b0d22274f862a6c5987bb25f9ea61b34f21b54c23a2ee53f2d8c20ea" + +[[package]] +name = "p3-mds" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00e11f572a44aa3c91057e59625d0992aacc6ffdb80dc1b44948d5587d66a159" +dependencies = [ + "p3-dft", + "p3-field", + "p3-symmetric", + "p3-util", + "rand", +] + +[[package]] +name = "p3-merkle-tree" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1508ed6e0211a8375ffdcd08746d81841526fe36140d985acd81b4bfe4103649" +dependencies = [ + "itertools", + "p3-commit", + "p3-field", + "p3-matrix", + "p3-maybe-rayon", + "p3-symmetric", + "p3-util", + "rand", + "serde", + "spin 0.12.3", + "thiserror", + "tracing", +] + +[[package]] +name = "p3-multilinear-util" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad6d6a4c1cf52da9a26779adece687e43cd3f989bcdf4d330dc896860b1194c6" +dependencies = [ + "itertools", + "p3-field", + "p3-matrix", + "p3-maybe-rayon", + "p3-util", + "rand", + "serde", + "tracing", +] + +[[package]] +name = "p3-poseidon1" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "457e895bcf89b77e062653021b60c12ccd94dce599c54898d9ced4bfbabc820d" +dependencies = [ + "p3-field", + "p3-mds", + "p3-symmetric", + "rand", +] + +[[package]] +name = "p3-poseidon2" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65501f32d58b5055c9470ccff459b2576de5f4e6ba72e91f78457231bc67b1c6" +dependencies = [ + "p3-field", + "p3-mds", + "p3-symmetric", + "p3-util", + "rand", +] + +[[package]] +name = "p3-security" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2347869521f4b61e8851ccb8327879a70e64291e884748d14ebc58bc0dd4dbe5" +dependencies = [ + "libm", + "p3-air", + "p3-field", + "p3-util", + "serde", +] + +[[package]] +name = "p3-symmetric" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3335886a1e2bec45877e050f76e6bf7a1a77019111c5f599d8b41c5889a2ea1c" +dependencies = [ + "itertools", + "p3-field", + "p3-util", + "serde", +] + +[[package]] +name = "p3-uni-stark" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b153514563fef4c3eb87eb26c670a56eff029c333877a13e03e0b2e4897eb84a" +dependencies = [ + "itertools", + "libm", + "p3-air", + "p3-challenger", + "p3-commit", + "p3-field", + "p3-matrix", + "p3-maybe-rayon", + "p3-security", + "p3-util", + "serde", + "thiserror", + "tracing", +] + +[[package]] +name = "p3-util" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e020b468e9188da32310d8c876225e5183df105a1970368df97f8a76b85dcc5b" +dependencies = [ + "p3-maybe-rayon", + "serde", +] + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "pkcs8" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "451913da69c775a56034ea8d9003d27ee8948e12443eae7c038ba100a4f21cb7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "poly1305" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e2d0073b297041425c7c3df6eb4792d598a15323fe63346852b092eca02904c" +dependencies = [ + "cpufeatures", + "universal-hash", +] + +[[package]] +name = "postcard" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6764c3b5dd454e283a30e6dfe78e9b31096d9e32036b5d1eaac7a6119ccb9a24" +dependencies = [ + "cobs", + "embedded-io 0.4.0", + "embedded-io 0.6.1", + "heapless", + "serde", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rand" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80" +dependencies = [ + "chacha20", + "getrandom", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + +[[package]] +name = "rand_zkvm" +version = "0.1.0" +dependencies = [ + "chacha20", + "chacha20poly1305", + "dilithium-core", + "evm-core", + "ml-kem", + "p3-air", + "p3-batch-stark", + "p3-challenger", + "p3-commit", + "p3-dft", + "p3-field", + "p3-fri", + "p3-goldilocks", + "p3-keccak", + "p3-lookup", + "p3-matrix", + "p3-merkle-tree", + "p3-poseidon2", + "p3-symmetric", + "p3-uni-stark", + "postcard", + "rand", + "rand_core", + "sbpf-core", + "serde", +] + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "sbpf-core" +version = "0.1.0" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.5", +] + +[[package]] +name = "sha3" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be176f1a57ce4e3d31c1a166222d9768de5954f811601fb7ca06fc8203905ce1" +dependencies = [ + "digest", + "keccak", +] + +[[package]] +name = "spin" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3763264f6b73151db08c50ff20d7d8a0b8796e021cdea7ceedad07b80155fa0e" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spin" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0134f9043ed38b087ac4f7d4af44c79e2c9e5094421fe3164f435ce585953b10" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spki" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d9efca8738c78ee9484207732f728b1ef517bbb1833d6fc0879ca898a522f6f" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12df2e0110f65b775f769bb17ef989067a1d931b2eb822bd4346631eeada89f9" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.5", +] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" + +[[package]] +name = "typenum" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "universal-hash" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4987bdc12753382e0bec4a65c50738ffaabc998b9cdd1f952fb5f39b0048a96" +dependencies = [ + "crypto-common", + "ctutils", +] + +[[package]] +name = "zeroize" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" diff --git a/exporter/Cargo.toml b/exporter/Cargo.toml new file mode 100644 index 0000000..e6dc3b7 --- /dev/null +++ b/exporter/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "air2lean" +version = "0.1.0" +edition = "2021" +description = "Exports the Plonky3 AIR constraints of rand_zkvm's chips as Lean 4 definitions" +license = "GPL-3.0-only" +publish = false + +[[bin]] +name = "air2lean" +path = "src/main.rs" + +# Its own workspace root: never absorbed into the fetched circuits checkout's. +[workspace] + +[dependencies] +# The circuits crate at the commit pinned in ../SOURCES.toml (scripts/fetch-sources.sh). +rand_zkvm = { path = "../third_party/zkp-circuits/research" } +# Exactly the Plonky3 versions research/Cargo.toml pins. research/ declares no [patch] +# (the vendored forks under vendor/ are used by recursion/ and the fullnode, and touch +# proving only), so none is replicated here. +p3-air = "=0.7.0" +p3-lookup = "=0.7.0" +p3-field = "=0.7.0" +p3-matrix = "=0.7.0" +p3-goldilocks = "=0.7.0" + +[profile.dev] +debug = 0 + +[profile.dev.package."*"] +opt-level = 3 +debug = 0 diff --git a/exporter/rust-toolchain.toml b/exporter/rust-toolchain.toml new file mode 100644 index 0000000..6422209 --- /dev/null +++ b/exporter/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.98.1" diff --git a/exporter/src/main.rs b/exporter/src/main.rs new file mode 100644 index 0000000..3cc573b --- /dev/null +++ b/exporter/src/main.rs @@ -0,0 +1,632 @@ +//! `air2lean`: prints the constraints a `rand_zkvm` chip enforces as Lean 4 definitions. +//! +//! The expressions are never restated by hand: each chip's `Air::eval` is run against Plonky3's +//! own symbolic builder (`p3_lookup::InteractionSymbolicBuilder`), and the recorded DAG is +//! translated node by node. +//! +//! * **Base constraints** become one `F` each, in the order `eval` asserted them. +//! * **Interactions** (global, then exclusive branches) become `Rand.Interaction` values. +//! * **Extension constraints** must be absent: `eval` of these chips asserts none (the LogUp +//! gadget adds its own later, and those are the bus mechanism, covered by the bus-soundness +//! assumption). Any present is an error. +//! +//! **Fail loudly.** Every leaf other than a current-row main column or a constant (next-row, +//! preprocessed, public, periodic, the row selectors), every bus the catalogue below does not +//! classify, every interaction shape the kind rules do not cover, and every local interaction is +//! an error naming the chip: a silently dropped term would make the Lean model weaker than the +//! AIR. Later chips extend the translator; they never get a default. +//! +//! **Sharing.** The DAG shares interior nodes through `Arc`s. A node referenced more than once +//! (counted over all roots of one Lean function) is emitted once as a `let`, keyed by its +//! `Arc` address; names are assigned in first-use post-order, so the output depends only on the +//! DAG's shape, never on the addresses. Leaves are printed inline. +//! +//! The output is deterministic: no timestamps, the header names only the circuits commit. + +use std::collections::HashMap; +use std::fmt::Write as _; +use std::path::{Path, PathBuf}; +use std::process::ExitCode; +use std::sync::Arc; + +use p3_air::symbolic::{AirLayout, BaseEntry, BaseLeaf, SymbolicExpr, SymbolicExpression}; +use p3_air::{Air, BaseAir}; +use p3_field::extension::BinomialExtensionField; +use p3_field::{PrimeCharacteristicRing, PrimeField64}; +use p3_lookup::{InteractionSymbolicBuilder, LookupBus, PermutationCheckBus}; +use p3_matrix::dense::RowMajorMatrix; +use rand_zkvm::asm::{ops::*, Assembler}; +use rand_zkvm::emulator::execute; +use rand_zkvm::isa::{AluOp, BranchCond, Instr, Program}; +use rand_zkvm::tables::{alu, bus, nibble, range, F}; + +/// The machine's challenge field (`rand_zkvm::machine::Challenge`). +type EF = BinomialExtensionField; +type Expr = SymbolicExpression; +type Result = std::result::Result; + +/// The circuits commit this exporter is built against, read from `SOURCES.toml` at compile time. +fn circuits_rev() -> Result { + const SOURCES: &str = include_str!("../../SOURCES.toml"); + let mut in_circuits = false; + for line in SOURCES.lines() { + let line = line.trim(); + if line.starts_with('[') { + in_circuits = line == "[circuits]"; + } else if in_circuits && line.starts_with("rev") { + let rev = line.split('"').nth(1).ok_or("SOURCES.toml: malformed circuits rev")?; + return Ok(rev.to_string()); + } + } + Err("SOURCES.toml: no [circuits] rev".into()) +} + +/// Refuses to export from a checkout that is not at the pinned commit. +fn check_checkout(rev: &str) -> Result<()> { + let dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("../third_party/zkp-circuits"); + let out = std::process::Command::new("git") + .arg("-C").arg(&dir).args(["rev-parse", "HEAD"]) + .output().map_err(|e| format!("git rev-parse in {}: {e}", dir.display()))?; + let head = String::from_utf8_lossy(&out.stdout).trim().to_string(); + if head != rev { + return Err(format!("{} is at {head:?}, SOURCES.toml pins {rev}; run scripts/fetch-sources.sh", dir.display())); + } + Ok(()) +} + +// ───────────────────────────────────────────────────────────── interaction kinds + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Kind { Lookup, Provide, Send, Receive } + +impl Kind { + fn lean(self) -> &'static str { + match self { Kind::Lookup => ".lookup", Kind::Provide => ".provide", Kind::Send => ".send", Kind::Receive => ".receive" } + } +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum BusClass { Lookup, Permutation } + +/// The Goldilocks prime `2^64 - 2^32 + 1`. +const GOLDILOCKS_P: u64 = 0xffff_ffff_0000_0001; + +/// Every bus of `rand_zkvm::tables::bus`, classified by the type of its constant (so a bus that +/// changes type fails to compile here). A bus missing from this list is an export error. +fn bus_class(name: &str) -> Option { + let lookups: [&LookupBus<'static>; 16] = [ + &bus::PROGRAM, &bus::PROGRAM_WORD, &bus::INPUT_DIGEST, &bus::INPUT_READ, &bus::PUBLIC_DIGEST, + &bus::PUBLIC_READ, &bus::ALU, &bus::RANGE8, &bus::AND4, &bus::OR4, &bus::XOR4, &bus::POW2, + &bus::POSEIDON2, &bus::KECCAK, &bus::SHA256, &bus::MODQ, + ]; + let perms: [&PermutationCheckBus<'static>; 3] = [&bus::MEMORY, &bus::BLIND, &bus::MODQ_WIRE]; + if lookups.iter().any(|b| b.name() == name) { return Some(BusClass::Lookup); } + if perms.iter().any(|b| b.name() == name) { return Some(BusClass::Permutation); } + None +} + +/// The symbolic builder records `(bus, fields, count, weight)` and not which bus method pushed +/// it, so the kind is recovered from what each method records (`p3-lookup-0.7.0/src/bus.rs`): +/// +/// * `LookupBus::lookup_key(k, c)` pushes `c` with its declared weight (≥ 1 in this crate); +/// * `LookupBus::table_entry(k, n)` pushes `Count::provided(-n)`: weight 0, count `-n` — so the +/// count is a `Neg` node, or a folded constant when `n` is one; +/// * `PermutationCheckBus::send(f, c)` pushes `c`; `receive(f, c)` pushes `-c`. +/// +/// On a permutation bus a `send` whose count is itself a negation is recorded identically to a +/// `receive`; the two are the same LogUp term, so reading it as a `receive` is exact. +/// Returns the kind and the count to emit (`provide`/`receive` carry the multiplicity, sign +/// removed). +fn classify(chip: &str, owned: &str, bus_name: &str, count: &Expr, weight: u32) -> Result<(Kind, Expr)> { + let unneg = |e: &Expr| -> Option { + match e { + SymbolicExpr::Neg { x, .. } => Some((**x).clone()), + SymbolicExpr::Leaf(BaseLeaf::Constant(c)) => Some(SymbolicExpr::Leaf(BaseLeaf::Constant(-*c))), + _ => None, + } + }; + match bus_class(bus_name) { + None => Err(format!("{chip}: interaction on unknown bus {bus_name:?} (add it to bus_class)")), + Some(BusClass::Lookup) if weight > 0 => { + // A lookup count is a (gated) multiplicity. A negation, or a constant in the upper + // half of the field, is a `table_entry`'s `-n` pushed with a positive weight: a + // table-side entry that would be wrongly modelled as a lookup. + let negated = match count { + SymbolicExpr::Neg { .. } => true, + SymbolicExpr::Leaf(BaseLeaf::Constant(c)) => c.as_canonical_u64() >= GOLDILOCKS_P / 2, + _ => false, + }; + if negated { + return Err(format!("{chip}: weight-{weight} interaction on lookup bus {bus_name:?} has a negated count; a table-side entry, not a lookup")); + } + Ok((Kind::Lookup, count.clone())) + } + Some(BusClass::Lookup) => match unneg(count) { + Some(_) if bus_name != owned => Err(format!("{chip}: provide on bus {bus_name:?}, but the chip owns {owned:?}")), + Some(n) => Ok((Kind::Provide, n)), + None => Err(format!("{chip}: weight-0 interaction on lookup bus {bus_name:?} whose count is not a negation; not a table_entry")), + }, + Some(BusClass::Permutation) => match count { + SymbolicExpr::Neg { x, .. } => Ok((Kind::Receive, (**x).clone())), + _ => Ok((Kind::Send, count.clone())), + }, + } +} + +// ───────────────────────────────────────────────────────────── symbolic capture + +struct Interaction { bus: String, kind: Kind, tuple: Vec, count: Expr } + +struct Captured { width: usize, constraints: Vec, interactions: Vec } + +fn capture(chip: &str, owned: &str, air: &A) -> Result +where + A: BaseAir + Air>, +{ + let layout = AirLayout::from_air::(air); + let mut b = InteractionSymbolicBuilder::::new(layout); + air.eval(&mut b); + let ext = b.extension_constraints(); + if !ext.is_empty() { + return Err(format!("{chip}: eval asserted {} extension constraint(s); not exported", ext.len())); + } + if !b.local_interactions().is_empty() { + return Err(format!("{chip}: {} local interaction(s); the Lean model has no local bus", b.local_interactions().len())); + } + let mut interactions = Vec::new(); + for i in b.global_interactions() { + let (kind, count) = classify(chip, owned, &i.bus_name, &i.count, i.count_weight)?; + interactions.push(Interaction { bus: i.bus_name.clone(), kind, tuple: i.fields.clone(), count }); + } + // An exclusive group is one LogUp column whose numerator is Σ flag·count over its + // branches; each branch is the interaction `(fields, flag·count)`. + for g in b.exclusive_interactions() { + for br in &g.branches { + let gated = br.flag.clone() * br.count.clone(); + let (kind, count) = classify(chip, owned, &g.bus_name, &gated, br.count_weight)?; + interactions.push(Interaction { bus: g.bus_name.clone(), kind, tuple: br.fields.clone(), count }); + } + } + Ok(Captured { width: air.width(), constraints: b.base_constraints(), interactions }) +} + +// ───────────────────────────────────────────────────────────── Lean printing + +/// Prints expressions of one Lean function, sharing interior nodes referenced more than once. +struct Printer<'a> { + chip: &'a str, + width: usize, + refs: HashMap<*const Expr, usize>, + names: HashMap<*const Expr, String>, + lets: Vec, +} + +impl<'a> Printer<'a> { + fn new(chip: &'a str, width: usize) -> Self { + Self { chip, width, refs: HashMap::new(), names: HashMap::new(), lets: Vec::new() } + } + + /// First pass: reference counts of every interior node reachable from `e`. + fn count(&mut self, e: &Expr) { + match e { + SymbolicExpr::Leaf(_) => {} + SymbolicExpr::Add { x, y, .. } | SymbolicExpr::Sub { x, y, .. } | SymbolicExpr::Mul { x, y, .. } => { + self.count_child(x); + self.count_child(y); + } + SymbolicExpr::Neg { x, .. } => self.count_child(x), + } + } + + fn count_child(&mut self, a: &Arc) { + let n = self.refs.entry(Arc::as_ptr(a)).or_insert(0); + *n += 1; + if *n == 1 { self.count(a); } + } + + fn leaf(&self, l: &BaseLeaf) -> Result { + match l { + BaseLeaf::Constant(c) => Ok(format!("({} : F)", c.as_canonical_u64())), + BaseLeaf::Variable(v) => match v.entry { + BaseEntry::Main { offset: 0 } if v.index < self.width => Ok(format!("m ⟨{}, by decide⟩", v.index)), + _ => Err(format!("{}: untranslated leaf {:?} (entry {:?}, index {})", self.chip, l, v.entry, v.index)), + }, + BaseLeaf::IsFirstRow | BaseLeaf::IsLastRow | BaseLeaf::IsTransition => { + Err(format!("{}: untranslated leaf {:?} (row selector)", self.chip, l)) + } + } + } + + /// Second pass: the Lean term for `e`, pushing `let`s for shared children first. + fn render(&mut self, e: &Expr) -> Result { + Ok(match e { + SymbolicExpr::Leaf(l) => self.leaf(l)?, + SymbolicExpr::Add { x, y, .. } => format!("({} + {})", self.child(x)?, self.child(y)?), + SymbolicExpr::Sub { x, y, .. } => format!("({} - {})", self.child(x)?, self.child(y)?), + SymbolicExpr::Mul { x, y, .. } => format!("({} * {})", self.child(x)?, self.child(y)?), + SymbolicExpr::Neg { x, .. } => format!("(-{})", self.child(x)?), + }) + } + + fn child(&mut self, a: &Arc) -> Result { + if let SymbolicExpr::Leaf(l) = &**a { return self.leaf(l); } + let k = Arc::as_ptr(a); + if let Some(n) = self.names.get(&k) { return Ok(n.clone()); } + let body = self.render(a)?; + if self.refs.get(&k).copied().unwrap_or(0) < 2 { return Ok(body); } + let name = format!("x{}", self.lets.len()); + self.lets.push(format!(" let {name} := {body}")); + self.names.insert(k, name.clone()); + Ok(name) + } +} + +fn header(rev: &str) -> String { + format!("-- GENERATED by exporter from zkp-circuits @{rev}. Do not edit.\n") +} + +/// One Lean function `name (m : Fin width → F) : List ty := let …; [items]`. +fn lean_fn(out: &mut String, doc: &str, name: &str, ty: &str, width: usize, lets: &[String], items: &[String]) { + writeln!(out, "/-- {doc} -/").unwrap(); + writeln!(out, "def {name} (m : Fin {width} → F) : List {ty} :=").unwrap(); + for l in lets { writeln!(out, "{l}").unwrap(); } + if items.is_empty() { + writeln!(out, " []").unwrap(); + } else { + for (i, it) in items.iter().enumerate() { + let open = if i == 0 { " [ " } else { " , " }; + writeln!(out, "{open}{it}").unwrap(); + } + writeln!(out, " ]").unwrap(); + } + out.push('\n'); +} + +/// The Lean module for one chip: `width`, `constraints`, `interactions`. +fn export_chip(rev: &str, chip: &str, namespace: &str, cap: &Captured) -> Result { + let mut out = header(rev); + writeln!(out, "import Rand.Bus\n").unwrap(); + writeln!(out, "/-! The `{chip}` chip's base constraints and bus interactions, read off its `Air::eval`").unwrap(); + writeln!(out, "through Plonky3's symbolic builder: {} constraints, {} interactions. -/\n", + cap.constraints.len(), cap.interactions.len()).unwrap(); + writeln!(out, "namespace {namespace}\n\nopen Rand\n").unwrap(); + writeln!(out, "/-- Main trace width. -/\ndef width : ℕ := {}\n", cap.width).unwrap(); + + let mut p = Printer::new(chip, cap.width); + for c in &cap.constraints { p.count(c); } + let items = cap.constraints.iter().map(|c| p.render(c)).collect::>>()?; + lean_fn(&mut out, "Every base constraint, in `eval` order; a row is accepted iff all are `0`.", + "constraints", "F", cap.width, &p.lets, &items); + + let mut p = Printer::new(chip, cap.width); + for i in &cap.interactions { + for t in &i.tuple { p.count(t); } + p.count(&i.count); + } + let mut items = Vec::new(); + for i in &cap.interactions { + let tuple = i.tuple.iter().map(|t| p.render(t)).collect::>>()?; + let count = p.render(&i.count)?; + items.push(format!("{{ bus := {:?}, kind := {}, tuple := [{}], count := {} }}", + i.bus, i.kind.lean(), tuple.join(", "), count)); + } + lean_fn(&mut out, "Every bus interaction, in push order (global, then exclusive branches).", + "interactions", "Interaction", cap.width, &p.lets, &items); + writeln!(out, "end {namespace}").unwrap(); + Ok(out) +} + +// ───────────────────────────────────────────────────────────── honest ALU rows + +/// A small guest that runs every one of the 19 ALU ops, the M-extension on an ordinary pair and +/// on division by zero, and `Eq` through a `beq`. +fn alu_program() -> Program { + let mut a = Assembler::new(0); + type Op = fn(u32, u32, u32) -> Instr; + let ops: [Op; 18] = [add, sub, and, or, xor, sll, srl, sra, slt, sltu, mul, mulh, mulhu, mulhsu, div, divu, rem, remu]; + for (x, y) in [(0x1234_5678, -7), (-7, 0)] { + a.extend(li(5, x)); + a.extend(li(6, y)); + for f in ops { a.push(f(7, 5, 6)); } + } + a.branch(BranchCond::Eq, 5, 5, "eq"); + a.label("eq"); + a.extend(halt()); + a.assemble() +} + +/// Rows of the real `alu_trace` for [`alu_program`]: every distinct real row in trace order, +/// then the first padding row. Checked here against the captured constraints before printing. +fn honest_rows(cap: &Captured) -> Result>> { + let e = execute(&alu_program(), &[], &[], 10_000).map_err(|e| format!("alu program: {e:?}"))?; + let n: usize = e.events.iter().map(|c| c.alu.len()).sum(); + let height = (n + 1).next_power_of_two(); + let mut rc = range::RangeCounts::default(); + let mut nc = nibble::NibbleCounts::default(); + let t: RowMajorMatrix = alu::alu_trace(&e.events, height, &mut rc, &mut nc); + let mut rows: Vec> = Vec::new(); + let mut padding = None; + for r in t.values.chunks(alu::col::WIDTH) { + let r: Vec = r.iter().map(|x| x.as_canonical_u64()).collect(); + if r[alu::col::IS_REAL] == 1 { + if !rows.contains(&r) { rows.push(r); } + } else if padding.is_none() { + padding = Some(r); + } + } + for op in AluOp::ALL { + if !rows.iter().any(|r| r[alu::col::FLAG0 + op.code() as usize] == 1) { + return Err(format!("alu program never runs {op:?}")); + } + } + rows.push(padding.ok_or("alu trace has no padding row")?); + for (k, r) in rows.iter().enumerate() { + let vals: Vec = r.iter().map(|&x| F::from_u64(x)).collect(); + for (j, c) in cap.constraints.iter().enumerate() { + let v = eval(c, &vals, &mut HashMap::new()); + if v != F::ZERO { return Err(format!("honest row {k} fails constraint {j}")); } + } + } + Ok(rows) +} + +/// Evaluates a captured expression on one row (memoised by node, as the DAG is shared). +fn eval(e: &Expr, row: &[F], memo: &mut HashMap<*const Expr, F>) -> F { + let child = |a: &Arc, memo: &mut HashMap<*const Expr, F>| -> F { + if let Some(v) = memo.get(&Arc::as_ptr(a)) { return *v; } + let v = eval(a, row, memo); + memo.insert(Arc::as_ptr(a), v); + v + }; + match e { + SymbolicExpr::Leaf(BaseLeaf::Constant(c)) => *c, + SymbolicExpr::Leaf(BaseLeaf::Variable(v)) => row[v.index], + SymbolicExpr::Leaf(l) => panic!("eval: leaf {l:?}"), + SymbolicExpr::Add { x, y, .. } => { let a = child(x, memo); a + child(y, memo) } + SymbolicExpr::Sub { x, y, .. } => { let a = child(x, memo); a - child(y, memo) } + SymbolicExpr::Mul { x, y, .. } => { let a = child(x, memo); a * child(y, memo) } + SymbolicExpr::Neg { x, .. } => -child(x, memo), + } +} + +fn export_honest(rev: &str, cap: &Captured) -> Result { + let rows = honest_rows(cap)?; + let mut out = header(rev); + writeln!(out, "import Rand.Field\n").unwrap(); + writeln!(out, "/-! Rows of the real `alu_trace` on a small guest running all 19 ALU ops (every distinct").unwrap(); + writeln!(out, "real row in trace order, then one padding row): {} rows. -/\n", rows.len()).unwrap(); + writeln!(out, "namespace Rand.Generated.RV32.Alu\n\nopen Rand\n").unwrap(); + writeln!(out, "/-- A row from its 64 cells as canonical values. -/").unwrap(); + writeln!(out, "def row (l : List ℕ) : Fin {} → F := fun i => (l.getD i.val 0 : F)\n", alu::col::WIDTH).unwrap(); + writeln!(out, "/-- Honest rows produced by the Rust trace generator. -/").unwrap(); + writeln!(out, "def honestRows : List (Fin {} → F) :=", alu::col::WIDTH).unwrap(); + for (i, r) in rows.iter().enumerate() { + let open = if i == 0 { " [ " } else { " , " }; + let cells: Vec = r.iter().map(|x| x.to_string()).collect(); + writeln!(out, "{open}row [{}]", cells.join(", ")).unwrap(); + } + writeln!(out, " ]\n\nend Rand.Generated.RV32.Alu").unwrap(); + Ok(out) +} + +// ───────────────────────────────────────────────────────────── ALU vectors + +/// SplitMix64 with a fixed seed: the random vector pairs are reproducible without a dependency. +fn splitmix(state: &mut u64) -> u64 { + *state = state.wrapping_add(0x9e37_79b9_7f4a_7c15); + let mut z = *state; + z = (z ^ (z >> 30)).wrapping_mul(0xbf58_476d_1ce4_e5b9); + z = (z ^ (z >> 27)).wrapping_mul(0x94d0_49bb_1331_11eb); + z ^ (z >> 31) +} + +/// The operand pairs every op is run on: the 9x9 edge set, then 64 seeded-random pairs. +fn vector_pairs() -> Vec<(u32, u32)> { + const EDGE: [u32; 9] = [0, 1, 2, 31, 32, 0x7fff_ffff, 0x8000_0000, 0xffff_fffe, 0xffff_ffff]; + let mut pairs: Vec<(u32, u32)> = EDGE.iter().flat_map(|&a| EDGE.iter().map(move |&b| (a, b))).collect(); + let mut st = 0x5eed_a1u64; + for _ in 0..64 { + let r = splitmix(&mut st); + pairs.push((r as u32, (r >> 32) as u32)); + } + pairs +} + +/// `(code, a, b, AluOp::eval(a, b))` for every op and pair, evaluated by the Rust itself. +fn export_vectors(rev: &str) -> String { + let pairs = vector_pairs(); + let mut out = header(rev); + writeln!(out, "import Mathlib.Data.Nat.Notation\n").unwrap(); + writeln!(out, "/-! `AluOp::eval` of `rand_zkvm::isa`, run by the exporter on {} operand pairs (the edge set", pairs.len()).unwrap(); + writeln!(out, "{{0, 1, 2, 31, 32, 0x7fffffff, 0x80000000, 0xfffffffe, 0xffffffff}}², then 64 seeded-random pairs)").unwrap(); + writeln!(out, "for each of the {} ops: {} vectors `(code, a, b, result)`. -/\n", AluOp::ALL.len(), pairs.len() * AluOp::ALL.len()).unwrap(); + writeln!(out, "namespace Rand.Generated.RV32.AluVectors\n").unwrap(); + writeln!(out, "-- One list per op: a single 2755-element literal exceeds the elaborator's recursion limit.").unwrap(); + writeln!(out, "set_option maxRecDepth 8000\n").unwrap(); + for op in AluOp::ALL { + writeln!(out, "/-- `{op:?}` (code {}): `(code, a, b, AluOp::eval(a, b))` for each pair. -/", op.code()).unwrap(); + writeln!(out, "def vectors{} : List (ℕ × ℕ × ℕ × ℕ) :=", op.code()).unwrap(); + for (i, &(a, b)) in pairs.iter().enumerate() { + let open = if i == 0 { " [ " } else { " , " }; + writeln!(out, "{open}({}, {a}, {b}, {})", op.code(), op.eval(a, b)).unwrap(); + } + writeln!(out, " ]\n").unwrap(); + } + let names: Vec = AluOp::ALL.iter().map(|o| format!("vectors{}", o.code())).collect(); + writeln!(out, "/-- All vectors, ops in code order. -/\ndef aluVectors : List (ℕ × ℕ × ℕ × ℕ) :=\n {}\n", names.join(" ++ ")).unwrap(); + writeln!(out, "end Rand.Generated.RV32.AluVectors").unwrap(); + out +} + +// ───────────────────────────────────────────────────────────── fixed tables + +fn canonical_rows(m: RowMajorMatrix, width: usize, what: &str) -> Result>> { + if m.width != width { return Err(format!("{what}: preprocessed width {} != {width}", m.width)); } + Ok(m.values.chunks(width).map(|r| r.iter().map(|x| x.as_canonical_u64()).collect()).collect()) +} + +fn export_tables(rev: &str) -> Result { + use range::pre as rp; + use nibble::pre as np; + let r = >::preprocessed_trace(&range::RangeAir).ok_or("range: no preprocessed trace")?; + let r = canonical_rows(r, rp::WIDTH, "range")?; + let n = >::preprocessed_trace(&nibble::NibbleAir).ok_or("nibble: no preprocessed trace")?; + let n = canonical_rows(n, np::WIDTH, "nibble")?; + let mut out = header(rev); + writeln!(out, "import Mathlib.Data.Nat.Notation\n").unwrap(); + writeln!(out, "/-! The fixed tables' `preprocessed_trace`s, as canonical values. -/\n").unwrap(); + writeln!(out, "namespace Rand.Generated.RV32.Tables\n").unwrap(); + writeln!(out, "/-- `range.rs`: (A, POW2, IS_POW2) for each of the {} rows. -/", r.len()).unwrap(); + writeln!(out, "def range8Rows : List (ℕ × ℕ × ℕ) :=").unwrap(); + for (i, x) in r.iter().enumerate() { + let open = if i == 0 { " [ " } else { " , " }; + writeln!(out, "{open}({}, {}, {})", x[rp::A], x[rp::POW2], x[rp::IS_POW2]).unwrap(); + } + writeln!(out, " ]\n").unwrap(); + writeln!(out, "/-- `nibble.rs`: (a, b, a AND b, a OR b, a XOR b) for each of the {} rows. -/", n.len()).unwrap(); + writeln!(out, "def nibbleRows : List (ℕ × ℕ × ℕ × ℕ × ℕ) :=").unwrap(); + for (i, x) in n.iter().enumerate() { + let open = if i == 0 { " [ " } else { " , " }; + writeln!(out, "{open}({}, {}, {}, {}, {})", x[np::A], x[np::B], x[np::AND], x[np::OR], x[np::XOR]).unwrap(); + } + writeln!(out, " ]\n\nend Rand.Generated.RV32.Tables").unwrap(); + Ok(out) +} + +// ───────────────────────────────────────────────────────────── CLI + +const USAGE: &str = "usage: air2lean --out "; + +fn run(args: &[String]) -> Result<()> { + let (cmd, out) = match args { + [cmd, flag, out] if flag == "--out" => (cmd.as_str(), PathBuf::from(out)), + _ => return Err(USAGE.into()), + }; + let rev = circuits_rev()?; + check_checkout(&rev)?; + let text = match cmd { + "alu" => export_chip(&rev, "alu", "Rand.Generated.RV32.Alu", &capture("alu", "ALU", &alu::AluAir)?)?, + "alu-honest" => export_honest(&rev, &capture("alu", "ALU", &alu::AluAir)?)?, + "alu-vectors" => export_vectors(&rev), + "tables" => export_tables(&rev)?, + _ => return Err(USAGE.into()), + }; + if let Some(dir) = out.parent() { std::fs::create_dir_all(dir).map_err(|e| e.to_string())?; } + std::fs::write(&out, text).map_err(|e| format!("{}: {e}", out.display()))?; + Ok(()) +} + +fn main() -> ExitCode { + let args: Vec = std::env::args().skip(1).collect(); + match run(&args) { + Ok(()) => ExitCode::SUCCESS, + Err(e) => { eprintln!("air2lean: {e}"); ExitCode::FAILURE } + } +} + +// ───────────────────────────────────────────────────────────── tests + +#[cfg(test)] +mod tests { + use super::*; + use p3_air::{AirBuilder, WindowAccess}; + use p3_lookup::{Count, InteractionBuilder}; + + /// A two-column toy AIR whose single constraint is selected by `MODE`. + struct Toy; + impl BaseAir for Toy { fn width(&self) -> usize { 2 } } + impl Air for Toy { + fn eval(&self, b: &mut AB) { + let m = b.main(); + let x: AB::Expr = m.current(0).unwrap().into(); + let y: AB::Expr = m.current(1).unwrap().into(); + match MODE { + 0 => { let n: AB::Expr = m.next(0).unwrap().into(); b.assert_zero(n - y); } + 1 => b.when_transition().assert_zero(x - y), + 2 => bus::RANGE8.lookup_key(b, [x], Count::bounded(y, 1)), + 3 => b.push_interaction("NOT_A_BUS", [x], Count::bounded(y, 1)), + 4 => b.push_interaction(bus::RANGE8.name(), [x], Count::bounded(y, 0)), + 5 => { bus::MEMORY.send(b, [x.clone()], Count::bounded(y.clone(), 1)); bus::MEMORY.receive(b, [x], Count::bounded(y, 1)); } + 6 => { bus::RANGE8.table_entry(b, [x.clone()], y); bus::RANGE8.table_entry(b, [x], AB::Expr::from_u32(3)); } + 7 => bus::RANGE8.lookup_key(b, [x], Count::bounded(-y, 1)), + 8 => bus::RANGE8.lookup_key(b, [x], Count::bounded(AB::Expr::from_u64(GOLDILOCKS_P - 1), 1)), + _ => unreachable!(), + } + } + } + + fn lean_of() -> Result { + export_chip("REV", "toy", "Toy", &capture("toy", "RANGE8", &Toy::)?) + } + + /// Review Focus 1: a next-row leaf is refused, never dropped. + #[test] + fn next_row_leaf_is_an_error() { + let e = lean_of::<0>().unwrap_err(); + assert!(e.contains("toy") && e.contains("untranslated leaf") && e.contains("offset: 1"), "{e}"); + } + + #[test] + fn transition_selector_is_an_error() { + let e = lean_of::<1>().unwrap_err(); + assert!(e.contains("IsTransition"), "{e}"); + } + + #[test] + fn unknown_bus_is_an_error() { + assert!(lean_of::<3>().unwrap_err().contains("unknown bus")); + } + + #[test] + fn weight_zero_without_negation_is_an_error() { + assert!(lean_of::<4>().unwrap_err().contains("not a table_entry")); + } + + #[test] + fn kinds_are_recovered() { + assert!(lean_of::<2>().unwrap().contains(r#"{ bus := "RANGE8", kind := .lookup, tuple := [m ⟨0, by decide⟩], count := m ⟨1, by decide⟩ }"#)); + let s = lean_of::<5>().unwrap(); + assert!(s.contains(r#"kind := .send, tuple := [m ⟨0, by decide⟩], count := m ⟨1, by decide⟩"#), "{s}"); + assert!(s.contains(r#"kind := .receive, tuple := [m ⟨0, by decide⟩], count := m ⟨1, by decide⟩"#), "{s}"); + let s = lean_of::<6>().unwrap(); + assert!(s.contains(r#"kind := .provide, tuple := [m ⟨0, by decide⟩], count := m ⟨1, by decide⟩"#), "{s}"); + assert!(s.contains(r#"kind := .provide, tuple := [m ⟨0, by decide⟩], count := (3 : F)"#), "{s}"); + } + + /// Hardening (a): a provide is accepted only on the bus the chip owns. + #[test] + fn provide_on_foreign_bus_is_an_error() { + let cap = capture("toy", "ALU", &Toy::<6>); + assert!(cap.err().unwrap().contains("the chip owns \"ALU\"")); + // …and the owned bus is accepted (kinds_are_recovered, owner RANGE8). + assert!(lean_of::<6>().is_ok()); + } + + /// Hardening (b): a positive-weight lookup with a negated count is a table-side entry. + #[test] + fn negated_lookup_count_is_an_error() { + assert!(lean_of::<7>().unwrap_err().contains("negated count")); + assert!(lean_of::<8>().unwrap_err().contains("negated count")); + assert!(lean_of::<2>().is_ok()); + } + + /// The vectors: counts, the code order, and that the Rust edge cases are in them. + #[test] + fn vectors_cover_the_edge_cases() { + let s = export_vectors("REV"); + assert_eq!(s.matches("\n , (").count() + 19, 19 * (81 + 64)); + assert!(s.contains("(15, 2147483648, 4294967295, 2147483648)")); // MIN / -1 + assert!(s.contains("(17, 2147483648, 4294967295, 0)")); // MIN % -1 + assert!(s.contains("(15, 31, 0, 4294967295)")); // div by zero + assert!(s.contains("(17, 31, 0, 31)")); // rem by zero + assert_eq!(s, export_vectors("REV"), "deterministic"); + } + + /// The ALU exports with no extension constraints and its honest rows pass in Rust. + #[test] + fn alu_exports() { + let cap = capture("alu", "ALU", &alu::AluAir).unwrap(); + export_chip("REV", "alu", "A", &cap).unwrap(); + assert!(honest_rows(&cap).unwrap().len() > 19); + } +} diff --git a/lake-manifest.json b/lake-manifest.json new file mode 100644 index 0000000..9fe8206 --- /dev/null +++ b/lake-manifest.json @@ -0,0 +1,96 @@ +{"version": "1.3.0", + "packagesDir": ".lake/packages", + "packages": + [{"url": "https://github.com/leanprover-community/mathlib4", + "type": "git", + "subDir": null, + "scope": "leanprover-community", + "rev": "56a005855ea17e0b0958f73ec801ae140b0a1679", + "name": "mathlib", + "manifestFile": "lake-manifest.json", + "inputRev": "v4.35.0", + "inherited": false, + "configFile": "lakefile.lean"}, + {"url": "https://github.com/leanprover-community/plausible", + "type": "git", + "subDir": null, + "scope": "leanprover-community", + "rev": "dfa4f38190d07c37e315953e08b90fe2d95b3c24", + "name": "plausible", + "manifestFile": "lake-manifest.json", + "inputRev": "main", + "inherited": true, + "configFile": "lakefile.toml"}, + {"url": "https://github.com/leanprover-community/LeanSearchClient", + "type": "git", + "subDir": null, + "scope": "leanprover-community", + "rev": "d6b4c7be5be75ec4917c873ac50c756dc1436372", + "name": "LeanSearchClient", + "manifestFile": "lake-manifest.json", + "inputRev": "main", + "inherited": true, + "configFile": "lakefile.toml"}, + {"url": "https://github.com/leanprover-community/import-graph", + "type": "git", + "subDir": null, + "scope": "leanprover-community", + "rev": "a41f0e9a4dea23188ea9cc1c41ac9f8bbafe0b93", + "name": "importGraph", + "manifestFile": "lake-manifest.json", + "inputRev": "main", + "inherited": true, + "configFile": "lakefile.toml"}, + {"url": "https://github.com/leanprover-community/ProofWidgets4", + "type": "git", + "subDir": null, + "scope": "leanprover-community", + "rev": "df72b022e558978a1c50264cfc4d7fec86fa8e04", + "name": "proofwidgets", + "manifestFile": "lake-manifest.json", + "inputRev": "main", + "inherited": true, + "configFile": "lakefile.lean"}, + {"url": "https://github.com/leanprover-community/aesop", + "type": "git", + "subDir": null, + "scope": "leanprover-community", + "rev": "4a174c490d8707121c4a9290800489f105d85e07", + "name": "aesop", + "manifestFile": "lake-manifest.json", + "inputRev": "master", + "inherited": true, + "configFile": "lakefile.toml"}, + {"url": "https://github.com/leanprover-community/quote4", + "type": "git", + "subDir": null, + "scope": "leanprover-community", + "rev": "dce0ad79c486cb1fb504af04f953c3466b0c6db8", + "name": "Qq", + "manifestFile": "lake-manifest.json", + "inputRev": "master", + "inherited": true, + "configFile": "lakefile.toml"}, + {"url": "https://github.com/leanprover-community/batteries", + "type": "git", + "subDir": null, + "scope": "leanprover-community", + "rev": "66e469188fe07963e5cf666c7d4433f45b8131c5", + "name": "batteries", + "manifestFile": "lake-manifest.json", + "inputRev": "main", + "inherited": true, + "configFile": "lakefile.toml"}, + {"url": "https://github.com/leanprover/lean4-cli", + "type": "git", + "subDir": null, + "scope": "leanprover", + "rev": "c24fe6078c630e89b489bffe59b3e20ac30d12c8", + "name": "Cli", + "manifestFile": "lake-manifest.json", + "inputRev": "v4.35.0", + "inherited": true, + "configFile": "lakefile.toml"}], + "name": "rand", + "lakeDir": ".lake", + "fixedToolchain": false} diff --git a/lakefile.toml b/lakefile.toml new file mode 100644 index 0000000..6ec8beb --- /dev/null +++ b/lakefile.toml @@ -0,0 +1,17 @@ +name = "rand" +defaultTargets = ["Rand"] + +[leanOptions] +autoImplicit = false + +[[require]] +name = "mathlib" +scope = "leanprover-community" +rev = "v4.35.0" + +[[lean_lib]] +name = "Rand" + +[[lean_lib]] +name = "RandTest" +globs = ["RandTest.+"] diff --git a/lean-toolchain b/lean-toolchain new file mode 100644 index 0000000..a6aff06 --- /dev/null +++ b/lean-toolchain @@ -0,0 +1 @@ +leanprover/lean4:v4.35.0 diff --git a/scripts/audit.sh b/scripts/audit.sh new file mode 100755 index 0000000..7105466 --- /dev/null +++ b/scripts/audit.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +# Fails if Rand/ contains sorry/admit/axiom/native_decide, or if any published +# theorem depends on an axiom outside {propext, Classical.choice, Quot.sound}. +set -euo pipefail +cd "$(dirname "$0")/.." + +if grep -rnE '\bsorry\b|\badmit\b|^[[:space:]]*(private[[:space:]]+|protected[[:space:]]+)?axiom\b|\bnative_decide\b' Rand Rand.lean RandTest RandTest.lean Audit.lean 2>/dev/null \ + | grep -v 'Audit.lean:.*native_decide'; then + echo "audit: forbidden token found (sorry|admit|axiom|native_decide)" >&2 + exit 1 +fi + +out=$(lake env lean Audit.lean 2>&1) || { echo "$out" >&2; exit 1; } +echo "$out" | grep -v 'module system' +if echo "$out" | grep -q 'error'; then exit 1; fi +echo "audit: ok" diff --git a/scripts/check-generated.sh b/scripts/check-generated.sh new file mode 100755 index 0000000..143fd21 --- /dev/null +++ b/scripts/check-generated.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# Regenerates every file under Rand/Generated/ from the pinned circuits commit and fails +# on any difference from what is committed (generated files are never edited by hand). +# +# RAND_SOURCES_LOCAL_CIRCUITS=/path/to/zkp-circuits fetches from a local clone instead. +set -euo pipefail +cd "$(dirname "$0")/.." + +scripts/fetch-sources.sh circuits +(cd exporter && cargo build --locked --quiet) +bin=exporter/target/debug/air2lean + +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT +mkdir -p "$tmp/RV32" +"$bin" alu --out "$tmp/RV32/Alu.lean" +"$bin" alu-honest --out "$tmp/RV32/AluHonest.lean" +"$bin" alu-vectors --out "$tmp/RV32/AluVectors.lean" +"$bin" tables --out "$tmp/RV32/Tables.lean" + +if ! diff -r "$tmp" Rand/Generated; then + echo "check-generated: Rand/Generated/ differs from the exporter's output (diff above)" >&2 + exit 1 +fi +echo "check-generated: ok" diff --git a/scripts/fetch-sources.sh b/scripts/fetch-sources.sh new file mode 100755 index 0000000..d5d4951 --- /dev/null +++ b/scripts/fetch-sources.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# Clones each repo in SOURCES.toml into third_party/ at its pinned +# rev (a shallow fetch of exactly that commit). Idempotent: a checkout already at +# the rev is left alone. +# +# scripts/fetch-sources.sh # every source +# scripts/fetch-sources.sh circuits # only the named [sections] +# +# RAND_SOURCES_LOCAL_
=/path/to/repo (e.g. RAND_SOURCES_LOCAL_CIRCUITS) +# fetches from a local clone instead of the URL; the rev is still checked. +set -euo pipefail +cd "$(dirname "$0")/.." + +# section repo rev, one line per [section] +entries=$(awk ' + /^\[/ { if (name != "") print name, repo, rev; gsub(/[][]/, ""); name = $0; repo = ""; rev = ""; next } + /^repo[[:space:]]*=/ { sub(/^[^"]*"/, ""); sub(/".*$/, ""); repo = $0 } + /^rev[[:space:]]*=/ { sub(/^[^"]*"/, ""); sub(/".*$/, ""); rev = $0 } + END { if (name != "") print name, repo, rev } +' SOURCES.toml) + +mkdir -p third_party +while read -r name repo rev; do + [ -n "$name" ] || continue + if [ "$#" -gt 0 ]; then + want=0 + for a in "$@"; do [ "$a" = "$name" ] && want=1; done + [ "$want" = 1 ] || continue + fi + case "$rev" in + *[!0-9a-f]*|"") echo "fetch-sources: $name: rev '$rev' is not a full commit hash" >&2; exit 1 ;; + esac + [ "${#rev}" = 40 ] || { echo "fetch-sources: $name: rev must be 40 hex digits" >&2; exit 1; } + dir="third_party/$(basename "$repo" .git)" + var="RAND_SOURCES_LOCAL_$(echo "$name" | tr '[:lower:]-' '[:upper:]_')" + url="${!var:-$repo}" + if [ -d "$url" ]; then url="file://$(cd "$url" && pwd)"; fi + + if [ -d "$dir/.git" ] && [ "$(git -C "$dir" rev-parse HEAD 2>/dev/null)" = "$rev" ]; then + echo "fetch-sources: $name already at $rev ($dir)" + continue + fi + echo "fetch-sources: $name $rev from $url -> $dir" + [ -d "$dir/.git" ] || git init -q "$dir" + git -C "$dir" fetch -q --depth 1 "$url" "$rev" + git -C "$dir" -c advice.detachedHead=false checkout -q --force "$rev" + got=$(git -C "$dir" rev-parse HEAD) + [ "$got" = "$rev" ] || { echo "fetch-sources: $name: checked out $got, wanted $rev" >&2; exit 1; } +done <<< "$entries"