1
function createUser(data) {
 var time=Date()
 var newUser=new User(data.username)
 newUser.setCreateDate(time)

 var res={result:newUser,duration:Date()-time}
 return res
}

so maybe i'd like to put that on a smart contract, but i don't want the node to have even the slightest clue what's this function is doing however if it's a function, i could use the bandwidth to mix it with some extra side-noise, i.e. the function needs to be "sampled" into a 1000 smaller functions and encrypted or something like that. Does that mean it needs to be rewritten from imperative into functional?

It's probably only possible via obfuscation when run-time mutations are introduced to conceal the control-flow... I mean it's just when the contract is open, everyone can see my code right but it's kind of proprietary so there must be some way to use polynomials like in an encryption algorithm to automatically "encrypt" the function as well... that would be groundbreaking because that would mean that on the blockchain, aws-style lambda compute (homomorphically encrypted) could be performed but the fact that nodes get access to source code now is making the whole thing kind of. useless .

Andrej Bauer
  • 31,657
  • 1
  • 75
  • 121

1 Answers1

1

You are looking for homomorphic encryption. As Wikipedia puts it:

Homomorphic encryption is a form of encryption that allows computations to be performed on encrypted data without first having to decrypt it. The resulting computations are left in an encrypted form which, when decrypted, result in an output that is identical to that produced had the operations been performed on the unencrypted data. Homomorphic encryption can be used for privacy-preserving outsourced storage and computation. This allows data to be encrypted and outsourced to commercial cloud environments for processing, all while encrypted.

So, essentially, the idea is that

  1. You encode data locally and send it encrypted to the untrusted node for computation.
  2. Without decrypting the data, the node runs the (special) code that you provided, computes an encrypted result, and sends it back to you.
  3. You decode the result locally.

Note that in the second step the node has access to your code and it can precisely observe what the code does, but it still cannot tell what got computed, because the data it is operating with is encrypted at all times. Encryption of input and decryption of output only occurs locally in an environment that you trust.

The Wikipedia page has a bunch of references and it also lists libraries that implement homomorphic encryption.

Andrej Bauer
  • 31,657
  • 1
  • 75
  • 121