Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Add SafeReadBytes from VM #71

Merged
merged 7 commits into from
Dec 10, 2018

Conversation

igormcoelho
Copy link
Contributor

I believe ReadVarBytes is not necessary for NeoVM, and it's even misleading now that its limits on NeoVM (int max = 0X7fffffc7) differ from Neo limits of the "same" function (int max = 0x1000000).
ReadVarInt was also duplicated, so it was removed too.
A new function called SafeReadBytes (inspired by @shargon discussion neo-project/neo#511) was added, and it can be reused inside Neo project if necessary.

@igormcoelho
Copy link
Contributor Author

A strict limit of 16MB was imposed (0x100000), that looks good enough for practice (better than GB...). Do you think we can validate this to see if it causes conflicts? @vncoelho @erikzhang @shargon @PeterLinX

@vncoelho
Copy link
Member

vncoelho commented Dec 9, 2018

With the storage history we could sync and see any difference, but it would be better with a Merkle Tree.

@erikzhang
Copy link
Member

What's the difference between this and the old implemention?


public static ulong ReadVarInt(this BinaryReader reader, ulong max = ulong.MaxValue)
{
byte fb = reader.ReadByte();
Copy link
Member

Choose a reason for hiding this comment

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

You can't remove this logic

value = fb;
if (value > max) throw new FormatException();
return value;
if((max > 0x1000000) || (!reader.BaseStream.CanSeek) || (reader.BaseStream.Length - reader.BaseStream.Position) < max))
Copy link
Member

Choose a reason for hiding this comment

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

If we want to throw an exception, then is not needed to check CanSeek, because this could throw an exception when you access to length in wrong streams

Copy link
Member

@shargon shargon left a comment

Choose a reason for hiding this comment

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

If you remove byte fb = reader.ReadByte(); you will break the chain

Copy link
Member

@shargon shargon left a comment

Choose a reason for hiding this comment

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

Is good for me

@erikzhang erikzhang changed the title Removed ReadVarBytes from VM Add SafeReadBytes from VM Dec 10, 2018
@erikzhang erikzhang merged commit 45e1e95 into neo-project:master Dec 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants