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

Cross chain restaking system #18

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/v1-core"]
path = lib/v1-core
url = https://github.com/glacislabs/v1-core
8 changes: 7 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ libs = ["lib"]
# optimizer = true (default)
optimizer_runs = 200
fs_permissions = [{ access = "read-write", path = "./" }]
solc = "0.8.19"
solc = "0.8.20"

remappings = [
"@openzeppelin/=node_modules/@openzeppelin/"
]


[profile.ci]
verbosity = 4
Expand All @@ -34,3 +39,4 @@ depth = 100
arbitrum_goerli = "${ARBITRUM_GOERLI_RPC}"
arbitrum = "${ARBITRUM_RPC}"
mainnet = "${MAINNET_RPC}"

12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "tnt-core",
"version": "1.0.0",
"main": "index.js",
"repository": "https://github.com/tangle-network/tnt-core.git",
"author": "Tangle <drew@tangle.tools>",
"license": "MIT",
"dependencies": {
"@openzeppelin/contracts": "^5.1.0",
"@openzeppelin/contracts-upgradeable": "^5.1.0"
}
}
90 changes: 18 additions & 72 deletions src/BlueprintServiceManagerBase.sol
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;

import "src/Permissions.sol";
import "src/IBlueprintServiceManager.sol";
import "./Permissions.sol";
import "./interfaces/IBlueprintServiceManager.sol";

