Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

chore: add re-encrypt #28

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

chore: add re-encrypt #28

wants to merge 3 commits into from

Conversation

kenta-mori3322
Copy link

@kenta-mori3322 kenta-mori3322 commented May 27, 2024

  • 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

@lovenoble lovenoble deleted the branch main May 28, 2024 13:31
@lovenoble lovenoble closed this May 28, 2024
@lovenoble lovenoble reopened this May 28, 2024
@lovenoble lovenoble changed the base branch from main1 to main May 28, 2024 13:47
Comment on lines 109 to 113
decryptedValue, err := tee.DecryptToBigInt(ct.ciphertext)

if err != nil {
logger.Error("reencrypt decryption failed", "err", err)
return nil, err
}

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)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

Comment on lines +313 to +318
TeeReencrypt: map[tfhe.FheUintType]uint64{
tfhe.FheBool: 1000,
tfhe.FheUint4: 1000,
tfhe.FheUint8: 1000,
tfhe.FheUint16: 1100,
tfhe.FheUint32: 1200,
Copy link

@lovenoble lovenoble May 28, 2024

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.

Copy link
Author

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.

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?

Copy link
Collaborator

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

Comment on lines +130 to +135
// 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
}
Copy link

@lovenoble lovenoble May 28, 2024

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

@kenta-mori3322 kenta-mori3322 requested a review from lovenoble May 29, 2024 04:14
@@ -248,6 +248,169 @@ var fhelibMethods = []*FheLibMethod{
requiredGasFunction: getCiphertextRequiredGas,
runFunction: getCiphertextRun,
},
// TEE operations
Copy link
Collaborator

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.

Comment on lines +241 to +246
func newTestEVMEnvironmentWithEthCall() *MockEVMEnvironment {
mockEVM := newTestEVMEnvironment()
mockEVM.ethCall = true
return mockEVM
}

Copy link
Collaborator

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

Comment on lines +313 to +318
TeeReencrypt: map[tfhe.FheUintType]uint64{
tfhe.FheBool: 1000,
tfhe.FheUint4: 1000,
tfhe.FheUint8: 1000,
tfhe.FheUint16: 1100,
tfhe.FheUint32: 1200,
Copy link
Collaborator

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
Copy link
Collaborator

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)
Copy link
Collaborator

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants