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

Let the staking provider to refresh KEEP stake owner #103

Merged
merged 3 commits into from
Aug 23, 2022
Merged

Conversation

pdyraga
Copy link
Member

@pdyraga pdyraga commented May 6, 2022

T network staking contract supports existing KEEP stakes by allowing KEEP stakers to use their stakes in T network and weights them based on KEEP<>T token ratio.

KEEP stake owner is cached in T staking contract and used to restrict access to all functions only the owner should be able to execute. To cache KEEP staking contract in T staking contract, T staking contract first needs to resolve the owner. Resolving liquid KEEP stake owner is easy. Resolving token grant stake owner is complicated and not possible to do on-chain from a contract external to KEEP TokenStaking contract. Keep TokenStaking knows the grant ID but does not expose it externally.

This problem is solved by KeepStake contract. It contains operator-owner pairs that were snapshotted 2021-11-11. If KEEP staker does not want to go liquid and instead they use their grant for delegation, and their grant was created after the snapshot date of 2021-11-11, KeepStake contract owner needs to register a new owner-operator pair for them.

The problem though is when the owner staked before KeepStake owner registered a pair of them.

An example is staking provider 0xA5f6822ef1A7DF72628259f9D1dc17eb2BCb2385 that received tokens delegated by owner 0x78dc7f84a8da5c96c4c54dcf5bd6e9ccd4fe2bb5 at transaction 0x262a7b173e2572e4494b3470c4978903e4d9f95141a18ad79c7d9090f16c9874.

Before that delegation was done, no owner-pair was registered in KeepStake for 0x78dc7f84a8da5c96c4c54dcf5bd6e9ccd4fe2bb5 and KeepStake.resolveOwner(0xA5f6822ef1A7DF72628259f9D1dc17eb2BCb2385) returns 0xF139B3137D5bF24848e4F8FbE1d6AB70dF90c5Fa which is the master Keep TokenGrantStake contract. As a result, 0xA5f6822ef1A7DF72628259f9D1dc17eb2BCb2385 can not execute calls as an owner.

The solution for this kind of situation would be to register the pair in KeepStake contract and call TokenStaking.refreshKeepOwner() but this function has a rule authorizing only the old owner to call this function. The owner is the master TokenGrantStake contract though.

The fix proposed here is to allow TokenStaking.refreshKeepOwner() call from the staking provider as well. We could probably also allow the authorizer to call it, but the staking provider feels good enough and such situations should be rare.

T network staking contract supports existing KEEP stakes by allowing KEEP
stakers to use their stakes in T network and weights them based on KEEP<>T token
ratio. KEEP stake owner is cached in T staking contract and used to restrict
access to all functions only owner should be able to execute. To cache KEEP
stake owner in T staking contract, T staking contract first needs to resolve the
owner.

Resolving liquid KEEP stake owner is easy. Resolving token grant stake owner is
complicated and not possible to do on-chain from a contract external to KEEP
`TokenStaking` contract. Keep `TokenStaking` knows the grant ID but does not
expose it externally.

This problem is solved by `KeepStake` contract. It contains operator-owner pairs
that were snapshotted 2021-11-11. If KEEP staker does not want to go liquid and
instead they use their grant for delegation, and their grant was created after
the snapshot date of 2021-11-11, `KeepStake` contract owner needs to register
a new owner-operator pair for them.

The problem though is when the owner staked *before* `KeepStake` owner
registered a pair of them. An example is staking provider
`0xA5f6822ef1A7DF72628259f9D1dc17eb2BCb2385` that received tokens delegated by
owner `0x78dc7f84a8da5c96c4c54dcf5bd6e9ccd4fe2bb5` at transaction
`0x262a7b173e2572e4494b3470c4978903e4d9f95141a18ad79c7d9090f16c9874`. Before
that delegation was done, no owner-pair was registered in `KeepStake` for
`0x78dc7f84a8da5c96c4c54dcf5bd6e9ccd4fe2bb5` and
`KeepStake.resolveOwner(0xA5f6822ef1A7DF72628259f9D1dc17eb2BCb2385)` returns
`0xF139B3137D5bF24848e4F8FbE1d6AB70dF90c5Fa` which is the master Keep
`TokenGrantStake` contract. As a result,
`0xA5f6822ef1A7DF72628259f9D1dc17eb2BCb2385` can not execute calls as an owner.

The solution for this kind of situation would be to register the pair in
`KeepStake` contract and call `TokenStaking.refreshKeepOwner()` but this
function has a rule authorizing only the old owner to call this function.
The owner is the master `TokenGrantStake` contract though.

The fix proposed here is to allow `TokenStaking.refreshKeepOwner()` call from
the staking provider as well. We could probably also allow the authorizer to
call it, but the staking provider feels good enough and such situations should
be rare.
@pdyraga
Copy link
Member Author

pdyraga commented May 6, 2022

System tests are in fact passing if you look at the execution log. It looks like some configuration problem, yet one issue after the fix from #102.

@pdyraga pdyraga requested review from vzotova and cygnusv May 6, 2022 13:07
vzotova
vzotova previously approved these changes May 6, 2022
manumonti
manumonti previously approved these changes Aug 17, 2022
Copy link
Member

@manumonti manumonti left a comment

Choose a reason for hiding this comment

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

LGTM! ✌️

cygnusv
cygnusv previously approved these changes Aug 17, 2022
The versions were updated to more recent ones, the same as used by
tbtc-v2. This update allows to elimimnate the problem when running
system tests. Although all system tests were passing, the process kept
failing with:

Error: Cannot find module './test/system/staking.test.js'

This was happening both on CI and locally. After the update, the problem
is gone.
@pdyraga pdyraga dismissed stale reviews from cygnusv, manumonti, and vzotova via 7c05a34 August 19, 2022 13:12
@pdyraga
Copy link
Member Author

pdyraga commented Aug 19, 2022

@vzotova @manumonti @cygnusv I updated hardhat, ethers, and hardhat plugin versions in 7c05a34 and now system tests job is passing. System tests were passing before as well but the job was exiting with some test-unrelated error.

@cygnusv cygnusv merged commit d7f61f2 into main Aug 23, 2022
@cygnusv cygnusv deleted the who-is-the-owner branch August 23, 2022 22:44
@pdyraga pdyraga added this to the v1.2.0 milestone Sep 29, 2022
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.

4 participants