Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imp(distribution): replace bech32 address with evm hex address for distribution precompile contract #2241

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ce75e87
imp(staking): replace bech32 address with evm hex address for delegat…
luchenqun Dec 16, 2023
f27afbd
imp(staking): replace bech32 address with evm hex address for Staking…
luchenqun Dec 16, 2023
12ea41c
Merge remote-tracking branch 'origin/main' into luke/staking-bech32-t…
luchenqun Jan 2, 2024
ea49edb
imp(staking): query replace bech32 address with evm hex address
luchenqun Jan 2, 2024
907f468
imp(staking): update ValidatorInfo OperatorAddress to evm address
luchenqun Jan 3, 2024
57f008c
Merge remote-tracking branch 'origin/main' into luke/staking-bech32-t…
luchenqun Jan 3, 2024
910d155
imp(staking): fix precompile staking unit test
luchenqun Jan 3, 2024
0d0dc34
imp(staking): fix precompile staking unit test
luchenqun Jan 4, 2024
44df345
imp(staking): fix precompile staking integration test
luchenqun Jan 4, 2024
224293d
Merge remote-tracking branch 'origin/main' into luke/staking-bech32-t…
luchenqun Jan 4, 2024
5b54901
chore: format code
luchenqun Jan 4, 2024
b39cd63
chore: make lint-fix
luchenqun Jan 4, 2024
596e325
imp(staking): update StakingCaller.sol testCallDelegation
luchenqun Jan 4, 2024
1bd7a45
imp(staking): update StakingCaller.sol testCallDelegation
luchenqun Jan 4, 2024
aa2745f
imp(staking): deal err
luchenqun Jan 4, 2024
ad48ff8
chore: update CHANGELOG.md
luchenqun Jan 4, 2024
15b6bc4
chore: remove TODO
luchenqun Jan 4, 2024
4f7ab9d
imp(distribution): update distribution solidity contract
luchenqun Jan 5, 2024
deea69f
fix(staking): fix NewMsgCreateValidator return err info is wrong
luchenqun Jan 5, 2024
54798a7
Merge branch 'luke/fix-NewMsgCreateValidator' into luke/distribution-…
luchenqun Jan 5, 2024
08a194d
imp(distribution): replace bech32 address with evm hex address for di…
luchenqun Jan 5, 2024
57537eb
imp(distribution): fix distribution query test
luchenqun Jan 5, 2024
ce3a0f6
imp(distribution): fix distribution integration test
luchenqun Jan 5, 2024
e1ca0b7
imp(distribution): update distribution integration test
luchenqun Jan 5, 2024
abe0156
imp(distribution): update distribution integration test and Distribut…
luchenqun Jan 5, 2024
39f3c65
chore: add CHANGELOG.md
luchenqun Jan 5, 2024
ff60297
chore: update CHANGELOG.md
luchenqun Jan 5, 2024
3e4e459
Merge remote-tracking branch 'origin/main' into luke/distribution-bec…
luchenqun Jan 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
- (osmosis-outpost) [#2206](https://github.com/evmos/evmos/pull/2206) Update swap function input to custom struct.
- (stride-outpost) [#2207](https://github.com/evmos/evmos/pull/2207) Update Stride Outpost to include additional arguments.
- (incentives) [#2221](https://github.com/evmos/evmos/pull/2221) Burn the usage incentives pool balance during v16 upgrade.
- (staking-precompile) [#2200](https://github.com/evmos/evmos/pull/2200) Replace bech32 address with evm hex address for staking precompile contract.
- (staking-distribution) [#2241](https://github.com/evmos/evmos/pull/2241) Replace bech32 address with evm hex address for distribution precompile contract.

### API Breaking

Expand Down
2 changes: 2 additions & 0 deletions precompiles/common/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const (
ErrInvalidDelegator = "invalid delegator address: %s"
// ErrInvalidValidator is raised when the Validator address is not valid.
ErrInvalidValidator = "invalid validator address: %s"
// ErrInvalidWithdrawer is raised when the withdrawer address is not valid.
ErrInvalidWithdrawer = "invalid withdrawer address: %s"
// ErrInvalidDenom is raised when the denom is not valid.
ErrInvalidDenom = "invalid denom: %s"
// ErrInvalidMsgType is raised when the transaction type is not valid for the given precompile.
Expand Down
26 changes: 13 additions & 13 deletions precompiles/distribution/DistributionI.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ struct ValidatorSlashEvent {
}

struct ValidatorDistributionInfo {
string operatorAddress;
address operatorAddress;
DecCoin[] selfBondRewards;
DecCoin[] commission;
}

struct DelegationDelegatorReward {
string validatorAddress;
address validatorAddress;
DecCoin[] reward;
}

Expand All @@ -50,7 +50,7 @@ interface DistributionI {
/// @param withdrawerAddress the newly set withdrawer address
event SetWithdrawerAddress(
address indexed caller,
string withdrawerAddress
address indexed withdrawerAddress
);

/// @dev WithdrawDelegatorRewards defines an Event emitted when rewards from a delegation are withdrawn
Expand All @@ -67,7 +67,7 @@ interface DistributionI {
/// @param validatorAddress is the address of the validator
/// @param commission is the total commission earned by the validator
event WithdrawValidatorCommission(
string indexed validatorAddress,
address indexed validatorAddress,
uint256 commission
);

Expand All @@ -89,7 +89,7 @@ interface DistributionI {
/// the given delegator address
function setWithdrawAddress(
address delegatorAddress,
string memory withdrawerAddress
address withdrawerAddress
) external returns (bool success);

/// @dev Withdraw the rewards of a delegator from a validator
Expand All @@ -98,22 +98,22 @@ interface DistributionI {
/// @return amount The amount of Coin withdrawn
function withdrawDelegatorRewards(
address delegatorAddress,
string memory validatorAddress
address validatorAddress
) external returns (Coin[] calldata amount);

/// @dev Withdraws the rewards commission of a validator.
/// @param validatorAddress The address of the validator
/// @return amount The amount of Coin withdrawn
function withdrawValidatorCommission(
string memory validatorAddress
address validatorAddress
) external returns (Coin[] calldata amount);

/// QUERIES
/// @dev Queries validator commission and self-delegation rewards for validator.
/// @param validatorAddress The address of the validator
/// @return distributionInfo The validator's distribution info
function validatorDistributionInfo(
string memory validatorAddress
address validatorAddress
)
external
view
Expand All @@ -125,14 +125,14 @@ interface DistributionI {
/// @param validatorAddress The address of the validator
/// @return rewards The validator's outstanding rewards
function validatorOutstandingRewards(
string memory validatorAddress
address validatorAddress
) external view returns (DecCoin[] calldata rewards);

/// @dev Queries the accumulated commission for a validator.
/// @param validatorAddress The address of the validator
/// @return commission The validator's commission
function validatorCommission(
string memory validatorAddress
address validatorAddress
) external view returns (DecCoin[] calldata commission);

/// @dev Queries the slashing events for a validator in a given height interval
Expand All @@ -144,7 +144,7 @@ interface DistributionI {
/// @return slashes The validator's slash events
/// @return pageResponse The pagination response for the query
function validatorSlashes(
string memory validatorAddress,
address validatorAddress,
uint64 startingHeight,
uint64 endingHeight,
PageRequest calldata pageRequest
Expand All @@ -162,7 +162,7 @@ interface DistributionI {
/// @return rewards The total rewards accrued by a delegation.
function delegationRewards(
address delegatorAddress,
string memory validatorAddress
address validatorAddress
) external view returns (DecCoin[] calldata rewards);

/// @dev Queries the total rewards accrued by each validator, that a given
Expand Down Expand Up @@ -192,6 +192,6 @@ interface DistributionI {
/// @return withdrawAddress The address capable of withdrawing rewards for the delegator.
function delegatorWithdrawAddress(
address delegatorAddress
) external view returns (string memory withdrawAddress);
) external view returns (address withdrawAddress);

}
54 changes: 27 additions & 27 deletions precompiles/distribution/abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
"type": "address"
},
{
"indexed": false,
"internalType": "string",
"indexed": true,
"internalType": "address",
"name": "withdrawerAddress",
"type": "string"
"type": "address"
}
],
"name": "SetWithdrawerAddress",
Expand Down Expand Up @@ -67,9 +67,9 @@
"inputs": [
{
"indexed": true,
"internalType": "string",
"internalType": "address",
"name": "validatorAddress",
"type": "string"
"type": "address"
},
{
"indexed": false,
Expand Down Expand Up @@ -113,9 +113,9 @@
"type": "address"
},
{
"internalType": "string",
"internalType": "address",
"name": "validatorAddress",
"type": "string"
"type": "address"
}
],
"name": "delegationRewards",
Expand Down Expand Up @@ -159,9 +159,9 @@
{
"components": [
{
"internalType": "string",
"internalType": "address",
"name": "validatorAddress",
"type": "string"
"type": "address"
},
{
"components": [
Expand Down Expand Up @@ -246,9 +246,9 @@
"name": "delegatorWithdrawAddress",
"outputs": [
{
"internalType": "string",
"internalType": "address",
"name": "withdrawAddress",
"type": "string"
"type": "address"
}
],
"stateMutability": "view",
Expand All @@ -262,9 +262,9 @@
"type": "address"
},
{
"internalType": "string",
"internalType": "address",
"name": "withdrawerAddress",
"type": "string"
"type": "address"
}
],
"name": "setWithdrawAddress",
Expand All @@ -281,9 +281,9 @@
{
"inputs": [
{
"internalType": "string",
"internalType": "address",
"name": "validatorAddress",
"type": "string"
"type": "address"
}
],
"name": "validatorCommission",
Expand Down Expand Up @@ -317,19 +317,19 @@
{
"inputs": [
{
"internalType": "string",
"internalType": "address",
"name": "validatorAddress",
"type": "string"
"type": "address"
}
],
"name": "validatorDistributionInfo",
"outputs": [
{
"components": [
{
"internalType": "string",
"internalType": "address",
"name": "operatorAddress",
"type": "string"
"type": "address"
},
{
"components": [
Expand Down Expand Up @@ -387,9 +387,9 @@
{
"inputs": [
{
"internalType": "string",
"internalType": "address",
"name": "validatorAddress",
"type": "string"
"type": "address"
}
],
"name": "validatorOutstandingRewards",
Expand Down Expand Up @@ -423,9 +423,9 @@
{
"inputs": [
{
"internalType": "string",
"internalType": "address",
"name": "validatorAddress",
"type": "string"
"type": "address"
},
{
"internalType": "uint64",
Expand Down Expand Up @@ -530,9 +530,9 @@
"type": "address"
},
{
"internalType": "string",
"internalType": "address",
"name": "validatorAddress",
"type": "string"
"type": "address"
}
],
"name": "withdrawDelegatorRewards",
Expand Down Expand Up @@ -561,9 +561,9 @@
{
"inputs": [
{
"internalType": "string",
"internalType": "address",
"name": "validatorAddress",
"type": "string"
"type": "address"
}
],
"name": "withdrawValidatorCommission",
Expand Down
13 changes: 6 additions & 7 deletions precompiles/distribution/distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (s *PrecompileTestSuite) TestRun() {
input, err := s.precompile.Pack(
distribution.SetWithdrawAddressMethod,
s.address,
s.address.String(),
s.address,
)
s.Require().NoError(err, "failed to pack input")
return s.address, input
Expand All @@ -87,10 +87,9 @@ func (s *PrecompileTestSuite) TestRun() {
{
name: "pass - withdraw validator commissions transaction",
malleate: func() (common.Address, []byte) {
hexAddr := common.Bytes2Hex(s.address.Bytes())
valAddr, err := sdk.ValAddressFromHex(hexAddr)
s.Require().NoError(err)
caller := common.BytesToAddress(valAddr)
valHexAddr := s.address
valAddr := sdk.ValAddress(valHexAddr.Bytes())
caller := s.address

valCommission := sdk.DecCoins{sdk.NewDecCoinFromDec(utils.BaseDenom, math.LegacyNewDecWithPrec(1000000000000000000, 1))}
// set outstanding rewards
Expand All @@ -100,7 +99,7 @@ func (s *PrecompileTestSuite) TestRun() {

input, err := s.precompile.Pack(
distribution.WithdrawValidatorCommissionMethod,
valAddr.String(),
valHexAddr,
)
s.Require().NoError(err, "failed to pack input")
return caller, input
Expand All @@ -120,7 +119,7 @@ func (s *PrecompileTestSuite) TestRun() {
input, err := s.precompile.Pack(
distribution.WithdrawDelegatorRewardsMethod,
s.address,
valAddr.String(),
common.BytesToAddress(valAddr.Bytes()),
)
s.Require().NoError(err, "failed to pack input")

Expand Down
16 changes: 9 additions & 7 deletions precompiles/distribution/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,32 @@

// EmitSetWithdrawAddressEvent creates a new event emitted on a SetWithdrawAddressMethod transaction.
func (p Precompile) EmitSetWithdrawAddressEvent(ctx sdk.Context, stateDB vm.StateDB, caller common.Address, withdrawerAddress string) error {
withdrawerAddr, err := sdk.AccAddressFromBech32(withdrawerAddress)
if err != nil {
return err
}

Check warning on line 67 in precompiles/distribution/events.go

View check run for this annotation

Codecov / codecov/patch

precompiles/distribution/events.go#L66-L67

Added lines #L66 - L67 were not covered by tests

// Prepare the event topics
event := p.ABI.Events[EventTypeSetWithdrawAddress]
topics := make([]common.Hash, 2)
topics := make([]common.Hash, 3)

// The first topic is always the signature of the event.
topics[0] = event.ID

var err error
topics[1], err = cmn.MakeTopic(caller)
if err != nil {
return err
}

// Pack the arguments to be used as the Data field
arguments := abi.Arguments{event.Inputs[1]}
packed, err := arguments.Pack(withdrawerAddress)
topics[2], err = cmn.MakeTopic(common.BytesToAddress(withdrawerAddr.Bytes()))
if err != nil {
return err
}

stateDB.AddLog(&ethtypes.Log{
Address: p.Address(),
Topics: topics,
Data: packed,
Data: nil,
BlockNumber: uint64(ctx.BlockHeight()),
})

Expand Down Expand Up @@ -130,7 +132,7 @@
}

// EmitWithdrawValidatorCommissionEvent creates a new event emitted on a WithdrawValidatorCommission transaction.
func (p Precompile) EmitWithdrawValidatorCommissionEvent(ctx sdk.Context, stateDB vm.StateDB, validatorAddress string, coins sdk.Coins) error {
func (p Precompile) EmitWithdrawValidatorCommissionEvent(ctx sdk.Context, stateDB vm.StateDB, validatorAddress common.Address, coins sdk.Coins) error {
// Prepare the event topics
event := p.ABI.Events[EventTypeWithdrawValidatorCommission]
topics := make([]common.Hash, 2)
Expand Down