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

Sha256 fix #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Sha256 fix #1

wants to merge 3 commits into from

Conversation

guilledk
Copy link
Collaborator

@guilledk guilledk commented Jan 21, 2025

Issue

While developing snarktor contracts and aggregator service it was found that in order to find the table an endianess transformation was necessary, as seen here:

This test was a clear example of the issue:

Reproducing

Created two contracts that perform exactly same tasks and define same structs one in rust and one in C:

Then created test that auto deploys contracts and calls the actions in three batches:

  1. Emplace a pre-defined hash on both tables using store actions
  2. Call rload function on both contracts to read and compare stored hash
  3. Call cload function on both contracts to read and compare stored hash

Here is test python version: https://gist.github.com/guilledk/4b561aacaec627c5504754d3bc55f968
Here is test rust version: https://gist.github.com/guilledk/eb0bf73fa2b4788208d8d12f3cde6d62

When run without this branch, the test will succed until step 3, rust contract will fail to find the row in the C contract. Another interesting result is the output of the dump function on the rust contract:

rindextest::dump:

        #[chain(action = "dump")]
        pub fn dump(&self) {
            // print table contents using primary index
            let cdb = MyData::new_table(Name::from_str("cindextest"));
            let cit = cdb.find(0);
            chain_println!(cit.get_value().unwrap().hash);

            // print table contents using find_primary from secondary index interface
            let s_idx = cdb.get_idx_by_hash();
            let (it, mut s_val) = s_idx.find_primary(0);

            if it.is_ok() {
                chain_println!(s_val);
            } else {
                chain_println!("not found!");
            }
        }

this prints:

dump: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1e1f20
201f1e1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100

so clearly table data works fine when searching by simple primary index, but is printed with its 16 byte chunks reversed, as well as endianess swap internaly on each 16 byte chunk.

Conclusion

Changes in this PR make the test suite run correctly as well as the zk proof submit test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants