Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add miller loop in Huff #15

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/miller_loop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
A generator for huff code for parts of BLS12-381 pairing.

# Files

```
main.huff huff source which sets up memory and calls the miller loop
miller_loop.huff huff source for miller loop, generated by gen.py
gen.py encodes the algorithms and outputs huff code to execute the algorithms
miller_loop_bench.json Ethereum test file, with benchmark bytecode under the field "code"

compile.js calls the huff compiler
huff.patch patch to tell huff how to handle evm384 opcodes
```

# Compile

get this directory
```
git clone https://gist.github.com/bf50b9c8f18c33c0883461ede3a4ae8a.git evm384_miller_loop
cd evm384_miller_loop
```

get huff, note: put huff inside the directory `evm384_miller_loop` because the path to huff is hardcoded in `compile.js`
```
git clone https:/AztecProtocol/huff.git
```

patch huff with new opcodes
```
#diff -ruN huff huff_modified > huff.patch
patch -s -p0 < huff.patch
```

get dependencies listed in `huff/package.json`, (don't worry, everything is local to the created dir `node_modules/`, can just delete this dir)
```
cd huff
npm install # note: npm caches packages in /home/<user>/.npm. To remove cache: npm cache clean
cd ..
```

finally generate the evm bytecode for miller loop benchmark
```
python3 gen.py > miller_loop.huff
node compile.js > miller_loop.hex
```
17 changes: 17 additions & 0 deletions src/miller_loop/compile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const path = require('path');
const fs = require('fs');

const { compiler } = require('./huff/src');
const parser = require('./huff/src/parser');

const pathToData = path.posix.resolve(__dirname, './');

const { inputMap, macros, jumptables } = parser.parseFile('main.huff', pathToData);

const {
data: { bytecode: macroCode },
//} = parser.processMacro('MILLER_LOOP_TEST_HARDCODED', 0, [], macros, inputMap, jumptables);
} = parser.processMacro('MILLER_LOOP_BENCH', 0, [], macros, inputMap, jumptables);

console.log("0x"+macroCode)

Loading