firestack-lab / laksaruby Goto Github PK
View Code? Open in Web Editor NEWLaksaRuby -- Zilliqa Blockchain Library
License: GNU General Public License v3.0
LaksaRuby -- Zilliqa Blockchain Library
License: GNU General Public License v3.0
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)
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
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.
Hi,
Could you publish your gem to rubygems? Currently gem 'laksa'
doesn't work.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.