Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cast/decrypt and hardcoded keys #12

Merged
merged 6 commits into from
Oct 19, 2023
Merged

Add cast/decrypt and hardcoded keys #12

merged 6 commits into from
Oct 19, 2023

Conversation

david-zk
Copy link
Collaborator

Implement cast/decrypt

Also, hardcodes the keys in our library (We'll load them in the future from interface)
This should be sufficient to run add operator tests.

Implement cast/decrypt
@david-zk david-zk changed the title Fhevm-go Add cast/decrypt and hardcoded keys Oct 17, 2023
@david-zk david-zk force-pushed the add-and-decrypt branch 3 times, most recently from 9af0095 to 24df344 Compare October 17, 2023 09:43
@@ -18,7 +18,7 @@ package fhevm

/*
#cgo CFLAGS: -O3 -I../tfhe-rs/target/release
#cgo LDFLAGS: -L../tfhe-rs/target/release -l:libtfhe.a -lm
#cgo LDFLAGS: -L../tfhe-rs/target/release -ltfhe -lm
Copy link
Member

Choose a reason for hiding this comment

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

You should be able to use #ifdef directive to conditionally link dynamically on mac only

Suggested change
#cgo LDFLAGS: -L../tfhe-rs/target/release -ltfhe -lm
// FIXME: link statically on mac as well
#ifdef __APPLE__
#cgo LDFLAGS: -L../tfhe-rs/target/release -ltfhe -lm
#else
#cgo LDFLAGS: -L../tfhe-rs/target/release -l:libtfhe.a -lm
#endif

Copy link
Member

Choose a reason for hiding this comment

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

I tried it locally, and it doesn't seem to work. The #ifdef isn't evaluated to get those flags

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the sks is relatively big, would it make sense to provide a script or something else to generate the keys on-demand?

var pksHash common.Hash
var networkKeysDir string
var usersKeysDir string

//go:embed test-fhevm-keys/sks
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wow, clever!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Btw, what would it do if the file doesn't exist?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If file doesn't exist it is compile time error

Copy link
Collaborator

@dartdart26 dartdart26 left a comment

Choose a reason for hiding this comment

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

I think it looks good. We need to remove the decryption stuff, because we can't support it in the way it works at Evmos.

Comment on lines +269 to +272
// If there are optimistic requires, check them by doing bitwise AND on all of them.
// That works, because we assume their values are either 0 or 1. If there is at least
// one 0, the result will be 0 (false).
func evaluateRemainingOptimisticRequires(environment EVMEnvironment) (bool, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this will have to be removed, because we won't support decryptions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we can't have decryptions in non-view functions, we can't have optimistic requires too in non-views. Wondering if we should keep optimistic requires in view functions, though. And how useful they would be.

@@ -159,3 +222,131 @@ func fheAddRun(environment *EVMEnvironment, caller common.Address, addr common.A
return resultHash[:], nil
}
}

func decryptRun(environment EVMEnvironment, caller common.Address, addr common.Address, input []byte, readOnly bool) ([]byte, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this will have to be removed, because we won't support decryptions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I spoke too early. We need to disable decryptions in non-view functions. For views, it is fine to leave them.

@david-zk david-zk merged commit e344e38 into main Oct 19, 2023
1 check failed
@david-zk david-zk deleted the add-and-decrypt branch October 19, 2023 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants