Firewall.sol
The Firewall contract is the main contract of the system. It stores and manages all the Policies to which Firewall Consumers subscribe to, and executes them as needed.
Properties
approvedPolicies
mapping
(address => bool)
the Policies that can be used by Firewall Consumers that use this Firewall
subscribedPolicies
mapping
(address =>
mapping
(bytes4 => address[])
)
a mapping between the Protected Methods of a Firewall Consumer and the Policies configured for these methods
subscribedGlobalPolicies
mapping
(address => address[])
a mapping between a Firewall Consumer and the Policies that are configured on it
Modifiers
onlyConsumerAdmin()
Only allows the modified function to run if it was called by the Firewall Admin (see setFirewallAdmin()) .
Methods
preExecution()
function preExecution(address sender, bytes calldata data, uint value)
function preExecution(address sender, bytes calldata data, uint value)Runs the Pre Execution hook on all the Policies that msg.sender has subscribed to for the method described by the first 4 bytes of data.
sender
address
the sender of the transaction
data
bytes calldata
the transaction data
value
uint
the value that was sent with the transaction
postExecution()
function postExecution(address sender, bytes calldata data, uint value)
function postExecution(address sender, bytes calldata data, uint value)Runs the Post Execution hook on all the Policies that msg.sender has subscribed to for the method described by the first 4 bytes of data.
sender
address
the sender of the transaction
data
bytes calldata
the transaction data
value
uint
the value that was sent with the transaction
setPolicyStatus()
function setPolicyStatus(address policy, bool status)
function setPolicyStatus(address policy, bool status)Callable only by the Firewall Owner, used to approve or revoke approval of a Policy. Revoking approval doesn’t remove existing consumer subscriptions.
status
bool
the new status of the policy, true meaning approved and false meaning unapproved
see Approved Policies for more details
addPolicy()
function addPolicy(address consumer, bytes4 methodSig, address policy)
function addPolicy(address consumer, bytes4 methodSig, address policy)Callable only by the Firewall Admin of the Firewall Consumer, this method adds the Policy to the list of subscribed policies for the given method signature.
removePolicy()
function removePolicy(address consumer, bytes4 methodSig, uint policyIndex)
function removePolicy(address consumer, bytes4 methodSig, uint policyIndex)Callable only by the Firewall Admin of the consumer, this method removes the Policy found at the policyIndex from the list of subscribed policies for the given method signature.
addPolicies()
function addPolicies(address consumer, bytes4[] calldata methodSigs, address[] calldata policies)
function addPolicies(address consumer, bytes4[] calldata methodSigs, address[] calldata policies)Callable only by the Firewall Admin of the Firewall Consumer, this method adds multiple policies to the list of subscribed policies for the given method signatures. Each Policy will be subscribed to the corresponding Method-Sig from the methodSigs array.
removePolicies()
function removePolicies(address consumer, bytes4[] calldata methodSigs, address[] calldata policies)
function removePolicies(address consumer, bytes4[] calldata methodSigs, address[] calldata policies)Callable only by the Firewall Admin of the Firewall Consumer, this method removes multiple policies from the list of subscribed policies for the given method signatures. Each Policy will be removed from the corresponding Method-Sig from the methodSigs array.
addGlobalPolicy()
function addGlobalPolicy(address consumer, address policy)
function addGlobalPolicy(address consumer, address policy)Callable only by the Firewall Admin of the Firewall Consumer, this method adds a Global Policy to the list of subscribed policies for the Firewall Consumer.
removeGlobalPolicy()
function removeGlobalPolicy(address consumer, uint policyIndex)
function removeGlobalPolicy(address consumer, uint policyIndex)Callable only by the Firewall Admin of the Firewall Consumer, this method removes a Global Policy from the list of subscribed policies for the Firewall Consumer.
addGlobalPoliciesForConsumers()
function addGlobalPoliciesForConsumers(address[] consumers, address policy)
function addGlobalPoliciesForConsumers(address[] consumers, address policy)Callable only by the Firewall Admin of all the Firewall Consumers, this method adds a Global Policy to the list of subscribed policies for the all the Firewall Consumers.
removeGlobalPoliciesForConsumers()
function removeGlobalPoliciesForConsumers(address[] consumers, address policy)
function removeGlobalPoliciesForConsumers(address[] consumers, address policy)Callable only by the Firewall Admin of all the Firewall Consumers, this method removes a Global Policy from a list of Firewall Consumers.
View Functions
getActivePolicies()
function getActivePolicies(address consumer, bytes4 methodSig) public returns (address[] memory)
function getActivePolicies(address consumer, bytes4 methodSig) public returns (address[] memory)Returns an array of all the policies a Firewall Consumer has subscribed to a method.
methodSig
bytes4
the method signature we’re getting the active policies for
getActiveGloablPolicies()
function getActiveGloablPolicies(address consumer) public returns (address[] memory)
function getActiveGloablPolicies(address consumer) public returns (address[] memory)Returns an array of all the Global Policies a Firewall Consumer is subscribed to.
Source Code
On our GitHub repository: Firewall.sol
Last updated