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)
subscribedPolicies
mapping
(address =>
mapping
(bytes4 => address[])
)
subscribedGlobalPolicies
mapping
(address => address[])
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.
policy
address
status
bool
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.
consumer
address
methodSig
bytes4
policy
address
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.
consumer
address
methodSig
bytes4
policyIndex
uint
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.
consumer
address
methodSigs
bytes4[] calldata
policies
address[] calldata
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.
consumer
address
methodSig
bytes4 calldata
policyIndex
uint calldata
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.
consumer
address
policy
address
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.
consumer
address
policyIndex
uint
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.
consumers
address[]
policy
address
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.
consumers
address[]
policy
address
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.
consumer
address
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.
consumer
address
Source Code
On our GitHub repository: Firewall.sol
Last updated