From 6195643fdea721fc1356c8cbda35a0e9098b3c4b Mon Sep 17 00:00:00 2001 From: Mohanson Date: Tue, 30 Jan 2024 18:15:59 +0800 Subject: [PATCH] Use CKB 2nd hardfork (#16) * Change to 1st hardfork --- Makefile | 6 ++--- tests/omni_lock_rust/tests/misc.rs | 27 +++++++++++++++----- tests/omni_lock_rust/tests/test_omni_lock.rs | 2 +- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index b723893..b1cd02e 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ TARGET := riscv64-unknown-linux-gnu CC := $(TARGET)-gcc LD := $(TARGET)-gcc 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 +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 -Wno-array-bounds -Wno-stringop-overflow -g LDFLAGS := -nostdlib -nostartfiles -fno-builtin -Wl,-static -Wl,--gc-sections SECP256K1_SRC_20210801 := deps/secp256k1-20210801/src/ecmult_static_pre_context.h @@ -20,8 +20,8 @@ PROTOCOL_URL := https://raw.githubusercontent.com/nervosnetwork/ckb/${PROTOCOL_V MOLC := moleculec MOLC_VERSION := 0.7.0 -# docker pull nervos/ckb-riscv-gnu-toolchain:gnu-bionic-20191012 -BUILDER_DOCKER := nervos/ckb-riscv-gnu-toolchain@sha256:aae8a3f79705f67d505d1f1d5ddc694a4fd537ed1c7e9622420a470d59ba2ec3 +# docker pull nervos/ckb-riscv-gnu-toolchain:gnu-jammy-20230214 +BUILDER_DOCKER := nervos/ckb-riscv-gnu-toolchain@sha256:d3f649ef8079395eb25a21ceaeb15674f47eaa2d8cc23adc8bcdae3d5abce6ec CLANG_FORMAT_DOCKER := kason223/clang-format@sha256:3cce35b0400a7d420ec8504558a02bdfc12fd2d10e40206f140c4545059cd95d all: build/omni_lock build/always_success diff --git a/tests/omni_lock_rust/tests/misc.rs b/tests/omni_lock_rust/tests/misc.rs index eecc28f..050486d 100644 --- a/tests/omni_lock_rust/tests/misc.rs +++ b/tests/omni_lock_rust/tests/misc.rs @@ -254,7 +254,7 @@ fn build_script( let hash_type = if is_type { ScriptHashType::Type } else { - ScriptHashType::Data + ScriptHashType::Data1 }; let script = Script::new_builder() @@ -492,7 +492,7 @@ pub fn build_always_success_script() -> Script { let data_hash = CellOutput::calc_data_hash(&ALWAYS_SUCCESS); Script::new_builder() .code_hash(data_hash.clone()) - .hash_type(ScriptHashType::Data.into()) + .hash_type(ScriptHashType::Data1.into()) .build() } @@ -519,7 +519,7 @@ pub fn build_omni_lock_script(config: &mut TestConfig, args: Bytes) -> Script { Script::new_builder() .args(args.pack()) .code_hash(sighash_all_cell_data_hash.clone()) - .hash_type(ScriptHashType::Data.into()) + .hash_type(ScriptHashType::Data1.into()) .build() } @@ -560,7 +560,7 @@ pub fn append_input_lock_script_hash( let script = Script::new_builder() .args(Default::default()) .code_hash(hash.clone()) - .hash_type(ScriptHashType::Data.into()) + .hash_type(ScriptHashType::Data1.into()) .build(); let blake160 = { let hash = script.calc_script_hash(); @@ -995,7 +995,7 @@ pub fn gen_tx_with_grouped_args( let script = Script::new_builder() .args(args.pack()) .code_hash(sighash_all_cell_data_hash.clone()) - .hash_type(ScriptHashType::Data.into()) + .hash_type(ScriptHashType::Data1.into()) .build(); config.running_script = script.clone(); let previous_output_cell = CellOutput::new_builder() @@ -2124,7 +2124,18 @@ pub fn verify_tx( resolved_tx: ResolvedTransaction, data_loader: DummyDataLoader, ) -> TransactionScriptsVerifier { - let hard_fork = HardForks::new_mirana(); + let hard_fork = HardForks { + ckb2021: ckb_types::core::hardfork::CKB2021::new_mirana() + .as_builder() + .rfc_0032(5) + .build() + .unwrap(), + ckb2023: ckb_types::core::hardfork::CKB2023::new_mirana() + .as_builder() + .rfc_0049(10) + .build() + .unwrap(), + }; let consensus = ConsensusBuilder::default() .hardfork_switch(hard_fork) .build(); @@ -2133,7 +2144,9 @@ pub fn verify_tx( data_loader.clone(), Arc::new(consensus), Arc::new(TxVerifyEnv::new_commit( - &HeaderView::new_advanced_builder().build(), + &HeaderView::new_advanced_builder() + .epoch(ckb_types::core::EpochNumberWithFraction::new(5, 0, 1).pack()) + .build(), )), ) } diff --git a/tests/omni_lock_rust/tests/test_omni_lock.rs b/tests/omni_lock_rust/tests/test_omni_lock.rs index 071fdc5..72899f3 100644 --- a/tests/omni_lock_rust/tests/test_omni_lock.rs +++ b/tests/omni_lock_rust/tests/test_omni_lock.rs @@ -680,7 +680,7 @@ fn test_binary_unchanged() { let actual_hash = faster_hex::hex_string(&hash); assert_eq!( - "091cd5995b23f1f1e5041b88f302a1c25bc4aa2a7e223358084d1ae0f990369e", + "a519c447eef1e3d0a22b2e1bec4403eb7d9305849bc2905a49917ff5565c14f0", &actual_hash ); }