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

Add std::tx::get_predicate_data #1984

Merged
merged 23 commits into from Jul 2, 2022
Merged

Conversation

camsjams
Copy link
Contributor

@camsjams camsjams commented Jun 14, 2022

Closes #1981

@camsjams camsjams marked this pull request as draft June 14, 2022 23:48
@adlerjohn adlerjohn added enhancement New feature or request lib: std Standard library labels Jun 15, 2022
@camsjams camsjams requested review from mohammadfawaz and removed request for otrho June 20, 2022 19:15
@camsjams camsjams marked this pull request as ready for review June 20, 2022 19:16
sway-lib-std/src/tx.sw Show resolved Hide resolved
sway-lib-std/src/tx.sw Outdated Show resolved Hide resolved
r1: u64
};

let predicate_data_ptr = is + predicate_code_length;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be

Suggested change
let predicate_data_ptr = is + predicate_code_length;
let predicate_data_ptr = is + predicate_code_length * 4;

The fact that it's not means there's a bug in the SDKs where they're not dividing the lengths by 4 to get the number of instructions instead of the number of bytes, as described in the specs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it @adlerjohn

So to be clear, on the SDK side which statement is true:

  1. divide predicate code length by 4
  2. divide predicate data length by 4
  3. divide both predicate code length and predicate data by 4

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only (1). Code length is in instructions (each instruction is 4 bytes), data length is in bytes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So does this still need to be resolved somewhere? Is there an open issue to fix the code length thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am investigating one more thing on the SDK side so will respond once I have more information

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the TypeScript SDK side, there is immediate failure if the predicate code length is divided by 4. On the Rust SDK side most of the work is offloaded out of the SDK into Input::coin_predicate - see here.

I think we should add this helper as is currently and add some issues to investigate further. Allowing this to merge will cleanup unit tests on TS and RS side of things and permit a good initial level of Predicate support, and any changes that need to occur in regards to dividing by 4 in here can be address fairly easily downstream.

@camsjams camsjams requested review from otrho and adlerjohn June 27, 2022 04:44
otrho
otrho previously approved these changes Jun 27, 2022
@camsjams
Copy link
Contributor Author

camsjams commented Jul 1, 2022

@adlerjohn @otrho can we re-review based on my comments?

Getting this particular helper in place would be wonderful to reduce copy pasted code across the Rust and TypeScript Sway programs (used by unit tests of Predicate) where I've duplicated this helper logic.

The helper is working as-is with Rust and TS SDK, changing it to divide by 4 causes issues on the GraphQL server. I think the vm team may have to investigate further on the issue, and at that point, updating this helper and the SDKs would be simple changes.

@adlerjohn adlerjohn enabled auto-merge (squash) July 2, 2022 23:34
@adlerjohn adlerjohn merged commit 8889ba0 into master Jul 2, 2022
@adlerjohn adlerjohn deleted the feature/stdlib-tx-get-predicate-data branch July 2, 2022 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lib: std Standard library
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add predicate data helper into std lib
3 participants