mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-05 23:55:11 +00:00
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:
parent
05c1b8746a
commit
833bbb1d35
2 changed files with 41 additions and 5 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue