Skip to content

Commit

Permalink
Omnilock (#21)
Browse files Browse the repository at this point in the history
Omnilock
  • Loading branch information
XuJiandong authored Mar 7, 2022
1 parent e570c11 commit ddaeae8
Show file tree
Hide file tree
Showing 45 changed files with 15,636 additions and 33 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ jobs:
run: cd tests/xudt_rce_rust && cargo test
- name: Run xudt simulator tests
run: cd tests/xudt_rce && bash run.sh
- name: Run omni_lock tests
run: cd tests/omni_lock_rust && cargo test
- name: Run omni_lock simulator tests
run: cd tests/omni_lock && bash run.sh
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ tests/xudt_rce/smt_fuzzer/smt_fuzzer.dSYM
smt_coverage
smt_fuzzer
.vscode
tests/omni_lock/simulator-build-debug
cmake-build-debug
tests/validate_signature_rsa/build.simulator
tests/validate_signature_rsa/corpus
Expand All @@ -14,4 +15,6 @@ tests/validate_signature_rsa/dlopen_coverage
tests/validate_signature_rsa/dlopen_fuzzer
tests/validate_signature_rsa/coverage
tests/validate_signature_rsa/fuzz-*.log

tests/omni_lock/exec_fuzzer/exec_fuzzer.dSYM
fuzzer.profraw
fuzzer.profdata
8 changes: 8 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
[submodule "deps/ckb-c-std-lib"]
path = deps/ckb-c-std-lib
url = https://github.com/nervosnetwork/ckb-c-stdlib.git
[submodule "deps/ckb-c-stdlib-20210801"]
path = deps/ckb-c-stdlib-20210801
url = https://github.com/XuJiandong/ckb-c-stdlib.git
branch = ckb-identity
[submodule "deps/ckb-c-stdlib-20210713"]
path = deps/ckb-c-stdlib-20210713
url = https://github.com/nervosnetwork/ckb-c-stdlib.git
Expand All @@ -18,3 +22,7 @@
[submodule "deps/ckb-c-stdlib-20210413"]
path = deps/ckb-c-stdlib-20210413
url = https://github.com/nervosnetwork/ckb-c-stdlib.git
[submodule "deps/secp256k1-20210801"]
path = deps/secp256k1-20210801
url = https://github.com/nervosnetwork/secp256k1.git
branch = schnorr
51 changes: 47 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ OBJCOPY := $(TARGET)-objcopy
CFLAGS := -fPIC -O3 -fno-builtin-printf -fno-builtin-memcmp -nostdinc -nostdlib -nostartfiles -fvisibility=hidden -fdata-sections -ffunction-sections -I deps/secp256k1/src -I deps/secp256k1 -I deps/ckb-c-std-lib -I deps/ckb-c-std-lib/libc -I deps/ckb-c-std-lib/molecule -I c -I build -Wall -Werror -Wno-nonnull -Wno-nonnull-compare -Wno-unused-function -g
LDFLAGS := -Wl,-static -fdata-sections -ffunction-sections -Wl,--gc-sections
SECP256K1_SRC := deps/secp256k1/src/ecmult_static_pre_context.h
SECP256K1_SRC_20210801 := deps/secp256k1-20210801/src/ecmult_static_pre_context.h

XUDT_RCE_CFLAGS=$(subst ckb-c-std-lib,ckb-c-stdlib-20210713,$(CFLAGS)) -I deps/sparse-merkle-tree/c

OMNI_LOCK_CFLAGS :=$(subst ckb-c-std-lib,ckb-c-stdlib-20210801,$(CFLAGS)) -I deps/sparse-merkle-tree/c
OMNI_LOCK_CFLAGS := $(subst secp256k1,secp256k1-20210801,$(OMNI_LOCK_CFLAGS))

PROTOCOL_HEADER := c/blockchain.h
PROTOCOL_SCHEMA := c/blockchain.mol
PROTOCOL_VERSION := d75e4c56ffa40e17fd2fe477da3f98c5578edcd1
Expand All @@ -20,8 +26,9 @@ PASSED_MBEDTLS_CFLAGS := -O3 -fPIC -nostdinc -nostdlib -DCKB_DECLARATION_ONLY -I

# docker pull nervos/ckb-riscv-gnu-toolchain:gnu-bionic-20191012
BUILDER_DOCKER := nervos/ckb-riscv-gnu-toolchain@sha256:aae8a3f79705f67d505d1f1d5ddc694a4fd537ed1c7e9622420a470d59ba2ec3
CLANG_FORMAT_DOCKER := kason223/clang-format@sha256:3cce35b0400a7d420ec8504558a02bdfc12fd2d10e40206f140c4545059cd95d

all: build/simple_udt build/anyone_can_pay build/always_success build/validate_signature_rsa build/xudt_rce build/rce_validator
all: build/simple_udt build/anyone_can_pay build/always_success build/validate_signature_rsa build/xudt_rce build/rce_validator build/omni_lock

all-via-docker: ${PROTOCOL_HEADER}
docker run --rm -v `pwd`:/code ${BUILDER_DOCKER} bash -c "cd /code && make"
Expand All @@ -44,16 +51,31 @@ build/always_success: c/always_success.c
build/secp256k1_data_info.h: build/dump_secp256k1_data
$<

build/secp256k1_data_info_20210801.h: build/dump_secp256k1_data_20210801
$<

build/dump_secp256k1_data: c/dump_secp256k1_data.c $(SECP256K1_SRC)
mkdir -p build
gcc -I deps/secp256k1/src -I deps/secp256k1 -o $@ $<

build/dump_secp256k1_data_20210801: c/dump_secp256k1_data_20210801.c $(SECP256K1_SRC_20210801)
mkdir -p build
gcc -I deps/secp256k1-20210801/src -I deps/secp256k1-20210801 -o $@ $<


$(SECP256K1_SRC):
cd deps/secp256k1 && \
./autogen.sh && \
CC=$(CC) LD=$(LD) ./configure --with-bignum=no --enable-ecmult-static-precomputation --enable-endomorphism --enable-module-recovery --host=$(TARGET) && \
make src/ecmult_static_pre_context.h src/ecmult_static_context.h

$(SECP256K1_SRC_20210801):
cd deps/secp256k1-20210801 && \
./autogen.sh && \
CC=$(CC) LD=$(LD) ./configure --with-bignum=no --enable-ecmult-static-precomputation --enable-endomorphism --enable-module-recovery --host=$(TARGET) && \
make src/ecmult_static_pre_context.h src/ecmult_static_context.h


deps/mbedtls/library/libmbedcrypto.a:
cp deps/mbedtls-config-template.h deps/mbedtls/include/mbedtls/config.h
make -C deps/mbedtls/library CC=${CC} LD=${LD} CFLAGS="${PASSED_MBEDTLS_CFLAGS}" libmbedcrypto.a
Expand Down Expand Up @@ -90,9 +112,15 @@ validate_signature_rsa_clean:
${PROTOCOL_SCHEMA}:
curl -L -o $@ ${PROTOCOL_URL}

ALL_C_SOURCE := $(wildcard c/omni_lock.c c/omni_lock_acp.h c/omni_lock_time_lock.h \
tests/omni_lock/omni_lock_sim.c tests/omni_lock/ckb_syscall_omni_lock_sim.h tests/omni_lock/omni_lock_supply.h\
c/rce_validator.c /always_success.c c/rce.h c/xudt_rce.c \
c/rce_validator.c tests/xudt_rce/*.c tests/xudt_rce/*.h\
c/validate_signature_rsa.h c/validate_signature_rsa.c)

fmt:
clang-format -i -style=Google $(wildcard c/rce_validator.c /always_success.c c/anyone_can_pay.c c/smt.h c/rce.h c/xudt_rce.c c/rce_validator.c tests/xudt_rce/*.c tests/xudt_rce/*.h)
git diff --exit-code $(wildcard c/rce_validator.c /always_success.c c/anyone_can_pay.c c/smt.h c/rce.h c/xudt_rce.c tests/xudt_rce/*.c tests/xudt_rce/*.h)
docker run --rm -v `pwd`:/code ${CLANG_FORMAT_DOCKER} bash -c "cd code && clang-format -i -style=Google $(ALL_C_SOURCE)"
git diff --exit-code $(ALL_C_SOURCE)

mol:
rm -f c/xudt_rce_mol.h
Expand All @@ -101,7 +129,7 @@ mol:
make c/xudt_rce_mol.h
make c/xudt_rce_mol2.h
make xudt/src/xudt_rce_mol.rs

make omni_lock_mol

xudt/src/xudt_rce_mol.rs: c/xudt_rce.mol
${MOLC} --language rust --schema-file $< | rustfmt > $@
Expand All @@ -113,6 +141,12 @@ c/xudt_rce_mol2.h: c/xudt_rce.mol
moleculec --language - --schema-file c/xudt_rce.mol --format json > build/blockchain_mol2.json
moleculec-c2 --input build/blockchain_mol2.json | clang-format -style=Google > c/xudt_rce_mol2.h

omni_lock_mol:
${MOLC} --language rust --schema-file c/omni_lock.mol | rustfmt > tests/omni_lock_rust/src/omni_lock.rs
${MOLC} --language c --schema-file c/omni_lock.mol > c/omni_lock_mol.h
${MOLC} --language - --schema-file c/omni_lock.mol --format json > build/omni_lock_mol2.json
moleculec-c2 --input build/omni_lock_mol2.json | clang-format -style=Google > c/omni_lock_mol2.h

build/xudt_rce: c/xudt_rce.c c/rce.h
$(CC) $(XUDT_RCE_CFLAGS) $(LDFLAGS) -o $@ $<
$(OBJCOPY) --only-keep-debug $@ $@.debug
Expand All @@ -123,6 +157,11 @@ build/rce_validator: c/rce_validator.c c/rce.h
$(OBJCOPY) --only-keep-debug $@ $@.debug
$(OBJCOPY) --strip-debug --strip-all $@

build/omni_lock: c/omni_lock.c c/omni_lock_supply.h c/omni_lock_acp.h c/rce.h c/secp256k1_lock.h build/secp256k1_data_info_20210801.h $(SECP256K1_SRC_20210801) c/ckb_identity.h
$(CC) $(OMNI_LOCK_CFLAGS) $(LDFLAGS) -o $@ $<
cp $@ $@.debug
$(OBJCOPY) --strip-debug --strip-all $@

publish:
git diff --exit-code Cargo.toml
sed -i.bak 's/.*git =/# &/' Cargo.toml
Expand All @@ -145,11 +184,15 @@ clean:
rm -rf build/simple_udt
rm -rf build/anyone_can_pay
rm -rf build/secp256k1_data_info.h build/dump_secp256k1_data
rm -rf build/secp256k1_data_info_20210801.h build/dump_secp256k1_data_20210801
rm -rf build/secp256k1_data
rm -rf build/secp256k1_data_20210801
rm -rf build/*.debug
rm -f build/xudt_rce
rm -f build/rce_validator
rm -f build/omni_lock
cd deps/secp256k1 && [ -f "Makefile" ] && make clean
cd deps/secp256k1-20210801 && [ -f "Makefile" ] && make clean
make -C deps/mbedtls/library clean
rm -f build/validate_signature_rsa
rm -f build/validate_signature_rsa_sim
Expand Down
10 changes: 7 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ const BINARIES: &[(&str, &str)] = &[
),
(
"validate_signature_rsa",
"4358d3433c7e0db302346ff45b87aff05ca47166cf9cdede6242616b7936591e",
"a638f65f650bdac13bf91134ed7eec8feded1dac5e6add9e26cf658b2a693066",
),
(
"xudt_rce",
"8b4ecdfdb4279a5b27d55cc0c8362a0e135315ac387e600b043748dad2a247fb",
"022b3f6ad414bb3877d5618a417b06b7e306ce2c4f4bcbf68f617a16fb8ca697",
),
(
"rce_validator",
"8a359444a55b3bc8fcf77ef883939ea0fa9980629b66ad28e13b315728d29a08"
"fe951ccda3ada53ccb65e29fa4577d41030fa2b76cce7f24c5f114743bbcd66a"
),
(
"omni_lock",
"f18e295b6a9286108639df659b822b1cc75216776df3d52ac9ed11a1dadadee5"
)
];

fn main() {
Expand Down
Loading

0 comments on commit ddaeae8

Please sign in to comment.