Skip to content

Commit

Permalink
bug: trim first 32 bytes of proxy args
Browse files Browse the repository at this point in the history
  • Loading branch information
liyukun committed Jan 17, 2024
1 parent 5ff9090 commit 0e80292
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions contracts/cluster/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use spore_errors::error::Error;
use spore_types::generated::spore_types::ClusterData;
use spore_utils::{
check_spore_address, extract_spore_action, find_position_by_type, find_position_by_type_args,
load_type_args, verify_type_id,
load_self_id, verify_type_id,
};

use crate::hash::SPORE_EXTENSION_LUA;
Expand Down Expand Up @@ -111,7 +111,7 @@ fn process_transfer() -> Result<(), Error> {
let action::SporeActionUnion::TransferCluster(transfer) = extract_spore_action()?.to_enum() else {
return Err(Error::SporeActionMismatch);
};
if transfer.cluster_id().as_slice() != load_type_args(0, GroupInput).as_ref() {
if transfer.cluster_id().as_slice() != &load_self_id()? {
return Err(Error::SporeActionFieldMismatch);
}
check_spore_address(GroupInput, transfer.from())?;
Expand Down
6 changes: 3 additions & 3 deletions contracts/cluster_agent/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use ckb_std::{ckb_types::prelude::*, debug, high_level::load_script};
use spore_errors::error::Error;
use spore_types::generated::action;
use spore_utils::{
calc_capacity_sum, find_position_by_type, find_position_by_type_hash, load_type_args,
calc_capacity_sum, find_position_by_type, find_position_by_type_hash, load_self_id,
};
use spore_utils::{check_spore_address, extract_spore_action};

Expand Down Expand Up @@ -119,7 +119,7 @@ fn process_transfer() -> Result<(), Error> {
let action::SporeActionUnion::TransferAgent(transfer) = extract_spore_action()?.to_enum() else {
return Err(Error::SporeActionMismatch);
};
if load_type_args(0, GroupInput).as_ref() != transfer.cluster_id().as_slice() {
if &load_self_id()? != transfer.cluster_id().as_slice() {
return Err(Error::SporeActionFieldMismatch);
}
check_spore_address(GroupInput, transfer.from())?;
Expand All @@ -133,7 +133,7 @@ fn process_destruction() -> Result<(), Error> {
let action::SporeActionUnion::BurnAgent(burn) = extract_spore_action()?.to_enum() else {
return Err(Error::SporeActionMismatch);
};
if load_type_args(0, GroupInput).as_ref() != burn.cluster_id().as_slice() {
if &load_self_id()? != burn.cluster_id().as_slice() {
return Err(Error::SporeActionFieldMismatch);
}
check_spore_address(GroupInput, burn.from())?;
Expand Down
8 changes: 4 additions & 4 deletions contracts/cluster_proxy/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use spore_errors::error::Error;
use spore_types::generated::action;
use spore_utils::{
check_spore_address, extract_spore_action, find_position_by_lock_hash, find_position_by_type,
find_position_by_type_args, load_type_args, verify_type_id,
find_position_by_type_args, load_self_id, verify_type_id,
};

fn is_valid_cluster_cell(script_hash: &[u8; 32]) -> bool {
Expand Down Expand Up @@ -70,7 +70,7 @@ fn process_transfer() -> Result<(), Error> {
return Err(Error::SporeActionMismatch);
};
if input_data.as_slice() != transfer.cluster_id().as_slice()
|| load_type_args(0, GroupInput).as_ref() != transfer.proxy_id().as_slice()
|| &load_self_id()? != transfer.proxy_id().as_slice()
{
return Err(Error::SporeActionFieldMismatch);
}
Expand All @@ -82,14 +82,14 @@ fn process_transfer() -> Result<(), Error> {

fn process_destruction() -> Result<(), Error> {
let cluster_id = load_cell_data(0, GroupInput)?;
let proxy_id = load_type_args(0, GroupInput);
let proxy_id = load_self_id()?;

// co-build check @lyk
let action::SporeActionUnion::BurnProxy(burn) = extract_spore_action()?.to_enum() else {
return Err(Error::SporeActionMismatch);
};
if cluster_id.as_slice() != burn.cluster_id().as_slice()
|| proxy_id.as_ref() != burn.proxy_id().as_slice()
|| &proxy_id != burn.proxy_id().as_slice()
{
return Err(Error::SporeActionFieldMismatch);
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/spore/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use spore_types::generated::action;
use spore_types::generated::spore_types::{ClusterData, SporeData};
use spore_utils::{
calc_capacity_sum, check_spore_address, extract_spore_action, find_position_by_lock_hash,
find_position_by_type, find_position_by_type_args, load_type_args, verify_type_id, MIME,
find_position_by_type, find_position_by_type_args, load_self_id, verify_type_id, MIME,
};

use crate::hash::{CLUSTER_AGENT_CODE_HASHES, CLUSTER_CODE_HASHES};
Expand Down Expand Up @@ -181,7 +181,7 @@ fn process_destruction() -> Result<(), Error> {
let action::SporeActionUnion::BurnSpore(burn) = extract_spore_action()?.to_enum() else {
return Err(Error::SporeActionMismatch);
};
if burn.spore_id().as_slice() != load_type_args(0, GroupInput).as_ref() {
if burn.spore_id().as_slice() != &load_self_id()? {
return Err(Error::SporeActionFieldMismatch);
}
check_spore_address(GroupInput, burn.from())?;
Expand Down Expand Up @@ -216,7 +216,7 @@ fn process_transfer() -> Result<(), Error> {
let action::SporeActionUnion::TransferSpore(transfer) = extract_spore_action()?.to_enum() else {
return Err(Error::SporeActionMismatch);
};
if transfer.spore_id().as_slice() != load_type_args(0, GroupInput).as_ref() {
if transfer.spore_id().as_slice() != &load_self_id()? {
return Err(Error::SporeActionFieldMismatch);
}
check_spore_address(GroupInput, transfer.from())?;
Expand Down
7 changes: 6 additions & 1 deletion lib/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

extern crate alloc;

use alloc::vec::Vec;
use ckb_std::ckb_constants::Source;
use ckb_std::ckb_types::bytes::Bytes;
use ckb_std::ckb_types::packed::Script;
Expand All @@ -10,7 +11,7 @@ use ckb_std::ckb_types::util::hash::Blake2bBuilder;
use ckb_std::debug;
use ckb_std::high_level::{
load_cell, load_cell_data, load_cell_lock, load_cell_lock_hash, load_cell_type,
load_cell_type_hash, load_input, load_script_hash, QueryIter,
load_cell_type_hash, load_input, load_script, load_script_hash, QueryIter,
};

use spore_errors::error::Error;
Expand All @@ -24,6 +25,10 @@ pub mod co_build_types {

mod mime;

pub fn load_self_id() -> Result<Vec<u8>, Error> {
Ok(load_script()?.args().raw_data()[..32].to_vec())
}

pub fn load_type_args(index: usize, source: Source) -> Bytes {
load_cell_type(index, source)
.unwrap_or(None)
Expand Down

0 comments on commit 0e80292

Please sign in to comment.