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

feat: implement 0x37 - CALLDATACOPY Opcode #197

Merged
merged 37 commits into from
Sep 11, 2023

Conversation

khaeljy
Copy link
Contributor

@khaeljy khaeljy commented Aug 27, 2023

Pull Request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Build-related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Resolves: #123

What is the new behavior?

Does this introduce a breaking change?

  • Yes
  • No

Copy link
Member

@Eikix Eikix left a comment

Choose a reason for hiding this comment

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

Hey! Welcome, great first pr 🦾
Can we check if we can use slice instead of looping and copying?


// For out of bound bytes, 0s will be copied.
if (i + offset >= call_data.len()) {
assert(*results[i] == 0, 'wrong data value');
Copy link
Member

Choose a reason for hiding this comment

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

ah it's unlucky we can't assert equality for memory and felt dict, we should probably later create test utils for asserting equality @enitrat

Copy link
Collaborator

@enitrat enitrat left a comment

Choose a reason for hiding this comment

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

lgtm, will merge after thinking a bit about the type conversion thing :)

@github-actions
Copy link

Snapshot Comparison Report:

No changes in gas consumption.

out_of_bounds_bytes.append(0);
};

self.memory.store_n(out_of_bounds_bytes.span(), dest_offset + slice_size);
Copy link
Member

Choose a reason for hiding this comment

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

it looks non optimal to do two times memory.store_n because this function is quite expensive.

I think that it's cheaper to first pad data_to_copy, then to store_n only once, @enitrat

Copy link
Collaborator

Choose a reason for hiding this comment

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

@ClementWalter data_to_copy is a span and can't be padded, the solution would be to clone it into an array and then pad this array, but then I'm not sure it would actually be more effective. I will check and report back

@enitrat
Copy link
Collaborator

enitrat commented Sep 4, 2023

        if (copied.len() < size) {
            let n_zeroes = size - copied.len();
            self.memory.store_n(copied.pad_end_zeroes(n_zeroes).span(), dest_offset);
        } else {
            self.memory.store_n(copied, dest_offset);
        }

looks to be more optimized - I will re-verify once the requested changes have been applied

@enitrat enitrat self-requested a review September 4, 2023 14:22
@enitrat
Copy link
Collaborator

enitrat commented Sep 5, 2023

looks to be more optimized - I will re-verify once the requested changes have been applied

Given that this implies cloning an entire memory segment just to pad zeroes, I think there might be a point at which it becomes more expensive to do a clone than it is to call twice store_n. Will research this later in #278

@khaeljy
Copy link
Contributor Author

khaeljy commented Sep 8, 2023

Tests will be fixed after merge PR #331

Copy link
Collaborator

@enitrat enitrat left a comment

Choose a reason for hiding this comment

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

Looks good now ! Waiting for bugfix PR merge to finish. Sorry it was a bit long but it was the first PR you opened, now it's going to be easier 💪

Copy link
Collaborator

@enitrat enitrat left a comment

Choose a reason for hiding this comment

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

💯

@Eikix Eikix dismissed ClementWalter’s stale review September 11, 2023 11:21

Enitrat approved the PR

@enitrat enitrat added this pull request to the merge queue Sep 11, 2023
Merged via the queue into kkrt-labs:main with commit 61a6299 Sep 11, 2023
1 of 2 checks passed
@khaeljy khaeljy deleted the CALLDATACOPY branch September 11, 2023 19:46
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.

feat: implement 0x37 - CALLDATACOPY Opcode
4 participants