From d417669d558efc7ed318dbb8a42aa46ba829ecb5 Mon Sep 17 00:00:00 2001 From: Petar Ivanov <29689712+dartdart26@users.noreply.github.com> Date: Fri, 27 Oct 2023 15:13:26 +0300 Subject: [PATCH] feat: handle the read-only flag inside OpSstore --- fhevm/instructions.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fhevm/instructions.go b/fhevm/instructions.go index 68ab491..87237bd 100644 --- a/fhevm/instructions.go +++ b/fhevm/instructions.go @@ -263,7 +263,10 @@ func persistIfVerifiedCiphertext(flagHandleLocation common.Hash, handle common.H env.SetState(protectedStorage, metadataKey, metadata.serialize()) } -func OpSstore(pc *uint64, env EVMEnvironment, scope ScopeContext) []byte { +func OpSstore(pc *uint64, env EVMEnvironment, scope ScopeContext) ([]byte, error) { + if env.IsReadOnly() { + return nil, ErrWriteProtection + } loc := scope.GetStack().Pop() locHash := common.BytesToHash(loc.Bytes()) newVal := scope.GetStack().Pop() @@ -288,7 +291,7 @@ func OpSstore(pc *uint64, env EVMEnvironment, scope ScopeContext) []byte { } // Set the SSTORE's value in the actual contract. env.SetState(scope.GetContract().Address(), loc.Bytes32(), newValHash) - return nil + return nil, nil } // If there are ciphertext handles in the arguments to a call, delegate them to the callee.