Skip to content

Commit

Permalink
feat(bitwise): enable scalar operand for fheBitAnd, fheBitOr, fheBitXor
Browse files Browse the repository at this point in the history
  • Loading branch information
goshawk-3 committed Feb 14, 2025
1 parent abdd4f8 commit 0c7fa21
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 84 deletions.
6 changes: 3 additions & 3 deletions fhevm-engine/fhevm-go-coproc/fhevm/fhelib.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ func FheLibMethods() []*FheLibMethod {
Name: "fheBitAnd",
ArgTypes: "(uint256,uint256,bytes1)",
runFunction: fheBitAndRun,
ScalarSupport: false,
ScalarSupport: true,
},
{
Name: "fheBitOr",
ArgTypes: "(uint256,uint256,bytes1)",
runFunction: fheBitOrRun,
ScalarSupport: false,
ScalarSupport: true,
},
{
Name: "fheBitXor",
ArgTypes: "(uint256,uint256,bytes1)",
runFunction: fheBitXorRun,
ScalarSupport: false,
ScalarSupport: true,
},
{
Name: "fheShl",
Expand Down
151 changes: 70 additions & 81 deletions fhevm-engine/fhevm-go-coproc/fhevm/fhelib_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,36 +342,33 @@ func fheBitAndRun(sess CoprocessorSession, unslicedInput []byte, _ ExtraData, ou
}

operation := FheBitAnd
if !isScalar {
lhs, rhs, err := get2FheOperands(sess, input)
if err != nil {
return err
}
lhs, rhs, err := get2FheOperands(sess, input)
if err != nil {
return err
}

err = sess.GetStore().InsertComputation(ComputationToInsert{
Operation: operation,
OutputHandle: outputHandle,
Operands: []ComputationOperand{
{
Handle: lhs,
FheUintType: handleType(lhs),
IsScalar: false,
},
{
Handle: rhs,
FheUintType: handleType(rhs),
IsScalar: isScalar,
},
err = sess.GetStore().InsertComputation(ComputationToInsert{
Operation: operation,
OutputHandle: outputHandle,
Operands: []ComputationOperand{
{
Handle: lhs,
FheUintType: handleType(lhs),
IsScalar: false,
},
})
if err != nil {
return err
}

return nil
} else {
return errors.New("scalar fheBitAnd is not supported")
{
Handle: rhs,
FheUintType: handleType(rhs),
IsScalar: isScalar,
},
},
})
if err != nil {
return err
}

return nil

}

func fheBitOrRun(sess CoprocessorSession, unslicedInput []byte, _ ExtraData, outputHandle []byte) error {
Expand All @@ -386,36 +383,32 @@ func fheBitOrRun(sess CoprocessorSession, unslicedInput []byte, _ ExtraData, out
}

operation := FheBitOr
if !isScalar {
lhs, rhs, err := get2FheOperands(sess, input)
if err != nil {
return err
}
lhs, rhs, err := get2FheOperands(sess, input)
if err != nil {
return err
}

err = sess.GetStore().InsertComputation(ComputationToInsert{
Operation: operation,
OutputHandle: outputHandle,
Operands: []ComputationOperand{
{
Handle: lhs,
FheUintType: handleType(lhs),
IsScalar: false,
},
{
Handle: rhs,
FheUintType: handleType(rhs),
IsScalar: isScalar,
},
err = sess.GetStore().InsertComputation(ComputationToInsert{
Operation: operation,
OutputHandle: outputHandle,
Operands: []ComputationOperand{
{
Handle: lhs,
FheUintType: handleType(lhs),
IsScalar: false,
},
})
if err != nil {
return err
}

return nil
} else {
return errors.New("scalar fheBitOr is not supported")
{
Handle: rhs,
FheUintType: handleType(rhs),
IsScalar: isScalar,
},
},
})
if err != nil {
return err
}

return nil
}

func fheBitXorRun(sess CoprocessorSession, unslicedInput []byte, _ ExtraData, outputHandle []byte) error {
Expand All @@ -430,36 +423,32 @@ func fheBitXorRun(sess CoprocessorSession, unslicedInput []byte, _ ExtraData, ou
}

operation := FheBitXor
if !isScalar {
lhs, rhs, err := get2FheOperands(sess, input)
if err != nil {
return err
}
lhs, rhs, err := get2FheOperands(sess, input)
if err != nil {
return err
}

err = sess.GetStore().InsertComputation(ComputationToInsert{
Operation: operation,
OutputHandle: outputHandle,
Operands: []ComputationOperand{
{
Handle: lhs,
FheUintType: handleType(lhs),
IsScalar: false,
},
{
Handle: rhs,
FheUintType: handleType(rhs),
IsScalar: isScalar,
},
err = sess.GetStore().InsertComputation(ComputationToInsert{
Operation: operation,
OutputHandle: outputHandle,
Operands: []ComputationOperand{
{
Handle: lhs,
FheUintType: handleType(lhs),
IsScalar: false,
},
})
if err != nil {
return err
}

return nil
} else {
return errors.New("scalar fheBitXor is not supported")
{
Handle: rhs,
FheUintType: handleType(rhs),
IsScalar: isScalar,
},
},
})
if err != nil {
return err
}

return nil
}

func fheShlRun(sess CoprocessorSession, unslicedInput []byte, _ ExtraData, outputHandle []byte) error {
Expand Down

0 comments on commit 0c7fa21

Please sign in to comment.