{"id":2356,"date":"2022-10-30T15:49:45","date_gmt":"2022-10-30T20:49:45","guid":{"rendered":"http:\/\/www.ishygddt.xyz\/~blog\/?p=2356"},"modified":"2023-01-30T19:08:14","modified_gmt":"2023-01-31T01:08:14","slug":"getting-scale-mamba-working","status":"publish","type":"post","link":"http:\/\/www.ishygddt.xyz\/~blog\/2022\/10\/getting-scale-mamba-working","title":{"rendered":"Getting SCALE-MAMBA working"},"content":{"rendered":"<p><a href=\"https:\/\/homes.esat.kuleuven.be\/~nsmart\/SCALE\/\">https:\/\/homes.esat.kuleuven.be\/~nsmart\/SCALE\/<\/a><br \/>\n<a href=\"https:\/\/github.com\/KULeuven-COSIC\/SCALE-MAMBA\">https:\/\/github.com\/KULeuven-COSIC\/SCALE-MAMBA<\/a><\/p>\n<p>I opted to use their Nix shell file to avoid tainting the rest of my system with potentially incompatible junk. Feel free to use whatever other hazmat quarantine procedures strike your fancy (Docker, VMs, whatever). (EDIT: this doesn't <em>completely<\/em> work, sadly, as some of its build scripts call cargo, which touches your home directory. Alas.)<\/p>\n<ul>\n<li>Due to the presence of (P)CLMUL\u2014(polynomial) carry-less multiplication\u2014instructions in the source code, you (for now) <strong>cannot<\/strong> run this software on Intel Nehalem, AMD 10h\/K10, AMD Bobcat, or older CPUs. \ud83d\ude29\n<ul>\n<li>If you have such a CPU, apply my patch to <a href=\"https:\/\/github.com\/KULeuven-COSIC\/SCALE-MAMBA\/blob\/6449e807c99c68203f6584166a7130055da52adb\/src\/Math\/gf2n.h#L499-L516\"><code class=\"language-shell\" data-line=\"\">src\/Math\/gf2n.h@mul128<\/code><\/a> <strong>immediately after<\/strong> cloning the main repo:<br \/>\n<code class=\"\" data-line=\"\">git fetch --depth=50<br \/>\n&quot;https:\/\/github.com\/JamesTheAwesomeDude\/SCALE-MAMBA.git&quot;<br \/>\n&quot;feature\/nehalem_k10&quot;:&quot;feature\/nehalem_k10&quot; &amp;&amp; git -c<br \/>\n&quot;user.name=Anonymous&quot; -c &quot;user.email=nobody@localhost&quot; merge --no-commit<br \/>\n&quot;feature\/nehalem_k10&quot;<\/code><\/p>\n<ul>\n<li>As of 2023-01-14, the patch is <strong>necessary and sufficient<\/strong> to run the Rust player binary!<\/li>\n<li>As of 2023-01-14, the patch is <strong>insufficient<\/strong> to run the classic player binary! (It seems to be making calls to GMP that screw everything up.)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>Nix without root was achieved via the <strong>static binary<\/strong> at <a href=\"https:\/\/github.com\/nix-community\/nix-user-chroot\/releases\/latest\">https:\/\/github.com\/nix-community\/nix-user-chroot\/releases\/latest<\/a>\n<ul>\n<li><em>After<\/em> you've got this installed and set up, the oneshot to open a Nix session is:<br \/>\n<code class=\"language-shell\" data-line=\"\">exec nix-user-chroot ~\/.nix bash -l<\/code><\/li>\n<\/ul>\n<\/li>\n<li><strong>Regardless<\/strong> of how you use Nix\u2014system, OS, singleuser, multiuser, or chrooted\u2014the development environment can be entered via:<br \/>\n<code class=\"language-shell\" data-line=\"\">nix-shell .\/shell.nix<\/code><\/p>\n<ul>\n<li>On my machine, this took about 11 minutes the first time, and less than 5 seconds on subsequent runs.<\/li>\n<li>NOTE that this step allows you to SKIP installing Rustc, MPIR, OpenSSL, and Crypto++!<\/li>\n<li>The remaining steps assume you're using Nix and <strong>have the nix-shell session open<\/strong>.<\/li>\n<\/ul>\n<\/li>\n<li>You have to create and edit <code class=\"\" data-line=\"\">CONFIG.mine<\/code>; I used <code class=\"\" data-line=\"\">CONFIG<\/code> as a template, inserting \u201c<code class=\"language-shell\" data-line=\"\">..<\/code>\u201d for the first variable and commenting out the second, per the documentation.<br \/>\n<code class=\"language-shell\" data-line=\"\">sed &lt; CONFIG -e &#039;s\/^\\(ROOT \\?= \\?\\).*\/\\1&#039;&quot;..# $(pwd | sed -e &#039;s_\/_\\\\\\\/_g&#039;)&quot;&#039;\/;s*^#\\?\\(OSSL \\?= \\+\\).\\**#\\1&#039;&quot;$(echo &quot;$NIX_CFLAGS_COMPILE&quot; | sed -e &#039;s*.\\*\\(\\(&#039;&quot;${NIX_STORE-\/nix\/store}&quot;&#039;\/[^ \\:]\\*\\(openssl[^ :]\\*\\)-dev\\)\/include\\).\\**\\2*&#039;)&quot;&#039;*&#039; &gt; CONFIG.mine<\/code><\/li>\n<li>Be sure to follow the \u201cIdiot's Installation\u201d section if you can't be bothered to set up a CA for peer authentication during testing:<br \/>\n<code class=\"language-shell\" data-line=\"\">cp -v Auto-Test-Data\/Cert-Store\/* Cert-Store\/; cp -v Auto-Test-Data\/1\/* Data\/<\/code><\/li>\n<li>Compile:<br \/>\n<code class=\"language-shell\" data-line=\"\">time ( set -e; export USE_RUST=1; if [ -n &quot;${NIX_STORE+1}&quot; ]; then export NIX_OS_BUILD=&quot;${NIX_OS_BUILD-WORKAROUND for https:\/\/github.com\/KULeuven-COSIC\/SCALE-MAMBA\/blob\/6449e807c99c68203f6584166a7130055da52adb\/src\/build.rs#L72}&quot;; fi; make -j&quot;$(nproc || echo 1)&quot; progs; .\/compile.sh Programs\/tutorial; cargo build -j&quot;$(nproc || echo 1)&quot; --verbose --bin player )<\/code><\/li>\n<li>Execute:<br \/>\n<code class=\"language-shell\" data-line=\"\">time ( for n in $(grep -oP &#039;^(\\d+)(?=.*(P\\d+)$)&#039; &lt; Data\/NetworkData.txt | uniq); do USE_RUST=$(( $RANDOM % 2 )) .\/Player.x &quot;$n&quot; Programs\/tutorial &amp; done; wait )<\/code><\/p>\n<ul>\n<li>To get a stack trace for the old binary:<br \/>\n<code class=\"language-shell\" data-line=\"\">time ( for n in $(grep -oP &#039;^(\\d+)(?=.*(P\\d+)$)&#039; &lt; Data\/NetworkData.txt | uniq); do gdb PlayerBinary.x -batch -ex &quot;run 0 Programs\/tutorial&quot; -ex &quot;bt&quot; -ex &quot;disassemble&quot;  | grep -C5 -P &#039;^(?=\\S)&#039; &amp; done; wait )<\/code><\/li>\n<li>To get a stack trace for the Rust binary:<br \/>\n<code class=\"language-shell\" data-line=\"\">time ( export RUST_BACKTRACE=1; for n in $(grep -oP &#039;^(\\d+)(?=.*(P\\d+)$)&#039; &lt; Data\/NetworkData.txt | uniq); do cargo run --bin player &quot;$n&quot; Programs\/tutorial &amp; done; wait )<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>a wandering pile of shell script fragments to get the most robust\u2014and most technically bankrupt\u2014secure multiparty computing library working<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,97],"tags":[],"class_list":["post-2356","post","type-post","status-publish","format-standard","hentry","category-drafts","category-original-content"],"_links":{"self":[{"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/posts\/2356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/comments?post=2356"}],"version-history":[{"count":93,"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/posts\/2356\/revisions"}],"predecessor-version":[{"id":2371,"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/posts\/2356\/revisions\/2371"}],"wp:attachment":[{"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/media?parent=2356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/categories?post=2356"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/tags?post=2356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}