2. Integration
Learn about protecting your smart contracts using CUBE3 RASP interfaces.
Last updated
Learn about protecting your smart contracts using CUBE3 RASP interfaces.
Last updated
At its core, basic integration only takes 2 steps:
Inherit either Cube3Protection
or Cube3ProtectionUpgradeable
abstract contracts provided in this . This gives you access to cube3Protected
modifier.
Enforce cube3Protected
modifier on functions you wish to protect.
cube3Protected
modifiercube3Protected
takes in one parameter called cube3SecurePayload
.
Before initiating a transaction on-chain, an HTTP request has to be made to CUBE3 validation service in order to fetch the cube3SecurePayload
, providing transaction data in a request body. If the CUBE3 backend finds that transaction to be malicious, cube3SecurePayload
will not be provided and the transaction will not be possible.
Cube3Protection
constructor and Cube3ProtectionUpgradeable
initialize function takes 3 parameters:
address
- admin address of your protected smart contract
boolean
- enable CUBE3 protection
cube3Protected
modifierInherit from Cube3Protection
to get access to cube3Protected
modifier.
Inherit from Cube3Protection
to get access to _assertProtectWhenConnected
function.
Inherit from Cube3ProtectionUpgradeable
to get access to cube3Protected
modifier.
Important Note: This example is not an exhaustive demonstration of using the CUBE3 upgradeable contracts for all possible proxy patterns, but rather demonstrating usage in a single scenario.
Below is an example of inheriting the Cube3ProtectionUpgradeable.sol
contract into an upgradeable contract using the UUPS proxy pattern. Because initializers are not linearized by the compiler like constructors, we want to avoid initializing the same contract twice. As such, we follow OpenZeppelin's standards for Multiple Inheritance utilizing the _init
and _init_unchained
pattern. Upgradeable integrations will call __Cube3ProtectionUpgradeable_init(...args)
inside their own initialize functions. The integration MUST initialize Cube3ProtectionUpgradeable
in its initialize function to set the protocol contract addresses (implicitly) and the security admin account (explicitly).
To generate cube3SecurePayload
you would use CUBE3 SDK (learn more about it ).
address
- CUBE3 Router address, which you can find
Once you integrate with Cube3Protection
, you are ready to move to deployment (read more ).
Once you integrate with Cube3ProtectionUpgradeable
, you are ready to move to deployment (read more ).