Skip to content
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
40 changes: 20 additions & 20 deletions contracts/cluster/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ fn process_creation(index: usize) -> Result<(), Error> {
.ok_or(Error::MutantNotInDeps)?;
}

// check co-build action @lyk
let action::SporeActionUnion::MintCluster(mint) = extract_spore_action()?.to_enum() else {
return Err(Error::SporeActionMismatch);
};
if cluster_id != mint.cluster_id().as_slice()
|| blake2b_256(cluster_data.as_slice()) != mint.data_hash().as_slice()
{
return Err(Error::SporeActionFieldMismatch);
}
check_spore_address(GroupOutput, mint.to())?;
// // check co-build action @lyk
// let action::SporeActionUnion::MintCluster(mint) = extract_spore_action()?.to_enum() else {
// return Err(Error::SporeActionMismatch);
// };
// if cluster_id != mint.cluster_id().as_slice()
// || blake2b_256(cluster_data.as_slice()) != mint.data_hash().as_slice()
// {
// return Err(Error::SporeActionFieldMismatch);
// }
// check_spore_address(GroupOutput, mint.to())?;

Ok(())
}
Expand All @@ -73,16 +73,16 @@ fn process_transfer() -> Result<(), Error> {
return Err(Error::ModifyClusterPermanentField);
}

// check co-build action @lyk
let action::SporeActionUnion::TransferCluster(transfer) = extract_spore_action()?.to_enum()
else {
return Err(Error::SporeActionMismatch);
};
if transfer.cluster_id().as_slice() != &load_self_id()? {
return Err(Error::SporeActionFieldMismatch);
}
check_spore_address(GroupInput, transfer.from())?;
check_spore_address(GroupOutput, transfer.to())?;
// // check co-build action @lyk
// let action::SporeActionUnion::TransferCluster(transfer) = extract_spore_action()?.to_enum()
// else {
// return Err(Error::SporeActionMismatch);
// };
// if transfer.cluster_id().as_slice() != &load_self_id()? {
// return Err(Error::SporeActionFieldMismatch);
// }
// check_spore_address(GroupInput, transfer.from())?;
// check_spore_address(GroupOutput, transfer.to())?;

Ok(())
}
Expand Down
56 changes: 28 additions & 28 deletions contracts/cluster_agent/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,16 @@ fn process_creation(_index: usize) -> Result<(), Error> {
}
}

// co-build check @lyk
let action::SporeActionUnion::MintAgent(mint) = extract_spore_action()?.to_enum() else {
return Err(Error::SporeActionMismatch);
};
if &cluster_id != mint.cluster_id().as_slice()
|| &proxy_type.args().raw_data()[..CLUSTER_PROXY_ID_LEN] != mint.proxy_id().as_slice()
{
return Err(Error::SporeActionFieldMismatch);
}
check_spore_address(GroupOutput, mint.to())?;
// // co-build check @lyk
// let action::SporeActionUnion::MintAgent(mint) = extract_spore_action()?.to_enum() else {
// return Err(Error::SporeActionMismatch);
// };
// if &cluster_id != mint.cluster_id().as_slice()
// || &proxy_type.args().raw_data()[..CLUSTER_PROXY_ID_LEN] != mint.proxy_id().as_slice()
// {
// return Err(Error::SporeActionFieldMismatch);
// }
// check_spore_address(GroupOutput, mint.to())?;

Ok(())
}
Expand All @@ -119,29 +119,29 @@ fn process_transfer() -> Result<(), Error> {
return Err(Error::ImmutableAgentFieldModification);
}

// co-build check @lyk
let action::SporeActionUnion::TransferAgent(transfer) = extract_spore_action()?.to_enum()
else {
return Err(Error::SporeActionMismatch);
};
if &load_self_id()? != transfer.cluster_id().as_slice() {
return Err(Error::SporeActionFieldMismatch);
}
check_spore_address(GroupInput, transfer.from())?;
check_spore_address(GroupOutput, transfer.to())?;
// // co-build check @lyk
// let action::SporeActionUnion::TransferAgent(transfer) = extract_spore_action()?.to_enum()
// else {
// return Err(Error::SporeActionMismatch);
// };
// if &load_self_id()? != transfer.cluster_id().as_slice() {
// return Err(Error::SporeActionFieldMismatch);
// }
// check_spore_address(GroupInput, transfer.from())?;
// check_spore_address(GroupOutput, transfer.to())?;

Ok(())
}

