-
Notifications
You must be signed in to change notification settings - Fork 102
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
BigInteger 0 isn't able to be convert to Byte[]{ 0 } #201
Comments
I think it shouldn't be |
In Neo Storage.Put a zero length bytearray means delete a Key @superboyiii private static bool PutExInternal(ApplicationEngine engine, StorageContext context, byte[] key, byte[] value, StorageFlags flags)
{
if (key.Length > MaxKeySize) return false;
if (value.Length > MaxValueSize) return false;
if (context.IsReadOnly) return false;
StorageKey skey = new StorageKey
{
Id = context.Id,
Key = key
};
if (engine.Snapshot.Storages.TryGet(skey)?.IsConstant == true) return false;
if (value.Length == 0 && !flags.HasFlag(StorageFlags.Constant))
{
// If put 'value' is empty (and non-const), we remove it (implicit `Storage.Delete`)
engine.Snapshot.Storages.Delete(skey);
} |
I don't understand. This is correct. But what I expect is value.Length is 1 and value is { 0 }. I don't mean byte[0] but byte[1]{ 0 }. It shouldn't return |
Because BigInteger 0 convert to Bytes will got a Byte[0]. |
I remembered that in this case, it should really return |
If we don't change it to byte[1]{0}, we could meet issues in smart contract especially some cases of invoke balance. And we have to always notify developers we can't convert like this. This is a limit for sc. And for me, I think Byte[1]{0} is absolutely different from Byte[0], it should return Byte[1]{0}. |
I think we should convert
If we convert If we convert |
Perhaps putting 0 bytes of data should not be considered as deleting the record. Because the user can always call |
Agree 100% Therefore, we should incentive users to release resources. |
Agree |
Due to #196, we've improved a lot on smart contract convertion method. However, I still find a little issue that BigInteger 0 isn't able to be convert to Byte[]{ 0 } by
ToByteArray
method. This will cause many issues such like balance exception when make transaction. I've made a little example to replay this situation. For example:Then I could deploy it successfully, but I find the value is null in storage.
Try GetStorage:
If I change this num to any num except 0, it works well.
Try GetStorage:
@lightszero Sorry to bother you again.
The text was updated successfully, but these errors were encountered: