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

Commit

Permalink
fix: remove the need for cks except for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
youben11 committed Jan 5, 2024
1 parent 4e9c6dd commit c04cf17
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
17 changes: 4 additions & 13 deletions fhevm/tfhe.go
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ func generateFhevmKeys() (unsafe.Pointer, unsafe.Pointer, unsafe.Pointer) {
return keys.sks, keys.cks, keys.pks
}

func globalKeysPresent() bool {
func allGlobalKeysPresent() bool {
return sks != nil && cks != nil && pks != nil
}

Expand Down Expand Up @@ -1604,11 +1604,6 @@ func InitGlobalKeysFromFiles(keysDir string) error {
if err != nil {
return err
}
var cksPath = path.Join(keysDir, "cks")
cksBytes, err := os.ReadFile(cksPath)
if err != nil {
fmt.Println("INFO: cks not loaded from: " + keysDir)
}
var pksPath = path.Join(keysDir, "pks")
pksBytes, err := os.ReadFile(pksPath)
if err != nil {
Expand All @@ -1620,12 +1615,6 @@ func InitGlobalKeysFromFiles(keysDir string) error {
pksHash = crypto.Keccak256Hash(pksBytes)
pks = C.deserialize_compact_public_key(toBufferView(pksBytes))

// cks will be handled by the KMS from now on
// TODO: completely remove after KMS is well tested
if len(cksBytes) > 0 {
cks = C.deserialize_client_key(toBufferView(cksBytes))
}

initCiphertextSizes()

fmt.Println("INFO: global keys loaded from: " + keysDir)
Expand Down Expand Up @@ -1999,7 +1988,6 @@ func (lhs *tfheCiphertext) executeBinaryCiphertextOperation(rhs *tfheCiphertext,
return res, nil
}


func (first *tfheCiphertext) executeTernaryCiphertextOperation(lhs *tfheCiphertext, rhs *tfheCiphertext,
op8 func(first unsafe.Pointer, lhs unsafe.Pointer, rhs unsafe.Pointer) unsafe.Pointer,
op16 func(first unsafe.Pointer, lhs unsafe.Pointer, rhs unsafe.Pointer) unsafe.Pointer,
Expand Down Expand Up @@ -2743,6 +2731,9 @@ func (ct *tfheCiphertext) castTo(castToType FheUintType) (*tfheCiphertext, error
}

func (ct *tfheCiphertext) decrypt() (big.Int, error) {
if cks == nil {
return *new(big.Int).SetUint64(0), errors.New("cks is not initialized")
}
var value uint64
var ret C.int
switch ct.fheUintType {
Expand Down
2 changes: 1 addition & 1 deletion fhevm/tfhe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

// generate keys if not present
func setup() {
if !globalKeysPresent() {
if !allGlobalKeysPresent() {
fmt.Println("INFO: initializing global keys in tests")
initGlobalKeysWithNewKeys()
}
Expand Down

0 comments on commit c04cf17

Please sign in to comment.