-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
92 changed files
with
5,174 additions
and
59 deletions.
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 |
---|---|---|
@@ -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 |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,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" | ||
|
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,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)) ()) | ||
) | ||
) |
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,8 @@ | ||
( | ||
(defmacro assert items | ||
(if (r items) | ||
(list if (f items) (c assert (r items)) (q . (x))) | ||
(f items) | ||
) | ||
) | ||
) |
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,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
41
resources/tests/game-referee-in-cl21/condition_codes.clinc
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,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
92
resources/tests/game-referee-in-cl21/curry-and-treehash.clinc
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,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))) | ||
|
||
) |
Oops, something went wrong.