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 some refcounter issues #2498

Merged
merged 2 commits into from
May 17, 2022
Merged

Fix some refcounter issues #2498

merged 2 commits into from
May 17, 2022

Conversation

roman-khimov
Copy link
Member

@roman-khimov roman-khimov commented May 16, 2022

Thanks @ixje for spotting these.

@roman-khimov roman-khimov added bug Something isn't working vm VM tasks/bugs/issues labels May 16, 2022
@roman-khimov roman-khimov added this to the v0.99.0 milestone May 16, 2022
@codecov
Copy link

codecov bot commented May 16, 2022

Codecov Report

Merging #2498 (18d627e) into master (d2dcdec) will increase coverage by 0.06%.
The diff coverage is 100.00%.

❗ Current head 18d627e differs from pull request most recent head 0d93b35. Consider uploading reports for the commit 0d93b35 to get more accurate results

@@            Coverage Diff             @@
##           master    #2498      +/-   ##
==========================================
+ Coverage   85.09%   85.15%   +0.06%     
==========================================
  Files         293      294       +1     
  Lines       36923    36945      +22     
==========================================
+ Hits        31418    31460      +42     
+ Misses       4187     4165      -22     
- Partials     1318     1320       +2     
Impacted Files Coverage Δ
pkg/vm/ref_counter.go 100.00% <100.00%> (ø)
pkg/vm/vm.go 94.54% <100.00%> (+0.02%) ⬆️
pkg/network/server.go 74.11% <0.00%> (-0.10%) ⬇️
cli/input/readpass_unix.go 0.00% <0.00%> (ø)
pkg/services/oracle/request.go 63.01% <0.00%> (+5.02%) ⬆️
cli/input/input.go 62.16% <0.00%> (+10.94%) ⬆️
pkg/services/oracle/oracle.go 88.37% <0.00%> (+15.50%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 81fa751...0d93b35. Read the comment docs.

Match C# behavior. Thanks to @ixje for finding this.
@roman-khimov roman-khimov changed the title vm: count map key in the refcounter as well Fix some refcounter issues May 16, 2022
@ixje
Copy link
Contributor

ixje commented May 17, 2022

I think there might be an issue with circular references as well. I'll try to verify and otherwise provide an example.

@ixje
Copy link
Contributor

ixje commented May 17, 2022

Here's a test to reproduce the issue

func TestCircularRefs(t *testing.T) {
	h := "560110c34a4acf4a10c36058cf5810c34ecf10c34ecf58cf0b604a11d2"
	prog, err := hex.DecodeString(h)
	require.NoError(t, err)
	vm := load(prog)
	vm.Run()
	assert.Equal(t, 3, vm.refs)
}

This script comes from here https://github.com/neo-project/neo-vm/blob/master/tests/neo-vm.Tests/UtReferenceCounter.cs#L14-L41. The format of the comments in that file is {<evaluation stack contents>} | {<static field slot contents>}: <engine reference count>. fwiw; the right side of the evaluation stack is the top
So this

//{A[],A[]}|{null}:3

means 2 array items in the evaluation stack, 1 null stack item in the staticfields slot, total ref count of 3.


The last opcode is REMOVE which removes array B from this setup

{A[A,B[C[D[B]]]],A[A,B],1}|{null}:9

The problem is with B containing itself, therefore the rc of B will always remain > 0 and it won't decrease the count for the internal elements that are discarded.


I don't think this scenario is very realistic on chain, but you might want to solve it regardless of that. The implication I see is that the max stack items limit might be reached sooner than the C# VM.

@roman-khimov
Copy link
Member Author

Moved that to #2500 and merging this one as is.

@roman-khimov roman-khimov merged commit 1c0fae2 into master May 17, 2022
@roman-khimov roman-khimov deleted the fix-map-key-refcounting branch May 17, 2022 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working vm VM tasks/bugs/issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants