-
Notifications
You must be signed in to change notification settings - Fork 78
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
Manifest and script checks #1729
Merged
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
60dfffc
manifest: remove no longer used Serializable interface
roman-khimov 211fe30
manifest: move ABI code into file of its own
roman-khimov 5ba074b
manifest: return an error from IsValid
roman-khimov 1a4958b
manifest: add ABI validity check
roman-khimov 296c7a1
manifest: move Group code into a file of its own
roman-khimov e9ea89b
manifest: add group signature length check
roman-khimov f78e3fb
manifest: move Event into a file of its own
roman-khimov 0b2e931
manifest: add event validity check
roman-khimov f3c761e
manifest: move Parameter into a file of its own
roman-khimov f0c3066
manifest: add method validity check
roman-khimov 15ed905
manifest: add validity checks for Parameter
roman-khimov 284476c
manifest: add Permission and Permissions validity checks
roman-khimov dc3967a
manifest: add manifest validity checks
roman-khimov 62ef5a8
native: enforce contract manifest UTF-8 validity
roman-khimov a3abdbd
manifest: add duplicate events/methods checks to ABI
roman-khimov b892db9
vm: add instruction correctness check
roman-khimov a6e25cf
bitfield: add basic bit field package
roman-khimov 158f0d9
native/vm: add script check for deployed contracts
roman-khimov dd05cae
core: check all transaction scripts
roman-khimov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
Package bitfield provides a simple and efficient arbitrary size bit field implementation. | ||
It doesn't attempt to cover everything that could be done with bit fields, | ||
providing only things used by neo-go. | ||
*/ | ||
package bitfield | ||
|
||
// Field is a bit field represented as a slice of uint64 values. | ||
type Field []uint64 | ||
|
||
// Bits and bytes count in a basic element of Field. | ||
const elemBits = 64 | ||
const elemBytes = 8 | ||
|
||
// New creates a new bit field of specified length. Actual field length | ||
// can be rounded to the next multiple of 64, so it's a responsibility | ||
// of the user to deal with that. | ||
func New(n int) Field { | ||
return make(Field, 1+(n-1)/elemBits) | ||
} | ||
|
||
// Set sets one bit at specified offset. No bounds checking is done. | ||
func (f Field) Set(i int) { | ||
addr, offset := (i / elemBits), (i % elemBits) | ||
f[addr] |= (1 << offset) | ||
} | ||
|
||
// IsSet returns true if the bit with specified offset is set. | ||
func (f Field) IsSet(i int) bool { | ||
addr, offset := (i / elemBits), (i % elemBits) | ||
return (f[addr] & (1 << offset)) != 0 | ||
} | ||
|
||
// Copy makes a copy of current Field. | ||
func (f Field) Copy() Field { | ||
fn := make(Field, len(f)) | ||
copy(fn, f) | ||
return fn | ||
} | ||
|
||
// And implements logical AND between f's and m's bits saving the result into f. | ||
func (f Field) And(m Field) { | ||
l := len(m) | ||
for i := range f { | ||
if i >= l { | ||
f[i] = 0 | ||
continue | ||
} | ||
f[i] &= m[i] | ||
} | ||
} | ||
|
||
// Equals compares two Fields and returns true if they're equal. | ||
func (f Field) Equals(o Field) bool { | ||
if len(f) != len(o) { | ||
return false | ||
} | ||
for i := range f { | ||
if f[i] != o[i] { | ||
return false | ||
} | ||
} | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package bitfield | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestFields(t *testing.T) { | ||
a := New(128) | ||
b := New(128) | ||
a.Set(10) | ||
b.Set(10) | ||
a.Set(42) | ||
b.Set(42) | ||
a.Set(100) | ||
b.Set(100) | ||
require.True(t, a.IsSet(42)) | ||
require.False(t, b.IsSet(43)) | ||
|
||
v := uint64(1<<10 | 1<<42) | ||
require.Equal(t, v, a[0]) | ||
require.Equal(t, v, b[0]) | ||
|
||
require.True(t, a.Equals(b)) | ||
|
||
c := a.Copy() | ||
require.True(t, c.Equals(b)) | ||
|
||
z := New(128) | ||
c.And(a) | ||
require.True(t, c.Equals(b)) | ||
c.And(z) | ||
require.True(t, c.Equals(z)) | ||
|
||
c = New(64) | ||
c[0] = a[0] | ||
require.False(t, c.Equals(a)) | ||
|
||
b.And(c) | ||
require.False(t, b.Equals(a)) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expect it to compare
f
too
as sets (aslen
guarantee can't be provided fully because of upper-rounding inNew
). But if we don't need this, ok.