The distinction between derive_address_seed and derive_address was
unclear and we were inconsistent in it:
We ended up applying address Merkle tree public key in both
functions, which is confusing.
Before this change, there was no TypeScript function for deriving
address seed. There was only deriveAddress, but deriving the
unified seed was a mystery for developers.
We have two utilities for hashing and truncating to BN254:
hash_to_bn254_field_size_be - the older one, which:
Searches for a bump in a loop, adds it to the hash inputs and then
truncates the hash. That doesn't make sense, because truncating
the hash should be sufficient, adding a bump is unnecessary.
Another limitation is that it takes only one sequence of bytes,
making it difficult to provide multiple inputs without
concatenating them.
hashv_to_bn254_field_size - the newer one, which:
Just truncates the hash result, without the bump mechanism.
Takes 2D byte slice as input, making it possible to pass multiple
inputs.
Changes
Don't add MT pubkey in derive_address_seed. It's not a correct place
for it to be applied. The distinction between derive_address_seed
and derive_address should be:
derive_address_seed takes provided seeds (defined by the
developer) and hashes them together with the program ID. This
operation is done only in the third-party program.
derive_address takes the address seed (result of
address_address_seed) and hashes it together with the address
Merkle tree public key. This is done both in the third-party program
and in light-system-program. light-system-program does that as a
check whether the correct Merkle tree is used.
Adjust the stateless.js API:
Provide deriveAddressSeed function.
Add unit tests, make sure that deriveAddressSeed and
deriveAddress provide the same results as the equivalent functions
in Rust SDK.
Problems
derive_address_seed
andderive_address
was unclear and we were inconsistent in it:deriveAddress
, but deriving the unified seed was a mystery for developers.hash_to_bn254_field_size_be
- the older one, which:hashv_to_bn254_field_size
- the newer one, which:Changes
derive_address_seed
. It's not a correct place for it to be applied. The distinction betweenderive_address_seed
andderive_address
should be:derive_address_seed
takes provided seeds (defined by the developer) and hashes them together with the program ID. This operation is done only in the third-party program.derive_address
takes the address seed (result ofaddress_address_seed
) and hashes it together with the address Merkle tree public key. This is done both in the third-party program and in light-system-program. light-system-program does that as a check whether the correct Merkle tree is used.deriveAddressSeed
function.deriveAddressSeed
andderiveAddress
provide the same results as the equivalent functions in Rust SDK.