Skip to content

Commit

Permalink
feat: don't generate A instructions (#37)
Browse files Browse the repository at this point in the history
A instructions are only supported after ckb 2023 hardfork. It's not
supported on ckb testnet or mainnet now.

So we use some compiler and linking hacks to avoid generating A
instructions. See
https://github.com/xxuejie/ckb-contract-bytes-without-a/ for a more
detailed explanation.
  • Loading branch information
blckngm authored Dec 12, 2023
2 parents 885e77d + 4d96f0a commit d9f0136
Show file tree
Hide file tree
Showing 13 changed files with 497 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[build]
target = "riscv64imac-unknown-none-elf"
rustflags = [
"-C", "target-feature=-a"
]
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defaults:
shell: bash
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: -D warnings
RUSTFLAGS: -D warnings -C target-feature=-a
RUST_BACKTRACE: full
RUST_TOOLCHAIN: 1.68.2
jobs:
Expand Down
13 changes: 11 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
resolver = "2"
members = [
"crates/atomics-polyfill",
"contracts/eth_light_client/client_type_lock",
"contracts/eth_light_client/mock_business_type_lock",
"contracts/eth_light_client/verify_bin",
Expand Down
2 changes: 2 additions & 0 deletions contracts/eth_light_client/verify_bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ repository = "https://github.com/synapseweb3/ibc-ckb-contracts"

[dependencies]
ckb-std = "0.13.0"
atomics-polyfill = { path = "../../../crates/atomics-polyfill" }

[dependencies.eth_light_client_in_ckb-verification]
version = "0.3.0-alpha"
git = "https://github.com/synapseweb3/eth-light-client-in-ckb"
Expand Down
2 changes: 2 additions & 0 deletions contracts/eth_light_client/verify_bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use ckb_std::default_alloc;
ckb_std::entry!(program_entry);
default_alloc!();

atomics_polyfill::use_atomics_polyfill!();

fn program_entry() -> i8 {
match entry::main() {
Ok(_) => 0,
Expand Down
1 change: 1 addition & 0 deletions contracts/ics/base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ ckb-std = "0.13.0"
ckb-ics-axon = { git = "https://github.com/synapseweb3/ckb-ics.git", rev = "4e89e76d16" }
rlp = { version = "0.5.2", default-features = false }
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
atomics-polyfill = { path = "../../../crates/atomics-polyfill" }
2 changes: 2 additions & 0 deletions contracts/ics/base/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![no_std]
extern crate alloc;

atomics_polyfill::use_atomics_polyfill!();

pub mod error;
pub mod handler;
pub mod utils;
Expand Down
12 changes: 12 additions & 0 deletions crates/atomics-polyfill/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "atomics-polyfill"
version = "0.1.0"
edition = "2021"
license = "MIT"
homepage = "https://github.com/synapseweb3/ibc-ckb-contracts"
repository = "https://github.com/synapseweb3/ibc-ckb-contracts"

[lib]

[build-dependencies]
cc = "1.0.83"
1 change: 1 addition & 0 deletions crates/atomics-polyfill/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Inspired by https://github.com/xxuejie/ckb-contract-bytes-without-a/
23 changes: 23 additions & 0 deletions crates/atomics-polyfill/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
fn main() {
// let clang = match std::env::var_os("CLANG") {
// Some(val) => val,
// None => "clang-16".into(),
// };

cc::Build::new()
.file("src/atomics.c")
.static_flag(true)
// .compiler(clang)
.no_default_flags(true)
// .flag("--target=riscv64")
.flag("-march=rv64imc")
.flag("-O3")
.flag("-fvisibility=hidden")
.flag("-fdata-sections")
.flag("-ffunction-sections")
.flag("-Wall")
.flag("-Werror")
.flag("-Wno-unused-parameter")
.define("__SHARED_LIBRARY__", None)
.compile("atomics-polyfill");
}
Loading

0 comments on commit d9f0136

Please sign in to comment.