diff --git a/fhevm/instructions.go b/fhevm/instructions.go index 87237bd..6dfd108 100644 --- a/fhevm/instructions.go +++ b/fhevm/instructions.go @@ -4,11 +4,13 @@ import ( "bytes" "encoding/hex" "errors" + "math/big" "strings" "github.com/ethereum/go-ethereum/common" crypto "github.com/ethereum/go-ethereum/crypto" "github.com/holiman/uint256" + fhevm_crypto "github.com/zama-ai/fhevm-go/crypto" ps "github.com/zama-ai/fhevm-go/crypto" ) @@ -352,3 +354,14 @@ func OpReturn(pc *uint64, env EVMEnvironment, scope ScopeContext) []byte { delegateCiphertextHandlesToCaller(env, ret) return ret } + +func OpSelfdestruct(pc *uint64, env EVMEnvironment, scope ScopeContext) (beneficiary uint256.Int, balance *big.Int) { + beneficiary = scope.GetStack().Pop() + protectedStorage := fhevm_crypto.CreateProtectedStorageContractAddress(scope.GetContract().Address()) + balance = env.GetBalance(scope.GetContract().Address()) + balance.Add(balance, env.GetBalance(protectedStorage)) + env.AddBalance(beneficiary.Bytes20(), balance) + env.Suicide(scope.GetContract().Address()) + env.Suicide(protectedStorage) + return +} diff --git a/fhevm/interface.go b/fhevm/interface.go index ca3f3b4..75c8285 100644 --- a/fhevm/interface.go +++ b/fhevm/interface.go @@ -12,6 +12,10 @@ type EVMEnvironment interface { GetState(common.Address, common.Hash) common.Hash SetState(common.Address, common.Hash, common.Hash) GetNonce(common.Address) uint64 + AddBalance(common.Address, *big.Int) + GetBalance(common.Address) *big.Int + + Suicide(common.Address) bool // EVM call stack depth GetDepth() int