Skip to content

Commit

Permalink
fix(various): fix typo and wrong comparison (#267)
Browse files Browse the repository at this point in the history
Refactor `UnCmp` to `Uncmp` for consistency. Max UBI percent setters
allows new value to be equal to max, not only <

issue: none
  • Loading branch information
Ramarti authored Oct 22, 2024
1 parent 55172fc commit a4918f6
Show file tree
Hide file tree
Showing 9 changed files with 1,160 additions and 858 deletions.
1,956 changes: 1,129 additions & 827 deletions client/cmd/abi/IPTokenStaking.abi.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/cmd/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ func extractDelegationIDFromStake(cfg *stakeConfig, receipt *types.Receipt) (*bi
if vLog.Topics[0] == eventSignature {
eventData := struct {
DelegatorUncmpPubkey []byte
ValidatorUnCmpPubkey []byte
ValidatorUncmpPubkey []byte
StakeAmount *big.Int
StakingPeriod *big.Int
DelegationId *big.Int //nolint:revive,stylecheck // Definition comes from ABI
Expand Down
4 changes: 2 additions & 2 deletions client/x/evmstaking/keeper/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (k Keeper) ProcessDeposit(ctx context.Context, ev *bindings.IPTokenStakingD
types.EventTypeDelegateFailure,
sdk.NewAttribute(types.AttributeKeyBlockHeight, strconv.FormatInt(sdkCtx.BlockHeight(), 10)),
sdk.NewAttribute(types.AttributeKeyDelegatorUncmpPubKey, hex.EncodeToString(ev.DelegatorUncmpPubkey)),
sdk.NewAttribute(types.AttributeKeyValidatorUncmpPubKey, hex.EncodeToString(ev.ValidatorUnCmpPubkey)),
sdk.NewAttribute(types.AttributeKeyValidatorUncmpPubKey, hex.EncodeToString(ev.ValidatorUncmpPubkey)),
sdk.NewAttribute(types.AttributeKeyDelegateID, ev.DelegationId.String()),
sdk.NewAttribute(types.AttributeKeyPeriodType, strconv.FormatInt(ev.StakingPeriod.Int64(), 10)),
sdk.NewAttribute(types.AttributeKeyAmount, ev.StakeAmount.String()),
Expand All @@ -46,7 +46,7 @@ func (k Keeper) ProcessDeposit(ctx context.Context, ev *bindings.IPTokenStakingD
return errors.Wrap(err, "depositor pubkey to cosmos")
}

valCmpPubkey, err := UncmpPubKeyToCmpPubKey(ev.ValidatorUnCmpPubkey)
valCmpPubkey, err := UncmpPubKeyToCmpPubKey(ev.ValidatorUncmpPubkey)
if err != nil {
return types.WrapErrWithCode(types.InvalidUncmpPubKey, errors.Wrap(err, "compress validator pubkey"))
}
Expand Down
8 changes: 4 additions & 4 deletions client/x/evmstaking/keeper/deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (s *TestSuite) TestProcessDeposit() {
createDeposit := func(delPubKey, valPubKey []byte, amount *big.Int) *bindings.IPTokenStakingDeposit {
return &bindings.IPTokenStakingDeposit{
DelegatorUncmpPubkey: cmpToUncmp(delPubKey),
ValidatorUnCmpPubkey: cmpToUncmp(valPubKey),
ValidatorUncmpPubkey: cmpToUncmp(valPubKey),
StakeAmount: amount,
StakingPeriod: big.NewInt(0),
DelegationId: big.NewInt(0),
Expand Down Expand Up @@ -87,7 +87,7 @@ func (s *TestSuite) TestProcessDeposit() {
name: "fail: invalid delegator pubkey",
deposit: &bindings.IPTokenStakingDeposit{
DelegatorUncmpPubkey: cmpToUncmp(delPubKey.Bytes())[:16],
ValidatorUnCmpPubkey: cmpToUncmp(valPubKey.Bytes()),
ValidatorUncmpPubkey: cmpToUncmp(valPubKey.Bytes()),
StakeAmount: new(big.Int).SetUint64(1),
StakingPeriod: big.NewInt(0),
DelegationId: big.NewInt(0),
Expand All @@ -99,7 +99,7 @@ func (s *TestSuite) TestProcessDeposit() {
name: "fail: invalid validator pubkey",
deposit: &bindings.IPTokenStakingDeposit{
DelegatorUncmpPubkey: cmpToUncmp(delPubKey.Bytes()),
ValidatorUnCmpPubkey: cmpToUncmp(valPubKey.Bytes())[:16],
ValidatorUncmpPubkey: cmpToUncmp(valPubKey.Bytes())[:16],
StakeAmount: new(big.Int).SetUint64(1),
StakingPeriod: big.NewInt(0),
DelegationId: big.NewInt(0),
Expand All @@ -111,7 +111,7 @@ func (s *TestSuite) TestProcessDeposit() {
name: "fail: corrupted delegator pubkey",
deposit: &bindings.IPTokenStakingDeposit{
DelegatorUncmpPubkey: createCorruptedPubKey(cmpToUncmp(delPubKey.Bytes())),
ValidatorUnCmpPubkey: cmpToUncmp(valPubKey.Bytes()),
ValidatorUncmpPubkey: cmpToUncmp(valPubKey.Bytes()),
StakeAmount: new(big.Int).SetUint64(1),
StakingPeriod: big.NewInt(0),
DelegationId: big.NewInt(0),
Expand Down
4 changes: 2 additions & 2 deletions client/x/evmstaking/keeper/withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func (k Keeper) ProcessWithdraw(ctx context.Context, ev *bindings.IPTokenStaking
types.EventTypeUndelegateFailure,
sdk.NewAttribute(types.AttributeKeyBlockHeight, strconv.FormatInt(sdkCtx.BlockHeight(), 10)),
sdk.NewAttribute(types.AttributeKeyDelegatorUncmpPubKey, hex.EncodeToString(ev.DelegatorUncmpPubkey)),
sdk.NewAttribute(types.AttributeKeyValidatorUncmpPubKey, hex.EncodeToString(ev.ValidatorUnCmpPubkey)),
sdk.NewAttribute(types.AttributeKeyValidatorUncmpPubKey, hex.EncodeToString(ev.ValidatorUncmpPubkey)),
sdk.NewAttribute(types.AttributeKeyDelegateID, ev.DelegationId.String()),
sdk.NewAttribute(types.AttributeKeyAmount, ev.StakeAmount.String()),
sdk.NewAttribute(types.AttributeKeySenderAddress, ev.OperatorAddress.Hex()),
Expand Down Expand Up @@ -352,7 +352,7 @@ func (k Keeper) ProcessWithdraw(ctx context.Context, ev *bindings.IPTokenStaking
return errors.Wrap(err, "depositor pubkey to cosmos")
}

valCmpPubkey, err := UncmpPubKeyToCmpPubKey(ev.ValidatorUnCmpPubkey)
valCmpPubkey, err := UncmpPubKeyToCmpPubKey(ev.ValidatorUncmpPubkey)
if err != nil {
return types.WrapErrWithCode(types.InvalidUncmpPubKey, errors.Wrap(err, "compress validator pubkey"))
}
Expand Down
14 changes: 7 additions & 7 deletions client/x/evmstaking/keeper/withdraw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (s *TestSuite) TestProcessWithdraw() {
},
withdraw: &bindings.IPTokenStakingWithdraw{
DelegatorUncmpPubkey: cmpToUncmp(delPubKey1.Bytes()),
ValidatorUnCmpPubkey: cmpToUncmp(valPubKey.Bytes()),
ValidatorUncmpPubkey: cmpToUncmp(valPubKey.Bytes()),
StakeAmount: new(big.Int).SetUint64(1),
DelegationId: big.NewInt(0),
OperatorAddress: cmpToEVM(delPubKey1.Bytes()),
Expand All @@ -296,7 +296,7 @@ func (s *TestSuite) TestProcessWithdraw() {
name: "fail: invalid delegator pubkey",
withdraw: &bindings.IPTokenStakingWithdraw{
DelegatorUncmpPubkey: cmpToUncmp(delPubKey1.Bytes())[:16],
ValidatorUnCmpPubkey: cmpToUncmp(valPubKey.Bytes()),
ValidatorUncmpPubkey: cmpToUncmp(valPubKey.Bytes()),
StakeAmount: new(big.Int).SetUint64(1),
DelegationId: big.NewInt(0),
OperatorAddress: cmpToEVM(delPubKey1.Bytes()),
Expand All @@ -307,7 +307,7 @@ func (s *TestSuite) TestProcessWithdraw() {
name: "fail: invalid validator pubkey",
withdraw: &bindings.IPTokenStakingWithdraw{
DelegatorUncmpPubkey: cmpToUncmp(delPubKey1.Bytes()),
ValidatorUnCmpPubkey: cmpToUncmp(valPubKey.Bytes())[:16],
ValidatorUncmpPubkey: cmpToUncmp(valPubKey.Bytes())[:16],
StakeAmount: new(big.Int).SetUint64(1),
DelegationId: big.NewInt(0),
OperatorAddress: cmpToEVM(delPubKey1.Bytes()),
Expand All @@ -318,7 +318,7 @@ func (s *TestSuite) TestProcessWithdraw() {
name: "fail: corrupted delegator pubkey",
withdraw: &bindings.IPTokenStakingWithdraw{
DelegatorUncmpPubkey: createCorruptedPubKey(cmpToUncmp(delPubKey1.Bytes())),
ValidatorUnCmpPubkey: cmpToUncmp(valPubKey.Bytes()),
ValidatorUncmpPubkey: cmpToUncmp(valPubKey.Bytes()),
StakeAmount: new(big.Int).SetUint64(1),
DelegationId: big.NewInt(0),
OperatorAddress: cmpToEVM(delPubKey1.Bytes()),
Expand All @@ -329,7 +329,7 @@ func (s *TestSuite) TestProcessWithdraw() {
name: "fail: corrupted validator pubkey",
withdraw: &bindings.IPTokenStakingWithdraw{
DelegatorUncmpPubkey: cmpToUncmp(delPubKey1.Bytes()),
ValidatorUnCmpPubkey: createCorruptedPubKey(cmpToUncmp(valPubKey.Bytes())),
ValidatorUncmpPubkey: createCorruptedPubKey(cmpToUncmp(valPubKey.Bytes())),
StakeAmount: new(big.Int).SetUint64(1),
DelegationId: big.NewInt(0),
OperatorAddress: cmpToEVM(delPubKey1.Bytes()),
Expand All @@ -343,7 +343,7 @@ func (s *TestSuite) TestProcessWithdraw() {
},
withdraw: &bindings.IPTokenStakingWithdraw{
DelegatorUncmpPubkey: cmpToUncmp(unknownPubKey.Bytes()),
ValidatorUnCmpPubkey: cmpToUncmp(valPubKey.Bytes()),
ValidatorUncmpPubkey: cmpToUncmp(valPubKey.Bytes()),
StakeAmount: new(big.Int).SetUint64(1),
DelegationId: big.NewInt(0),
OperatorAddress: cmpToEVM(unknownPubKey.Bytes()),
Expand All @@ -357,7 +357,7 @@ func (s *TestSuite) TestProcessWithdraw() {
},
withdraw: &bindings.IPTokenStakingWithdraw{
DelegatorUncmpPubkey: cmpToUncmp(delPubKey1.Bytes()),
ValidatorUnCmpPubkey: cmpToUncmp(valPubKey.Bytes()),
ValidatorUncmpPubkey: cmpToUncmp(valPubKey.Bytes()),
StakeAmount: new(big.Int).SetUint64(math.MaxUint64),
DelegationId: big.NewInt(0),
OperatorAddress: cmpToEVM(delPubKey1.Bytes()),
Expand Down
20 changes: 10 additions & 10 deletions contracts/bindings/iptokenstaking.go

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions contracts/src/interfaces/IIPTokenStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ interface IIPTokenStaking {

/// @notice Emitted when a user deposits token into the contract.
/// @param delegatorUncmpPubkey Delegator's 65 bytes uncompressed secp256k1 public key.
/// @param validatorUnCmpPubkey Validator's 65 bytes uncompressed secp256k1 public key.
/// @param validatorUncmpPubkey Validator's 65 bytes uncompressed secp256k1 public key.
/// @param stakeAmount Token deposited.
/// @param stakingPeriod of the deposit
/// @param delegationId The ID of the delegation
/// @param operatorAddress The caller's address
/// @param data Additional data for the deposit
event Deposit(
bytes delegatorUncmpPubkey,
bytes validatorUnCmpPubkey,
bytes validatorUncmpPubkey,
uint256 stakeAmount,
uint256 stakingPeriod,
uint256 delegationId,
Expand All @@ -90,14 +90,14 @@ interface IIPTokenStaking {

/// @notice Emitted when a user withdraws her stake and starts the unbonding period.
/// @param delegatorUncmpPubkey Delegator's 65 bytes uncompressed secp256k1 public key.
/// @param validatorUnCmpPubkey Validator's 65 bytes uncompressed secp256k1 public key.
/// @param validatorUncmpPubkey Validator's 65 bytes uncompressed secp256k1 public key.
/// @param stakeAmount Token deposited.
/// @param delegationId The ID of the delegation, 0 if flexible
/// @param operatorAddress The caller's address
/// @param data Additional data for the deposit
event Withdraw(
bytes delegatorUncmpPubkey,
bytes validatorUnCmpPubkey,
bytes validatorUncmpPubkey,
uint256 stakeAmount,
uint256 delegationId,
address operatorAddress,
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/protocol/UBIPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contract UBIPool is
/// @notice Sets the UBI percentage distribution in CL
/// @param percentage The percentage of the UBI
function setUBIPercentage(uint32 percentage) external onlyOwner {
require(percentage < MAX_UBI_PERCENTAGE, "UBIPool: percentage too high");
require(percentage <= MAX_UBI_PERCENTAGE, "UBIPool: percentage too high");
emit UBIPercentageSet(percentage);
}

Expand Down

0 comments on commit a4918f6

Please sign in to comment.