Skip to content

Commit

Permalink
Merge up
Browse files Browse the repository at this point in the history
  • Loading branch information
prozacchiwawa committed Sep 27, 2023
2 parents 46ce12e + bbc4523 commit 63f0fd5
Show file tree
Hide file tree
Showing 92 changed files with 5,174 additions and 59 deletions.
25 changes: 20 additions & 5 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,26 @@ jobs:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
- name: Install tarpaulin
run: cargo +nightly install cargo-tarpaulin
- name: Run tarpaulin
run: cargo tarpaulin --no-dead-code --engine llvm --workspace --all-features --ignore-panics --out Lcov
toolchain: stable
- name: Run for coverage
run: |
sudo apt-get update
sudo apt-get install lcov -y
rustup component add llvm-tools-preview
cargo install grcov
export RUSTFLAGS="-Cinstrument-coverage"
export LLVM_PROFILE_FILE=$(pwd)/target/clvm_tools_rs-%p-%m.profraw
export CARGO_TARGET_DIR=$(pwd)/target
cargo test --release --workspace
python -m venv venv
source venv/bin/activate
git clone https://github.com/Chia-Network/clvm_tools.git --branch=main --single-branch
pip install ./clvm_tools
pip install maturin pytest
maturin develop --release
(cd resources/tests/cmdline/tests && pytest)
grcov . --binary-path target -s . --branch --ignore-not-existing --ignore='*/.cargo/*' --ignore='*/tests/*' -o rust_cov.info
python -c 'with open("rust_cov.info") as f: lines = [l for l in f if not (l.startswith("DA:") and int(l.split(",")[1].strip()) >= 2**63)]; open("lcov.info", "w").writelines(lines)'
- name: Upload to Coveralls
uses: coverallsapp/github-action@v2
if: always()
Expand Down
120 changes: 120 additions & 0 deletions .github/workflows/extensive-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Taken from clvm_rs' version.
name: Extensive tests

on:
push:
branches:
- main
- dev
tags:
- '**'
pull_request:
branches:
- '**'

jobs:
extensive_tests:
name: Extensive tests
runs-on: ubuntu-latest
strategy:
fail-fast: false

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up rusts
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy

- name: Set up rust (stable)
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy

- uses: actions/setup-python@v4
name: Install Python 3.11
with:
python-version: 3.11

- name: Update pip
run: |
python -m pip install --upgrade pip
- name: Set up rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable

- name: Install dependencies
run: |
python -m pip install maturin==1.1.0
- name: Build Linux in manylinux2010 with maturin on Python ${{ matrix.python }}
run: |
podman run --rm=true \
-v ${{ github.workspace }}:/ws:rw --workdir=/ws \
ghcr.io/chia-network/build-images/centos-pypa-rust-x86_64 \
bash -exc '\
yum -y install libc6 openssl-devel && \
source $HOME/.cargo/env && \
rustup target add x86_64-unknown-linux-musl && \
rm -rf venv && \
PY_VERSION=${{ matrix.python }}
PY_VERSION=${PY_VERSION/.} && \
echo "Python version with dot removed is $PY_VERSION" && \
if [ "$PY_VERSION" = "37" ]; \
then export SCND_VERSION="${PY_VERSION}m"; \
else export SCND_VERSION="$PY_VERSION"; fi && \
echo "Exporting path /opt/python/cp$PY_VERSION-cp$SCND_VERSION/bin" && \
export PATH=/opt/python/cp$PY_VERSION-cp$SCND_VERSION/bin/:$PATH && \
/opt/python/cp38-cp38/bin/python -m venv venv && \
if [ ! -f "activate" ]; then ln -s venv/bin/activate; fi && \
. ./activate && \
pip install --upgrade pip
'
docker run --rm -v $(pwd):/io ghcr.io/pyo3/maturin:v1.1.0 build --release --strip --manylinux 2014
# Refresh in case any ownerships changed.
mv target target.docker && cp -r target.docker target
# Ensure an empty .cargo-lock file exists.
touch target/release/.cargo-lock
- name: Install clvm_tools_rs wheel
if: ${{ !startsWith(matrix.os, 'windows') }}
run: |
. ./activate
ls target/wheels/
# this mess puts the name of the `.whl` file into `$WHEEL_PATH`
# remove the dot, use the `glob` lib to grab the file from the directory
export WHEEL_PATH=$(echo ${{ matrix.python }} | python -c 'DOTLESS=input().replace(".", ""); import glob; print(" ".join(filter(lambda x: "musl" not in x, glob.glob("target/wheels/clvm_tools_rs-*-cp*-*.whl"))))' )
echo ${WHEEL_PATH}
pip install ${WHEEL_PATH}
- name: Install other wheels
run: |
. ./activate
python -m pip install pytest
python -m pip install blspy
- name: install clvm & clvm_tools
run: |
. ./activate
git clone https://github.com/Chia-Network/clvm.git --branch=main --single-branch
python -m pip install ./clvm
echo "installing clvm_rs via pip"
pip install clvm_rs
echo "installing clvm_tools for clvm tests"
# clvm tools is required to run the tests is clvm
python -m pip install clvm_tools
- name: Run game referee test
run: |
. ./activate
cp support/test-game-referee.sh .
sh test-game-referee.sh resources/tests/game-referee-in-cl21
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
SECRET: "${{ secrets.NPM_TOKEN }}"

