core: calculate gas for System.Storage.Put correctly

If `Put` creates new key, its length should contribute
to a GAS cost of the syscall.
This commit is contained in:
Evgenii Stratonikov 2020-10-05 12:32:04 +03:00
parent 05c1b8746a
commit 833bbb1d35
2 changed files with 41 additions and 5 deletions

View file

@ -389,14 +389,14 @@ func putWithContextAndFlags(ic *interop.Context, stc *StorageContext, key []byte
return errors.New("StorageContext is read only")
}
si := ic.DAO.GetStorageItem(stc.ID, key)
if si == nil {
si = &state.StorageItem{}
}
if si.IsConst {
if si != nil && si.IsConst {
return errors.New("storage item exists and is read-only")
}
sizeInc := 1
if len(value) > len(si.Value) {
if si == nil {
si = &state.StorageItem{}
sizeInc = len(key) + len(value)
} else if len(value) > len(si.Value) {
sizeInc = len(value) - len(si.Value)
}
if !ic.VM.AddGas(int64(sizeInc) * StoragePrice) {