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: contract is now upgradeable through participants voting for updates #714

Merged
merged 3 commits into from
Jul 24, 2024

Conversation

ChaoticTempest
Copy link
Member

The contract can now be upgraded or config updated through calling into:

  • propose_update: (config | wasm) -> UpdateId
  • vote_update: (UpdateId) -> bool

Only participants from the contract are able to partake. Added config here just to test it can work there too.

chain-signatures/contract/src/config.rs Show resolved Hide resolved
chain-signatures/contract/src/config.rs Show resolved Hide resolved
chain-signatures/contract/src/config.rs Show resolved Hide resolved
&mut self,
code: Option<Vec<u8>>,
config: Option<Config>,
) -> Result<UpdateId, VoteError> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was asking about this pattern in one of my previous PRs. Does it make sense to return more specific errors on all, or all user-facing functions instead of the generic MPC error?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah we should flatten the errors out similar to workspace errors because we have too many similar sounding errors that can pop up for categories of errors. Let me see if I can whip up something real quick for this before release

chain-signatures/contract/src/errors.rs Show resolved Hide resolved
chain-signatures/contract/src/lib.rs Show resolved Hide resolved
chain-signatures/contract/tests/tests.rs Show resolved Hide resolved
chain-signatures/contract/tests/tests.rs Show resolved Hide resolved
chain-signatures/contract/tests/tests.rs Show resolved Hide resolved
contract.view("state").await.unwrap().json().unwrap();

// Let's propose a contract update instead now.
let new_wasm = std::fs::read(CONTRACT_FILE_PATH).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Technically, it is the same contract.
Not blocking, but we will need to have a test, that the contract was updated. More than that, it would be great to have a test, that this new contract is also upgradable :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add a status_msg contract to show that it does indeed change if we send in a different contract. I'm trying to figure out a way to safeguard against a case where we deploy unwanted contract. In that case, I think we should just validate the core interfaces to see that they still exist like:

  • state
  • sign
  • respond

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to validating interface. We should probably also check that contract is still upgradable, otherwise it's locked

Copy link
Member Author

Choose a reason for hiding this comment

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

the contract will always be upgradeable since there's no stopping the contract itself from calling deploy on itself even if the contract is locked

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, but if we break the function that is triggering this logic - we will loose the contract

Copy link
Collaborator

@volovyks volovyks left a comment

Choose a reason for hiding this comment

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

Looks awesome! And delivered in 1 day, cool.

chain-signatures/contract/src/lib.rs Show resolved Hide resolved
chain-signatures/contract/src/lib.rs Show resolved Hide resolved
chain-signatures/contract/src/lib.rs Show resolved Hide resolved
Copy link
Contributor

@ppca ppca left a comment

Choose a reason for hiding this comment

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

LGTM.
Just wondering is there anyway we could check that the included wasm code is valid? Because even a benign partner could accidentally propose some bad code.
And what is our remedy if partner gets compromised and propose malicious contract code? But I guess we'd be the only official source to propose update and partners (assuming most are benign) will only vote for our proposed update.

chain-signatures/contract/src/config.rs Show resolved Hide resolved
Some(votes)
}

pub fn remove(&mut self, id: &UpdateId) -> Option<Vec<Update>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

So if partner keeps proposing updates and no do_update is done, the updates map will keep piling up? Will that cause issue some day?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, we need to charge a deposit for propose_update

@ChaoticTempest
Copy link
Member Author

@ppca it's really hard to test valid upgrades. What I'm thinking is checking core interfaces like state, sign and respond to see if the contract got updated correctly but that would be at the contract level.

We can actually make voters pull down the update and verify locally it themselves to see if everything is running correctly. We probably need a CLI tool for this to run through the checks, but right now not a priority

@ChaoticTempest
Copy link
Member Author

Merging this one for now to let @ppca test the release candidate, will make a separate PR to address the issues noted here

@ChaoticTempest ChaoticTempest merged commit 84ff24c into develop Jul 24, 2024
4 checks passed
@ChaoticTempest ChaoticTempest deleted the phuong/feat/upgrade-contract-through-votes branch July 24, 2024 19:18
Copy link

Terraform Feature Environment Destroy (dev-714)

Terraform Initialization ⚙️success

Terraform Destroy success

Show Destroy Plan


No changes. No objects need to be destroyed.

Either you have not created any objects yet or the existing objects were
already deleted outside of Terraform.

Destroy complete! Resources: 0 destroyed.

Pusher: @ChaoticTempest, Action: pull_request, Working Directory: ``, Workflow: Terraform Feature Env (Destroy)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants