Integration

spherex Protect can be integrated in either of two alternative integration modes:

Proxy Mode

Proxy integration mode is suitable for upgradeable contracts. In this mode, a ready made protected proxy is provided to replace existing proxies, leaving the implementation contracts untouched. Proxy integration steps:

  • Adding spherex contracts to the codebase

  • Replace any proxy with spherex protected proxy

Inline Mode

Inline integration mode is suitable for either immutable or upgradeable contracts. In this mode, spherex’s code is automatically integrated into the implementation code (using spherex's automated integration pipeline), along the following steps:

  • Add spherex contracts to the codebase

  • Import and inherit spherexProtected.sol to protected contracts

  • Add spherex modifier to protected functions

The integrated contracts include configuration functions to set the protection admin, operator, engine address, and list the protected functions (in proxy mode).

In case of hybrid projects (including both immutable and upgradeable contracts), both integration modes can be used.

Although the integration is simple, it should Ideally start as early as possible, as security should be an integral part in the very early phases of a project. Still, using spherex's automated integration pipeline we allow projects in all phases of the development to integrate sphere with maximum speed and simplicity.

The integration can also be done either during the development phase, or using spherex integration pipeline, given finalized smart contracts with a mature codebase.

For example, the following contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Counter {
    	int private count = 0;
    
	function inc() external {
		count += 1;
	}
    
	function getCount() public view returns (int){
		return count;
	}
}

Will be transformed to (inline mode):

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "SphereXProtected.sol";

contract Counter is SphereXProtected {
    	int private count = 0;
    
	function inc() external sphereXGuardExternal(1){
		count += 1;
	}
    
	function getCount() public view returns (int) {
		return count;
	}
}

Last updated