feat: require deposits for a few migration functions - #3874
Conversation
b7ad059 to
e207ebc
Compare
|
Since this PR changes source code behavior by adding deposit requirements to contract functions, the type should probably be Suggested title: |
Pull request overviewAdds a Changes:
Reviewed changesPer-file summary
FindingsBlocking (must fix before merge):
Non-blocking (nits, follow-ups, suggestions):
✅ Approved |
e207ebc to
b456de8
Compare
|
PR title type suggestion: This PR modifies the behavior of existing contract functions (adding deposit requirements), which is a functional change rather than routine maintenance. The type prefix should probably be Suggested title: |
| // Given | ||
| let running_state = gen_running_state(NUM_DOMAINS); | ||
| let account_id = running_state.parameters.participants().participants()[0] | ||
| .0 | ||
| .clone(); | ||
| let mut contract = | ||
| MpcContract::new_from_protocol_state(ProtocolContractState::Running(running_state)); | ||
| let mut test_env = Environment::new(None, Some(account_id), None); | ||
| test_env.set_deposit(NearToken::from_yoctonear(0)); | ||
| let backup_service_info = BackupServiceInfo { | ||
| public_key: bogus_ed25519_public_key(), | ||
| }; |
There was a problem hiding this comment.
There’s a bit of copy-paste between these two tests. Perhaps it’s worth extracting the boilerplate, if possible?
There was a problem hiding this comment.
For these tests we usually have a similar structure, that extracting might hide. Leaving as is for now, although we could consider changing it if the boilerplate keeps growing
There was a problem hiding this comment.
Pull request overview
Adds a 1 yoctoNEAR deposit requirement to selected operator-initiated node-migration / node-management contract methods to prevent calls from restricted keys, and updates tooling/tests/docs accordingly.
Changes:
- Mark
register_backup_service,start_node_migration, andupdate_participant_urlas#[payable]and enforce a minimum attached deposit viarequire_deposit. - Update E2E harness + backup-cli output + migration guide examples to attach
1 yoctoNEAR. - Extend contract test utilities and add/adjust tests to cover “no deposit attached” rejections.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/node-migration-guide.md | Updates example near CLI invocations to attach 1 yoctoNEAR for migration-related calls. |
| crates/e2e-tests/src/cluster.rs | Switches operator calls to use a new “call with deposit” helper and attaches 1 yoctoNEAR. |
| crates/e2e-tests/src/blockchain.rs | Introduces call_from_deposit convenience wrapper (JSON args + default gas). |
| crates/contract/tests/snapshots/abi__abi_has_not_changed.snap | ABI snapshot updated to reflect payable modifiers + updated method docs. |
| crates/contract/tests/inprocess/update_participant_url.rs | Updates inprocess tests to attach deposit; adds a “reject without deposit” test. |
| crates/contract/tests/inprocess/common.rs | Adds participant_context_with_deposit VM context helper for payable methods. |
| crates/contract/src/tee/test_utils.rs | Extends Environment to track/apply attached deposit in VM context. |
| crates/contract/src/lib.rs | Adds MINIMUM_NODE_MANAGEMENT_DEPOSIT, makes methods payable, enforces deposit, and updates tests. |
| crates/backup-cli/src/backup.rs | Updates printed registration command to attach 1 yoctoNEAR. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…-is-required-for-migration-functions
|
PR title type suggestion: This PR modifies contract behavior by adding deposit requirements to migration functions, which changes the contract's interface (ABI snapshot updated). Since source code changes add new requirements rather than routine maintenance, the type prefix should probably be Suggested title: |
|
PR title type suggestion: This PR adds new requirements (deposits) to migration functions in the contract, which is a behavioral change rather than routine maintenance. The type prefix should probably be Suggested title: |
|
PR title type suggestion: This PR adds a new functional requirement (deposits) to migration functions, which is a feature/capability addition rather than routine maintenance. The type should probably be Suggested title: |
|
PR title type suggestion: This PR adds deposit requirements to three user-facing contract functions, which is a behavioral change to the contract's public API. Consider using Suggested title: |
| /// Minimum deposit required for the operator-authenticated node-management methods | ||
| /// (`register_backup_service`, `start_node_migration`, `update_participant_url`). | ||
| /// | ||
| /// A non-zero deposit forces the call to be signed by a full-access key: the node's own key | ||
| /// is registered as a function-call access key, which cannot attach a deposit, so a leaked | ||
| /// node key cannot invoke these methods. |
There was a problem hiding this comment.
Nit: Could you compact this verbose comment?
There was a problem hiding this comment.
It is very non-trivial why we require this deposits, so being a bit verbose here will probably help future devs
…-is-required-for-migration-functions
|
PR title type suggestion: This PR modifies contract source code to add new behavior (deposit requirements for migration functions), so the type prefix should probably be |
Resolve modify/delete on test-migration.sh by keeping the delete (the script moved to mpc-private). #3874's deposit change to that file is ported to the mpc-private copy (mpc-private#495).
Closes #1163
I added deposits for the functions that are started by operators independently to make sure function-call keys cannot call such functions. For
conclude_node_migrationit was not added as this is currently called directly by the node, and should be running inside a TEE anyway.Some of these deposits might need to be removed after the full backup service is implemented, but for now it is good to have them as defense in depth.