BaseACL
To implement access controls for a contract call using BaseAuthorizer
, developers would typically need to manually write abi.decode
codes in order to decode complicated transaction data.
To simplify this process, Cobo Safe
has introduced the BaseACL
contract, which is based upon BaseAuthorizer
.
Developers can use BaseACL
to define a function declaration to be exactly the same as the function of the target contract they intend to control. By doing so, the compiler will automatically generate the decoding codes. Developers can then focus on coding the core access control logic within the function body.
BaseACL
only implements the preExecCheck
function, which is commonly used for access control validation. Developers can, however, extend BaseACL
to configure customized access controls at both the address and function levels.
The process of using BaseACL
to implement a customized Authorizer
is as follows:
Configure variables such as
NAME
andVERSION
.Implement the
contracts()
function. A list of smart contract addresses controlled by theAuthorizer
will be returned. TheAuthorizer
will continue the validation process only if theto
address of a transaction is in the whitelist. Otherwise, theAuthorizer
will directly reject the transaction.The "Caller" is the party initiating a call to the smart contract, but they might not be the one initiating the transaction. Misconfiguring the "Caller" can result in permission errors. Based on Cobo Argus' smart contract framework, the "Caller" should be designated as the "rootAuthorizer."
Implement functions that are used to conduct access control validation for the target contract. These functions should be exactly the same as the function declarations of the target contract. However, they should not return any values and should not be decorated as
payable
. We recommend that you convert them toexternal view
(i.e., modifying the smart contract state is not allowed). If you choose not to follow this approach, additional caller checks must be placed appropriately.When a validation function is called, its parameters must be identical to those used in the smart contract call. This ensures that you can verify the parameters in a validation function body by directly using Solidity's
require()
statement. If the validation fails, theAuthorizer
will reject the transaction.If the
Authorizer
needs to manage multiple smart contracts, amodifier
namedonlyContract
must be used in a validation function to verify the contract address of the transaction. This prevents theDelegate
from calling another smart contract that contains the same function.
The following example uses BaseACL
to implement a customized Authorizer
. The Authorizer
allows Delegate
to engage in yield farming activities on PancakeSwap.
Delegate
is allowed to call theapprove()
function of LP Token but thespender
is restricted toMasterChef
.Delegate
is allowed to call thedeposit()
function ofMasterChef
and thepid
parameter value is 3.Delegate
is allowed to call thewithdraw()
function ofMasterChef
and thepid
parameter value is 3.
Last updated