Skip to content

Commit ae0f57f

Browse files
committed
Upgrade multisig
Signed-off-by: Eval EXEC <[email protected]>
1 parent efb5bb0 commit ae0f57f

File tree

14 files changed

+366
-102
lines changed

14 files changed

+366
-102
lines changed

Cargo.lock

Lines changed: 18 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ckb-util = "=0.200.0"
1919
ckb-error = "=0.200.0"
2020
ckb-script = "=0.200.0"
2121
ckb-chain-spec = "=0.200.0"
22-
ckb-sdk = { version = "3.7.0", features = ["native-tls-vendored"] }
22+
ckb-sdk = { git="https://github.com/eval-exec/ckb-sdk-rust", branch="exec/upgrade-multisig", features = ["native-tls-vendored"] }
2323
ckb-mock-tx-types = "=0.200.0"
2424
ckb-signer = { path = "ckb-signer", version = "0.4.1" }
2525
plugin-protocol = { path = "plugin-protocol", package = "ckb-cli-plugin-protocol", version = "=1.3.1" }

ckb-signer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ anyhow = "1.0.63"
2727
ckb-types = "=0.200.0"
2828
ckb-hash = "=0.200.0"
2929
ckb-crypto = { version = "=0.200.0", features = ["secp"] }
30-
ckb-sdk = { version = "3.7.0", features = ["native-tls-vendored"] }
30+
ckb-sdk = { git="https://github.com/eval-exec/ckb-sdk-rust", branch="exec/upgrade-multisig", features = ["native-tls-vendored"] }

src/subcommands/deploy/tx_builder.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::HashMap;
22

33
use anyhow::{anyhow, Result};
44
use ckb_sdk::{
5-
constants::{MULTISIG_TYPE_HASH, SIGHASH_TYPE_HASH},
5+
constants::{MultisigScript, SIGHASH_TYPE_HASH},
66
traits::{
77
CellCollector, CellQueryOptions, DefaultCellCollector, DefaultHeaderDepResolver,
88
DefaultTransactionDependencyProvider, OffchainTransactionDependencyProvider, Signer,
@@ -79,10 +79,7 @@ pub fn build_tx<T: ChangeInfo>(
7979
.iter()
8080
.filter_map(|info| info.build_cell_output(lock_script, first_cell_input))
8181
.unzip();
82-
let mut cell_deps = vec![genesis_info.sighash_dep()];
83-
if multisig_config.is_some() {
84-
cell_deps.push(genesis_info.multisig_dep());
85-
}
82+
8683
let mut unlockers = HashMap::new();
8784
let signer = DummySigner {
8885
args: vec![from_address.payload().args()],
@@ -93,10 +90,22 @@ pub fn build_tx<T: ChangeInfo>(
9390
sighash_script_id,
9491
Box::new(sighash_unlocker) as Box<dyn ScriptUnlocker>,
9592
);
93+
94+
let mut cell_deps = vec![genesis_info.sighash_dep()];
9695
if let Some(cfg) = multisig_config {
96+
let multisig_script =
97+
MultisigScript::try_from(cfg.lock_code_hash()).unwrap_or_else(|_err| {
98+
panic!(
99+
"Failed to get multisig script from {}",
100+
cfg.lock_code_hash(),
101+
)
102+
});
103+
104+
cell_deps.push(genesis_info.multisig_dep(multisig_script));
105+
97106
let multisig_signer = SecpMultisigScriptSigner::new(Box::new(signer), cfg.clone());
98107
let multisig_unlocker = SecpMultisigUnlocker::new(multisig_signer);
99-
let multisig_script_id = ScriptId::new_type(MULTISIG_TYPE_HASH.clone());
108+
let multisig_script_id = multisig_script.script_id();
100109
unlockers.insert(
101110
multisig_script_id,
102111
Box::new(multisig_unlocker) as Box<dyn ScriptUnlocker>,

src/subcommands/mod.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ pub mod wallet;
1414

1515
pub use account::AccountSubCommand;
1616
pub use api_server::ApiServerSubCommand;
17+
use ckb_sdk::constants::MultisigScript;
18+
use ckb_types::H256;
1719
pub use dao::DAOSubCommand;
1820
pub use deploy::DeploySubCommand;
1921
pub use mock_tx::MockTxSubCommand;
@@ -26,10 +28,13 @@ pub use tx::TxSubCommand;
2628
pub use util::UtilSubCommand;
2729
pub use wallet::{TransferArgs, WalletSubCommand};
2830

29-
use clap::ArgMatches;
31+
use clap::{Arg, ArgMatches};
3032
use serde::Serialize;
3133

32-
use crate::utils::printer::{OutputFormat, Printable};
34+
use crate::utils::{
35+
arg_parser::{ArgParser, FixedHashParser},
36+
printer::{OutputFormat, Printable},
37+
};
3338

3439
pub struct Output {
3540
stdout: Option<serde_json::Value>,
@@ -95,3 +100,29 @@ Key Considerations:
95100
- Permanent Immutability: Script logic and data will be permanently fixed on-chain.
96101
- No Recovery Mechanism: If vulnerabilities or defects exist in the script, there is no way to upgrade, patch, or revoke it.
97102
- Use with Caution: Thoroughly audit and test the script before deployment. This option is recommended only for scenarios requiring absolute finality, where script behavior must remain tamper-proof indefinitely.";
103+
104+
fn arg_multisig_code_hash() -> Arg<'static> {
105+
let arg_multisig_code_hash = Arg::with_name("multisig-code-hash")
106+
.long("multisig-code-hash")
107+
.takes_value(true)
108+
.multiple(false)
109+
.required(true)
110+
.possible_values(&[
111+
// legacy code hash
112+
"legacy",
113+
"0x5c5069eb0857efc65e1bca0c07df34c31663b3622fd3876c876320fc9634e2a8",
114+
// V2 code hash
115+
"v2",
116+
"0x36c971b8d41fbd94aabca77dc75e826729ac98447b46f91e00796155dddb0d29",
117+
])
118+
.about("Specifies the multisig code hash to use:\n - v2(default): `0x36c971b8d41fbd94aabca77dc75e826729ac98447b46f91e00796155dddb0d29`. \n - legacy(deprecated): `0x5c5069eb0857efc65e1bca0c07df34c31663b3622fd3876c876320fc9634e2a8` is NOT recommended for use.\n\n");
119+
arg_multisig_code_hash
120+
}
121+
122+
fn arg_get_multisig_code_hash(m: &ArgMatches) -> Result<H256, String> {
123+
match m.value_of("multisig-code-hash").unwrap() {
124+
"legacy" => Ok(MultisigScript::Legacy.script_id().code_hash),
125+
"v2" => Ok(MultisigScript::V2.script_id().code_hash),
126+
_ => FixedHashParser::<H256>::default().from_matches(m, "multisig-code-hash"),
127+
}
128+
}

0 commit comments

Comments
 (0)