-
Notifications
You must be signed in to change notification settings - Fork 4
Implement Cobuild integration and Solana support #3
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
Open
XuJiandong
wants to merge
17
commits into
nervosnetwork:main
Choose a base branch
from
XuJiandong:cobuild
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 5 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
41d6fed
Add missing auth id(0x02~0x05)
XuJiandong 90ad8ba
Cobuild support
XuJiandong 1fe80a8
Check type scripts from message existing in tx (#14)
XuJiandong 6195643
Use CKB 2nd hardfork (#16)
mohanson e754bd1
Support cobuild OTX (#18)
XuJiandong 7045a2f
Update according to reviews (#38)
joii2020 df44cc5
Fix relative since issue (#39)
XuJiandong e06ad7e
Cobuild refactor (#40)
xxuejie c9be032
Validate witnesses (#42)
joii2020 50c7adf
Validate actions to lock script hashes (#43)
XuJiandong 45ef4e5
Add testcases (#44)
joii2020 79b8e4b
Testcase Otx support header_dep (#45)
joii2020 91efc8a
Add test vectors for cobuild (#46)
joii2020 fd6674d
Refactor cobuild into a standalone library (#47)
XuJiandong 2a04f15
Solana (phantom wallet) support (#48)
XuJiandong f7e6590
Disable log (#49)
XuJiandong 151e75a
Add exec test case (#50)
XuJiandong 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 hidden or 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,17 @@ | ||
| name: Clang | ||
|
|
||
| on: [push, pull_request] | ||
|
|
||
| jobs: | ||
| build: | ||
|
|
||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v1 | ||
| - name: Update submodules | ||
| run: git submodule update --init | ||
| - name: Build contract | ||
| run: make -f Makefile.clang all-via-docker | ||
| - name: Run omni_lock tests | ||
| run: cd tests/omni_lock_rust && cargo test |
This file contains hidden or 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,30 @@ | ||
| FROM debian:bullseye-slim AS intermediate | ||
|
|
||
| # Install dependencies | ||
| RUN apt-get -qq update; \ | ||
| apt-get install -qqy --no-install-recommends \ | ||
| gnupg2 wget ca-certificates apt-transport-https \ | ||
| autoconf automake cmake dpkg-dev file make patch libc6-dev libtool | ||
|
|
||
| # Install LLVM | ||
| RUN echo "deb https://apt.llvm.org/bullseye llvm-toolchain-bullseye-16 main" \ | ||
| > /etc/apt/sources.list.d/llvm.list && \ | ||
| wget -qO /etc/apt/trusted.gpg.d/llvm.asc \ | ||
| https://apt.llvm.org/llvm-snapshot.gpg.key && \ | ||
| apt-get -qq update && \ | ||
| apt-get install -qqy -t llvm-toolchain-bullseye-16 clang-16 clang-tidy-16 clang-format-16 lld-16 libc++-16-dev libc++abi-16-dev && \ | ||
| for f in /usr/lib/llvm-*/bin/*; do ln -sf "$f" /usr/bin; done && \ | ||
| ln -sf clang /usr/bin/cc && \ | ||
| ln -sf clang /usr/bin/c89 && \ | ||
| ln -sf clang /usr/bin/c99 && \ | ||
| ln -sf clang++ /usr/bin/c++ && \ | ||
| ln -sf clang++ /usr/bin/g++ && \ | ||
| rm -rf /var/lib/apt/lists/* | ||
|
|
||
| FROM intermediate as test | ||
|
|
||
| COPY tests /tests | ||
|
|
||
| RUN /tests/run.sh 16 | ||
|
|
||
| FROM intermediate as final |
This file contains hidden or 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 hidden or 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,118 @@ | ||
| CC := clang-16 | ||
| LD := ld.lld-16 | ||
| OBJCOPY := llvm-objcopy-16 | ||
| CFLAGS := \ | ||
| --target=riscv64 -march=rv64imc_zba_zbb_zbc_zbs \ | ||
| -fPIC -O2 -fno-builtin-printf -fno-builtin-memcmp -fno-builtin-memset -nostdinc -nostdlib -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-unused-function -Wno-bitwise-instead-of-logical -g | ||
| LDFLAGS := -nostdlib -static --gc-sections | ||
| SECP256K1_SRC_20210801 := deps/secp256k1-20210801/src/ecmult_static_pre_context.h | ||
|
|
||
|
|
||
| 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)) | ||
| # enable log | ||
| OMNI_LOCK_CFLAGS += -DCKB_C_STDLIB_PRINTF -DCKB_C_STDLIB_PRINTF_BUFFER_SIZE=1024 | ||
|
|
||
|
|
||
| PROTOCOL_HEADER := c/blockchain.h | ||
| PROTOCOL_SCHEMA := c/blockchain.mol | ||
| PROTOCOL_VERSION := d75e4c56ffa40e17fd2fe477da3f98c5578edcd1 | ||
| PROTOCOL_URL := https://raw.githubusercontent.com/nervosnetwork/ckb/${PROTOCOL_VERSION}/util/types/schemas/blockchain.mol | ||
| MOLC := moleculec | ||
| MOLC_VERSION := 0.7.0 | ||
|
|
||
| BUILDER_DOCKER := xujiandong/ckb-riscv-llvm-toolchain@sha256:6409ab0d3e335c74088b54f4f73252f4b3367ae364d5c7ca7acee82135f5af4d | ||
|
|
||
| all: build/omni_lock build/always_success | ||
|
|
||
| all-via-docker: ${PROTOCOL_HEADER} | ||
| docker run --rm -v `pwd`:/code ${BUILDER_DOCKER} bash -c "cd /code && make -f Makefile.clang all" | ||
|
|
||
|
|
||
| build/always_success: c/always_success.c | ||
| $(CC) $(OMNI_LOCK_CFLAGS) -nostdlib -static -Wl,--gc-sections -o $@ $< | ||
| $(OBJCOPY) --only-keep-debug $@ $@.debug | ||
| $(OBJCOPY) --strip-debug --strip-all $@ | ||
|
|
||
| build/secp256k1_data_info_20210801.h: build/dump_secp256k1_data_20210801 | ||
| $< | ||
|
|
||
| build/dump_secp256k1_data_20210801: c/dump_secp256k1_data_20210801.c $(SECP256K1_SRC_20210801) | ||
| mkdir -p build | ||
| $(CC) -I deps/secp256k1-20210801/src -I deps/secp256k1-20210801 -o $@ $< | ||
|
|
||
|
|
||
| $(SECP256K1_SRC_20210801): | ||
| cd deps/secp256k1-20210801 && \ | ||
| ./autogen.sh && \ | ||
| CC=$(CC) LD=$(LD) ./configure --with-asm=no --enable-ecmult-static-precomputation --with-ecmult-window=6 --enable-module-recovery && \ | ||
| make src/ecmult_static_pre_context.h src/ecmult_static_context.h | ||
|
|
||
| ${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/blake2b_decl_only.h c/cobuild.h c/cobuild.c) | ||
|
|
||
| fmt: | ||
| docker run --rm -v `pwd`:/code ${BUILDER_DOCKER} bash -c "cd code && clang-format -i -style=Google $(ALL_C_SOURCE)" | ||
| git diff --exit-code $(ALL_C_SOURCE) | ||
|
|
||
| mol: | ||
| make omni_lock_mol | ||
| make cobuild_mol | ||
|
|
||
| c/xudt_rce_mol.h: c/xudt_rce.mol | ||
| ${MOLC} --language c --schema-file $< > $@ | ||
|
|
||
| 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/cobuild.o: c/cobuild.c c/cobuild.h | ||
| $(CC) -c $(OMNI_LOCK_CFLAGS) -o $@ $< | ||
|
|
||
| build/omni_lock.o: c/omni_lock.c c/omni_lock_supply.h c/omni_lock_acp.h build/secp256k1_data_info_20210801.h $(SECP256K1_SRC_20210801) c/ckb_identity.h | ||
| $(CC) -c $(OMNI_LOCK_CFLAGS) -o $@ $< | ||
|
|
||
| build/omni_lock: build/omni_lock.o build/cobuild.o | ||
| $(LD) $(LDFLAGS) -o $@ $^ | ||
| cp $@ $@.debug | ||
| $(OBJCOPY) --strip-debug --strip-all $@ | ||
| ls -l $@ | ||
|
|
||
| cobuild_mol: | ||
| ${MOLC} --language rust --schema-file c/basic.mol | rustfmt > tests/omni_lock_rust/src/schemas/basic.rs | ||
| ${MOLC} --language rust --schema-file c/top_level.mol | rustfmt > tests/omni_lock_rust/src/schemas/top_level.rs | ||
| ${MOLC} --language - --schema-file c/basic.mol --format json > build/cobuild_basic_mol2.json | ||
| moleculec-c2 --input build/cobuild_basic_mol2.json | clang-format -style=Google > c/cobuild_basic_mol2.h | ||
|
|
||
| clean: clean2 | ||
| rm -rf build/secp256k1_data_info_20210801.h build/dump_secp256k1_data_20210801 | ||
| rm -f build/secp256k1_data_20210801 | ||
| cd deps/secp256k1-20210801 && [ -f "Makefile" ] && make clean | ||
|
|
||
| clean2: | ||
| rm -rf build/*.debug | ||
| rm -f build/omni_lock | ||
| rm -f build/*.o | ||
| rm -f build/always_success | ||
|
|
||
| install-tools: | ||
| if [ ! -x "$$(command -v "${MOLC}")" ] \ | ||
| || [ "$$(${MOLC} --version | awk '{ print $$2 }' | tr -d ' ')" != "${MOLC_VERSION}" ]; then \ | ||
| cargo install --force --version "${MOLC_VERSION}" "${MOLC}"; \ | ||
| fi | ||
|
|
||
| dist: clean all | ||
|
|
||
| .PHONY: all all-via-docker dist clean package-clean package publish |
This file contains hidden or 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 hidden or 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,81 @@ | ||
| import blockchain; | ||
|
|
||
| array Hash [byte; 32]; | ||
| vector String <byte>; // UTF-8 encoded | ||
| option Uint32Opt (Uint32); | ||
|
|
||
| table Action { | ||
| script_info_hash: Byte32, // script info | ||
| script_hash: Byte32, // script | ||
| data: Bytes, // action data | ||
| } | ||
|
|
||
| vector ActionVec <Action>; | ||
|
|
||
| table Message { | ||
| actions: ActionVec, | ||
| } | ||
|
|
||
| table ScriptInfo { | ||
| // The dapp name and domain the script belongs to | ||
| name: String, | ||
| url: String, | ||
|
|
||
| // Script info. | ||
| // schema: script action schema | ||
| // message_type: the entry action type used in WitnessLayout | ||
| script_hash: Byte32, | ||
| schema: String, | ||
| message_type: String, | ||
| } | ||
|
|
||
| vector ScriptInfoVec <ScriptInfo>; | ||
|
|
||
| table ResolvedInputs { | ||
| outputs: CellOutputVec, | ||
XuJiandong marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| outputs_data: BytesVec, | ||
| } | ||
|
|
||
| table BuildingPacketV1 { | ||
| message: Message, | ||
| payload: Transaction, | ||
| resolved_inputs: ResolvedInputs, | ||
| change_output: Uint32Opt, | ||
| script_infos: ScriptInfoVec, | ||
| lock_actions: ActionVec, | ||
| } | ||
|
|
||
| union BuildingPacket { | ||
| BuildingPacketV1, | ||
| } | ||
|
|
||
| table SighashAll { | ||
| message: Message, | ||
| seal: Bytes, | ||
| } | ||
|
|
||
| table SighashAllOnly { | ||
| seal: Bytes, | ||
| } | ||
|
|
||
| table SealPair { | ||
| script_hash: Byte32, | ||
| seal: Bytes, | ||
| } | ||
| vector SealPairVec <SealPair>; | ||
|
|
||
| table OtxStart { | ||
| start_input_cell: Uint32, | ||
| start_output_cell: Uint32, | ||
| start_cell_deps: Uint32, | ||
| start_header_deps: Uint32, | ||
| } | ||
|
|
||
| table Otx { | ||
| input_cells: Uint32, | ||
| output_cells: Uint32, | ||
| cell_deps: Uint32, | ||
| header_deps: Uint32, | ||
| message: Message, | ||
| seals: SealPairVec, | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.