Skip to content
Open
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 .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
[submodule "deps/evmc"]
path = deps/evmc
url = https://github.com/ethereum/evmc
[submodule "src/native/intx"]
path = src/native/intx
url = https://github.com/chfast/intx
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ build_dir:
mkdir build

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

# TODO: v1 test case and fix this Makefile so that solidity causes the build to end when it finds errors
native_cpp:
cd src/native && rm -rf build && mkdir build && cd build && cmake .. && make -j4

circleci_build_image:
docker build -t jwasinger/solc-evm384-v2 -f .circleci/Dockerfile .
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 4 additions & 5 deletions src/v2/test.yul → src/evm/v2/test.yul
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

// 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)
Expand Down Expand Up @@ -115,7 +114,7 @@
// tmp3 <- tmp2 * tmp1
f2m_mul(tmp2, tmp1, tmp3, modulus, inv, arena)

// tmp1 <- aA * bB
// tmp1 <- aA + bB
f2m_add(aA, add(aA, 64), bB, add(bB, 64), tmp1, add(tmp1, 64), modulus, arena)

// tmp2 <- tmp3 - tmp1
Expand Down Expand Up @@ -311,10 +310,10 @@

function test_f2m_mul() {
/*
8f2990f3e598f5b1b8f480a3c388306bc023fac151c0104d13ec3aa18159940272d1c8c528a1ce3bcaa280a8e735aa0d992d7a27906d4cd530b23a7e8c48c0778f8653fbc3332d63db24339d8bc65d7ee83b6e91c6550f5aceab102e88e918097299907146816f08c4c6a394e91374ed6ff3618a57358cfb124ee6ab4c560e5cac40700b41e2ee8674680728f0c5a618 *
ecd347c808af644c7a3a971a556576f434e302b6b490004fb418a4a7da330a6743adeca931169b8b92e91df73ae1e11512a2829e11e843d764d5e3b80e75432d93f69b23ad79c38d43ebbc9bd2b17b9e903033351357b03602624762e5ad360dd7f9857dce663301f393f9fac66f5c49168494e0d20797a6c4f96327ed4fa47dd36d0078d217a712407d35046871d40f =
8f2990f3e598f5b1b8f480a3c388306bc023fac151c0104d13ec3aa18159940272d1c8c528a1ce3bcaa280a8e735aa0d992d7a27906d4cd530b23a7e8c48c0778f8653fbc3332d63db24339d8bc65d7ee83b6e91c6550f5aceab102e88e91809 *
ecd347c808af644c7a3a971a556576f434e302b6b490004fb418a4a7da330a6743adeca931169b8b92e91df73ae1e11512a2829e11e843d764d5e3b80e75432d93f69b23ad79c38d43ebbc9bd2b17b9e903033351357b03602624762e5ad360d =

1a984f235709ab3941e22b5e67d5ba892ce9242e227c0c6bb38aa1ace4d4b64aaba753d350d98f4c05570f525d67a901b1297e4e9ca0c757dfe693ea0d2f5216daeaa4ad06964e2f7c242200049d386d860b25d4718a2c4240fb89c90abe4e10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1a984f235709ab3941e22b5e67d5ba892ce9242e227c0c6bb38aa1ace4d4b64aaba753d350d98f4c05570f525d67a901b1297e4e9ca0c757dfe693ea0d2f5216daeaa4ad06964e2f7c242200049d386d860b25d4718a2c4240fb89c90abe4e10
*/
let mem := msize()

Expand Down
7 changes: 7 additions & 0 deletions src/native/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required (VERSION 3.0)
project (f6m_mul_native)

include_directories(./intx/include)

add_executable(test f6m_mul.h test.cpp)
add_executable(synth_loop_benchmark f6m_mul.h benchmark.cpp)
61 changes: 61 additions & 0 deletions src/native/benchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// #include "f6m_mul.h" TODO how to fix this error?
#include "f6m_mul.cpp"
#include <chrono>

int main(int argc, char **argv) {
F6 p1 {
.a = {
.x = F1(intx::from_string<intx::uint512>("0x0daa35e7a880a2ca3bcea128c5c8d17202945981a13aec134d10c051c1fa23c06b3088c3a380f4b8b1f598e5f390298f")),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.x = F1(intx::from_string<intx::uint512>("0x0daa35e7a880a2ca3bcea128c5c8d17202945981a13aec134d10c051c1fa23c06b3088c3a380f4b8b1f598e5f390298f")),
.x = F1(0x0daa35e7a880a2ca3bcea128c5c8d17202945981a13aec134d10c051c1fa23c06b3088c3a380f4b8b1f598e5f390298f_u512),

.y = F1(intx::from_string<intx::uint512>("0x0918e9882e10abce5a0f55c6916e3be87e5dc68b9d3324db632d33c3fb53868f77c0488c7e3ab230d54c6d90277a2d99")),
},
.b = {
.x = F1(intx::from_string<intx::uint512>("0x18a6c5f02807687486eee2410b7040ac5c0e564cabe64e12fb8c35578a61f36fed7413e994a3c6c4086f814671909972")),
.y = F1(intx::from_string<intx::uint512>("0x00d2a9d9e2674057794afa89fcf3e8edb7b032354dddf7dd8268a83a92d72dd6b1931fec1cd2f8a052b99eb3627fd70f")),
},
.c = {
.x = F1(intx::from_string<intx::uint512>("0x13ac019d8914d7479fe7c4731a4033251a384cb89a53b823e1c635ab7589a4a67eeff9aa243283c4b48c3db146de697a")),
.y = F1(intx::from_string<intx::uint512>("0x181bf207cb40cbf95b6d18e0bf2789982fccb608f7b9fe2b9f78880e569b144d8f27ef73cbda9d1a6ac356810d0bfaa9")),
}
};

F6 p2 {
.a = {
.x = F1(intx::from_string<intx::uint512>("0x15e1e13af71de9928b9b1631a9ecad43670a33daa7a418b44f0090b4b602e334f47665551a973a7a4c64af08c847d3ec")),
.y = F1(intx::from_string<intx::uint512>("0x0d36ade56247620236b05713353330909e7bb1d29bbceb438dc379ad239bf6932d43750eb8e3d564d743e8119e82a212")),
},
.b = {
.x = F1(intx::from_string<intx::uint512>("0x0fd4716804357d4012a717d278006dd37da44fed2763f9c4a69707d2e0948416495c6fc6faf993f3013366ce7d85f9d7")),
.y = F1(intx::from_string<intx::uint512>("0x13a2fd8719f04ccb3910d3b47ff5044cd63ad849bfe1345e74aae8038d54a7e4d26a90e7bca076eb90c11e6c7f761b2f")),
},
.c = {
.x = F1(intx::from_string<intx::uint512>("0x06d6c6cd0b01a8102b1be07b8558d51865b7cd0f3980d8f1e444c4cfcb379f2fedeea333d4b090588847aef2a28d3f7b")),
.y = F1(intx::from_string<intx::uint512>("0x10f6503d1e2158bbdaf82c0121b3880c97ce174a73906ee53cb0e39a3e30fea5a9ad25588b867763788a2c13f6029c31")),
}
};

F6 result {
.a = {
.x = F1(intx::from_string<intx::uint512>("0x0e929cf37e24b30a658a997a1014c38782a91ea00b42d5b62300423b9220cdae82f6712eee5a66acea6850a3e0f4f3f4")),
.y = F1(intx::from_string<intx::uint512>("0x08727ed9bc62fc242e2693adf24da55d65ba14cdadd0fcc021782b29b77cf88a64aaf4a965d123e6ad2ba293d920962c")),
},
.b = {
.x = F1(intx::from_string<intx::uint512>("0x17ca0639b783a2e475f679efe11ce71b280ab24f0f6012a8b7dc9262027006946f57ebea873c094385165e6c8e83d1ea")),
.y = F1(intx::from_string<intx::uint512>("0x0b125bf61e3d5acdd4198c7e2fd3d0af7f23281deaf20de1a555901d60872c9cf60923565d63d70db2455440762c8b9c")),
},
.c = {
.x = F1(intx::from_string<intx::uint512>("0x18c774ca6acaf4bfff4f95a5c4f84e2983ee924817b19b3ebb5fc8db4990e0c15779a845f1beb783c9be4dc7f01e5940")),
.y = F1(intx::from_string<intx::uint512>("0x08130179231df0116c0e2d2100dab1e5a8d29140b2dd79ebadd55250016d7eab84a0ed68bd215152bb635d1c8f2b249b")),
}
};

auto start = std::chrono::system_clock::now();

for (auto i = 0; i < 1350; i++) {
result = p1.Mul(p2);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be too easy to figure out that Mul always produce the same result or result is discarded. Make sure, Mul() is compiled in separate file. I.e. fix https://github.com/ewasm/evm384_f6m_mul/pull/4/files#diff-7a5bec3042d5d314cdc3d35cd7a2411dR1.

}

auto end = std::chrono::system_clock::now();
double elapsed_seconds = std::chrono::duration_cast<
std::chrono::duration<double> >(end - start).count();
std::cout << elapsed_seconds << '\n';
}
Loading