Skip to content

Commit

Permalink
fix: do not persist FHE public key hash in state
Browse files Browse the repository at this point in the history
Persisting the FHE public key hash in state brings more issues (i.e.
during deployment) than benefits. Furthermore, we will be changing the
FHE keys in the future and that will require a redesign anyway.
  • Loading branch information
dartdart26 committed Aug 9, 2024
1 parent bf2cf64 commit 11557d2
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 20 deletions.
12 changes: 1 addition & 11 deletions fhevm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,7 @@ func insertRandomCiphertext(environment EVMEnvironment, t tfhe.FheUintType) []by
return ct.GetHash().Bytes()
}

func InitFhevm(accessibleState EVMEnvironment) {
persistFhePubKeyHash(accessibleState)
}

func persistFhePubKeyHash(accessibleState EVMEnvironment) {
existing := accessibleState.GetState(fhePubKeyHashPrecompile, fhePubKeyHashSlot)
if newInt(existing[:]).IsZero() {
var pksHash = tfhe.GetPksHash()
accessibleState.SetState(fhePubKeyHashPrecompile, fhePubKeyHashSlot, pksHash)
}
}
func InitFhevm(accessibleState EVMEnvironment) {}

func Create(evm EVMEnvironment, caller common.Address, code []byte, gas uint64, value *big.Int) (ret []byte, contractAddr common.Address, leftOverGas uint64, err error) {
contractAddr = crypto.CreateAddress(caller, evm.GetNonce(caller))
Expand Down
9 changes: 0 additions & 9 deletions fhevm/operators_crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,18 +319,9 @@ func castRun(environment EVMEnvironment, caller common.Address, addr common.Addr
return resHash.Bytes(), nil
}

var fhePubKeyHashPrecompile = common.BytesToAddress([]byte{93})
var fhePubKeyHashSlot = common.Hash{}

func fhePubKeyRun(environment EVMEnvironment, caller common.Address, addr common.Address, input []byte, readOnly bool, runSpan trace.Span) ([]byte, error) {
input = input[:minInt(1, len(input))]

existing := environment.GetState(fhePubKeyHashPrecompile, fhePubKeyHashSlot)
if existing != tfhe.GetPksHash() {
msg := "fhePubKey FHE public key hash doesn't match one stored in state"
environment.GetLogger().Error(msg, "existing", existing.Hex(), "pksHash", tfhe.GetPksHash().Hex())
return nil, errors.New(msg)
}
// serialize public key
pksBytes, err := tfhe.SerializePublicKey()
if err != nil {
Expand Down

0 comments on commit 11557d2

Please sign in to comment.