Skip to content
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

Changing contract encoding. #444

Open
Vineet77 opened this issue Mar 17, 2020 · 0 comments
Open

Changing contract encoding. #444

Vineet77 opened this issue Mar 17, 2020 · 0 comments
Labels
Priority: Critical Type: Bug Something is broken Type: Enhancement New feature or request

Comments

@Vineet77
Copy link
Member

Vineet77 commented Mar 17, 2020

Branch: newPubKeyEncode
Since we are in the process of changing the changing the public key encoding, those changes affect other aspects of the system.

One aspect of the system that needs to be changed is the way that we encode contracts.
Previously, we encoded contracts with the assumption that the encoded public key is of length 171. With the new system moving forward, the length of the public key is not longer constant.

So the encoding of contracts is now:

  • First two bytes contains the version, an unsigned 16 bit integer, encoded little endian style.
  • The next bytes will be the encoded sender public key. The encoding of the public key contains a byte prefix that gives information about the length of the encoding. If the public key is null (in the case of mining contracts), then the third byte will be 0.
  • The byte after the encoded sender public key is the length of the signature. If the signature is nil (the contract is unsigned), then the signature length is 0. Following this byte is the signature (if it exists).
  • Following the signature length and signature, is the recipient public key hash, which is of size 32 bytes.
  • After the recipient public key hash, is the value, an unsigned 64 bit integer, little endian encoded.
  • After the value, is the state nonce which is also an unsigned 64 bit integer, little endian encoded.

The functions func (c *Contract) Serialize() ([]byte, error) and func (c *Contract) Deserialize(b []byte) errorin contracts.go.

The old implementation still exists, as a reference. Feel free to replace as much as you need. The unit tests have been refactored.

@Vineet77 Vineet77 added Priority: Critical Type: Bug Something is broken Type: Enhancement New feature or request labels Mar 17, 2020
@Vineet77 Vineet77 assigned Vineet77 and unassigned Vineet77 Mar 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: Critical Type: Bug Something is broken Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant