Boost.sol
Overview
Boost.sol defines the Boost smart contract, which is an auxiliary contract designed to work closely with the PopitGame contract. It provides mechanisms for managing and updating an internal state variable (_mbiCur), interacting with the PopitGame contract, and enabling controlled upgrade and destruction of the contract itself. The contract includes strict access control through ownership verification and sender restrictions.
This contract imports several dependencies, including custom modifiers (Modifiers), a verifier library (VerifiersLib), the root contract (MobileVerifiersContractRoot), and the PopitGame contract, allowing it to integrate securely and efficiently with the broader system.
Contract: Boost
State Variables
Variable | Type | Description |
|---|---|---|
|
| Constant string representing the contract version ( |
|
| Address of the wallet associated with this contract. |
|
| Static address of the linked |
|
| Address of the root contract derived from the contract's code salt. |
|
| Current value of the mobile boost index or similar metric managed by this contract. |
|
| Public key of the root owner, used for access control. |
Constructor
constructor (address wallet, uint256 rootPubkey) senderIs(_popitGame) accept
Purpose: Initializes the contract with the wallet address and root owner public key. It verifies the sender and ensures the contract's code salt matches the expected library version.
Parameters:
wallet: The wallet address to be associated with this contract.rootPubkey: Public key of the root owner for ownership verification.
Behavior:
Decodes the contract's code salt to extract the library version and root address.
Verifies that the version of the verifier library matches the expected version.
Sets
_root,_wallet, and_rootPubkeyaccordingly.
Modifiers Used:
senderIs(_popitGame): Ensures only thePopitGamecontract can deploy this contract.accept: Accepts the incoming external message.
Private Functions
ensureBalance()
function ensureBalance() private pure
Purpose: Ensures the contract maintains a minimum balance defined by
CONTRACT_BALANCE(presumably a constant in the modifiers or imported files).Behavior:
Checks if the contract's balance exceeds
CONTRACT_BALANCE.If not, mints tokens (via
gosh.mintshellq(CONTRACT_BALANCE)) to top up the balance.
Note: This method is marked as
purebut performs an external call to mint tokens, indicating possible inconsistency or reliance on compiler specifics.
Public Functions
deleteMbiCur()
function deleteMbiCur() public senderIs(_popitGame) accept
Purpose: Resets the
_mbiCurvariable to zero.Access Control: Can only be called by the
PopitGamecontract.Behavior:
Calls
ensureBalance()to maintain contract balance before state change.Sets
_mbiCurto0.
setMbiCur(uint64 mbiCur)
function setMbiCur(uint64 mbiCur) public onlyOwnerPubkey(_rootPubkey) accept
Purpose: Updates the
_mbiCurvalue and notifies the linkedPopitGamecontract about this update.Parameters:
mbiCur: New value to set for_mbiCur.
Access Control: Only callable by the owner identified by
_rootPubkey.Behavior:
Calls
ensureBalance()to maintain balance.Sets
_mbiCurto the provided value.Calls
PopitGame(_popitGame).setMbiCurwith a small value transfer (0.1 vmshell) and a flag to change state.
updateCode(TvmCell newcode, TvmCell cell)
function updateCode(TvmCell newcode, TvmCell cell) public view onlyOwnerPubkey(_rootPubkey) accept
Purpose: Allows the contract owner to update the contract's code, enabling contract upgradeability.
Parameters:
newcode: New contract code to set.cell: Additional data passed toonCodeUpgrade.
Access Control: Only callable by the owner identified by
_rootPubkey.Behavior:
Calls
ensureBalance().Sets the contract's code and current code to
newcode.Calls
onCodeUpgrade(cell)for any post-upgrade initialization (empty implementation here).
onCodeUpgrade(TvmCell cell)
function onCodeUpgrade(TvmCell cell) private pure
Purpose: Hook for code upgrade logic.
Parameters:
cell: Data for post-upgrade initialization.
Behavior: Empty implementation, reserved for override or future use.
destroyNode()
function destroyNode() public senderIs(address(this)) accept
Purpose: Self-destructs the contract.
Access Control: Only callable by the contract itself.
Behavior:
Calls
selfdestructsending remaining balance to the contract’s own address.
getDetails()
function getDetails() external view returns(uint64 mbiCur, address wallet)
Purpose: Returns current state details of the contract.
Returns:
_mbiCur: Current mobile boost index value._wallet: Wallet address associated with the contract.
getVersion()
function getVersion() external pure returns(string, string)
Purpose: Returns the contract version and name.
Returns:
version: Contract version string ("1.0.0")."Boost": Contract name.
Implementation Details and Algorithms
The contract uses a code salt mechanism to validate deployment origin and compatibility with the verifier library version.
Access control is enforced using
senderIsandonlyOwnerPubkeymodifiers, which are imported fromModifiers.sol. These ensure that only authorized entities (e.g., thePopitGamecontract or the root owner) can invoke sensitive functions.The
ensureBalancefunction attempts to prevent contract failure due to insufficient funds by minting tokens when balance is below a certain threshold.The
setMbiCurfunction not only updates the internal state but also notifies thePopitGamecontract with a small value transfer and a specific flag, indicating a state change that may trigger further processing in the game contract.Upgradeability is supported via
updateCodewhich replaces the contract code and invokes an upgrade hook, a common pattern in smart contract design to enable fixes and feature additions.The contract supports self-destruction with controlled invocation limited to itself, preventing unauthorized destruction.
Interactions with Other Contracts
PopitGame Contract:
The
_popitGameaddress is static and represents the linked game contract.deleteMbiCurandsetMbiCurfunctions can only be called or initiated by authorized entities and communicate state updates back to thePopitGamecontract.The contract sends a small value transfer to
PopitGameduringsetMbiCurto notify about the update.
VerifiersLib:
Used to validate the version of the verifier library embedded in the contract's code salt during construction.
Modifiers:
Provides access control and sender verification logic.
MobileVerifiersContractRoot:
The
_rootaddress is derived from code salt and represents the root contract, indicating a hierarchical contract structure.
Visual Diagram
classDiagram
class Boost {
-string version
-address _wallet
-address static _popitGame
-address _root
-uint64 _mbiCur
-uint256 _rootPubkey
+constructor(wallet, rootPubkey)
-ensureBalance()
+deleteMbiCur()
+setMbiCur()
+updateCode()
-onCodeUpgrade()
+destroyNode()
+getDetails()
+getVersion()
}
Boost ..> Modifiers : inherits
Boost --> PopitGame : interacts with
Boost --> VerifiersLib : verifies version
This diagram illustrates the Boost contract's main state variables and methods, its inheritance from Modifiers, and its interaction dependencies with the PopitGame contract and VerifiersLib library.