Skip to content

Commit

Permalink
feat(div): Support fheDiv operation with/without scalar operand
Browse files Browse the repository at this point in the history
  • Loading branch information
goshawk-3 committed Dec 30, 2024
1 parent 9e31ae6 commit 0fd93e2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
6 changes: 6 additions & 0 deletions fhevm-engine/fhevm-go-native/fhevm/fhelib.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ func FheLibMethods() []*FheLibMethod {
runFunction: fheMulRun,
ScalarSupport: true,
},
{
Name: "fheDiv",
ArgTypes: "(uint256,uint256,bytes1)",
runFunction: fheDivRun,
ScalarSupport: true,
},
{
Name: "fheRem",
ArgTypes: "(uint256,uint256,bytes1)",
Expand Down
41 changes: 41 additions & 0 deletions fhevm-engine/fhevm-go-native/fhevm/fhelib_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,47 @@ func fheSubRun(sess ExecutorSession, unslicedInput []byte, _ ExtraData, outputHa
}
}

func fheDivRun(sess ExecutorSession, 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 ExecutorSession, unslicedInput []byte, _ ExtraData, outputHandle []byte) error {
if len(unslicedInput) < 65 {
return fmt.Errorf("expected at least 65 bytes as input, got %d", len(unslicedInput))
Expand Down

0 comments on commit 0fd93e2

Please sign in to comment.