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

refactor: staking factory to check mech and requester staking instances #38

Merged
merged 3 commits into from
Aug 26, 2024

Conversation

kupermind
Copy link
Collaborator

  • Staking factory to check mech and requester staking instances.

/// @dev Performs actions before the delivery of a request.
/// @param data Self-descriptive opaque data-blob.
/// @return requestData Data for the request processing.
function _preDeliver(address, uint256, bytes memory data) internal virtual returns (bytes memory requestData) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not deleting, just moving around to have a better contract visibility.

/// @dev Checks agent mech for contract validity.
/// @param mech Agent mech address.
/// @param mechServiceId Mech operator service Id.
function checkMech(address mech, uint256 mechServiceId) public view {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These are changed to ones below

Comment on lines 315 to 299

// Check if the requester service is staked
IStaking.StakingState state = IStaking(requesterStakingInstance).getStakingState(requesterServiceId);
if (state != IStaking.StakingState.Staked) {
revert ServiceNotStaked(requesterStakingInstance, requesterServiceId);
}
checkMech(priorityMech, priorityMechStakingInstance, priorityMechServiceId);

// Get the staked service info
IStaking.ServiceInfo memory serviceInfo = IStaking(requesterStakingInstance).getServiceInfo(requesterServiceId);
// Check staked service multisig
if (serviceInfo.multisig != msg.sender) {
revert OwnerOnly(msg.sender, serviceInfo.multisig);
}
// Check requester
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Mechs and requester services are verified in these functions

/// @dev Checks for staking instance contract validity.
/// @param stakingInstance Staking instance address.
/// @param serviceId Service Id.
function checkStakingInstance(address stakingInstance, uint256 serviceId) public view {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This function verifies that the staking contract of either requester / mech is valid and that the corresponding service is staked.

/// @dev mech Agent mech contract address.
/// @param mechStakingInstance Agent mech staking instance address.
/// @param mechServiceId Agent mech service Id.
function checkMech(address mech, address mechStakingInstance, uint256 mechServiceId) public view {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This function then additionally checks that the mech is correct

/// @dev requester Requester contract address.
/// @param requesterStakingInstance Requester staking instance address.
/// @param requesterServiceId Requester service Id.
function checkRequester(address requester, address requesterStakingInstance, uint256 requesterServiceId) public view {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This function is additionally checkin that the requester is correct.

Copy link
Contributor

@DavidMinarsch DavidMinarsch left a comment

Choose a reason for hiding this comment

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

nice!

@kupermind kupermind merged commit 370ac4e into staking_checker Aug 26, 2024
1 of 2 checks passed
@kupermind kupermind deleted the staking_factory_verification branch August 26, 2024 15:27
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