- name: Publish wasm
if: env.FULL_RELEASE == 'true' && steps.check_secrets.HAS_SECRET
if: env.FULL_RELEASE == 'true' && steps.check_secrets.outputs.HAS_SECRET
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
working-directory: ${{ github.workspace }}/wasm/pkg
Expand Down
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ wasm/tests/node_modules
resources/tests/bridgeref/*.sym
resources/tests/bridgeref/*.clvm.hex
resources/tests/gameref21/*.sym
resources/tests/gameref21/*.clvm.hex
resources/tests/gameref21/*.clvm.hex
resources/tests/gameref21/*.clvm.hex
resources/tests/game-referee/*.sym
resources/tests/game-referee/*.clvm.hex
__pycache__
.pytest_cache
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ Skipped
- &rest arguments.
- new bls and sec256 operators.

## 0.1.36

- modern lambda added
- updated some internal data strucutres and call interfaces to support env variable renaming at during closure generation / lambda capture, or any step during transformation.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clvm_tools_rs"
version = "0.1.35"
version = "0.1.36"
edition = "2018"
authors = ["Art Yerkes <[email protected]>"]
description = "tools for working with chialisp language; compiler, repl, python and wasm bindings"
Expand Down
12 changes: 12 additions & 0 deletions resources/tests/game-referee-in-cl21/all-in-list.clinc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(
(defun enquote-rest (L)
(if L
(c (c 1 (f L)) (enquote-rest (r L)))
()
)
)

(defun all-in-list (L)
(a (c 34 (enquote-rest L)) ())
)
)
8 changes: 8 additions & 0 deletions resources/tests/game-referee-in-cl21/assert.clinc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(
(defmacro assert items
(if (r items)
(list if (f items) (c assert (r items)) (q . (x)))
(f items)
)
)
)
11 changes: 11 additions & 0 deletions resources/tests/game-referee-in-cl21/busy.clinc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(
(defun busy (myfunc mylist returnval)
(if mylist
(last
(a myfunc (list (f mylist)))
(busy myfunc (r mylist) returnval)
)
returnval
)
)
)
41 changes: 41 additions & 0 deletions resources/tests/game-referee-in-cl21/condition_codes.clinc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
; See chia/types/condition_opcodes.py

(
(defconstant AGG_SIG_UNSAFE 49)
(defconstant AGG_SIG_ME 50)

; the conditions below reserve coin amounts and have to be accounted for in output totals

(defconstant CREATE_COIN 51)
(defconstant RESERVE_FEE 52)

; the conditions below deal with announcements, for inter-coin communication

; coin announcements
(defconstant CREATE_COIN_ANNOUNCEMENT 60)
(defconstant ASSERT_COIN_ANNOUNCEMENT 61)

; puzzle announcements
(defconstant CREATE_PUZZLE_ANNOUNCEMENT 62)
(defconstant ASSERT_PUZZLE_ANNOUNCEMENT 63)

; the conditions below let coins inquire about themselves

(defconstant ASSERT_MY_COIN_ID 70)
(defconstant ASSERT_MY_PARENT_ID 71)
(defconstant ASSERT_MY_PUZZLEHASH 72)
(defconstant ASSERT_MY_AMOUNT 73)

; the conditions below ensure that we're "far enough" in the future

; wall-clock time
(defconstant ASSERT_SECONDS_RELATIVE 80)
(defconstant ASSERT_SECONDS_ABSOLUTE 81)

; block index
(defconstant ASSERT_HEIGHT_RELATIVE 82)
(defconstant ASSERT_HEIGHT_ABSOLUTE 83)

; A condition that is always true and always ignore all arguments
(defconstant REMARK 1)
)
92 changes: 92 additions & 0 deletions resources/tests/game-referee-in-cl21/curry-and-treehash.clinc
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
(
;; The code below is used to calculate of the tree hash of a curried function
;; without actually doing the curry, and using other optimization tricks
;; like unrolling `shatree`.

(defconstant ONE 1)
(defconstant TWO 2)
(defconstant A_KW #a)
(defconstant Q_KW #q)
(defconstant C_KW #c)

;; Given the tree hash `environment-hash` of an environment tree E
;; and the tree hash `parameter-hash` of a constant parameter P
;; return the tree hash of the tree corresponding to
;; `(c (q . P) E)`
;; This is the new environment tree with the addition parameter P curried in.
;;
;; Note that `(c (q . P) E)` = `(c . ((q . P) . (E . 0)))`

(defun-inline update-hash-for-parameter-hash (parameter-hash environment-hash)
(sha256 TWO (sha256 ONE C_KW)
(sha256 TWO (sha256 TWO (sha256 ONE Q_KW) parameter-hash)
(sha256 TWO environment-hash (sha256 ONE 0))))
)

;; This function recursively calls `update-hash-for-parameter-hash`, updating `environment-hash`
;; along the way.

(defun build-curry-list (reversed-curry-parameter-hashes environment-hash)
(if reversed-curry-parameter-hashes
(build-curry-list (r reversed-curry-parameter-hashes)
(update-hash-for-parameter-hash (f reversed-curry-parameter-hashes) environment-hash))
environment-hash
)
)

;; Given the tree hash `environment-hash` of an environment tree E
;; and the tree hash `function-hash` of a function tree F
;; return the tree hash of the tree corresponding to
;; `(a (q . F) E)`
;; This is the hash of a new function that adopts the new environment E.
;; This is used to build of the tree hash of a curried function.
;;
;; Note that `(a (q . F) E)` = `(a . ((q . F) . (E . 0)))`

(defun-inline tree-hash-of-apply (function-hash environment-hash)
(sha256 TWO (sha256 ONE A_KW)
(sha256 TWO (sha256 TWO (sha256 ONE Q_KW) function-hash)
(sha256 TWO environment-hash (sha256 ONE 0))))
)

;; function-hash:
;; the hash of a puzzle function, ie. a `mod`
;;
;; reversed-curry-parameter-hashes:
;; a list of pre-hashed trees representing parameters to be curried into the puzzle.
;; Note that this must be applied in REVERSED order. This may seem strange, but it greatly simplifies
;; the underlying code, since we calculate the tree hash from the bottom nodes up, and the last
;; parameters curried must have their hashes calculated first.
;;
;; we return the hash of the curried expression
;; (a (q . function-hash) (c (cp1 (c cp2 (c ... 1)...))))
;;
;; Note that from a user's perspective the hashes passed in here aren't simply
;; the hashes of the desired parameters, but their treehash representation since
;; that's the form we're assuming they take in the actual curried program.

(defun puzzle-hash-of-curried-function (function-hash . reversed-curry-parameter-hashes)
(tree-hash-of-apply function-hash
(build-curry-list reversed-curry-parameter-hashes (sha256 ONE ONE)))
)

(defconstant b32 32)

(defun-inline size_b32 (var)
(= (strlen var) b32)
)

(defun calculate_coin_id (parent puzzlehash amount)
(if (all (size_b32 parent) (size_b32 puzzlehash) (> amount -1))
(sha256 parent puzzlehash amount)
(x)
)
)

; takes a lisp tree and returns the hash of it
(defun shatree (TREE)
(if (l TREE)
(sha256 2 (shatree (f TREE)) (shatree (r TREE)))
(sha256 1 TREE)))

)
Loading

0 comments on commit 63f0fd5

Please sign in to comment.