Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

Commit

Permalink
feat: add implementation of OpSelfdestruct
Browse files Browse the repository at this point in the history
  • Loading branch information
dartdart26 committed Nov 2, 2023
1 parent 3a2f516 commit 09ad1dd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions fhevm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions fhevm/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 09ad1dd

Please sign in to comment.