Giter Site home page Giter Site logo

laksaruby's People

Contributors

nickcen avatar poctek avatar snowsledge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

snowsledge poctek

laksaruby's Issues

"Unable to verify transaction" when trying to submit transaction to the network

Hi! I've been trying to submit a transaction to the network with this library and he only response I've managed to get is the following json:

"{\"error\":{\"code\":-26,\"data\":null,\"message\":\"Unable to verify transaction\"},\"id\":1,\"jsonrpc\":\"2.0\"}\n"

It seems that something is broken in the transaction signing. Tested the python version and it worked well.

Here's a snippet to reproduce the issue:

id = nil
version = 21_823_489
nonce = '9'
gas_price = '1000000000'
gas_limit = '1'

sender_pub_key = '027eaa76955940798e22ec4007b00dbf0002fcd34f501f58c04b06c604f2228076'
to_addr = '0xFeEd7997A0a45682CD4D8CEda27f2d81F6ba587c'
amount = '1000000000000'

provider = Laksa::Jsonrpc::Provider.new('https://dev-api.zilliqa.com')
signer = Laksa::Account::Wallet.new(provider)

private_key = '7e78c742bca06824e4a5f0591260a2646339507c231daa5a47bf91d801f98239'
signer.add_by_private_key(private_key)

tx_params = Laksa::Account::TxParams.new

tx_params.id = id

tx_params.version = version
tx_params.nonce = nonce
tx_params.sender_pub_key = sender_pub_key
tx_params.gas_price = gas_price
tx_params.gas_limit = gas_limit
tx_params.to_addr = to_addr
tx_params.amount = amount

tx = Laksa::Account::Transaction.new(tx_params, provider)

signed = signer.sign(tx)
payload = signed.to_payload
payload = {
  version: payload[:version],
  nonce: payload[:nonce],
  toAddr: Laksa::Account::Wallet.to_checksum_address(payload[:to_addr]),
  amount: payload[:amount],
  pubKey: payload[:pub_key],
  gasPrice: payload[:gas_price],
  gasLimit: payload[:gas_limit],
  code: nil,
  data: nil,
  signature: payload[:signature].downcase
}

provider.CreateTransaction(payload)

Missing checks on randomness used in the sign function in schnorr.rb

PROBLEM: The sign function uses a random k_bn. In the current implementation, k_bn is generated as a set of 32 random bytes. However, Schnorr signing requires k_bn to be smaller than N (order of the elliptic group) which in turn is smaller than the largest value represented by a set of 32 random random bytes.

SOLUTION: Instead of generating a set of 32 random bytes, we should instead generate a random number between 1 and N-1. In case, such a function does not exist in the used library, we should generate k_bn in a while loop by generating it as a set of 32 random bytes but checking at each iteration whether k_bn lies between 1 and N-1. Note that we should not attempt to do a modulo N here. @nickcen @neeboo

Laksa::Crypto::Schnorr.sign signature size issue

Sometimes Laksa::Crypto::Schnorr.sign returns 126 bytes signature.

When trying to submit TX ZIL node returns: {"error":{"code":-8,"data":null,"message":"Invalid Signature size"},"id":1,"jsonrpc":"2.0"}

I noticed this issue on production account so I can't provide private key for testing but I will keep monitoring this in testing environment and if I catch this I will provide you a private key.

Here is how I use this gem:

      tx_parameters = Laksa::Account::TxParams.new.tap do |x|
        x.version        = 65537
        x.nonce          = nonce_of(issuer.fetch(:address)) + 1
        x.amount         = convert_to_base_unit(amount)
        x.gas_price      = 1000000000
        x.gas_limit      = 1
        x.sender_pub_key = issuer.fetch(:public_key)
        x.to_addr        = Laksa::Util::Bech32.from_bech32(recipient.fetch(:address))
      end

      tx = Laksa::Account::Transaction.new(tx_parameters, nil).tap do |t|
        t.signature = Laksa::Crypto::Schnorr.sign(Laksa::Util.encode_hex(t.bytes), issuer.fetch(:private_key), issuer.fetch(:public_key))
      end

      payload = tx.to_payload.tap do |p|
        p.merge! \
          amount:    p[:amount].to_s,
          gasPrice:  p[:gasPrice].to_s,
          gasLimit:  p[:gasLimit].to_s,
          signature: p[:signature].to_s
      end

Then I submit payload to ZIL by using CreateTransaction JSON-RPC call.

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.