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

feat: wasm binary for the oracle resolvers #78

Draft
wants to merge 18 commits into
base: kb/oracles
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
35 changes: 34 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,38 @@ jobs:
uses: noir-lang/[email protected]
with:
toolchain: ${{ matrix.toolchain }}
# run the PRC server in the oracles directory in the background

# install wasm-bindgen-cli with the version specified in the cargo.toml file
- name: Install wasm-bindgen-cli
run: |
if ! command -v wasm-bindgen &> /dev/null || [ "$(wasm-bindgen --version | cut -d' ' -f2)" != "0.2.86" ]; then
echo "Building wasm-bindgen..."
cargo install cargo-binstall
cargo binstall [email protected] --force --no-confirm
fi
# - name: Install wasm32 target
# run: rustup target add wasm32-unknown-unknown
# run the build.sh script in the oracles directory
# cargo build
# or alternatively as a simple command:
- name: Add wasm target
run: rustup target add wasm32-unknown-unknown
- name: Run build.sh
run: |
cd oracles && ./build.sh
# run yarn install in the oracles directory
- name: Run yarn install
uses: borales/actions-yarn@v4
with:
cmd: install
dir: oracles
# run the tests
- name: Run tests
uses: borales/actions-yarn@v4
with:
cmd: test
dir: oracles
# run the PRC server
- name: run the PRC server
run: |
cd oracles && cargo build
Expand All @@ -41,6 +72,8 @@ jobs:
# Wait for port 3000 to become available
timeout 30 bash -c 'until nc -z localhost 3000; do sleep 1; done'
echo "Server is ready!"

# run the noir tests with the oracle resolver
- name: Run Noir tests with oracle resolver.
run: nargo test --oracle-resolver http://127.0.0.1:3000

Expand Down
5 changes: 5 additions & 0 deletions oracles/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extension": ["ts"],
"spec": "test/node/**/*.test.ts",
"require": "ts-node/register"
}
111 changes: 111 additions & 0 deletions oracles/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 19 additions & 6 deletions oracles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,35 @@ name = "oracle"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
# For the server
anyhow = "1"
# hyper = "1.5.0"
jsonrpsee = { version = "0.24.7", features = ["server", "http-client", "ws-client", "macros", "client-ws-transport-tls"] }
serde = "1.0.213"
serde_json = "1.0.132"
tokio = "1.41.0"
tokio-stream = { version = "0.1.16", features = ["sync"] }
# tower = { version = "0.4.13", features= ["full"]}
# tower-http = { version = "0.6.1", features = ["full"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }

getrandom = { version = "*", features = ["js"] }
serde = {version = "1.0.213", features = ["derive"]}
serde_json = "1.0.132"
# For the example ops
ark-bn254 = "0.4.0"
ark-ff = "0.4.2"
num-bigint = "0.4.6" # todo: find a way to remove this dep
num-traits = "0.2.19" # todo: find a way to remove this dep
wasm-bindgen = { version = "=0.2.86", features = ["serde-serialize"] }
gloo-utils = { version = "0.1", features = ["serde"] }
js-sys = "0.3.62"
console_error_panic_hook = "0.1.7"


[target.'cfg(not(target_arch = "wasm32"))'.dependencies]

jsonrpsee = { version = "0.24.7", features = ["server", "http-client", "ws-client", "macros", "client-ws-transport-tls"] }
tokio = "1.41.0"
tokio-stream = { version = "0.1.16", features = ["sync"] }


53 changes: 53 additions & 0 deletions oracles/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash

function require_command {
if ! command -v "$1" >/dev/null 2>&1; then
echo "Error: $1 is required but not installed." >&2
exit 1
fi
}
function run_or_fail {
"$@"
local status=$?
if [ $status -ne 0 ]; then
echo "Command '$*' failed with exit code $status" >&2
exit $status
fi
}
function run_if_available {
if command -v "$1" >/dev/null 2>&1; then
"$@"
else
echo "$1 is not installed. Please install it to use this feature." >&2
fi
}

require_command jq
require_command cargo
require_command wasm-bindgen
# require_command wasm-opt

self_path=$(dirname "$(readlink -f "$0")")
pname=$(cargo read-manifest | jq -r '.name')

NODE_DIR=$self_path/nodejs
BROWSER_DIR=$self_path/web

# Clear out the existing build artifacts as these aren't automatically removed by wasm-bindgen.
if [ -d ./pkg/ ]; then
rm -r $NODE_DIR
rm -r $BROWSER_DIR
fi

TARGET=wasm32-unknown-unknown
WASM_BINARY=${self_path}/target/$TARGET/release/${pname}.wasm

NODE_WASM=${NODE_DIR}/${pname}_bg.wasm
BROWSER_WASM=${BROWSER_DIR}/${pname}_bg.wasm

# Build the new wasm package
run_or_fail cargo build --lib --release --target $TARGET --package ${pname}
run_or_fail wasm-bindgen $WASM_BINARY --out-dir $NODE_DIR --typescript --target nodejs
run_or_fail wasm-bindgen $WASM_BINARY --out-dir $BROWSER_DIR --typescript --target web
run_if_available wasm-opt $NODE_WASM -o $NODE_WASM -O
run_if_available wasm-opt $BROWSER_WASM -o $BROWSER_WASM -O
1 change: 1 addition & 0 deletions oracles/node_modules/.bin/_mocha

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/acorn

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/browsers

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/cspell

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/cspell-esm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/cspell-gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/cspell-grammar

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/esbuild

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/escodegen

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/esgenerate

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/eslint

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/esparse

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/esvalidate

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/extract-zip

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/flat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/he

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/is-docker

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/js-yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/mkdirp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/mocha

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/nanoid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/node-which

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/playwright

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/playwright-core

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/prettier

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oracles/node_modules/.bin/print-chrome-path

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading