-
Notifications
You must be signed in to change notification settings - Fork 2
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
Commitment of RGB++ Tx should be verified #622
Labels
bug
Something isn't working
Comments
def calculate_commitment
data = JSON.parse('{
"inputs": [
{
"previous_output": {
"tx_hash": "0x047b6894a0b7a4d7a73b1503d1ae35c51fc5fa6306776dcf22b1fb3daaa32a29",
"index": "0x0"
},
"since": "0x0"
}
],
"outputs": [
{
"lock": {
"code_hash": "0xd5a4e241104041f6f12f11bddcf30bd7b2f818722f78353fde019f5081cd6b49",
"hash_type": "type",
"args": "0x010000000000000000000000000000000000000000000000000000000000000000000000"
},
"capacity": "0x0000000000000000",
"type": {
"code_hash": "0xc4957f239eb3db9f5c5fb949e9dd99adbb8068b8ac7fe7ae49495486d5e5d235",
"hash_type": "type",
"args": "0x43094caf2f2bcdf6f5ab02c2de744936897278d558a2b6924db98a4f27d629e2"
}
},
{
"lock": {
"code_hash": "0xd5a4e241104041f6f12f11bddcf30bd7b2f818722f78353fde019f5081cd6b49",
"hash_type": "type",
"args": "0x010000000000000000000000000000000000000000000000000000000000000000000000"
},
"capacity": "0x0000000000000000",
"type": {
"code_hash": "0xc4957f239eb3db9f5c5fb949e9dd99adbb8068b8ac7fe7ae49495486d5e5d235",
"hash_type": "type",
"args": "0x43094caf2f2bcdf6f5ab02c2de744936897278d558a2b6924db98a4f27d629e2"
}
}
],
"outputs_data": [
"0x2c010000000000000000000000000000",
"0xbc020000000000000000000000000000"
],
"cell_deps": []
}').with_indifferent_access
transaction = CKB::Types::Transaction.from_h(data)
hash = Digest::SHA256.new
hash.update("RGB++")
version = [0, 0].pack("C*")
hash.update(version)
hash.update([transaction.inputs.length, transaction.outputs.length].pack("C*"))
transaction.inputs.each do |input|
out_point = input.previous_output
binary_out_point = CKB::Utils.hex_to_bin(CKB::Serializers::OutPointSerializer.new(out_point).serialize)
hash.update(binary_out_point.bytes.pack("C*"))
end
transaction.outputs.each_with_index do |output, index|
binary_output = CKB::Utils.hex_to_bin(CKB::Serializers::OutputSerializer.new(output).serialize)
hash.update(binary_output.bytes.pack("C*"))
output_data = transaction.outputs_data[index]
output_data_serializer = CKB::Serializers::OutputDataSerializer.new(output_data)
output_data_length = output_data_serializer.as_json["items_count"]
binary_output_data_length = CKB::Utils.hex_to_bin("0x#{[output_data_length].pack('V').unpack1('H*')}")
hash.update(binary_output_data_length.bytes.pack("C*"))
binary_output_data = CKB::Utils.hex_to_bin(output_data).bytes.pack("C*")
hash.update(binary_output_data.bytes.pack("C*"))
end
Digest::SHA256.hexdigest(hash.digest.bytes.pack("C*"))
end The commitment calculated using the above code is consistent with the test case results ( |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This transaction https://pudge.explorer.nervos.org/transaction/0x235835820029c1438a11f1ee62056e353aa5f36dedb1320025960604a312a464 contains an RGB++ Cell, which is expected to be bound to BTC Tx https://mempool.space/testnet/tx/aee4e8e3aa95e9e9ab1f0520714031d92d3263262099dcc7f7d64e62fa2fcb44
But the commitment in that BTC tx is invalid, it doesn't cover the CKB Transaction, so it's not an effective RGB++ isomorphic transaction.
To make the RGB++ recognition more precise, the commitment should be verified.
Noted that the calculation might lead to performance issue, please make it asynchronous and return its process status in API for clarity.
Ref:
The text was updated successfully, but these errors were encountered: