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 (libzkp): free Rust CString by from_raw #998

Merged
merged 1 commit into from
Oct 24, 2023

Conversation

silathdiir
Copy link
Contributor

@silathdiir silathdiir commented Oct 22, 2023

Purpose or design rationale of this PR

Proof results and VKs are returned by vec_to_c_char or string_to_c_char as *const c_char which calls CString::into_raw, reference its doc, the C ptr must be freed by CString::from_raw (memory leak otherwise).

  • adds a new function free_c_chars.
  • calls it when returns proof result or VK.

Test

The memory available could restore (983 -> 983) when running a loop (50 chunks from yesterday to morning of today).
The chunk-prover and batch-prover are created for each run of loop.

date time total used free shared buff/cache available
.... .... ..... .... .... ...... .......... .........
2023-10-23 17:47:16 995 5 793 0 197 983
2023-10-23 17:47:46 995 6 791 0 197 981
2023-10-23 17:48:16 995 5 793 0 197 983
2023-10-23 17:48:46 995 7 790 0 198 981
2023-10-23 17:49:16 995 25 772 0 198 963
2023-10-23 17:49:46 995 24 773 0 198 964
2023-10-23 17:50:16 995 24 773 0 198 964
2023-10-23 17:50:46 995 26 770 0 198 961
2023-10-23 17:51:16 995 40 757 0 198 948
2023-10-23 17:51:46 995 76 720 0 198 911
2023-10-23 17:52:16 995 141 655 0 198 846
2023-10-23 17:52:46 995 141 655 0 198 846
.... .... ..... .... .... ...... .......... .........
2023-10-24 08:23:28 995 4 788 0 202 983
2023-10-24 08:23:58 995 4 788 0 202 983
2023-10-24 08:24:28 995 4 788 0 202 983
2023-10-24 08:24:58 995 4 788 0 202 983
.... .... ..... .... .... ...... .......... .........

PR title

Your PR title must follow conventional commits (as we are doing squash merge for each PR), so it must start with one of the following types:

  • build: Changes that affect the build system or external dependencies (example scopes: yarn, eslint, typescript)
  • ci: Changes to our CI configuration files and scripts (example scopes: vercel, github, cypress)
  • docs: Documentation-only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that doesn't fix a bug, or add a feature, or improves performance
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • test: Adding missing tests or correcting existing tests

Deployment tag versioning

Has tag in common/version.go been updated or have you added bump-version label to this PR?

  • No, this PR doesn't involve a new deployment, git tag, docker image tag
  • Yes

Breaking change label

Does this PR have the breaking-change label?

  • No, this PR is not a breaking change
  • Yes

@silathdiir silathdiir marked this pull request as draft October 22, 2023 10:08
@codecov
Copy link

codecov bot commented Oct 22, 2023

Codecov Report

Merging #998 (1fd5038) into develop (c2ab4bf) will increase coverage by 0.00%.
The diff coverage is n/a.

@@           Coverage Diff            @@
##           develop     #998   +/-   ##
========================================
  Coverage    48.13%   48.14%           
========================================
  Files          100      100           
  Lines        10591    10591           
========================================
+ Hits          5098     5099    +1     
+ Misses        5071     5070    -1     
  Partials       422      422           
Flag Coverage Δ
common 54.94% <ø> (+0.08%) ⬆️
coordinator 18.94% <ø> (ø)
database 42.85% <ø> (ø)
prover 27.32% <ø> (ø)
rollup 66.20% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

see 1 file with indirect coverage changes

@silathdiir silathdiir marked this pull request as ready for review October 23, 2023 03:45
@silathdiir silathdiir requested a review from lispc October 23, 2023 03:45
lispc
lispc previously approved these changes Oct 23, 2023
@lispc
Copy link
Contributor

lispc commented Oct 23, 2023

btw do you need to fix this in l2geth ccc?

Copy link
Contributor

@0xmountaintop 0xmountaintop left a comment

Choose a reason for hiding this comment

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

LGTM

@silathdiir silathdiir changed the title [Testing] fix (libzkp): free Rust CString by from_raw fix (libzkp): free Rust CString by from_raw Oct 24, 2023
@silathdiir silathdiir requested review from georgehao and lispc October 24, 2023 00:42
@silathdiir silathdiir requested a review from johnsonjie October 24, 2023 01:27
@0xmountaintop 0xmountaintop merged commit 2102e16 into develop Oct 24, 2023
24 checks passed
@0xmountaintop 0xmountaintop deleted the libkzp-free-c-chars branch October 24, 2023 02:44
if cfg.ProofType == message.ProofTypeBatch {
C.init_batch_prover(paramsPathStr, assetsPathStr)
rawVK = C.get_batch_vk()
} else if cfg.ProofType == message.ProofTypeChunk {
C.init_chunk_prover(paramsPathStr, assetsPathStr)
rawVK = C.get_chunk_vk()
}
defer C.free_c_chars(rawVK)
Copy link

Choose a reason for hiding this comment

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

the rawVK is newed in go code, so it should be released in defer C.free(unsafe.Pointer(rawVK))?

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.

5 participants