Skip to content
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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ v3:
v2:
./deps/v2/solidity/build/solc/solc --strict-assembly --optimize src/v2/benchmark.yul | awk '/Binary representation:/ { getline; print $0 }' | grep . > build/v2-f6m_mul_bench.bin
./deps/v2/solidity/build/solc/solc --strict-assembly --optimize src/v2/test.yul | awk '/Binary representation:/ { getline; print $0 }' | grep . > build/v2-test.bin
./deps/v2/solidity/build/solc/solc --strict-assembly --optimize src/v2/f2m_mul_benchmark.yul | awk '/Binary representation:/ { getline; print $0 }' | grep . > build/v2-f2m_mul_bench.bin
v2_no_curve_params:
./deps/v2-no-curve-params/solidity/build/solc/solc --strict-assembly --optimize src/v2-no-curve-params/benchmark.yul | awk '/Binary representation:/ { getline; print $0 }' | grep . > build/v2-no-curve-params-f6m_mul_bench.bin
./deps/v2-no-curve-params/solidity/build/solc/solc --strict-assembly --optimize src/v2-no-curve-params/test.yul | awk '/Binary representation:/ { getline; print $0 }' | grep . > build/v2-no-curve-params-test.bin
v3_no_curve_params:
./deps/v2-no-curve-params/solidity/build/solc/solc --strict-assembly --optimize src/v3-no-curve-params/benchmark.yul | awk '/Binary representation:/ { getline; print $0 }' | grep . > build/v3-no-curve-params-f6m_mul_bench.bin


v1:
./deps/v1/solidity/build/solc/solc --strict-assembly --optimize src/v1/benchmark.yul | awk '/Binary representation:/ { getline; print $0 }' | grep . > build/v1-f6m_mul_bench.bin

Expand Down
4 changes: 4 additions & 0 deletions benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ set -e

./deps/v3/evmone/build/bin/evmone-bench --benchmark_format=json --benchmark_color=false --benchmark_min_time=5 build/v3-f6m_mul_bench.bin 00 74229fc665e6c3f4401905c1a454ea57c8931739d05a074fd60400f19684d680a9e1305c25f13613dcc6cdd6e6e57d0800000000000000000000000000000000 | python3 catch_evmone_bench_err.py
./deps/v3-no-curve-params/evmone/build/bin/evmone-bench --benchmark_format=json --benchmark_color=false --benchmark_min_time=5 build/v3-no-curve-params-f6m_mul_bench.bin 00 74229fc665e6c3f4401905c1a454ea57c8931739d05a074fd60400f19684d680a9e1305c25f13613dcc6cdd6e6e57d0800000000000000000000000000000000 | python3 catch_evmone_bench_err.py
./deps/v3-no-curve-params/evmone/build/bin/evmone-bench --benchmark_format=json --benchmark_color=false --benchmark_min_time=5 build/v3-no-curve-params-f2m_mul_bench.bin 00 aff6e01e71b0709e0f7f6528dd81ea41aed732761d712e6884576a7b04a9490e64be863464e7b928ab4a709d2e2e7b0e00000000000000000000000000000000bb65fcee5ae7b04cef799771e1fd0e597838d8088633a9f99a3e9c62d4d48989b3ef3e3451ad30b40dedb7b6f928ae1400000000000000000000000000000000 | python3 catch_evmone_bench_err.py

# test yul f2m_mul loop
./deps/v2/evmone/build/bin/evmone-bench --benchmark_format=json --benchmark_color=false --benchmark_min_time=5 build/v2-f2m_mul_bench.bin 00 aff6e01e71b0709e0f7f6528dd81ea41aed732761d712e6884576a7b04a9490e64be863464e7b928ab4a709d2e2e7b0e00000000000000000000000000000000bb65fcee5ae7b04cef799771e1fd0e597838d8088633a9f99a3e9c62d4d48989b3ef3e3451ad30b40dedb7b6f928ae1400000000000000000000000000000000 | python3 catch_evmone_bench_err.py
1 change: 1 addition & 0 deletions build/v2-f2m_mul_bench.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
597fabaafffffffffeb9ffff53b1feffab1e24f6b0f6a0d23067bf1285f3844b776481527fd7ac4b43b6a71b4b9ae67f39ea11011a000000000000000000000000000000006020820152604081017f8f2990f3e598f5b1b8f480a3c388306bc023fac151c0104d13ec3aa18159940281527f72d1c8c528a1ce3bcaa280a8e735aa0d0000000000000000000000000000000060608301527f992d7a27906d4cd530b23a7e8c48c0778f8653fbc3332d63db24339d8bc65d7e60808301527fe83b6e91c6550f5aceab102e88e918090000000000000000000000000000000060a083015260c082017f7299907146816f08c4c6a394e91374ed6ff3618a57358cfb124ee6ab4c560e5c81527fac40700b41e2ee8674680728f0c5a6180000000000000000000000000000000060e08401527f0fd77f62b39eb952a0f8d21cec1f93b1d62dd7923aa86882ddf7dd4d3532b0b76101008401527fede8f3fc89fa4a79574067e2d9a9d2000000000000000000000000000000000061012084015261024083016102c084016789f3fffcfffcfffd61019e82828886888a6101e3565b60005b6105468110156101d3576101b983838988888b6101e3565b6101c783838989888a6101e3565b5b6001810190506101a1565b505050608081f350505050610246565b604086016080870160c0880160008152600060e08a015260408501604085018989838387c28884848ac18989888888c28885898ac088848686c088828887c060408801925088818785c050508787848384c286828283c15050505b505050505050565b
1 change: 1 addition & 0 deletions build/v3-no-curve-params-f2m_mul_bench.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
600180610ffa52597f8f2990f3e598f5b1b8f480a3c388306bc023fac151c0104d13ec3aa18159940281527f72d1c8c528a1ce3bcaa280a8e735aa0d0000000000000000000000000000000060208201527f992d7a27906d4cd530b23a7e8c48c0778f8653fbc3332d63db24339d8bc65d7e60408201527fe83b6e91c6550f5aceab102e88e91809000000000000000000000000000000006060820152608081017f7299907146816f08c4c6a394e91374ed6ff3618a57358cfb124ee6ab4c560e5c81527fac40700b41e2ee8674680728f0c5a6180000000000000000000000000000000060a08301527f0fd77f62b39eb952a0f8d21cec1f93b1d62dd7923aa86882ddf7dd4d3532b0b760c08301527fede8f3fc89fa4a79574067e2d9a9d2000000000000000000000000000000000060e08301526102008201610280830161014b8183858761018a565b60005b61054681101561017b576101648285858861018a565b6101708286858761018a565b5b858101905061014e565b5050608081f3505050506101df565b604084016080850160c0860160008152600060e08801526040850160408501818185c2838389c1868686c2848889c0838585c0818786c0604088019250808684c05050828182c2818182c15050505b50505050565b
83 changes: 83 additions & 0 deletions src/v2/f2m_mul_benchmark.yul
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
function zero512(dst) {
mstore(dst, 0)
mstore(add(dst, 32), 0)
}

