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

hardhat_api: Implement hardhat_dropTransaction method #148

Open
4 tasks
dutterbutter opened this issue Sep 28, 2023 · 0 comments
Open
4 tasks

hardhat_api: Implement hardhat_dropTransaction method #148

dutterbutter opened this issue Sep 28, 2023 · 0 comments
Labels
hardhat_api 👷 Indicates hardhat namespace api tasks p3 🔵 Indicates low priority item

Comments

@dutterbutter
Copy link
Collaborator

Description:

The hardhat_dropTransaction endpoint needs to be implemented. The purpose of this endpoint is to remove a transaction from the mempool. Hardhat docs for reference, test implementations can be found here.

// Interface in the `trait`
#[rpc(name = "hardhat_dropTransaction")]
fn drop_transaction(&self, tx_hash: H256) -> BoxFuture<Result<bool>>;

// Actual code in the `impl`
fn drop_transaction(&self, tx_hash: H256) -> BoxFuture<Result<bool>> {
    // TODO: Solution here
}

JS implementation:

/**
 * Removes the given transaction from the mempool, if it exists.
 *
 * @param txHash Transaction hash to be removed from the mempool.
 * @returns `true` if successful, otherwise `false`.
 * @throws if the transaction was already mined.
 */
export async function dropTransaction(txHash: string): Promise<boolean> {
  const provider = await getHardhatProvider();

  assertTxHash(txHash);

  return (await provider.request({
    method: "hardhat_dropTransaction",
    params: [txHash],
  })) as boolean;
}

Expected response

Command returns proper response:

curl -X POST http://localhost:8011 \
     -H "Content-Type: application/json" \
     --data '{
       "jsonrpc": "2.0",
       "id": 1,
       "method": "hardhat_dropTransaction",
       "params": ["0x7fTf4C4Bf8Ecd85dEf3E1c5Df137a7512a6a57bd987f3b8e"]
     }'

Response:

{"jsonrpc":"2.0", "result":true, "id":1}

