-
Notifications
You must be signed in to change notification settings - Fork 0
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
Browser integration of prover #10
Open
diS3e
wants to merge
18
commits into
main
Choose a base branch
from
browser-prover
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0b2a08e
fix: remove changelog from cabal
diS3e e6f4011
fix: rename to `zkfold-prover`
diS3e 6f35322
fix: cabal
diS3e b3506a4
fix: full path to Cargo.toml
diS3e 46a31d1
fix: update to symbolic-base
diS3e a3c1417
feat: add rust polynomial division
diS3e 314c0a4
break cabal build
diS3e 6af46e3
draft: debug info
diS3e 93a012b
fix: path in dependency build
diS3e 88d39f8
fix: filter directories
diS3e a19a725
fix: path to rust-wrapper
diS3e 5bd9446
fix: path
diS3e d91d467
stylish-haskell auto-commit
diS3e f6df7c7
fix: artifact-dir path
diS3e d1fad63
fix: update gitignore
diS3e e79ab6c
fix: unused imports
diS3e fec9927
draft: add RustBLS
diS3e 0d545ef
stylish-haskell auto-commit
diS3e File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,50 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
import Control.Exception (throwIO) | ||
import Control.Monad | ||
import Data.Char (isSpace) | ||
import Data.List (dropWhile, isPrefixOf) | ||
import Data.List (dropWhile, find, findIndex, isPrefixOf, tails) | ||
import Data.Maybe (fromJust) | ||
import Distribution.Simple | ||
import Distribution.Types.HookedBuildInfo | ||
import PseudoMacros | ||
import System.Directory | ||
import System.Exit | ||
import System.Process (readProcess, system) | ||
|
||
main :: IO () | ||
main = defaultMainWithHooks simpleUserHooks | ||
{ preConf = buildRustLib | ||
{ | ||
preConf = buildRustLib | ||
} | ||
|
||
buildRustLib :: Args -> a -> IO HookedBuildInfo | ||
buildRustLib _ flags = do | ||
|
||
buildResult <- system "cargo +nightly cbuild --release --manifest-path rust-wrapper/Cargo.toml" | ||
case buildResult of | ||
ExitSuccess -> return () | ||
ExitFailure exitCode -> throwIO $ userError $ "Build rust library failed with exit code " <> show exitCode | ||
let file = $__FILE__ | ||
let pathToDistNewstyle = take (fromJust $ findIndex (isPrefixOf "dist-newstyle") (tails file)) file | ||
|
||
isNotDependency <- doesFileExist (pathToDistNewstyle ++ "rust-wrapper/Cargo.toml") | ||
|
||
output <- readProcess "rustc" ["--version", "--verbose"] "" | ||
case filter ("host: " `isPrefixOf`) (lines output) of | ||
[line] -> do | ||
let host = dropWhile isSpace $ drop 5 line | ||
pathToLib = "rust-wrapper/target/" <> host <> "/release/librust_wrapper.so" | ||
pathToRustWrapper <- if isNotDependency | ||
then return pathToDistNewstyle | ||
else do | ||
contents <- listDirectory (pathToDistNewstyle ++ "dist-newstyle/src/") | ||
print $ contents | ||
depLibs <- filterM (\p -> do | ||
let prefixCond = isPrefixOf "zkfold-pr" p | ||
dirCond <- doesDirectoryExist (pathToDistNewstyle ++ "dist-newstyle/src/" ++ p) | ||
return $ dirCond && prefixCond) contents | ||
print $ depLibs | ||
return $ pathToDistNewstyle ++ "dist-newstyle/src/" ++ (head depLibs) ++ "/" | ||
|
||
libExist <- doesFileExist pathToLib | ||
unless libExist $ throwIO $ userError "Can't find rust library" | ||
buildResult <- system ("cargo +nightly build --release " ++ | ||
"--manifest-path " ++ pathToRustWrapper ++ "rust-wrapper/Cargo.toml " ++ | ||
"--artifact-dir=" ++ pathToDistNewstyle ++ "libs/ -Z unstable-options" | ||
) | ||
|
||
copyFile pathToLib "./lib.so" | ||
case buildResult of | ||
ExitSuccess -> return () | ||
ExitFailure exitCode -> do | ||
throwIO $ userError $ "Build rust library failed with exit code " <> show exitCode | ||
|
||
_ -> throwIO $ userError "Can't find default rust target" | ||
return emptyHookedBuildInfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
module Main where | ||
|
||
import Control.DeepSeq (force) | ||
import Control.Exception (evaluate) | ||
import Control.Monad (replicateM) | ||
import Data.Tuple.Extra | ||
import qualified Data.Vector as V | ||
import Foreign | ||
import Prelude hiding (sum, (*), (+), (-), (/), (^)) | ||
import qualified Prelude as P | ||
import RustFunctions (rustDivFft) | ||
import System.Random (randomIO) | ||
import Test.Tasty.Bench | ||
|
||
import ZkFold.Base.Algebra.Basic.Class | ||
import ZkFold.Base.Algebra.Basic.Field | ||
import ZkFold.Base.Algebra.Basic.Number (Prime) | ||
import ZkFold.Base.Algebra.EllipticCurve.BLS12_381 | ||
import ZkFold.Base.Algebra.Polynomials.Univariate | ||
-- | Generate random polynomials of given size | ||
-- | ||
polynomials :: forall a. Prime a => Int -> IO (Poly (Zp a), Poly (Zp a)) | ||
polynomials size = do | ||
coeffs1 <- replicateM size (toZp @a <$> randomIO) | ||
coeffs2 <- replicateM size (toZp @a <$> randomIO) | ||
evaluatedCoeffs1 <- evaluate . force . V.fromList $ coeffs1 | ||
evaluatedCoeffs2 <- evaluate . force . V.fromList $ coeffs2 | ||
pure (toPoly evaluatedCoeffs1, toPoly evaluatedCoeffs2) | ||
|
||
sizes :: [Int] | ||
sizes = ((2 :: Int) P.^) <$> [10 .. 14 :: Int] | ||
|
||
ops :: forall a . (Eq a, Field a, Storable a) => [(String, Poly a -> Poly a -> (Poly a, Poly a))] | ||
ops = [ ("Haskell division", qr) | ||
, ("Rust division", \x y -> both toPoly (rustDivFft @a (fromPoly x) (fromPoly y))) | ||
] | ||
|
||
benchOps :: Prime a => Int -> [(String, Poly (Zp a) -> Poly (Zp a) -> (Poly (Zp a), Poly (Zp a)) )] -> Benchmark | ||
benchOps size testOps = env (polynomials size) $ \ ~(p1, p2) -> | ||
bgroup ("Multiplying polynomials of size " <> show size) $ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The bench description should be updated. |
||
flip fmap testOps $ \(desc, op) -> bench desc $ nf (uncurry op) (p1, p2) | ||
|
||
main :: IO () | ||
main = do | ||
defaultMain | ||
[ bgroup "Field without roots of unity" $ flip fmap sizes $ \s -> benchOps @BLS12_381_Base s ops | ||
, bgroup "Field with roots of unity" $ flip fmap sizes $ \s -> benchOps @BLS12_381_Scalar s ops | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
packages: . | ||
|
||
source-repository-package | ||
type: git | ||
location: https://github.com/BeFunctional/haskell-foreign-rust.git | ||
tag: 90b1c210ae4e753c39481a5f3b141b74e6b6d96e | ||
|
||
source-repository-package | ||
type: git | ||
location: https://github.com/zkFold/zkfold-base.git | ||
tag: 204a983ce39dd683c1776a0c54a6fb02e53305f6 | ||
tag: c8d4695e7f5e0140b76d819f82c4d41d1510b385 | ||
subdir: symbolic-base |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am getting an unexpected result that Rust implementation slower than the Haskell one. Does it make sense to compare
qr
with polynomial division using FFT?