Skip to content

Commit

Permalink
added precompile logging for allowFeeRecipient
Browse files Browse the repository at this point in the history
  • Loading branch information
abi87 committed Oct 19, 2023
1 parent ee2f6c2 commit ff4d354
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
6 changes: 4 additions & 2 deletions contracts/contracts/interfaces/IRewardManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ pragma solidity ^0.8.0;
import "./IAllowList.sol";

interface IRewardManager is IAllowList {
event RewardAddress(address indexed sender, address indexed reward);

event AllowFeeRecipients(address indexed sender);

// setRewardAddress sets the reward address to the given address
function setRewardAddress(address addr) external;

Expand All @@ -17,6 +21,4 @@ interface IRewardManager is IAllowList {

// areFeeRecipientsAllowed returns true if fee recipients are allowed
function areFeeRecipientsAllowed() external view returns (bool isAllowed);

event RewardAddress(address indexed sender, address indexed reward);
}
2 changes: 1 addition & 1 deletion precompile/contracts/rewardmanager/contract.abi
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"reward","type":"address"}],"name":"RewardAddress","type":"event"},{"inputs":[],"name":"allowFeeRecipients","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"areFeeRecipientsAllowed","outputs":[{"internalType":"bool","name":"isAllowed","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentRewardAddress","outputs":[{"internalType":"address","name":"rewardAddress","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"disableRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"readAllowList","outputs":[{"internalType":"uint256","name":"role","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"setAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"setEnabled","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"setManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"setNone","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"setRewardAddress","outputs":[],"stateMutability":"nonpayable","type":"function"}]
[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"AllowFeeRecipients","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"reward","type":"address"}],"name":"RewardAddress","type":"event"},{"inputs":[],"name":"allowFeeRecipients","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"areFeeRecipientsAllowed","outputs":[{"internalType":"bool","name":"isAllowed","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentRewardAddress","outputs":[{"internalType":"address","name":"rewardAddress","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"disableRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"readAllowList","outputs":[{"internalType":"uint256","name":"role","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"setAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"setEnabled","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"setManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"setNone","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"setRewardAddress","outputs":[],"stateMutability":"nonpayable","type":"function"}]
23 changes: 17 additions & 6 deletions precompile/contracts/rewardmanager/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ import (
)

const (
AllowFeeRecipientsGasCost uint64 = (contract.WriteGasCostPerSlot) + allowlist.ReadAllowListGasCost // write 1 slot + read allow list
AreFeeRecipientsAllowedGasCost uint64 = allowlist.ReadAllowListGasCost
CurrentRewardAddressGasCost uint64 = allowlist.ReadAllowListGasCost
DisableRewardsGasCost uint64 = (contract.WriteGasCostPerSlot) + allowlist.ReadAllowListGasCost // write 1 slot + read allow list

DuplicatedLogGas uint64 = 375 // TODO: duplicated from params/protocol_params.go to avoid import cycle in tests.
DuplicatedLogTopicGas uint64 = 375 // TODO: duplicated from params/protocol_params.go to avoid import cycle in tests.

SetRewardAddressGasCost uint64 = DuplicatedLogGas + 2*DuplicatedLogTopicGas + (contract.WriteGasCostPerSlot) + allowlist.ReadAllowListGasCost // write 1 slot + read allow list
AllowFeeRecipientsGasCost uint64 = DuplicatedLogGas + DuplicatedLogTopicGas + contract.WriteGasCostPerSlot + allowlist.ReadAllowListGasCost // logging cost + write 1 slot + read allow list
AreFeeRecipientsAllowedGasCost uint64 = allowlist.ReadAllowListGasCost
CurrentRewardAddressGasCost uint64 = allowlist.ReadAllowListGasCost
DisableRewardsGasCost uint64 = (contract.WriteGasCostPerSlot) + allowlist.ReadAllowListGasCost // write 1 slot + read allow list
SetRewardAddressGasCost uint64 = DuplicatedLogGas + 2*DuplicatedLogTopicGas + contract.WriteGasCostPerSlot + allowlist.ReadAllowListGasCost // logging cost + write 1 slot + read allow list
)

// Singleton StatefulPrecompiledContract and signatures.
Expand Down Expand Up @@ -105,6 +104,18 @@ func allowFeeRecipients(accessibleState contract.AccessibleState, caller common.
EnableAllowFeeRecipients(stateDB)
packedOutput := []byte{}

// Add a log to be handled if this action is finalized.
topics, data, err := PackAllowFeeRecipientsEvent(caller)
if err != nil {
return nil, remainingGas, err
}
accessibleState.GetStateDB().AddLog(
ContractAddress,
topics,
data,
accessibleState.GetBlockContext().Number().Uint64(),
)

// Return the packed output and the remaining gas
return packedOutput, remainingGas, nil
}
Expand Down
8 changes: 8 additions & 0 deletions precompile/contracts/rewardmanager/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ accessibleState.GetStateDB().AddLog(
)
*/

// PackAllowFeeRecipientsEvent packs the event into the appropriate arguments for AllowFeeRecipients.
// It returns topic hashes and the encoded non-indexed data.
func PackAllowFeeRecipientsEvent(sender common.Address) ([]common.Hash, []byte, error) {
return RewardManagerABI.PackEvent("AllowFeeRecipients", sender)
}

// UnpackAllowFeeRecipientsEvent won't be generated because the event does not have any non-indexed data.

// PackRewardAddressEvent packs the event into the appropriate arguments for RewardAddress.
// It returns topic hashes and the encoded non-indexed data.
func PackRewardAddressEvent(sender common.Address, reward common.Address) ([]common.Hash, []byte, error) {
Expand Down

0 comments on commit ff4d354

Please sign in to comment.