fn process_destruction() -> Result<(), Error> {
// co-build check @lyk
let action::SporeActionUnion::BurnAgent(burn) = extract_spore_action()?.to_enum() else {
return Err(Error::SporeActionMismatch);
};
if &load_self_id()? != burn.cluster_id().as_slice() {
return Err(Error::SporeActionFieldMismatch);
}
check_spore_address(GroupInput, burn.from())?;
// // co-build check @lyk
// let action::SporeActionUnion::BurnAgent(burn) = extract_spore_action()?.to_enum() else {
// return Err(Error::SporeActionMismatch);
// };
// if &load_self_id()? != burn.cluster_id().as_slice() {
// return Err(Error::SporeActionFieldMismatch);
// }
// check_spore_address(GroupInput, burn.from())?;
Ok(())
}

Expand Down
40 changes: 20 additions & 20 deletions contracts/cluster_proxy/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ fn process_creation(index: usize) -> Result<(), Error> {
.ok_or(Error::ClusterOwnershipVerifyFailed)?;
}

// co-build check @lyk
let action::SporeActionUnion::MintProxy(create) = extract_spore_action()?.to_enum() else {
return Err(Error::SporeActionMismatch);
};
if proxy_id != create.proxy_id().as_slice() || &cluster_id != create.cluster_id().as_slice() {
return Err(Error::SporeActionFieldMismatch);
}
check_spore_address(GroupOutput, create.to())?;
// // co-build check @lyk
// let action::SporeActionUnion::MintProxy(create) = extract_spore_action()?.to_enum() else {
// return Err(Error::SporeActionMismatch);
// };
// if proxy_id != create.proxy_id().as_slice() || &cluster_id != create.cluster_id().as_slice() {
// return Err(Error::SporeActionFieldMismatch);
// }
// check_spore_address(GroupOutput, create.to())?;

Ok(())
}
Expand All @@ -74,18 +74,18 @@ fn process_transfer() -> Result<(), Error> {
return Err(Error::ImmutableProxyFieldModification);
}

// co-build check @lyk
let action::SporeActionUnion::TransferProxy(transfer) = extract_spore_action()?.to_enum()
else {
return Err(Error::SporeActionMismatch);
};
if input_data.as_slice() != transfer.cluster_id().as_slice()
|| &load_self_id()? != transfer.proxy_id().as_slice()
{
return Err(Error::SporeActionFieldMismatch);
}
check_spore_address(GroupInput, transfer.from())?;
check_spore_address(GroupOutput, transfer.to())?;
// // co-build check @lyk
// let action::SporeActionUnion::TransferProxy(transfer) = extract_spore_action()?.to_enum()
// else {
// return Err(Error::SporeActionMismatch);
// };
// if input_data.as_slice() != transfer.cluster_id().as_slice()
// || &load_self_id()? != transfer.proxy_id().as_slice()
// {
// return Err(Error::SporeActionFieldMismatch);
// }
// check_spore_address(GroupInput, transfer.from())?;
// check_spore_address(GroupOutput, transfer.to())?;

Ok(())
}
Expand Down
83 changes: 48 additions & 35 deletions contracts/spore/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,16 @@ fn process_creation(index: usize) -> Result<(), Error> {
}
}

// check co-build action @lyk
let action::SporeActionUnion::MintSpore(mint) = extract_spore_action()?.to_enum() else {
return Err(Error::SporeActionMismatch);
};
if mint.spore_id().as_slice() != spore_id
|| mint.data_hash().as_slice() != blake2b_256(spore_data.as_slice())
{
return Err(Error::SporeActionFieldMismatch);
}
check_spore_address(GroupOutput, mint.to())?;
// // check co-build action @lyk
// let action::SporeActionUnion::MintSpore(mint) = extract_spore_action()?.to_enum() else {
// return Err(Error::SporeActionMismatch);
// };
// if mint.spore_id().as_slice() != spore_id
// || mint.data_hash().as_slice() != blake2b_256(spore_data.as_slice())
// {
// return Err(Error::SporeActionFieldMismatch);
// }
// check_spore_address(GroupOutput, mint.to())?;

Ok(())
}
Expand All @@ -189,14 +189,14 @@ fn process_destruction() -> Result<(), Error> {
verify_extension(&mime, Operation::Burn, vec![index as u8])?;
}

// check co-build action @lyk
let action::SporeActionUnion::BurnSpore(burn) = extract_spore_action()?.to_enum() else {
return Err(Error::SporeActionMismatch);
};
if burn.spore_id().as_slice() != &load_self_id()? {
return Err(Error::SporeActionFieldMismatch);
}
check_spore_address(GroupInput, burn.from())?;
// // check co-build action @lyk
// let action::SporeActionUnion::BurnSpore(burn) = extract_spore_action()?.to_enum() else {
// return Err(Error::SporeActionMismatch);
// };
// if burn.spore_id().as_slice() != &load_self_id()? {
// return Err(Error::SporeActionFieldMismatch);
// }
// check_spore_address(GroupInput, burn.from())?;

Ok(())
}
Expand Down Expand Up @@ -226,16 +226,16 @@ fn process_transfer() -> Result<(), Error> {
)?;
}

