Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add co-build integration in code base #28

Merged
merged 16 commits into from
Jan 17, 2024

Conversation

ashuralyk
Copy link
Contributor

@ashuralyk ashuralyk commented Jan 2, 2024

Description

co-build integration for Spore contract.

Address in Spore action definition means the intense of users if to check corresponding address, like from and to, since each Spore transaction has its from or to address, we require co-build related contracts to check their validation of addresses.

I've deleted and adjusted some duplicated and misunderstanding test cases for simplicity.

tests has been refactored.

Tasks list

  • integrate co-build in Spore contract code base
  • adjust test cases for adapting co-build check

@ashuralyk ashuralyk self-assigned this Jan 2, 2024
@ashuralyk ashuralyk changed the base branch from master to develope January 2, 2024 13:23
@ashuralyk ashuralyk marked this pull request as ready for review January 4, 2024 06:20
lib/utils/src/lib.rs Outdated Show resolved Hide resolved
lib/utils/src/lib.rs Outdated Show resolved Hide resolved
lib/utils/src/lib.rs Outdated Show resolved Hide resolved
contracts/spore/src/entry.rs Outdated Show resolved Hide resolved
lib/utils/src/lib.rs Outdated Show resolved Hide resolved
lib/utils/src/lib.rs Outdated Show resolved Hide resolved
tests/src/utils/co_build.rs Show resolved Hide resolved
tests/src/tests/cluster.rs Outdated Show resolved Hide resolved
@ashuralyk ashuralyk requested review from Flouse and quake January 5, 2024 12:24
@ashuralyk ashuralyk changed the base branch from develope to master January 5, 2024 12:41
lib/utils/src/lib.rs Outdated Show resolved Hide resolved
lib/types/schemas/action.mol Outdated Show resolved Hide resolved
@Flouse
Copy link
Contributor

Flouse commented Jan 5, 2024

Is this code useless?

#[allow(unused)]
fn process_input(
index: usize,
input_source: Source,
group_cell_in_outputs: &mut Vec<usize>,
output_source: Source,
) -> Result<(), Error> {
let group_id = load_cell_type(index, input_source)?
.unwrap_or_default()
.args();
for i in 0..group_cell_in_outputs.len() {
let output_index = group_cell_in_outputs.get(i).unwrap();
let output_group_id = load_cell_type(*output_index, output_source)?
.unwrap_or_default()
.args();
if group_id.as_slice()[..] == output_group_id.as_slice()[..] {
let group_data = load_cluster_data(index, input_source)?;
let output_group_data = load_cluster_data(i, output_source)?;
if group_data.name().as_slice()[..] != output_group_data.name().as_slice()[..] {
return Err(Error::ModifyClusterPermanentField);
}
group_cell_in_outputs.remove(i);
return Ok(());
}
}
// can not destroy a group cell now
Err(Error::InvalidClusterOperation)
}

Never mind, maybe it could be deleted later.

@ashuralyk ashuralyk force-pushed the feat/integrate-co-build branch from 6921c15 to 1d6f158 Compare January 6, 2024 02:26
@ashuralyk ashuralyk requested a review from Flouse January 6, 2024 02:27
contracts/cluster_agent/src/entry.rs Outdated Show resolved Hide resolved
@ashuralyk ashuralyk force-pushed the feat/integrate-co-build branch from 9fe4dd6 to 74e831d Compare January 11, 2024 09:04
@ashuralyk
Copy link
Contributor Author

@ShookLyngs rerun CI again once spore-sdk enabled its co-build feature

@ashuralyk ashuralyk added the feature New things to append label Jan 11, 2024
Copy link
Collaborator

@ShookLyngs ShookLyngs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About the action.mol, I have found a few potential issues, please check the following:

  1. The corresponding "melt" actions for ClusterProxy and ClusterAgent are not defined. ClusterProxy and ClusterAgent are both designed to be meltable, so maybe they should be added.
  2. The code_hash field is not defined in both the ProxyCreate and the AgentCreate actions, but the field is defined in the Mint and the ClusterCreate actions.
  3. The proxy_id field is not defined in the AgentCreate action, but when creating a ClusterAgent, a ClusterProxy must be referenced in the transaction (via payment or cell reference).

@ShookLyngs
Copy link
Collaborator

I have some thoughts regarding the naming of the SporeAction (just some personal suggestions):

  • Inconsistent names such as Mint and ClusterCreate can be renamed to align with each other.
  • Personally I feel like the naming of ClusterCreate looks off, perhaps alternatives like CreateCluster or ClusterCreation would be more appropriate.

@ashuralyk
Copy link
Contributor Author

ashuralyk commented Jan 12, 2024

