diff --git a/rpc/README.md b/rpc/README.md index a42bd48d05..10125a38d0 100644 --- a/rpc/README.md +++ b/rpc/README.md @@ -1654,7 +1654,7 @@ Response "result": { "block_version": "0x0", "cellbase_maturity": "0x10000000000", - "dao_type_hash": null, + "dao_type_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "epoch_duration_target": "0x3840", "genesis_hash": "0x7978ec7ce5b507cfb52e149e36b1a23f6062ed150503c85bbf825da3599095ed", "hardfork_features": [ @@ -5703,7 +5703,7 @@ Consensus defines various parameters that influence chain consensus * `genesis_hash`: [`H256`](#type-h256) - The genesis block hash -* `dao_type_hash`: [`H256`](#type-h256) `|` `null` - The dao type hash +* `dao_type_hash`: [`H256`](#type-h256) - The dao type hash * `secp256k1_blake160_sighash_all_type_hash`: [`H256`](#type-h256) `|` `null` - The secp256k1_blake160_sighash_all_type_hash diff --git a/rpc/src/module/chain.rs b/rpc/src/module/chain.rs index 36e0f4238f..6a013be67c 100644 --- a/rpc/src/module/chain.rs +++ b/rpc/src/module/chain.rs @@ -1336,7 +1336,7 @@ pub trait ChainRpc { /// "result": { /// "block_version": "0x0", /// "cellbase_maturity": "0x10000000000", - /// "dao_type_hash": null, + /// "dao_type_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", /// "epoch_duration_target": "0x3840", /// "genesis_hash": "0x7978ec7ce5b507cfb52e149e36b1a23f6062ed150503c85bbf825da3599095ed", /// "hardfork_features": [ diff --git a/rpc/src/module/pool.rs b/rpc/src/module/pool.rs index 1fe3e45de6..8f30f9b571 100644 --- a/rpc/src/module/pool.rs +++ b/rpc/src/module/pool.rs @@ -616,9 +616,7 @@ impl<'a> WellKnownScriptsOnlyValidator<'a> { Some(script) => { if !script.is_hash_type_type() { Err(DefaultOutputsValidatorError::HashType) - } else if script.code_hash() - != self.consensus.dao_type_hash().expect("No dao system cell") - { + } else if script.code_hash() != self.consensus.dao_type_hash() { Err(DefaultOutputsValidatorError::CodeHash) } else if output.lock().args().len() == BLAKE160_LEN + SINCE_LEN { // https://github.com/nervosnetwork/ckb/wiki/Common-Gotchas#nervos-dao diff --git a/rpc/src/tests/module/pool.rs b/rpc/src/tests/module/pool.rs index dfdef67552..5d9ba19834 100644 --- a/rpc/src/tests/module/pool.rs +++ b/rpc/src/tests/module/pool.rs @@ -37,7 +37,7 @@ fn test_default_outputs_validator() { // invalid code hash let tx = build_tx( - &consensus.dao_type_hash().unwrap(), + &consensus.dao_type_hash(), core::ScriptHashType::Type, vec![1; 20], ); @@ -76,7 +76,7 @@ fn test_default_outputs_validator() { let lock_type_hash = consensus .secp256k1_blake160_multisig_all_type_hash() .unwrap(); - let type_type_hash = consensus.dao_type_hash().unwrap(); + let type_type_hash = consensus.dao_type_hash(); // valid output lock let tx = build_tx_with_type( &lock_type_hash, diff --git a/spec/src/consensus.rs b/spec/src/consensus.rs index 461225a3d9..0f059d1dfb 100644 --- a/spec/src/consensus.rs +++ b/spec/src/consensus.rs @@ -276,7 +276,7 @@ impl ConsensusBuilder { median_time_block_count: MEDIAN_TIME_BLOCK_COUNT, max_block_cycles: MAX_BLOCK_CYCLES, max_block_bytes: MAX_BLOCK_BYTES, - dao_type_hash: None, + dao_type_hash: Byte32::default(), secp256k1_blake160_sighash_all_type_hash: None, secp256k1_blake160_multisig_all_type_hash: None, genesis_epoch_ext, @@ -347,7 +347,7 @@ impl ConsensusBuilder { "genesis block must contain the witness for cellbase" ); - self.inner.dao_type_hash = self.get_type_hash(OUTPUT_INDEX_DAO); + self.inner.dao_type_hash = self.get_type_hash(OUTPUT_INDEX_DAO).unwrap_or_default(); self.inner.secp256k1_blake160_sighash_all_type_hash = self.get_type_hash(OUTPUT_INDEX_SECP256K1_BLAKE160_SIGHASH_ALL); self.inner.secp256k1_blake160_multisig_all_type_hash = @@ -514,7 +514,7 @@ pub struct Consensus { /// The dao type hash /// /// [nervos-dao](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0024-ckb-genesis-script-list/0024-ckb-genesis-script-list.md#nervos-dao) - pub dao_type_hash: Option, + pub dao_type_hash: Byte32, /// The secp256k1_blake160_sighash_all_type_hash /// /// [SECP256K1/blake160](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0024-ckb-genesis-script-list/0024-ckb-genesis-script-list.md#secp256k1blake160) @@ -626,7 +626,7 @@ impl Consensus { /// The dao type hash /// /// [nervos-dao](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0024-ckb-genesis-script-list/0024-ckb-genesis-script-list.md#nervos-dao) - pub fn dao_type_hash(&self) -> Option { + pub fn dao_type_hash(&self) -> Byte32 { self.dao_type_hash.clone() } @@ -1111,7 +1111,7 @@ impl From for ckb_jsonrpc_types::Consensus { Self { id: consensus.id, genesis_hash: consensus.genesis_hash.unpack(), - dao_type_hash: consensus.dao_type_hash.map(|h| h.unpack()), + dao_type_hash: consensus.dao_type_hash.unpack(), secp256k1_blake160_sighash_all_type_hash: consensus .secp256k1_blake160_sighash_all_type_hash .map(|h| h.unpack()), diff --git a/test/src/specs/dao/dao_user.rs b/test/src/specs/dao/dao_user.rs index 8b13ecfd09..aa729e8476 100644 --- a/test/src/specs/dao/dao_user.rs +++ b/test/src/specs/dao/dao_user.rs @@ -187,7 +187,7 @@ impl<'a> DAOUser<'a> { pub fn dao_type_script(&self) -> Script { Script::new_builder() - .code_hash(self.node.consensus().dao_type_hash().unwrap()) + .code_hash(self.node.consensus().dao_type_hash()) .hash_type(ScriptHashType::Type.into()) .build() } diff --git a/test/src/specs/dao/dao_verifier.rs b/test/src/specs/dao/dao_verifier.rs index feb1b6b0ee..b2b1fab86a 100644 --- a/test/src/specs/dao/dao_verifier.rs +++ b/test/src/specs/dao/dao_verifier.rs @@ -257,7 +257,7 @@ impl DAOVerifier { return false; } - let dao_type_hash = self.consensus.dao_type_hash().unwrap(); + let dao_type_hash = self.consensus.dao_type_hash(); self.get_output(out_point) .type_() .to_opt() diff --git a/util/dao/src/lib.rs b/util/dao/src/lib.rs index 069329681f..ebb550871c 100644 --- a/util/dao/src/lib.rs +++ b/util/dao/src/lib.rs @@ -221,8 +221,7 @@ impl<'a, DL: CellDataProvider + EpochProvider + HeaderProvider> DaoCalculator<'a let is_dao_type_script = |type_script: Script| { Into::::into(type_script.hash_type()) == Into::::into(ScriptHashType::Type) - && type_script.code_hash() - == self.consensus.dao_type_hash().expect("No dao system cell") + && type_script.code_hash() == self.consensus.dao_type_hash() }; let is_withdrawing_input = |cell_meta: &CellMeta| match self.data_loader.load_cell_data(cell_meta) { diff --git a/util/jsonrpc-types/src/blockchain.rs b/util/jsonrpc-types/src/blockchain.rs index 07bc13435e..d444f0f559 100644 --- a/util/jsonrpc-types/src/blockchain.rs +++ b/util/jsonrpc-types/src/blockchain.rs @@ -1339,7 +1339,7 @@ pub struct Consensus { /// The genesis block hash pub genesis_hash: H256, /// The dao type hash - pub dao_type_hash: Option, + pub dao_type_hash: H256, /// The secp256k1_blake160_sighash_all_type_hash pub secp256k1_blake160_sighash_all_type_hash: Option, /// The secp256k1_blake160_multisig_all_type_hash diff --git a/verification/src/tests/transaction_verifier.rs b/verification/src/tests/transaction_verifier.rs index 4dd123e90b..16f05fe1fe 100644 --- a/verification/src/tests/transaction_verifier.rs +++ b/verification/src/tests/transaction_verifier.rs @@ -104,7 +104,7 @@ pub fn test_capacity_outofbound() { resolved_dep_groups: vec![], }); let dao_type_hash = build_genesis_type_id_script(OUTPUT_INDEX_DAO).calc_script_hash(); - let verifier = CapacityVerifier::new(rtx, Some(dao_type_hash)); + let verifier = CapacityVerifier::new(rtx, dao_type_hash); assert_error_eq!( verifier.verify().unwrap_err(), @@ -136,7 +136,7 @@ pub fn test_skip_dao_capacity_check() { resolved_inputs: vec![], resolved_dep_groups: vec![], }); - let verifier = CapacityVerifier::new(rtx, Some(dao_type_script.calc_script_hash())); + let verifier = CapacityVerifier::new(rtx, dao_type_script.calc_script_hash()); assert!(verifier.verify().is_ok()); } @@ -329,7 +329,7 @@ pub fn test_capacity_invalid() { resolved_dep_groups: vec![], }); let dao_type_hash = build_genesis_type_id_script(OUTPUT_INDEX_DAO).calc_script_hash(); - let verifier = CapacityVerifier::new(rtx, Some(dao_type_hash)); + let verifier = CapacityVerifier::new(rtx, dao_type_hash); assert_error_eq!( verifier.verify().unwrap_err(), @@ -808,7 +808,7 @@ fn build_consensus_with_dao_limiting_block(block_number: u64) -> (Arc // the dao script. For simplicity, we are hacking consensus here with // a dao_type_hash value, a proper way should be creating a proper genesis // block here, but we will leave it till we really need it. - consensus.dao_type_hash = Some(dao_script.calc_script_hash()); + consensus.dao_type_hash = dao_script.calc_script_hash(); let dao_type_script = Script::new_builder() .code_hash(dao_script.calc_script_hash()) diff --git a/verification/src/transaction_verifier.rs b/verification/src/transaction_verifier.rs index 11214f583f..b9ec653022 100644 --- a/verification/src/transaction_verifier.rs +++ b/verification/src/transaction_verifier.rs @@ -523,16 +523,12 @@ impl<'a> DuplicateDepsVerifier<'a> { /// Perform inputs and outputs `capacity` field related verification pub struct CapacityVerifier { resolved_transaction: Arc, - // It's Option because special genesis block do not have dao system cell - dao_type_hash: Option, + dao_type_hash: Byte32, } impl CapacityVerifier { /// Create a new `CapacityVerifier` - pub fn new( - resolved_transaction: Arc, - dao_type_hash: Option, - ) -> Self { + pub fn new(resolved_transaction: Arc, dao_type_hash: Byte32) -> Self { CapacityVerifier { resolved_transaction, dao_type_hash, @@ -584,12 +580,7 @@ impl CapacityVerifier { self.resolved_transaction .resolved_inputs .iter() - .any(|cell_meta| { - cell_uses_dao_type_script( - &cell_meta.cell_output, - self.dao_type_hash.as_ref().expect("No dao system cell"), - ) - }) + .any(|cell_meta| cell_uses_dao_type_script(&cell_meta.cell_output, &self.dao_type_hash)) } } @@ -990,17 +981,14 @@ impl DaoScriptSizeVerifier
{ } } - fn dao_type_hash(&self) -> Option { + fn dao_type_hash(&self) -> Byte32 { self.consensus.dao_type_hash() } /// Verifies that for all Nervos DAO transactions, withdrawing cells must use lock scripts /// of the same size as corresponding deposit cells pub fn verify(&self) -> Result<(), Error> { - if self.dao_type_hash().is_none() { - return Ok(()); - } - let dao_type_hash = self.dao_type_hash().unwrap(); + let dao_type_hash = self.dao_type_hash(); for (i, (input_meta, cell_output)) in self .resolved_transaction .resolved_inputs