Encodings
Details about encodings used to represent core data structures using both field elements and bits.
Compressed Point Encoding
We often represent Baby Jubjub curve points in a "compressed" 255-bit encoding to save on hashing, bandwidth, and calldata. Our encoding scheme is identical to the scheme used in circomlib's PointBits
templates and circomlibjs's packPoint
and unpackPoint
methods.
check that the square root exists. If it doesn't, the pair does not represent a valid curve point.
Note that the compressed encoding does not fit in a field element, even though it does fit in a uint256
. Therefore it is (for the most part) not used in-circuit.
Asset Encoding
We define an Asset
by the following struct:
encodedAssetId
is the number represented by the 253 least-significant bits ofassetId
.encodedAssetAddr
is defined as the number represented by the following bits concatenated together, read from most-significant to least-significant (i.e. in big-endian order):3
0
bitsthe 3 most-significant bits of
assetId
88 bits that are left unspecified (currently they are ignored)
2 bits representing
assetType
-00
forERC20
,01
forERC721
,10
forERC1155
.160 bits representing
assetAddr
.
Note Encoding
We define the Note
and EncodedNote
structs as follows:
Within Nocturne, all amounts and balances are forced by the contracts and circuits to be 252-bit integers. This ensures it's impossible to overflow the field.
The encoding process for a Note
is:
encode the
asset
decompress the
stealthAddress
fieldpull out the
encodedAssetAddr
andencodedAssetId
fields.
Last updated