The code_hash field is not defined in both the ProxyCreate and the AgentCreate actions, but the field is defined in the Mint and the ClusterCreate actions

  1. data_hash in proxy is not necessary, because the data itself represents cluster_id, which is included in molecule definition
  2. data_hash in agent is proxy_type_hash that is used to locate proxy in celldep, I can add proxy_id to check instead

The corresponding "melt" actions for ClusterProxy and ClusterAgent are not defined. ClusterProxy and ClusterAgent are both designed to be meltable, so maybe they should be added.

in both proxy and agent contracts, there's no function to check validation of action melt, so I guess there's no need to add melt action for them

@ShookLyngs

@ShookLyngs
Copy link
Collaborator

  1. data_hash in proxy is not necessary, because the data itself represents cluster_id, which is included in molecule definition
  2. data_hash in agent is proxy_type_hash that is used to locate proxy in celldep, I can add proxy_id to check instead

Have I misunderstood why the data_hash is required in a creation action?
I thought it was for validating the code hashes. Could you please explain the design behind it? Thank you.

in both proxy and agent contracts, there's no function to check validation of action melt, so I guess there's no need to add melt action for them

Do you mean the co-build feature should be disabled when melting ClusterProxy and ClusterAgent?
I think I need more instructions about when it should be enabled/disabled.

@ashuralyk
Copy link
Contributor Author

Have I misunderstood why the data_hash is required in a creation action?

I guess no, because current co-build design is rely on us, we have responsibility to design it to match our need, so the molecule I designed is to match my need that collected from contracts implementation

I think if you have your sense of design from sdk, feel free to post it out, and we can discuss

@ShookLyngs
Copy link
Collaborator

ShookLyngs commented Jan 12, 2024

I guess no, because current co-build design is rely on us, we have responsibility to design it to match our need, so the molecule I designed is to match my need that collected from contracts implementation

From my perspective, co-build is a feature that enables typed messages in ckb wallets. To achieve this, each type of Spore-related transaction, such as creation, transfer, and melting, should have a corresponding action defined in the molecule. Otherwise, I'm not sure what would happen if a user tries to melt a ClusterProxy, would the wallet simply request the user to sign a hash instead of a typed message?

- User -> Melt Spore -> Sign for typed message: "melting spore 0x..."
- User -> Melt ClusterProxy -> ?

Need more info on this, thx.

@ashuralyk
Copy link
Contributor Author

To achieve this, each type of Spore-related transaction, such as creation, transfer, and melting, should have a corresponding action defined in the molecule

I got your concerns, I'll add melt action for proxy and agent only with from address as parameter

@Flouse
Copy link
Contributor

Flouse commented Jan 12, 2024

Cluster Proxy and Cluster Agent is planned in Stage 2.

Are you going to test them right now? or just focus on Stage 1 before 2024-01-20?

@ashuralyk
Copy link
Contributor Author

Cluster Proxy and Cluster Agent is planned in Stage 2.

Are you going to test them right now? or just focus on Stage 1 before 2024-01-20?

test process is the same and won't take more time, and it's better to test them all, thus we don't have to pay twice for re-deploying Cluster and Spore contracts again

@ashuralyk
Copy link
Contributor Author

@ShookLyngs proxy/agent actions are prepared, please check it out

@ashuralyk ashuralyk requested a review from ShookLyngs January 15, 2024 07:09
@ShookLyngs
Copy link
Collaborator

ShookLyngs commented Jan 16, 2024

Encountered some failed cases during my tests using this branch of code: sporeprotocol/spore-sdk#68.
On the other hand, Spore/Cluster related tests have passed.

Error 11:

  • Transfer ClusterProxy
  • Melt ClusterProxy
  • Create ClusterAgent with ClsuterProxy (via cell reference)
  • Melt ClusterAgent

I've only added detailed cobuild checks to the "Transfer ClusterProxy" test case, see: https://github.com/sporeprotocol/spore-sdk/pull/68/files#diff-0d580b1ad4f9eff4775817d276fc19a0c95a2e00cc6263f94bc8c394fe44b411. Maybe you can try unpack the extra witness and see what went wrong?

@ashuralyk ashuralyk force-pushed the feat/integrate-co-build branch from 1d7b3ab to 5a1e62f Compare January 17, 2024 02:53
@ashuralyk ashuralyk force-pushed the feat/integrate-co-build branch from 61b32c7 to 0e80292 Compare January 17, 2024 07:00
@ashuralyk ashuralyk merged commit f0a0ef3 into master Jan 17, 2024
2 checks passed
@ashuralyk ashuralyk deleted the feat/integrate-co-build branch January 17, 2024 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New things to append
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants