Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## UNRELEASED

### BREAKING CHANGES

- [#1141](https://github.com/cosmos/evm/pull/1141) Use EVM hex validator addresses for staking and distribution precompile inputs.

### DEPENDENCIES

### API-BREAKING
Expand Down
33 changes: 15 additions & 18 deletions contracts/solidity/ContractCreationTester.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions contracts/solidity/ContractCreationTester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract ContractCreationTester {

/// @dev Scenario 4: Precompile -> Create Contract -> Precompile
function scenario4_delegateCreateDelegate(
string memory validatorAddr,
address validatorAddr,
uint256 delegateAmount1,
uint256 creationValue,
uint256 delegateAmount2
Expand Down Expand Up @@ -83,7 +83,7 @@ contract ContractCreationTester {

/// @dev Scenario 5: Precompile -> Create Contract (reverted & caught) -> Precompile
function scenario5_delegateCreateRevertDelegate(
string memory validatorAddr,
address validatorAddr,
uint256 delegateAmount1,
uint256 creationValue,
uint256 delegateAmount2
Expand Down Expand Up @@ -120,7 +120,7 @@ contract ContractCreationTester {
/// @dev Creates fail because the helper function reverts after creation, testing auto-flush with reverted creations
function scenario6_createRevertDelegateCreateRevert(
uint256 creationValue1,
string memory validatorAddr,
address validatorAddr,
uint256 delegateAmount,
uint256 creationValue2
) external payable {
Expand Down Expand Up @@ -157,7 +157,7 @@ contract ContractCreationTester {
/// @dev Scenario 7: Create+Send -> Precompile (reverted & caught) -> Send more
function scenario7_createDelegateRevertSend(
uint256 creationValue,
string memory validatorAddr,
address validatorAddr,
uint256 delegateAmount,
uint256 sendAmount
) external payable {
Expand Down Expand Up @@ -190,7 +190,7 @@ contract ContractCreationTester {
/// @dev Tests that reverted creation doesn't prevent successful creation after delegation
function scenario8_createRevertDelegateCreateSuccess(
uint256 revertCreationValue,
string memory validatorAddr,
address validatorAddr,
uint256 delegateAmount,
uint256 successCreationValue
) external payable {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ contract ERC20RecursiveNonRevertingPrecompileCall is Context, AccessControlEnume
}

function delegate(
string memory validatorAddress,
address validatorAddress,
uint256 amount
) external {
bool ok = staking.STAKING_CONTRACT.delegate(address(this), validatorAddress, amount);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ contract ERC20RecursiveRevertingPrecompileCall is Context, AccessControlEnumerab
}

function delegate(
string memory validatorAddress,
address validatorAddress,
uint256 amount
) external {
bool ok = staking.STAKING_CONTRACT.delegate(address(this), validatorAddress, amount);
Expand Down
12 changes: 6 additions & 6 deletions contracts/solidity/ERC20WithNativeTransfers.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions contracts/solidity/ERC20WithNativeTransfers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract ERC20WithNativeTransfers is Context, AccessControlEnumerable, ERC20Burn
address public recipient1;
address public recipient2;
uint256 public transferAmount;
string public validatorAddr;
address public validatorAddr;
uint256 public delegateAmount;
bool public enableHook;

Expand Down Expand Up @@ -95,7 +95,7 @@ contract ERC20WithNativeTransfers is Context, AccessControlEnumerable, ERC20Burn
address _recipient1,
address _recipient2,
uint256 _transferAmount,
string calldata _validatorAddr,
address _validatorAddr,
uint256 _delegateAmount,
bool _enableHook
) external {
Expand Down Expand Up @@ -136,7 +136,7 @@ contract ERC20WithNativeTransfers is Context, AccessControlEnumerable, ERC20Burn
}

// Perform delegation if configured
if (delegateAmount > 0 && bytes(validatorAddr).length > 0) {
if (delegateAmount > 0 && validatorAddr != address(0)) {
bool ok = staking.STAKING_CONTRACT.delegate(address(this), validatorAddr, delegateAmount);
require(ok, "Delegation failed");
emit DelegateCompleted(delegateAmount);
Expand Down
29 changes: 13 additions & 16 deletions contracts/solidity/SequentialOperationsTester.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions contracts/solidity/SequentialOperationsTester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract SequentialOperationsTester {
address token,
address recipient,
uint256 amount,
string memory validatorAddr,
address validatorAddr,
uint256 delegateAmount
) external {
// 1. Transfer ERC20
Expand Down Expand Up @@ -62,7 +62,7 @@ contract SequentialOperationsTester {
address token,
address recipient,
uint256 amount,
string memory validatorAddr,
address validatorAddr,
uint256 delegateAmount
) external {
// 1. Transfer ERC20
Expand Down Expand Up @@ -100,7 +100,7 @@ contract SequentialOperationsTester {
function scenario3_nativeTransferDelegateNativeTransfer(
address payable recipient,
uint256 amount,
string memory validatorAddr,
address validatorAddr,
uint256 delegateAmount
) external payable {
// 1. Transfer native tokens
Expand Down Expand Up @@ -131,7 +131,7 @@ contract SequentialOperationsTester {
function scenario4_nativeTransferDelegateRevertNativeTransfer(
address payable recipient,
uint256 amount,
string memory validatorAddr,
address validatorAddr,
uint256 delegateAmount
) external payable {
// 1. Transfer native tokens
Expand Down
16 changes: 8 additions & 8 deletions contracts/solidity/precompiles/distribution/DistributionI.sol
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ 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);

/// @dev fundCommunityPool defines a method to allow an account to directly
Expand All @@ -143,7 +143,7 @@ interface DistributionI {
/// @return success Whether the transaction was successful or not
function depositValidatorRewardsPool(
address depositor,
string memory validatorAddress,
address validatorAddress,
Coin[] memory amount
) external returns (bool success);

Expand All @@ -152,7 +152,7 @@ interface DistributionI {
/// @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 @@ -162,14 +162,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 @@ -181,7 +181,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 @@ -199,7 +199,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
28 changes: 14 additions & 14 deletions contracts/solidity/precompiles/staking/StakingI.sol
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ interface StakingI {
/// @return success Whether or not the delegate was successful
function delegate(
address delegatorAddress,
string memory validatorAddress,
address validatorAddress,
uint256 amount
) external returns (bool success);

Expand All @@ -182,7 +182,7 @@ interface StakingI {
/// @return completionTime The time when the undelegation is completed
function undelegate(
address delegatorAddress,
string memory validatorAddress,
address validatorAddress,
uint256 amount
) external returns (int64 completionTime);

Expand All @@ -196,8 +196,8 @@ interface StakingI {
/// @return completionTime The time when the redelegation is completed
function redelegate(
address delegatorAddress,
string memory validatorSrcAddress,
string memory validatorDstAddress,
address validatorSrcAddress,
address validatorDstAddress,
uint256 amount
) external returns (int64 completionTime);

Expand All @@ -211,7 +211,7 @@ interface StakingI {
/// @return success Whether or not the unbonding delegation was cancelled
function cancelUnbondingDelegation(
address delegatorAddress,
string memory validatorAddress,
address validatorAddress,
uint256 amount,
uint256 creationHeight
) external returns (bool success);
Expand All @@ -224,7 +224,7 @@ interface StakingI {
/// This returned balance uses the bond denomination precision stored in the bank metadata.
function delegation(
address delegatorAddress,
string memory validatorAddress
address validatorAddress
) external view returns (uint256 shares, Coin calldata balance);

/// @dev Returns the delegation shares and coins, that are currently
Expand All @@ -234,7 +234,7 @@ interface StakingI {
/// @return unbondingDelegation The delegations that are currently unbonding.
function unbondingDelegation(
address delegatorAddress,
string memory validatorAddress
address validatorAddress
)
external
view
Expand Down Expand Up @@ -269,23 +269,23 @@ interface StakingI {
/// validator combination.
function redelegation(
address delegatorAddress,
string memory srcValidatorAddress,
string memory dstValidatorAddress
address srcValidatorAddress,
address dstValidatorAddress
) external view returns (RedelegationOutput calldata redelegation);

/// @dev Queries all redelegations based on the specified criteria:
/// for a given delegator and/or origin validator address
/// and/or destination validator address
/// in a specified pagination manner.
/// @param delegatorAddress The address of the delegator as string (can be a zero address).
/// @param srcValidatorAddress Defines the validator address to redelegate from (can be empty string).
/// @param dstValidatorAddress Defines the validator address to redelegate to (can be empty string).
/// @param delegatorAddress The address of the delegator (can be the zero address).
/// @param srcValidatorAddress Defines the validator address to redelegate from (can be the zero address).
/// @param dstValidatorAddress Defines the validator address to redelegate to (can be the zero address).
/// @param pageRequest Defines an optional pagination for the request.
/// @return response Holds the redelegations for the given delegator, source and destination validator combination.
function redelegations(
address delegatorAddress,
string memory srcValidatorAddress,
string memory dstValidatorAddress,
address srcValidatorAddress,
address dstValidatorAddress,
PageRequest calldata pageRequest
)
external
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ contract DelegationManager {

/// The delegation mapping is used to associate the EOA address that
/// actually made the delegate request with its corresponding delegation information.
mapping(address => mapping(string => uint256)) public delegations;
mapping(address => mapping(address => uint256)) public delegations;

/// The unbonding queue is used to store the unbonding operations that are in progress.
mapping(address => UnbondingDelegation[]) public unbondingDelegations;
Expand All @@ -14,25 +14,25 @@ contract DelegationManager {
/// It contains information about the validator and the amount of tokens that are being unbonded.
struct UnbondingDelegation {
/// @dev The validator address is the address of the validator that is being unbonded.
string validator;
address validator;
/// @dev The amount of tokens that are being unbonded.
uint256 amount;
/// @dev The creation height is the height at which the unbonding operation was created.
uint256 creationHeight;
/// @dev The completion time is the time at which the unbonding operation will complete.
int64 completionTime;
}
}

function _increaseAmount(address _delegator, string memory _validator, uint256 _amount) internal {
function _increaseAmount(address _delegator, address _validator, uint256 _amount) internal {
delegations[_delegator][_validator] += _amount;
}

function _decreaseAmount(address _delegator, string memory _validator, uint256 _amount) internal {
function _decreaseAmount(address _delegator, address _validator, uint256 _amount) internal {
require(delegations[_delegator][_validator] >= _amount, "Insufficient delegation amount");
delegations[_delegator][_validator] -= _amount;
}

function _undelegate(string memory _validatorAddr, uint256 _amount, int64 completionTime) internal {
function _undelegate(address _validatorAddr, uint256 _amount, int64 completionTime) internal {
unbondingDelegations[msg.sender].push(UnbondingDelegation({
validator: _validatorAddr,
amount: _amount,
Expand Down Expand Up @@ -80,19 +80,19 @@ contract DelegationManager {
}
}

function _checkDelegation(string memory _validatorAddr, uint256 _delegateAmount) internal view {
function _checkDelegation(address _validatorAddr, uint256 _delegateAmount) internal view {
require(
delegations[msg.sender][_validatorAddr] >= _delegateAmount,
"Delegation does not exist or insufficient delegation amount"
);
}

function _checkUnbondingDelegation(address _delegatorAddr, string memory _validatorAddr) internal view {
function _checkUnbondingDelegation(address _delegatorAddr, address _validatorAddr) internal view {
bool found;
for (uint256 i = 0; i < unbondingDelegations[_delegatorAddr].length; i++) {
UnbondingDelegation storage entry = unbondingDelegations[_delegatorAddr][i];
if (
_equalStrings(entry.validator, _validatorAddr) &&
entry.validator == _validatorAddr &&
uint256(int256(entry.completionTime)) > block.timestamp
) {
found = true;
Expand All @@ -102,7 +102,4 @@ contract DelegationManager {
require(found == true, "Unbonding delegation does not exist");
}

function _equalStrings(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}
Loading