// check co-build action @lyk
let action::SporeActionUnion::TransferSpore(transfer) = extract_spore_action()?.to_enum()
else {
return Err(Error::SporeActionMismatch);
};
if transfer.spore_id().as_slice() != &load_self_id()? {
return Err(Error::SporeActionFieldMismatch);
}
check_spore_address(GroupInput, transfer.from())?;
check_spore_address(GroupOutput, transfer.to())?;
// // check co-build action @lyk
// let action::SporeActionUnion::TransferSpore(transfer) = extract_spore_action()?.to_enum()
// else {
// return Err(Error::SporeActionMismatch);
// };
// if transfer.spore_id().as_slice() != &load_self_id()? {
// return Err(Error::SporeActionFieldMismatch);
// }
// check_spore_address(GroupInput, transfer.from())?;
// check_spore_address(GroupOutput, transfer.to())?;

Ok(())
}
Expand Down Expand Up @@ -271,8 +271,12 @@ fn verify_extension(mime: &MIME, op: Operation, argv: Vec<u8>) -> Result<(), Err
ScriptHashType::Data1,
&[
CStr::from_bytes_with_nul([b'0', 0].as_slice()).unwrap_or_default(),
CStr::from_bytes_with_nul([b'0' + mutant_index as u8, 0].as_slice(),) .unwrap_or_default(),
CStr::from_bytes_with_nul([b'0' + argv[0], 0].as_slice()) .unwrap_or_default(),
CStr::from_bytes_with_nul(
[b'0' + mutant_index as u8, 0].as_slice(),
)
.unwrap_or_default(),
CStr::from_bytes_with_nul([b'0' + argv[0], 0].as_slice())
.unwrap_or_default(),
],
)?;
}
Expand All @@ -282,9 +286,14 @@ fn verify_extension(mime: &MIME, op: Operation, argv: Vec<u8>) -> Result<(), Err
ScriptHashType::Data1,
&[
CStr::from_bytes_with_nul([b'1', 0].as_slice()).unwrap_or_default(),
CStr::from_bytes_with_nul([b'0' + mutant_index as u8, 0].as_slice(),) .unwrap_or_default(),
CStr::from_bytes_with_nul([b'0' + argv[0], 0].as_slice()) .unwrap_or_default(),
CStr::from_bytes_with_nul([b'0' + argv[1], 0].as_slice()) .unwrap_or_default(),
CStr::from_bytes_with_nul(
[b'0' + mutant_index as u8, 0].as_slice(),
)
.unwrap_or_default(),
CStr::from_bytes_with_nul([b'0' + argv[0], 0].as_slice())
.unwrap_or_default(),
CStr::from_bytes_with_nul([b'0' + argv[1], 0].as_slice())
.unwrap_or_default(),
],
)?;
}
Expand All @@ -294,8 +303,12 @@ fn verify_extension(mime: &MIME, op: Operation, argv: Vec<u8>) -> Result<(), Err
ScriptHashType::Data1,
&[
CStr::from_bytes_with_nul([b'2', 0].as_slice()).unwrap_or_default(),
CStr::from_bytes_with_nul([b'0' + mutant_index as u8, 0].as_slice(),) .unwrap_or_default(),
CStr::from_bytes_with_nul([b'0' + argv[0], 0].as_slice()) .unwrap_or_default(),
CStr::from_bytes_with_nul(
[b'0' + mutant_index as u8, 0].as_slice(),
)
.unwrap_or_default(),
CStr::from_bytes_with_nul([b'0' + argv[0], 0].as_slice())
.unwrap_or_default(),
],
)?;
}
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.74.0
1.78.0
20 changes: 10 additions & 10 deletions tests/src/tests/spore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,11 @@ mod spore_mint_from_cluster_transfer {
make_spore_mint_from_cluster_transfer(true, true);
}

#[should_panic]
#[test]
fn test_spore_mint_from_cluster_transfer_failed_with_no_cluster_action() {
make_spore_mint_from_cluster_transfer(false, true);
}
// #[should_panic]
// #[test]
// fn test_spore_mint_from_cluster_transfer_failed_with_no_cluster_action() {
// make_spore_mint_from_cluster_transfer(false, true);
// }

#[should_panic]
#[test]
Expand Down Expand Up @@ -525,11 +525,11 @@ mod spore_mint_from_agent_transfer {
make_spore_mint_from_agent_transfer(false, true);
}

#[should_panic]
#[test]
fn test_spore_mint_from_agent_transfer_failed_with_no_agent_action() {
make_spore_mint_from_agent_transfer(true, false);
}
// #[should_panic]
// #[test]
// fn test_spore_mint_from_agent_transfer_failed_with_no_agent_action() {
// make_spore_mint_from_agent_transfer(true, false);
// }
}

mod simple_spore_destroy {
Expand Down