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

vm: fix packmap operation #3685

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

vm: fix packmap operation #3685

wants to merge 1 commit into from

Conversation

AliceInHunterland
Copy link
Contributor

Close #3613

Copy link

codecov bot commented Nov 15, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 83.03%. Comparing base (c2b4d32) to head (6b34149).

Files with missing lines Patch % Lines
pkg/vm/stackitem/item.go 66.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3685      +/-   ##
==========================================
- Coverage   83.05%   83.03%   -0.03%     
==========================================
  Files         334      334              
  Lines       46599    46598       -1     
==========================================
- Hits        38704    38693      -11     
- Misses       6322     6327       +5     
- Partials     1573     1578       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

})
for i := 1; i < MaxSize/85; i++ {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe MaxSerialized better

Close #3613

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
require.NoError(t, err)
require.NotNil(t, m)
require.Equal(t, 0, len(m))

Copy link
Member

Choose a reason for hiding this comment

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

Useless change.

@@ -1214,15 +1214,14 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
panic("invalid length")
}

items := make([]stackitem.MapElement, n)
for i := range n {
newMap := stackitem.NewMap()
Copy link
Member

Choose a reason for hiding this comment

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

newMap

m

key := v.estack.Pop()
validateMapKey(key)
val := v.estack.Pop().value
items[i].Key = key.value
items[i].Value = val
newMap.Add(key.Item(), val)
Copy link
Member

Choose a reason for hiding this comment

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

This way is not optimal, verification is performed twice.

res := NewMap()
for i := range value {
if err := IsValidMapKey(value[i].Key); err != nil {
panic(err)
Copy link
Member

Choose a reason for hiding this comment

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

It's too risky to panic inside NewMapWithValue, it may be used outside the VM. Either adjust a documentation of this function and don't check for value correctness or change the signature of this function to return error. BTW, with the updated PACKMAP, do we really use this function anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, NewMapWithValue is used only in tests.

@AnnaShaleva
Copy link
Member

Add a designated compatibility test, please.

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.

packmap operation keeps duplicate entries
2 participants