Giter VIP home page Giter VIP logo

hermezjs's People

Contributors

adrifdez avatar albertoelias avatar amonsosanz avatar arnaubennassar avatar arnaucube avatar druiz0992 avatar elias-garcia avatar jbaylina avatar krlosmata avatar laisolizq avatar olomix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hermezjs's Issues

Improve gasLimit approach

gasLimit is currently hard-coded on constants.
It should be a parameter that could be overridden and takes default value from constants.

Remove tx from the pool when state is forged

Transactions from the pool are being removed only when a 404 response is returned from the API. Sometimes, they will be forged but also being returned from the API, so we need to remove them from the pool also when the state is fged.

RawData EIP712

Issue

  • EIP712 is not yet supported by hardware wallets

Solution

  • Retrieve hash message from EIP712 data type and sign in with signer.signMessage(message)

Info collected

Split unit and integrations testing

  • Separate tests which requires a running hermez environment (contracts, hermez-node, ...) in order to be ble to run unit testing from github actions
  • Setup github actions to:
    • run unit tests on every push & pull on master and develop branches
    • run check linter on every push & pull on master and develop branches

Compact L2Tx code

Right now, to make a L2Tx, the steps are the following:

  • Call generateL2Transaction to get the tansaction and encodedTransaction data
  • Sign the transaction data
  • Send L2Transaction
  // generate L2 transaction
  const l2Tx = {
    type: 'Transfer',
    from: srcAccount.accountIndex,
    to: dstAccount.accountIndex,
    amount: hermez.Float16.float2Fix(hermez.Float16.floorFix2Float(amountXfer)),
    fee
  }

  const xferTx = await hermez.TxUtils.generateL2Transaction(l2Tx,
    hermezWallet.publicKeyCompressedHex,
    srcAccount.token)
  hermezWallet.signTransaction(xferTx.transaction, xferTx.encodedTransaction)
  const XferResult = await hermez.Tx.sendL2Transaction(xferTx.transaction, hermezWallet.publicKeyCompressedHex)

I think we should compact this into something more user friendly. If intermediate data is required, it can be returned

  // generate L2 transaction
  const l2Tx = {
    type: 'Transfer',
    from: srcAccount.accountIndex,
    to: dstAccount.accountIndex,
    amount: hermez.Float16.float2Fix(hermez.Float16.floorFix2Float(amountXfer)),
    fee
  }
  const XferResult = await hermez.sendL2Transaction(l2Tx, hermezWallet.publicKeyCompressedHex)

Only send transactions to the boot coordinator

Hermez nodes sync transactions in the pool between them with Hermez Node v1.7.0. Now it's enough with sending the transaction to a single coordinator (Boot Coordinator) and it will be synced between nodes automatically.

Retrieve BJJ from wallet

If a user wants to get the BJJ associated to his account from the wallet to share it with a third party, it needs to do Wallet->My Account -> view in batch explorer.
I would like the user to be able to retrieve this BJJ without the explorer.

Audit on robustness

I would like to run some audit on the code to check if it is resistant against incorrect inputs. I think i have seen some vulnerabilities that incorrect inputs may make the program crash

Cannot create hermez-wallet without being connected to a provider

Current implementation does not allow create an HermezWallet from ethereum address in method createWalletFromEtherAccount.
In case HermezWallet is derived from signer type Wallet, meaning only privateKey is needed, there is no dependency on provider url.
I suggest to slightly modify the code and allow hermezWallet creation from ethereum private key without the need setting a provider.

Let me know your thoughts on this

Problems with ChainID

Right now the hermez-node only supports ChainID = 0 for checking signatures.
hermezjs should be updated to hardocde this CHainID until hermez-node is ready

Tx broadcast to nextForger doesn't reach nextForgers

I have s coordinator that has won the next slots. I send a transfer, and I see that the new coordinator never forges this transaction. However, I check the transactions-pool and this transaction is not present in the new coordinator, but it is present in the boot coordinator transactions-pool.

Padding for MTP siblings

Right now the API returns the array of siblings set to 0 instead of not being present. This will be fixed eventually but until then hermezjs should filter the 0ed siblings.

Incorrect request URL for CoordinatorAPI.getTokens

Summary of Bug

On request for tokens with filtering by multiple (more than one) tokenIds or tokenSymbols returns empty list.

Steps to Reproduce

