harmony-one / bounties

Bounty program is to help the community take part in the development of the Harmony blockchain. It covers from core feature to validator tooling, from dApp development to DeFi integration.
MIT License
59 stars 23 forks source link

Staking precompiles and caller lib #77

Closed JackyWYX closed 2 years ago

JackyWYX commented 2 years ago

1. Description

Currently, Harmony staking transactions are executed in a different logic other than the normal transaction. User can either send a normal transaction to do transfer or EVM call, or do staking transaction. This approach has restricted the use of staking protocol, and some DeFi products, E.g. liquidity staking, does not have access to the staking assets in consensus.

To improve the composability of the staking, we want to add the staking functions to the precompiles, so that the staking can be called from smart contract.

For this bounty, the features to be implemented includes:

  1. Add the staking operations to precompiles in core protocol.
  2. Implement and test the hard fork logic for the protocol change.
  3. Implement and deploy a smart contract which serves as a library with all pure functions for staking features.
  4. A full test report.

2. Some background and instructions

2.1 Staking transaction logic

The following code analysis is follows git commit dc27135dff1c948d186d345721edd26b4cf7edb9

When leader propose blocks (node/worker/worker.go:164) and node insert chain (core/blockchain.go:1451), the staking transactions will follow the logic at ApplyStakingTransaction (core/state_processor.go:112) to execute the staking transaction.

Staking transaction it has its own data structure where the staking directive type and data is inlcuded:

// staking/types/transaction.go:21
type txdata struct {
    Directive
    StakeMsg     interface{}
    ...
}
// core/state_processor.go:265
func ApplyStakingTransaction(
    config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.DB,
    header *block.Header, tx *staking.StakingTransaction, usedGas *uint64, cfg vm.Config) (receipt *types.Receipt, gas uint64, err error) {...}

One of this bounty's requirements is to add the staking processing logic to the precompiles (core/vm/contracts.go:101) and return the result as necessary.

2.2 Fork logic

It is also needed to add a hard fork logic for adding new precompiles.

type Rules struct {
    ChainID                                                                         *big.Int
    EthChainID                                                                      *big.Int
    IsCrossLink, IsEIP155, IsS3, IsReceiptLog, IsIstanbul, IsVRF, IsPrevVRF, IsSHA3 bool
}

func (c *ChainConfig) Rules(epoch *big.Int) Rules {...}

If you need more instruction, please add me on Discord Jacky | Harmony#9576 for further discussion

3. Features and acceptance criteria

3.1 Core protocol

3.2 Smart contract

3.3 Test reports

All test reports shall contain several test cases that include:

  1. Setup the test environment.
  2. Test cases for each test scenario.
  3. Reproducible steps and results.

The tests can be run manually. Another bounty can be added later to integrate the test cases to harmony-test repository.

3.4 Notice

The contracts and code changes are subject to code security audition, and developer may need to do some technically support even after the bounty closes.

4. Reward

$30,000 ONE

gitcoinbot commented 2 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


This issue now has a funding of 174102.9244 ONE (30009.08 USD @ $0.17/ONE) attached to it.

gitcoinbot commented 2 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work has been started.

These users each claimed they can complete the work by 264 years, 10 months from now. Please review their action plans below:

1) ndionxerz99 has started work.

Saya akan melakukan apa saja untuk memikki tiket 2) aungjr has started work.

What is the minimum amount of staking? 3) peekpi has started work.

great idea, I'll take care of it. 4) maxmustermann2 has started work.

Please refer to the following PR to see my proposed implementation https://github.com/harmony-one/harmony/pull/3906; the smart contract implementation is available at https://github.com/MaxMustermann2/harmony-staking-precompiles 5) ckanyemba has started work.

I want to work on this project, I am developer working towards building web3 programs

Learn more on the Gitcoin Issue Details page.

gitcoinbot commented 2 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work for 174102.9244 ONE (42901.40 USD @ $0.26/ONE) has been submitted by:


gitcoinbot commented 2 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work for 174102.9244 ONE (50313.48 USD @ $0.31/ONE) has been submitted by:

  1. @maxmustermann2

@leohchen please take a look at the submitted work: