Skip to content
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

Conversion tool improvement #13

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ dkms.conf
.DS_Store
build/
.vscode/
target/
Cargo.lock
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[workspace]
resolver = "2"
members = [
"tests/sphincsplus_rust",
"tools/ckb-sphincs-tools",
"tools/ckb-sphincs-utils"
]
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ BUILDER_DOCKER := nervos/ckb-riscv-gnu-toolchain@sha256:7601a814be2595ad471288fe
all: build/sphincsplus_lock

all-via-docker:
rm -rf build/
docker run --rm -v `pwd`:/code ${BUILDER_DOCKER} bash -c "cd /code && make PARAMS=$(PARAMS) THASH=$(THASH)"

build/convert_asm: c/ref/fips202_asm.S
Expand All @@ -87,4 +88,4 @@ build/sphincsplus_lock: c/ckb-sphincsplus-lock.c $(SOURCES) $(HEADERS)
$(OBJCOPY) --strip-debug --strip-all $@

clean:
rm -rf build/sphincsplus_lock
rm -rf build/
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Find out more information about different [parameters](https://github.com/sphinc
* Note: Default hash type: **shake-128f-simple** (Verify cycles: about 49.6M)

## Tool
This tool is to **convert a default Lock(SECP256K1/blake160) to quantum resistant lock script.**.
This tool is to **migrate Cells from default lock(SECP256K1/blake160) to quantum resistant lock.**

Follow steps below:

Expand All @@ -55,11 +55,11 @@ Follow steps below:
We can get a set of key files, including public and private keys.
* If the contract you compile does not use the default value, it needs to be the same here.
* Need to save this file.
4. Convert a SECP256K1/blake160 lock script to quantum resistant lock script.
4. Update a Cell's Lock Script from SECP256K1/blake160 to quantum resistant.
``` shell
cargo run -- cc_to_sphincsplus --tx_hash <tx-hash> --tx_index <index> --key_file key.json --prikey <You can use ckb-cli account export>
```
5. Convert a quantum resistant lock script to SECP256K1/blake160 lock script.
5. Update a Cell's Lock Script from quantum resistant to SECP256K1/blake160.
``` shell
cargo run -- cc_to_secp --tx_hash <tx-hash> --tx_index <index> --key_file key.json --lock_arg <LOCK-ARG> --sp_tx_hash <SPHINCS+ Script in step 2> --sp_tx_index <index> --fee 10000
```
Expand All @@ -81,8 +81,8 @@ Follow steps below:
[CKB Explorer](https://pudge.explorer.nervos.org/transaction/0x35f51257673c7a7edd009fa2166e6f8645156207c9da38202f04ba4d94d9e519)
| parameter | value |
| --------- | ------------------------------------------------------------------ |
| code_hash | 0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8 |
| hash_type | type |
| code_hash | 0x989ab456455509a1c2ad1cb8116b7d209df228144445c741b101ec3e55ee8351 |
| hash_type | data1 |
| tx_hash | 0x35f51257673c7a7edd009fa2166e6f8645156207c9da38202f04ba4d94d9e519 |
| index | 0 |
| dep_type | code |
Expand Down
31 changes: 25 additions & 6 deletions tools/ckb-sphincs-tools/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ fn main() {
Some(("signature", sub_matches)) => {
let key_file = sub_matches.get_one::<String>("key_file").expect("required");
let message =
H256::from_trimmed_str(sub_matches.get_one::<String>("message").expect("required"))
.unwrap();
H256::from_trimmed_str(
sub_matches.get_one::<String>("message").expect("required")
.trim_start_matches("0x")
.trim_start_matches('0')
).unwrap();
sub_sign::sub_sign(
sub_gen_key::parse_key_file(PathBuf::from(key_file)),
message,
Expand All @@ -81,9 +84,17 @@ fn main() {
sub_conversion::cc_to_sphincsplus(
sub_gen_key::parse_key_file(PathBuf::from(key_file)),
&ckb_rpc,
H256::from_trimmed_str(tx_hash).unwrap(),
H256::from_trimmed_str(
tx_hash
.trim_start_matches("0x")
.trim_start_matches('0')
).unwrap(),
tx_index.parse::<u32>().unwrap(),
H256::from_trimmed_str(prikey).unwrap(),
H256::from_trimmed_str(
prikey
.trim_start_matches("0x")
.trim_start_matches('0')
).unwrap(),
);
}
Some(("cc_to_secp", sub_matches)) => {
Expand All @@ -107,10 +118,18 @@ fn main() {
sub_conversion::cc_to_def_lock_script(
sub_gen_key::parse_key_file(PathBuf::from(key_file)),
&ckb_rpc,
H256::from_trimmed_str(tx_hash).unwrap(),
H256::from_trimmed_str(
tx_hash
.trim_start_matches("0x")
.trim_start_matches('0')
).unwrap(),
tx_index.parse::<u32>().unwrap(),
&str_to_bytes(&lock_arg),
H256::from_trimmed_str(sp_tx_hash).unwrap(),
H256::from_trimmed_str(
sp_tx_hash
.trim_start_matches("0x")
.trim_start_matches('0')
).unwrap(),
sp_tx_index.parse::<u32>().unwrap(),
fee.clone(),
);
Expand Down
Loading