/**
* @title BlueprintServiceManagerBase
* @dev This contract acts as a manager for the lifecycle of a Blueprint Instance,
* facilitating various stages such as registration, service requests, job execution,
* and job result handling. It is designed to be used by the service blueprint designer
* (gadget developer) and integrates with the RootChain for permissioned operations.
* Each function serves as a hook for different lifecycle events, and reverting any
* of these functions interrupts the process flow.
*/
contract BlueprintServiceManagerBase is IBlueprintServiceManager, RootChainEnabled {
/**
* @dev Hook for service operator registration. Called when a service operator
* attempts to register with the blueprint.
* @param operator The operator's details in bytes format.
* @param registrationInputs Inputs required for registration in bytes format.
*/
/// @title BlueprintServiceManagerBase
/// @dev This contract acts as a manager for the lifecycle of a Blueprint Instance,
/// facilitating various stages such as registration, service requests, job execution,
/// and job result handling. It is designed to be used by the service blueprint designer
/// (gadget developer) and integrates with the RootChain for permissioned operations.
/// Each function serves as a hook for different lifecycle events, and reverting any
/// of these functions interrupts the process flow.
contract BlueprintServiceManagerBase is IBlueprintServiceManager, RootChainEnabledOwnable {
/// @inheritdoc IBlueprintServiceManager
function onRegister(
bytes calldata operator,
bytes calldata registrationInputs
Expand All @@ -31,13 +24,7 @@ contract BlueprintServiceManagerBase is IBlueprintServiceManager, RootChainEnabl
onlyFromRootChain
{ }

/**
* @dev Hook for service instance requests. Called when a user requests a service
* instance from the blueprint.
* @param serviceId The ID of the requested service.
* @param operators The operators involved in the service in bytes array format.
* @param requestInputs Inputs required for the service request in bytes format.
*/
/// @inheritdoc IBlueprintServiceManager
function onRequest(
uint64 serviceId,
bytes[] calldata operators,
Expand All @@ -50,14 +37,7 @@ contract BlueprintServiceManagerBase is IBlueprintServiceManager, RootChainEnabl
onlyFromRootChain
{ }

/**
* @dev Hook for job calls on the service. Called when a job is called within
* the service context.
* @param serviceId The ID of the service where the job is called.
* @param job The job identifier.
* @param jobCallId A unique ID for the job call.
* @param inputs Inputs required for the job execution in bytes format.
*/
/// @inheritdoc IBlueprintServiceManager
function onJobCall(
uint64 serviceId,
uint8 job,
Expand All @@ -71,16 +51,7 @@ contract BlueprintServiceManagerBase is IBlueprintServiceManager, RootChainEnabl
onlyFromRootChain
{ }

/**
* @dev Hook for handling job result. Called when operators send the result
* of a job execution.
* @param serviceId The ID of the service related to the job.
* @param job The job identifier.
* @param jobCallId The unique ID for the job call.
* @param participant The participant (operator) sending the result in bytes format.
* @param inputs Inputs used for the job execution in bytes format.
* @param outputs Outputs resulting from the job execution in bytes format.
*/
/// @inheritdoc IBlueprintServiceManager
function onJobResult(
uint64 serviceId,
uint8 job,
Expand All @@ -96,13 +67,7 @@ contract BlueprintServiceManagerBase is IBlueprintServiceManager, RootChainEnabl
onlyFromRootChain
{ }

/**
* @dev Hook for handling unapplied slashes. Called when a slash is queued and still not yet applied to an offender.
* @param serviceId The ID of the service related to the slash.
* @param offender The offender's details in bytes format.
* @param slashPercent The percentage of the slash.
* @param totalPayout The total payout amount in wei.
*/
/// @inheritdoc IBlueprintServiceManager
function onUnappliedSlash(
uint64 serviceId,
bytes calldata offender,
Expand All @@ -115,13 +80,7 @@ contract BlueprintServiceManagerBase is IBlueprintServiceManager, RootChainEnabl
onlyFromRootChain
{ }

/**
* @dev Hook for handling applied slashes. Called when a slash is applied to an offender.
* @param serviceId The ID of the service related to the slash.
* @param offender The offender's details in bytes format.
* @param slashPercent The percentage of the slash.
* @param totalPayout The total payout amount in wei.
*/
/// @inheritdoc IBlueprintServiceManager
function onSlash(
uint64 serviceId,
bytes calldata offender,
Expand All @@ -134,25 +93,12 @@ contract BlueprintServiceManagerBase is IBlueprintServiceManager, RootChainEnabl
onlyFromRootChain
{ }

/**
* @dev Query the slashing origin for a service. This mainly used by the runtime to determine the allowed account
* that can slash a service. by default, the service manager is the only account that can slash a service. override this
* function to allow other accounts to slash a service.
* @param serviceId The ID of the service.
* @return slashingOrigin The list of accounts that can slash the service.
*/
/// @inheritdoc IBlueprintServiceManager
function querySlashingOrigin(uint64 serviceId) public view virtual override returns (address slashingOrigin) {
return address(this);
}

/**
* @dev Query the dispute origin for a service. This mainly used by the runtime to determine the allowed account
* that can dispute an unapplied slash and remove it. by default, the service manager is the only account that can dispute a
* service. override this
* function to allow other accounts to dispute a service.
* @param serviceId The ID of the service.
* @return disputeOrigin The account that can dispute the unapplied slash for that service
*/
/// @inheritdoc IBlueprintServiceManager
function queryDisputeOrigin(uint64 serviceId) public view virtual override returns (address disputeOrigin) {
return address(this);
}
Expand Down
94 changes: 0 additions & 94 deletions src/IBlueprintServiceManager.sol

This file was deleted.

38 changes: 38 additions & 0 deletions src/Permissions.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;

contract Ownable {
address internal _owner;

event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

constructor() {
_owner = msg.sender;
}

modifier onlyOwner() {
require(msg.sender == _owner, "Ownable: caller is not the owner");
_;
}

function owner() public view returns (address) {
return _owner;
}

function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}

contract PermittedCaller {
address public permitted;

Expand All @@ -18,10 +43,23 @@ contract RootChainEnabled {
/// @dev address(keccak256(pallet_services::Config::PalletId::to_account_id())[0:20])
address public constant ROOT_CHAIN = 0x6d6f646c70792F73727663730000000000000000;

function rootChainOrigin() public pure returns (address) {
return ROOT_CHAIN;
}

/// @dev Only root chain can call this function
/// @notice This function can only be called by the root chain
modifier onlyFromRootChain() {
require(msg.sender == ROOT_CHAIN, "RootChain: Only root chain can call this function");
_;
}
}

contract RootChainEnabledOwnable is Ownable, RootChainEnabled {
constructor() Ownable() RootChainEnabled() { }

modifier onlyOwnerOrRootChain() {
require(msg.sender == owner() || msg.sender == rootChainOrigin(), "Unauthorized");
_;
}
}
Loading