hermez.CoordinatorAPI.getTokens(null, ['ETH', 'HEZ']);

Additional Information & Screenshots:

In getTokens function tokenIds & tokenSymbols are join with coma ,, but according to API they should be join with pipe |.

pending changes from code review

The following is a list of changes suggested in #22 and not applied due to some time constraints. I leave them here for future consideration:

  • src/api.js
  return extractJSON(axios.get(`${baseApiUrl}/accounts`, { params }))

  try {
    const retVal = await axios.get(`${baseApiUrl}/accounts`, { params })
 
@AlbertoElias AlbertoElias 2 hours ago 
We should remove this try catch as the try catch should be done when executing the api call by the developer
  • src/contracts.js
 * @return {Contract} The request contract
 */
function getContract (contractAddress, abi, providerUrl) {
function getContract (contractAddress, abi, providerUrl, ethereumAddress) {
  // TODO cache not valid if using different EtherAddress Disable for now

AlbertoElias 2 hours ago 
What do you mean?
  • src/tx-utils.js
 * @param {object} transaction - Transaction object sent to generateL2Transaction
 * @return {string} transactionType
 */
function getTransactionType (transaction) {
 
@AlbertoElias AlbertoElias 2 hours ago 
Why remove this?
    nonce++
  let nonce = currentNonce

  if (typeof nonce === 'undefined') {
 
@AlbertoElias AlbertoElias 2 hours ago 
I don't get this. Why would it be undefined? The idea would be for developers to provide whatever the current nonce is. If you think it's better to retrieve it all automatically ourselves, we should just remove the currentNonce parameter
  • src/tx.js
import HermezABI from './abis/HermezABI.js'
import WithdrawalDelayerABI from './abis/WithdrawalDelayerABI.js'

/**
 * Get current average gas price from the last ethereum blocks and multiply it
 * @param {number} multiplier - multiply the average gas price by this parameter
 * @param {string} providerUrl - Network url (i.e, http://localhost:8545). Optional
 
@AlbertoElias AlbertoElias 2 hours ago 
Why was this removed?
  const ethereumAddress = getEthereumAddress(hezEthereumAddress)
  let account = (await getAccounts(ethereumAddress, [token.id])).accounts[0]
  const hermezContract = getContract(contractAddresses.Hermez, HermezABI, providerUrl, ethereumAddress)
  let account = await getAccounts(hezEthereumAddress, [token.id])
 
@AlbertoElias AlbertoElias 2 hours ago 
I would rewrite as:

const accounts = await getAccounts(hezEthereumAddress, [token.id])
const account = typeof accounts !== 'undefined' ? accounts.accounts[0] : null
 
@AlbertoElias AlbertoElias 2 hours ago 
We should avoid using let as much as possible, and we shouldn't call account when the value is the result of getAccounts
@@ -82,11 +88,14 @@ const deposit = async (amount, hezEthereumAddress, token, babyJubJub, providerUr
 * @returns {promise} transaction parameters
 */
const forceExit = async (amount, accountIndex, token, gasLimit = GAS_LIMIT, gasMultiplier = GAS_MULTIPLIER) => {
  const hermezContract = getContract(contractAddresses.Hermez, HermezABI)
  // TODO. Check call below as it can be invalid if accountIndex doesn't exist
  const hermezEthereumAddress = (await getAccount(accountIndex)).hezEthereumAddress
 
@AlbertoElias AlbertoElias 2 hours ago 
I would repeat the suggested structure above
  • test/tx.test.mjs
jest.mock('axios')

// Skipping this test. We cover transaction flow in hermez-sandbox.test.mjs
 
@AlbertoElias AlbertoElias 2 hours ago 
If you're skipping, can you leave things how they were so that they work with Swagger?

Support maxNumBatch and atomic transactions

New features

maxNumBatch

Allow the user to sign a maxNumBatch parameter when sending a L2 transaction.

  • Proposals implementation:
    • Add new param to transaction maxNumBatch which would be chosen by the user
    • Add numBatchOffset and internally compute the maxNumBatch

Atomic transactions

All the rq should be added to allow the user to link transactions.

  • Proposals implementation:
    • when a L2 transaction is done, return the necessary data which could be shared afterwards to link transactions. Therefore allow a single object as a parameter to link transactions
    • Add single parameters just related to atomic transactions and sign them internally

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.