Skip to content

Commit

Permalink
translate to C++ and make it pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jwasinger committed Aug 11, 2020
1 parent 5e95642 commit 9735ad8
Show file tree
Hide file tree
Showing 8 changed files with 528 additions and 849 deletions.
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:/ethereum/evmc
[submodule "src/native/intx"]
path = src/native/intx
url = https:/chfast/intx
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ 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

Expand Down
9 changes: 4 additions & 5 deletions 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
3 changes: 2 additions & 1 deletion src/native/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required (VERSION 3.0)
project (f6m_mul_native)

add_executable(f6m_mul_native f6m_mul.c)
include_directories(./intx/include)
add_executable(f6m_mul_native f6m_mul.cpp)
Loading

0 comments on commit 9735ad8

Please sign in to comment.