From 4a4528b75b321282ac27c26f886759184b0f3d2e Mon Sep 17 00:00:00 2001 From: Silas Davis <silas@monax.io> Date: Fri, 20 Apr 2018 12:39:40 -0400 Subject: [PATCH] Ensure storing zero value removes the key rather than panics Signed-off-by: Silas Davis <silas@monax.io> --- account/state/state.go | 2 +- execution/state.go | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/account/state/state.go b/account/state/state.go index 005d3082..d175f6e8 100644 --- a/account/state/state.go +++ b/account/state/state.go @@ -33,7 +33,7 @@ type StorageGetter interface { } type StorageSetter interface { - // Store a 32-byte value at key for the account at address + // Store a 32-byte value at key for the account at address, setting to Zero256 removes the key SetStorage(address acm.Address, key, value binary.Word256) error } diff --git a/execution/state.go b/execution/state.go index af168650..8c9b739e 100644 --- a/execution/state.go +++ b/execution/state.go @@ -235,7 +235,11 @@ func (s *State) GetStorage(address acm.Address, key binary.Word256) (binary.Word func (s *State) SetStorage(address acm.Address, key, value binary.Word256) error { s.Lock() defer s.Unlock() - s.tree.Set(prefixedKey(storagePrefix, address.Bytes(), key.Bytes()), value.Bytes()) + if value == binary.Zero256 { + s.tree.Remove(key.Bytes()) + } else { + s.tree.Set(prefixedKey(storagePrefix, address.Bytes(), key.Bytes()), value.Bytes()) + } return nil } -- GitLab