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

Fix incorrect query with 256-bit integer key #6591

Open
wants to merge 1 commit into
base: develop
from

Conversation

Projects
None yet
2 participants
@conr2d
Copy link
Contributor

commented Jan 12, 2019

Change Description

There is an issue when making a query with 256-bit integer key by get_table_rows API, because ::sha256() puts binary from the lowest address, but eosio::checksum256 (eosio::fixed_bytes<32>) rearranges binary by uint128_t unit.

struct [[eosio::table]] row {
   uint64_t    id;
   std::string nickname;
   uint64_t primary_key()const { return id; }
   checksum256 secondary_key()const { return sha256(nickname.data(), nickname.size()); }
}

typedef eosio::multi_index<"table"_n, row,
   indexed_by<"secondary"_n, const_mem_fun<row, checksum256, &row::secondary_key>
> table_index;

For example, if user add a row into multi_index like above with nickname = "eosio", the hashed value with ::sha256() is efbb5450f4528e0dd33ff1873f52a175 e8f280eb591c6725a1227b9aec8eac0e. However, eosio::checksum256 will be 75a1523f87f13fd30d8e52f45054bbef 0eac8eec9a7b22a125671c59eb80f2e8, so currently get_table_rows with 256-bit integer doesn't work in intuitive way. User cannot use hashed value directly, but need to change the sequence of binary.

This patch converts the passed hash value to fit the type eosio::chain::key256_t when calling get_table_rows.

Consensus Changes

None.

API Changes

None.

Documentation Additions

None.

@conr2d

This comment has been minimized.

Copy link
Contributor Author

commented Mar 7, 2019

@arhag

Do you think this patch breaks existing behavior? If then, I would add another option like --bypass not to change the sequence of binary instead of modifying original code.

@conr2d conr2d force-pushed the conr2d:fix-query branch from 1765a32 to 4a0dd8f Mar 15, 2019

@conr2d conr2d changed the base branch from release/1.6.x to develop Mar 15, 2019

@wangyilin1987

This comment has been minimized.

Copy link

commented Apr 26, 2019

Will the version be merged?and when?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.