Requirements:

  1. Implement the API:

    • The endpoint should return true if successful in removing the tx from the mempool, otherwise false.
    • Ensure the method executes the call reliably and efficiently.
    • Ensure errors are properly returned.
  2. Unit Tests:

    • Write unit tests to verify the functionality of the dropTransaction method.
    • Ensure coverage for multiple edge-case scenarios.
  3. Documentation:

    • Add inline Rust documentation (/// comments) detailing the method's purpose, return values, and any potential edge cases or error scenarios.
    • Update SUPPORTED_APIS.md with updated documentation and examples.
    • (Optional) Add request to test_endpoints.http for easier manual verification.

Task Checklist:

  • Implement the dropTransaction method.
  • Write unit tests for the dropTransaction method.
  • Add inline documentation for the hardhat_dropTransaction endpoint.
  • Update documentation for the hardhat_dropTransaction endpoint in SUPPORTED_APIS.md.

Additional Notes:

If you're an external contributor looking to take on this issue, please comment below to let us know you're working on it. If you need further clarification on the requirements or need assistance with anything related to the implementation, feel free to ask!

@dutterbutter dutterbutter added the hardhat_api 👷 Indicates hardhat namespace api tasks label Sep 28, 2023
@dutterbutter dutterbutter moved this to Todo 🔨 in Progress Board Sep 28, 2023
@MexicanAce MexicanAce added the p3 🔵 Indicates low priority item label Oct 5, 2023
IAvecilla added a commit to lambdaclass/era-test-node that referenced this issue Feb 29, 2024
* Initial new implementation

* Fix compilation error

* Implementation of add operation for big integers (matter-labs#136)

* Implement Big UInt Left Shift (matter-labs#139)

* Add `bigUIntShl` implementation

* Add constants

* Fix compilation

* Implement Big UInt Right Shift (matter-labs#137)

* Add `bigUIntShr` implementation

* Add constants

* Implement Big UInt Bitwise Or for modexp (matter-labs#135)

* Implement bigUIntBitOr

* Fix bigUIntBitOr

* Fix bigUIntBitOr

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Fix missing closing brackets

---------

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Implement big uint conditional select for modexp (matter-labs#148)

* Implement bigUIntCondSelect

* Fix missing curly braces

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Implement Big UInt Right Shift (matter-labs#137)

* Add `bigUIntShr` implementation

* Add constants

* Implement Big UInt Bitwise Or for modexp (matter-labs#135)

* Implement bigUIntBitOr

* Fix bigUIntBitOr

* Fix bigUIntBitOr

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Fix missing closing brackets

---------

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

---------

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Implement mul operation for big UInts (matter-labs#151)

* First implementation of mul operation for bigints

* Fix multiplication for big integers

* Fix some merge issues

* Improve comments and function docs

* Delete whitespaces

* Substraction with borrow (matter-labs#149)

* First substraction draft

* Fix compile problems

* Working implementation

* Updated code

* Updated code

* Update subtract implementation

* Remove console_log

* Add docs for function

* Update function docs

* Remove tests from from ModExp.yul

* Fix typo

* Restore horrible whitespaces to avoid an ugly merge conflict

* Update precompiles/Modexp.yul

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Revert "Update precompiles/Modexp.yul"

This reverts commit 582bc41a0bb7fb02a1a68717fdf83c6fe432d422.

---------

Co-authored-by: Joaquín P. Centeno <jpcenteno@users.noreply.github.com>
Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Refactor `modexp` reimplementation (matter-labs#156)

* Make Big UInt API functions naming consistent

* Refactor `bigUIntAdd` variable names

* Refactor `bigUIntMul` variable names

* Refactor `subLimbsWithBorrow`

* Refactor `bigUintSubtractionWithBorrow`

* Refactor `bigUIntAdd`

* Fix `bigUIntSubWithBorrow`

* Format `storeLimbValueAtOffset`

* Refactor `bigUIntBitOr`

Made it consistent with the rest of the code convention and naming

* Refactor `bigUIntCondSelect`

Made it consistent with the rest of the code convention and naming

* Reorder `overflowingSubWithBorrow`

* Move comment to modexp API Docs section

* Biguint division (matter-labs#159)

* Division draft

* Non working draft

* Fix compile errors

* Use proper pointers for quotient and remainder

* Add fix note, some more changes

* Add comment

* Implement `big_uint_bit_size`

* Increase pointer to prevent it from steping over console_log

* WIP divrem

* Fix loop and zero initializer

* Push test cases

* Add other test case

* Add docs and tests for `big_uint_inplace_or_1`

* Fix bug related to bit shifting

* Fix borrow return in big uint sub function

* Delete playground file used for debugging

* Fix sub with borrow function

* Add playground again to check more big integer division tests

* Remove playground used for testing

* Write documentation for new shift functions

* Improve naming and documentation for new helper functions

* Rename bigUIntOrWith1 to bigUintInPlaceOrWith1

* Add tmp buffer parameters to bigUIntDivRem. Improve docs.

* Simplify subLimbsWithBorrow

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Remove `mul` call from `bigUIntInPlaceOrWith1`

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Remove multiplications from copyBigUint

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Optimize bigUIntBitSize loop

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Simplify zeroWithLimbSizeAt

---------

Co-authored-by: Francisco Krause Arnim <fkrausear@gmail.com>
Co-authored-by: IAvecilla <iavecilla@fi.uba.ar>
Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Implement mul mod operation for big UInts (matter-labs#161)

* Division draft

* Non working draft

* Fix compile errors

* Use proper pointers for quotient and remainder

* Add fix note, some more changes

* Add comment

* Implement `big_uint_bit_size`

* Increase pointer to prevent it from steping over console_log

* WIP divrem

* Fix loop and zero initializer

* Push test cases

* Add other test case

* Add docs and tests for `big_uint_inplace_or_1`

* Fix bug related to bit shifting

* Fix borrow return in big uint sub function

* Delete playground file used for debugging

* Fix sub with borrow function

* Add playground again to check more big integer division tests

* Remove playground used for testing

* Write documentation for new shift functions

* Improve naming and documentation for new helper functions

* Rename bigUIntOrWith1 to bigUintInPlaceOrWith1

* Add tmp buffer parameters to bigUIntDivRem. Improve docs.

* Add big uint mul mod skeleton

* Remove wrong comment

* Update algorithm comment

* Add limb size doubling and divide by two for mul mod operation

* Functions to duplicate and halve limb size work in place

* Use camelCase

* Remove console_log

* Add docs

* Update doc

---------

Co-authored-by: Francisco Krause Arnim <fkrausear@gmail.com>
Co-authored-by: Joaquín P. Centeno <jpcenteno@users.noreply.github.com>

* Add parseCallData function

* Add function to left-pad big uints

* Remove console log function

* Change left padding functions for big uints to not work in place

* Add `parseCalldata` function (matter-labs#168)

* Remove redundant parse call data declaration

* Free memory pointer (matter-labs#169)

* Add free memory pointer function

* Update precompiles/Modexp.yul

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Update precompiles/Modexp.yul

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

---------

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>

* Start parsing the input calldata

* Correctly parse call data

* Add left pad steps for modexp inputs

* Add pad if needed function

* Modexp for big UInts skeleton (matter-labs#164)

* WIP: modexp skeleton

* Use of mul mod function for big integers

* imlement aux function to check if big uint is larger than 1

* minor fix

* Restore modexp from target branch

* Fix mul mod

* Finish modexp implementation

* Remove playground used for debugging

* Update modexp with final state of modular exponentiation function

* Fix merge issue

* Change all names to camel case

* fix typo

Co-authored-by: Francisco Krause Arnim <56402156+fkrause98@users.noreply.github.com>

---------

Co-authored-by: IAvecilla <iavecilla@fi.uba.ar>
Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>
Co-authored-by: Francisco Krause Arnim <56402156+fkrause98@users.noreply.github.com>

* Add simple integration

* Fix calldata buffer in zero check

* Uncomment checks for base cases

* Fix result length to match with mod length

* Fix condition in parse call data

* Update test assertions with new test node updates

* Add comment for tests with a temp patch

* Fix modexp result length

* Fix limb amount for modexp operands

* Clean sratch buffers in each iteration

* Clean sratch buffers for every operation

* Remove unused functions

* Delete free memory pointer usage and calculate pointers manually

* Replace all mul operations for shifts to improve gas usage

* Include basic optimizations

* Add optimizations for reminder calculations

* Add small improvement for main loop in modular exp

* Add temporary fix for modexp test

* Add modex reference script

* Remove unnecesary memory stores

* Reduce iterations in rem function

* Compilation fix

* Print gas used on tests

* Add build script to create gas reports

* Save gas used for each test of the precompiles

* Add aux functions to write lines in each report

* Merge main

* Fix tests lint

* Fix lint in test utils

* Change L1 url

---------

Co-authored-by: Nacho Avecilla <nachoavecilla@gmail.com>
Co-authored-by: Joaquín Centeno <jpcenteno@users.noreply.github.com>
Co-authored-by: Francisco Krause Arnim <56402156+fkrause98@users.noreply.github.com>
Co-authored-by: Francisco Krause Arnim <fkrausear@gmail.com>
Co-authored-by: IAvecilla <iavecilla@fi.uba.ar>
Co-authored-by: Javier Chatruc <jrchatruc@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hardhat_api 👷 Indicates hardhat namespace api tasks p3 🔵 Indicates low priority item
Projects
Status: Todo 🔨
Development

No branches or pull requests

2 participants