Skip to content

Commit d0af5bf

Browse files
fix(tfhe): remove unsafe integer parsing (ethereum#98)
* fix(tfhe): remove unsafe integer parsing * fix(tfhe): remove unused import
1 parent 93986eb commit d0af5bf

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

core/vm/tfhe.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ import "C"
410410

411411
import (
412412
"crypto/rand"
413-
"encoding/binary"
414413
"errors"
415414
"fmt"
416415
"math/big"
@@ -545,19 +544,11 @@ func (ct *tfheCiphertext) encrypt(value big.Int, t fheUintType) {
545544

546545
switch t {
547546
case FheUint8:
548-
valBytes := [1]byte{}
549-
value.FillBytes(valBytes[:])
550-
ct.setPtr(C.client_key_encrypt_fhe_uint8(cks, C.uchar(valBytes[len(valBytes)-1])))
547+
ct.setPtr(C.client_key_encrypt_fhe_uint8(cks, C.uchar(value.Uint64())))
551548
case FheUint16:
552-
valBytes := [2]byte{}
553-
value.FillBytes(valBytes[:])
554-
var valInt uint16 = binary.BigEndian.Uint16(valBytes[:])
555-
ct.setPtr(C.client_key_encrypt_fhe_uint16(cks, C.ushort(valInt)))
549+
ct.setPtr(C.client_key_encrypt_fhe_uint16(cks, C.ushort(value.Uint64())))
556550
case FheUint32:
557-
valBytes := [4]byte{}
558-
value.FillBytes(valBytes[:])
559-
var valInt uint32 = binary.BigEndian.Uint32(valBytes[:])
560-
ct.setPtr(C.client_key_encrypt_fhe_uint32(cks, C.uint(valInt)))
551+
ct.setPtr(C.client_key_encrypt_fhe_uint32(cks, C.uint(value.Uint64())))
561552
}
562553
ct.fheUintType = t
563554
ct.value = &value

0 commit comments

Comments
 (0)