LCS port to python and ruby

We release the python and ruby implementaion for the Libra Canonical Serialization (LCS) Spec.

LCS for pythoner

LCS for rubyer

Feedback is welcome.

5 Likes

LCS for python canoser-python is updated from version 0.3.x to version 0.4, with following updates:

  • Support optional type. Optional type is needed in ledger_info verification, because next_validator_set field of ledger_info is optional, and the hash of ledger_info is computed from its LCS bytes.
  • Support rust tuple struct in python with ‘canoser.DelegateT’ type.
  • Pretty printing

We implemented all libra test cases, even those in the libra readme document.
Libra Canonical Serialization Readme Test

1 Like

During writting test cases for the LCS Readme document, we found some mismatches between the document and the libra code. For example:

Program in document:

{
sender: 3a24a61e05d129cace9e0efc8bc9e33831fec9a9be66f50fd352a2638a49b9ee,
sequence_number: 32,
payload: Program {
code: “move”,
args: [{STRING: CAFE D00D}, {STRING: cafe d00d}],
modules: [[CA][FED0][0D]],
} ,
max_gas_amount: 10000,
gas_unit_price: 20000,
expiration_time: 86400 seconds
}

Real code output:

{
sender: 3a24a61e05d129cace9e0efc8bc9e33831fec9a9be66f50fd352a2638a49b9ee,
sequence_number: 32,
payload: Program(
Program {
code: “move”,
args: [
{STRING: CAFE D00D},
{STRING: cafe d00d},
],
},
),
max_gas_amount: 10000,
gas_unit_price: 20000,
expiration_time: 86400s,
}

The modules fields is missing.
The WriteSet has even more mismatches.

2 Likes

LCS for python canoser-python is updated to version 0.6, support the latest address change in LCS. Now, there are three types of bytes in LCS.

  1. varaible length. such as code:
code : [Uint8]
  1. fixed length, and the length info is written to LCS output. such as public_key and signature:
public_key, [Uint8, ED25519_PUBLIC_KEY_LENGTH]
signature, [Uint8, ED25519_SIGNATURE_LENGTH]
  1. fixed length, and the length info is NOT written to LCS output. The only case is Address, represented in canoser as:
Address, [Uint8, 32, False]

Because the address format is changed, many address related path is changed too.
For example:

  • account_resource_path, from which parse the account balance etc.
  • event_path, such as account_sent_event_path, account_received_event_path.
  • validator_set_address
  • faucet key
  • account_event

libra-client has made all this changes by using canoser-python.

1 Like

@yuan-xy thanks a lot!