-
Notifications
You must be signed in to change notification settings - Fork 2
chore: add re-encrypt #28
base: main
Are you sure you want to change the base?
Conversation
kenta-mori3322
commented
May 27, 2024
•
edited
Loading
edited
- Adds re-encrypt operator for TEE.
- Adds custom evm mock with EthCall enabled.
- Adds custom Decrypt function that returns in big.Int type.
- Unit test
- https://github.com/Inco-fhevm/inco-monorepo/issues/6 (Re-encrypt)
fhevm/tee_crypto.go
Outdated
decryptedValue, err := tee.DecryptToBigInt(ct.ciphertext) | ||
|
||
if err != nil { | ||
logger.Error("reencrypt decryption failed", "err", err) | ||
return nil, err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about removing the DecryptToBigInt
function and using the following lines?
plaintext, err := tee.Decrypt(ct.ciphertext)
if err != nil {
logger.Error("reencrypt decryption failed", "err", err)
return nil, err
}
decryptedValue := big.NewInt(0).SetBytes(plaintext.Value)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay
TeeReencrypt: map[tfhe.FheUintType]uint64{ | ||
tfhe.FheBool: 1000, | ||
tfhe.FheUint4: 1000, | ||
tfhe.FheUint8: 1000, | ||
tfhe.FheUint16: 1100, | ||
tfhe.FheUint32: 1200, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These values are much larger than the ones for other TEE operations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically copy & pasted code from tfhe reencrypt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amaury1093 Do you have any chance to look into this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Maybe we can do 100, so 10x cheaper than FHE. In the same order of magniture as a mul
// Always return a 32-byte big-endian integer. | ||
ret := make([]byte, 32) | ||
copy(ret[32-len(plaintext):], plaintext) | ||
|
||
return new(big.Int).SetBytes(ret), nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can just use big.NewInt(0).SetBytes(plaintext)
because it gives us the big-endian integer. In a word, we can remove this whole function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay
7a06d44
to
2c8138e
Compare
@@ -248,6 +248,169 @@ var fhelibMethods = []*FheLibMethod{ | |||
requiredGasFunction: getCiphertextRequiredGas, | |||
runFunction: getCiphertextRun, | |||
}, | |||
// TEE operations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In #31, there has been a refactor to move tee operations into teelib.go. Your new function should go there.
func newTestEVMEnvironmentWithEthCall() *MockEVMEnvironment { | ||
mockEVM := newTestEVMEnvironment() | ||
mockEVM.ethCall = true | ||
return mockEVM | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure it's super worth it to create a separate function in a separate file just for one instance.
I would rather add the line mockEVM.ethCall = true
inside tee_crypto_test.go
TeeReencrypt: map[tfhe.FheUintType]uint64{ | ||
tfhe.FheBool: 1000, | ||
tfhe.FheUint4: 1000, | ||
tfhe.FheUint8: 1000, | ||
tfhe.FheUint16: 1100, | ||
tfhe.FheUint32: 1200, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Maybe we can do 100, so 10x cheaper than FHE. In the same order of magniture as a mul
return nil, err | ||
} | ||
|
||
// TODO: decide if `res.Signature` should be verified here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this comment about?
environment.depth = depth | ||
addr := common.Address{} | ||
readOnly := false | ||
ct, err := importTeePlaintextToEVM(environment, depth, tc.expected, tc.typ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test doesn't use any pubkey. What is it testing exactly here?