diff --git a/fhevm-engine/fhevm-go-coproc/fhevm/api.go b/fhevm-engine/fhevm-go-coproc/fhevm/api.go index 4350794..8557336 100644 --- a/fhevm-engine/fhevm-go-coproc/fhevm/api.go +++ b/fhevm-engine/fhevm-go-coproc/fhevm/api.go @@ -543,6 +543,8 @@ func flushWorkItemsToCoprocessor(store *SqliteComputationStore) (int, error) { } defer conn.Close() + fmt.Printf("Sending %d computations to coproc\n", len(asyncCompReq.Computations)) + client := NewFhevmCoprocessorClient(conn) md := metadata.Pairs("Authorization", fmt.Sprintf("Bearer %s", store.coprocessorApiKey)) grpcContext := metadata.NewOutgoingContext(context.Background(), md) diff --git a/fhevm-engine/fhevm-go-coproc/fhevm/fhelib.go b/fhevm-engine/fhevm-go-coproc/fhevm/fhelib.go index e8a6b70..3de0075 100644 --- a/fhevm-engine/fhevm-go-coproc/fhevm/fhelib.go +++ b/fhevm-engine/fhevm-go-coproc/fhevm/fhelib.go @@ -39,6 +39,12 @@ func FheLibMethods() []*FheLibMethod { runFunction: fheMulRun, ScalarSupport: true, }, + { + Name: "fheDiv", + ArgTypes: "(uint256,uint256,bytes1)", + runFunction: fheDivRun, + ScalarSupport: true, + }, { Name: "fheRem", ArgTypes: "(uint256,uint256,bytes1)", @@ -188,6 +194,11 @@ func FheLibMethods() []*FheLibMethod { ArgTypes: "(bytes,bytes1)", runFunction: trivialEncryptBytesRun, }, + { + Name: "verifyCiphertext", + ArgTypes: "(bytes32,address,bytes,bytes1)", + runFunction: fheVerifyCiphertext, + }, } } diff --git a/fhevm-engine/fhevm-go-coproc/fhevm/fhelib_ops.go b/fhevm-engine/fhevm-go-coproc/fhevm/fhelib_ops.go index d8bb52f..883ad58 100644 --- a/fhevm-engine/fhevm-go-coproc/fhevm/fhelib_ops.go +++ b/fhevm-engine/fhevm-go-coproc/fhevm/fhelib_ops.go @@ -150,6 +150,47 @@ func fheSubRun(sess CoprocessorSession, unslicedInput []byte, _ ExtraData, outpu } } +func fheDivRun(sess CoprocessorSession, unslicedInput []byte, _ ExtraData, outputHandle []byte) error { + if len(unslicedInput) < 65 { + return fmt.Errorf("expected at least 65 bytes as input, got %d", len(unslicedInput)) + } + input := unslicedInput[:65] + + isScalar, err := isScalarOp(input) + if err != nil { + return err + } + + var lhs, rhs []byte + if isScalar { + lhs, rhs, err = getScalarOperands(sess, input) + } else { + lhs, rhs, err = get2FheOperands(sess, input) + } + if err != nil { + return err + } + + computation := ComputationToInsert{ + Operation: FheDiv, + OutputHandle: outputHandle, + Operands: []ComputationOperand{ + { + Handle: lhs, + FheUintType: handleType(lhs), + IsScalar: false, + }, + { + Handle: rhs, + FheUintType: handleType(rhs), + IsScalar: isScalar, + }, + }, + } + + return sess.GetStore().InsertComputation(computation) +} + func fheMulRun(sess CoprocessorSession, unslicedInput []byte, _ ExtraData, outputHandle []byte) error { if len(unslicedInput) < 65 { return fmt.Errorf("expected at least 65 bytes as input, got %d", len(unslicedInput)) @@ -1652,6 +1693,11 @@ func trivialEncryptBytesRun(sess CoprocessorSession, unslicedInput []byte, ed Ex return nil } +func fheVerifyCiphertext(_ CoprocessorSession, _ []byte, _ ExtraData, _ []byte) error { + // Added to suppress an unregistered operation error + return nil +} + func isScalarOp(input []byte) (bool, error) { if len(input) != 65 { return false, errors.New("input needs to contain two 256-bit sized values and 1 8-bit value")