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(staking): replace bech32 address with evm hex address for staking precompile contract #2200

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

luchenqun
Copy link
Contributor

@luchenqun luchenqun commented Dec 16, 2023

Description

This PR will convert all bech32 addresses in precompiled contract staking to evm hex address. The implementation itself is not difficult, but too many unit tests need to be fixed. I originally wanted to fix one function such as delegate with one PR, but I found that there is a strong correlation between all functions, and it would be more efficient to fix them all at once. It is roughly planned to complete all tasks by the end of January next year.

Please help me review whether the changes to the StakingI.sol file are reasonable, because subsequent updates need to be based on the StakingI.sol file. @fedekunze @Vvaradinov

More details see before #2122

@luchenqun luchenqun requested a review from a team as a code owner December 16, 2023 11:28
@luchenqun luchenqun requested review from Vvaradinov and GAtom22 and removed request for a team December 16, 2023 11:28
@0xstepit
Copy link
Contributor

Looks good @luchenqun, thanks for your contribution! I do agree it is a good idea to work with the evm hex in the precompile.

precompiles/staking/types.go Fixed Show fixed Hide fixed
precompiles/staking/types.go Fixed Show fixed Hide fixed
precompiles/staking/types.go Fixed Show fixed Hide fixed
precompiles/staking/types.go Fixed Show fixed Hide fixed
precompiles/staking/types.go Fixed Show fixed Hide fixed
@luchenqun
Copy link
Contributor Author

@GAtom22

Hello Tom, because I have changed the string validator to the address validator, one of the staking integration test should execute queries for calltype has failed. I think the solidity code here needs to be updated https://github.com/luchenqun/evmos/blob/224293dc3d6629a5640e2356e8abc423b3919142/precompiles/staking/testdata/StakingCaller.sol#L352-L393 But I am not particularly familiar with this part of the code , can you help me update this part of the code?

Copy link

codecov bot commented Jan 4, 2024

Codecov Report

Attention: Patch coverage is 76.19048% with 20 lines in your changes are missing coverage. Please review.

Project coverage is 70.48%. Comparing base (aa0b9d5) to head (d15fe4b).
Report is 152 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2200      +/-   ##
==========================================
- Coverage   70.53%   70.48%   -0.06%     
==========================================
  Files         291      291              
  Lines       22617    22639      +22     
==========================================
+ Hits        15953    15956       +3     
- Misses       5798     5811      +13     
- Partials      866      872       +6     
Files Coverage Δ
precompiles/staking/types.go 87.28% <76.19%> (-0.05%) ⬇️

... and 2 files with indirect coverage changes

@luchenqun
Copy link
Contributor Author

@GAtom22

Hello Tom, because I have changed the string validator to the address validator, one of the staking integration test should execute queries for calltype has failed. I think the solidity code here needs to be updated https://github.com/luchenqun/evmos/blob/224293dc3d6629a5640e2356e8abc423b3919142/precompiles/staking/testdata/StakingCaller.sol#L352-L393 But I am not particularly familiar with this part of the code , can you help me update this part of the code?

I modified it based on my intuition, and it seems to be OK. LOL

@luchenqun
Copy link
Contributor Author

@fedekunze @Vvaradinov It took an hour to implement the feature, but a day to fix the unit tests. Hahaha. Now you can start review the updated code.

@@ -334,15 +332,12 @@ contract StakingCaller {
(shares, coin) = abi.decode(data, (uint256, staking.Coin));
} else if (calltypeHash == keccak256(abi.encodePacked("callcode"))) {
//Function signature
bytes4 sig = bytes4(keccak256(bytes("delegation(address,string)")));
bytes4 sig = bytes4(keccak256(bytes("delegation(address,address)")));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need @GAtom22 to verify this change, I don't enough of solidity to be sure that it's the correct change (it looks good)

},
{
"success - undelegate transaction with correct gas estimation",
func() []byte {
input, err := s.precompile.Pack(
staking.UndelegateMethod,
s.address,
s.validators[0].GetOperator().String(),
common.BytesToAddress(s.validators[0].GetOperator().Bytes()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to a typescript library to convert from validator bech32 to hex in order to update the frontend. Without the lib the frontend will not be able to create staking transactions after upgrading the network with the new code.

@hanchon
Copy link
Contributor

hanchon commented Jan 18, 2024

Providing a Typescript lib to convert the validators addresses is a blocker to merge this PR. After having the lib ready we can finish the PR review and merge it.

@luchenqun I'll move the pr to draf until we have a tested typescript lib that works fine for this change, I guess that in theory the code provided by the now deprecated Evmosjs may work, but I have never tried it for validator addresses.

@hanchon hanchon marked this pull request as draft January 18, 2024 18:29
Copy link

github-actions bot commented Mar 4, 2024

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days-before-close if no further activity occurs.

@VictorTrustyDev
Copy link
Contributor

Not Stale

Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days-before-close if no further activity occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants