[SON for Hive] - Fix asset_symbol_type serialization #90

Closed
opened 2021-04-30 16:03:49 +00:00 by serkixenos · 4 comments
serkixenos commented 2021-04-30 16:03:49 +00:00 (Migrated from gitlab.com)

Comparing Hive wallet and SON for Hive transaction processing, we do have exactly the same string representation of the transactions:

Hive
{"ref_block_num":42214,"ref_block_prefix":2560592527,"expiration":"2021-04-26T10:38:51","operations":[{"type":"transfer_operation","value":{"from":"sonaccount01","to":"account05","amount":{"amount":"1000","precision":3,"nai":"@@000000021"},"memo":""}}],"extensions":[],"signatures":[]}

SON
{"ref_block_num":42214,"ref_block_prefix":2560592527,"expiration":"2021-04-26T10:38:51","operations":[{"type":"transfer_operation","value":{"from":"sonaccount01","to":"account05","amount":{"amount":"1000","precision":3,"nai":"@@000000021"},"memo":""}}],"extensions":[],"signatures":[]}

When we serialize transaction for signing, we get different binary representations

Hive
E6A48F8A9F983B98866001020C736F6E6163636F756E743031096163636F756E743035E8030000000000000354455354530000000000

SON
E6A48F8A9F983B98866001020C736F6E6163636F756E743031096163636F756E743035E8030000000000002320BCBE000000

Dissected, this is the binary layout

Hive:
E6A4 8F8A9F98 3B98866001 02 0C736F6E6163636F756E743031 09 6163636F756E743035 E803000000000000 0354455354530000 000000

E6A4                       ref_block_num
8F8A9F98                   ref_block_prefix
3B98866001                 expiration
02                         operation identifier (transfer)
0C736F6E6163636F756E743031 from (string of length 13 (0C), this is actually sonaccount01 in hex)
096163636F756E743035       to (string of length 9 (09), this is actually account05 in hex)
E803000000000000           amount.amount, 1000 in hex, 64 bit
0354455354530000           this is asset identifier, 03 - precision and TESTS in hex
000000                     ???

SON:
E6A4 8F8A9F98 3B98866001 02 0C736F6E6163636F756E743031 09 6163636F756E743035 E803000000000000 2320BCBE000000

E6A4                       ref_block_num
8F8A9F98                   ref_block_prefix
3B98866001                 expiration
02                         operation identifier (transfer)
0C736F6E6163636F756E743031 from (string of length 13 (0C), this is actually sonaccount01 in hex)
096163636F756E743035       to (string of length 9 (09), this is actually account05 in hex)
E803000000000000           amount.amount, 1000 in hex, 64 bit
2320BCBE000000             incorrectly serialized asset_symbol_type

There are pack/unpack functions here: https://gitlab.com/PBSA/peerplays/-/merge_requests/13/diffs#5c8314f993e94af6ba72e8316824670a6c9c50bc_0_239

which should handle asset_symbol_type serialization, but for some reason fc lib does not picks it for serialization.

Comparing Hive wallet and SON for Hive transaction processing, we do have exactly the same string representation of the transactions: ``` Hive {"ref_block_num":42214,"ref_block_prefix":2560592527,"expiration":"2021-04-26T10:38:51","operations":[{"type":"transfer_operation","value":{"from":"sonaccount01","to":"account05","amount":{"amount":"1000","precision":3,"nai":"@@000000021"},"memo":""}}],"extensions":[],"signatures":[]} SON {"ref_block_num":42214,"ref_block_prefix":2560592527,"expiration":"2021-04-26T10:38:51","operations":[{"type":"transfer_operation","value":{"from":"sonaccount01","to":"account05","amount":{"amount":"1000","precision":3,"nai":"@@000000021"},"memo":""}}],"extensions":[],"signatures":[]} ``` When we serialize transaction for signing, we get different binary representations ``` Hive E6A48F8A9F983B98866001020C736F6E6163636F756E743031096163636F756E743035E8030000000000000354455354530000000000 SON E6A48F8A9F983B98866001020C736F6E6163636F756E743031096163636F756E743035E8030000000000002320BCBE000000 ``` Dissected, this is the binary layout ``` Hive: E6A4 8F8A9F98 3B98866001 02 0C736F6E6163636F756E743031 09 6163636F756E743035 E803000000000000 0354455354530000 000000 E6A4 ref_block_num 8F8A9F98 ref_block_prefix 3B98866001 expiration 02 operation identifier (transfer) 0C736F6E6163636F756E743031 from (string of length 13 (0C), this is actually sonaccount01 in hex) 096163636F756E743035 to (string of length 9 (09), this is actually account05 in hex) E803000000000000 amount.amount, 1000 in hex, 64 bit 0354455354530000 this is asset identifier, 03 - precision and TESTS in hex 000000 ??? SON: E6A4 8F8A9F98 3B98866001 02 0C736F6E6163636F756E743031 09 6163636F756E743035 E803000000000000 2320BCBE000000 E6A4 ref_block_num 8F8A9F98 ref_block_prefix 3B98866001 expiration 02 operation identifier (transfer) 0C736F6E6163636F756E743031 from (string of length 13 (0C), this is actually sonaccount01 in hex) 096163636F756E743035 to (string of length 9 (09), this is actually account05 in hex) E803000000000000 amount.amount, 1000 in hex, 64 bit 2320BCBE000000 incorrectly serialized asset_symbol_type ``` There are pack/unpack functions here: https://gitlab.com/PBSA/peerplays/-/merge_requests/13/diffs#5c8314f993e94af6ba72e8316824670a6c9c50bc_0_239 which should handle asset_symbol_type serialization, but for some reason fc lib does not picks it for serialization.
serkixenos commented 2021-04-30 16:09:01 +00:00 (Migrated from gitlab.com)

mentioned in issue #76

mentioned in issue #76
serkixenos commented 2021-05-16 23:12:02 +00:00 (Migrated from gitlab.com)

https://gitlab.com/PBSA/peerplays/-/merge_requests/13/diffs?commit_id=595de9c3e88cef4398ac081cf422f24f0d2fd305#88e652b4c5cbb15c53b4c0795fc06e2764ae99a5_45_44

Encoding value initialization has to be changed, as this code will work only on testnet. We should implement network recognition code, similar to what we have in BTC SON, to be able to figure out whether we are running on Hive mainnet or testnet, and initialize the value to be encoded (HIVE/TESTS, HBD/TBD) properly. Contrary to this, Peerplays assets are named only HIVE and HBD.

https://gitlab.com/PBSA/peerplays/-/merge_requests/13/diffs?commit_id=595de9c3e88cef4398ac081cf422f24f0d2fd305#88e652b4c5cbb15c53b4c0795fc06e2764ae99a5_45_44 Encoding value initialization has to be changed, as this code will work only on testnet. We should implement network recognition code, similar to what we have in BTC SON, to be able to figure out whether we are running on Hive mainnet or testnet, and initialize the value to be encoded (HIVE/TESTS, HBD/TBD) properly. Contrary to this, Peerplays assets are named only HIVE and HBD.
serkixenos commented 2021-05-17 14:16:22 +00:00 (Migrated from gitlab.com)

changed time estimate to 24h

changed time estimate to 24h
serkixenos commented 2021-05-17 14:16:36 +00:00 (Migrated from gitlab.com)

changed time estimate to 40h

changed time estimate to 40h
serkixenos (Migrated from gitlab.com) closed this issue 2021-06-07 18:44:27 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Peerplays_Blockchain/peerplays_migrated#90
No description provided.