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: fix current cycles syscall on chunk run with snapshot #3188

Merged

Conversation

driftluo
Copy link
Collaborator

What problem does this PR solve?

The script group resume from the snapshot will lose the cycles consumed by the current execution, causing the value obtained by the current cycle syscall call to reset, causing potential inconsistencies.

This pr will fix the problem and only affects testnet

Check List

Tests

  • Unit test

Release note

Title Only: Include only the PR title in the release note.

@yangby-cryptape
Copy link
Collaborator

This BUG was found via the tests in #3187; see 4f12d9f for details.

Copy link
Collaborator

@yangby-cryptape yangby-cryptape left a comment

Choose a reason for hiding this comment

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

I tested this PR: this PR has passed all unit tests, included all unmerged tests.

Copy link
Contributor

@mohanson mohanson left a comment

Choose a reason for hiding this comment

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

LGTM

@driftluo driftluo force-pushed the fix-current-cycles-syscall-on-chunk-run branch from 615b899 to b2d831c Compare November 18, 2021 03:20
@driftluo driftluo marked this pull request as ready for review November 18, 2021 05:31
@driftluo driftluo requested a review from a team as a code owner November 18, 2021 05:31
@driftluo
Copy link
Collaborator Author

bors r=yangby-cryptape,mohanson,chanhsu001

@bors bors bot merged commit dd760ec into nervosnetwork:develop Nov 18, 2021
@driftluo driftluo deleted the fix-current-cycles-syscall-on-chunk-run branch November 18, 2021 07:19
bors bot added a commit that referenced this pull request Nov 22, 2021
3187: test(script): add more complicated scripts to unit tests r=driftluo,zhangsoledad a=yangby-cryptape

### What problem does this PR solve?

Add more complicated scripts to test the crate `ckb-script`.

#### Changes

**Tip: It's better to review this PR by reviewing each commits.**

- Refactor tests.

  - test(script): convert duplicate codes into functions to simplify them (7d060aa)

    At present, to add one test has to copy a lot of duplicate codes, so do refactor first.

  - test(script): add a Makefile to make almost all test scripts to be reproducible (883b3d9)

    Before this commit, only the latest 3 scripts could be re-built to same binaries from source files.

    I add a `Makefile` and a `README.md` to record the compile environments for almost all test scripts.
    So we can re-build these scripts more easily.

    **TODO**: Still left 4 binaries couldn't be built from source files.

- Add new tests.

  - test(script): current cycles should be always monotonically increased (794c539)

  - test(script): resume from snapshot with loading codes many times (d987413)

  - test(script): vm_version should be correct after resuming from snapshot (bd24f17)

  - test(script): current cycles should be correct after resuming from snapshot (5fc8bed)

    Find a bug which resolved in #3188.

  - test(script): to load code into global is not allowed in vm0 (d13e1f5)

    Ref:
    - nervosnetwork/ckb-vm@189d097
    - nervosnetwork/ckb-vm#142

  - test(script): hint instructions are not allowed in vm0 (b244812)

    Ref:
    - nervosnetwork/ckb-vm@5ace65b
    - nervosnetwork/ckb-vm#188

  - test(script): flags of stack memory are not reset after they freed (a0c8927)

    This feature looks like a bug but not.

    If any function initializes a piece of stack memory, after the lifetime of that function, the stack memory will be freed.
    But the flag of that piece of stack memory will not reset.

    So, if we call a function which load code into a piece of stack memory, then we call another function, it could raise an error `InvalidPermission` if the second function tries to write the previous piece of stack memory.

    Ref: [`W^X`](https://en.wikipedia.org/wiki/W%5EX)

### Check List

Tests

- Unit test

### Release note

```release-note
None: Exclude this PR from the release note.
```

Co-authored-by: Boyu Yang <yangby@cryptape.com>
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.

None yet

4 participants