// r <- x * y
function f2m_mul(x, y, r, modulus, inv, mem) {

let tmp := add(mem, 64)
let tmp2 := add(tmp, 64)
let zero := add(tmp2, 64)
zero512(zero)

// TODO also cache x0y0 calculation

// tmp2 = x1y1
mulmodmont384(tmp2, add(x, 64), add(y, 64), modulus, inv)

//r0 = mulNR(tmp2)
submod384(r, zero, tmp2, modulus)

// tmp = x0y0
mulmodmont384(tmp, x, y, modulus, inv)

//r0 = r0 + tmp (x0y0)
addmod384(r, r, tmp, modulus)

// r1 -------------------------------------

// r1 = ((y0 + y1) * (x0 + x1)) - ((x0 * y0) + (x1 * y1))

// tmp2 <- tmp (x0 * y0) + tmp2 (x1 * y1)
addmod384(tmp2, tmp, tmp2, modulus)

// tmp = y0 + y1
addmod384(tmp, y, add(y, 64), modulus)

// r1 = x0 + x1
addmod384(add(r, 64), x, add(x, 64), modulus)

// r1 <- r1 (x0 + x1) * tmp (y0 + y1)
mulmodmont384(add(r, 64), add(r, 64), tmp, modulus, inv)

// r1 = r1 [(x0 + x1) * (y0 + y1)] - tmp2 [(x0 * y0) + (x1 * y1)]
submod384(add(r, 64), add(r, 64), tmp2, modulus)
}

function test_f2m_mul_loop() {
let bls12_mod := msize()
mstore(bls12_mod, 0xabaafffffffffeb9ffff53b1feffab1e24f6b0f6a0d23067bf1285f3844b7764)
mstore(add(bls12_mod, 32), 0xd7ac4b43b6a71b4b9ae67f39ea11011a00000000000000000000000000000000)

let inv := 0x89f3fffcfffcfffd
let point1_a := add(bls12_mod, 64)
mstore(point1_a, 0x8f2990f3e598f5b1b8f480a3c388306bc023fac151c0104d13ec3aa181599402)
mstore(add(point1_a, 32), 0x72d1c8c528a1ce3bcaa280a8e735aa0d00000000000000000000000000000000)
mstore(add(point1_a, 64), 0x992d7a27906d4cd530b23a7e8c48c0778f8653fbc3332d63db24339d8bc65d7e)
mstore(add(point1_a, 96), 0xe83b6e91c6550f5aceab102e88e9180900000000000000000000000000000000)

let point1_b := add(point1_a, 128)
mstore(point1_b, 0x7299907146816f08c4c6a394e91374ed6ff3618a57358cfb124ee6ab4c560e5c)
mstore(add(point1_b, 32), 0xac40700b41e2ee8674680728f0c5a61800000000000000000000000000000000)
mstore(add(point1_b, 64), 0x0fd77f62b39eb952a0f8d21cec1f93b1d62dd7923aa86882ddf7dd4d3532b0b7)
mstore(add(point1_b, 96), 0xede8f3fc89fa4a79574067e2d9a9d20000000000000000000000000000000000)

let f2m_result := add(point1_b, 384) // allocate memory past bls12_mod

let mem := add(f2m_result, 128)

f2m_mul(point1_a, point1_b, f2m_result, bls12_mod, inv, mem)

let i := 0
for {} lt(i, 1350) {i := add(i, 1)} {
f2m_mul(point1_a, f2m_result, point1_b, bls12_mod, inv, mem)
f2m_mul(point1_b, f2m_result, point1_a, bls12_mod, inv, mem)
}

return(f2m_result, 128)
}

test_f2m_mul_loop()
}