scrtlabs / EnigmaBounties

Secret Contract samples
5 stars 2 forks source link

Secret Access-Control #1

Open ainsleys opened 5 years ago

ainsleys commented 5 years ago

Request

Enigma Secret Contracts enable apps to compute over encrypted data. One simple use-case for this is “access-control”, sharing a certain message only with a qualified user.

An example of how to create a secret contract with Enigma can be found here.

Solution Description

This solution should enable user A to encrypt a message, and specify a list of authorized recipient addresses. Users on the list of authorized recipients should be able to access and view the message.

This will involve:

Success

A running application, which should have a simple React-based UI (or similar), enable the solution, and handle failure (i.e., displays a meaningful message when a non-whitelist user attempts to access the secret message). Well-commented code both in the javascript and Rust.

Implementation Details & Data Flow

  1. Alice enters the Ethereum addresses of her intended recipients (Bob and Charles), and a short message, into fields in a UI.
  2. The Enigma-JS client encrypts these inputs, and submits them as a task to the secret contract in the Enigma network.
  3. Bob clicks a button in a UI “check for messages”, which uses Enigma-JS to submit a task to the secret contract via the UI.
  4. The secret contract receives Bob’s task, and compares Bob’s address to the whitelist of Bob and Charles that Alice submitted.
  5. Bob is on the list, so the secret contract encrypts Alice’s message for Bob and returns it to Bob.
  6. Enigma-JS receives the message from the secret contract on the Enigma network, and decrypts it locally by calling (enigma.decryptTaskResult(task) and enabling for Bob to read in his UI.

Elements of Submission:

Secret contract. Contract data: publisher: address authorized to save the message, can set to contract owner in construct whitelist: H160[] secretMessage: message data

Functions: sendSecretMessage(addresses: H160[], str: message)

readMessage()

Front end: Create 2 UI components, 1 for the owner/publisher to save a message and recipients, and another (possibly same) for a user to view the secret message

Other deliverables:

Migration scripts (if required) Integration tests Readme

Bounty Selection

For this first bounty round, the process works as follows:

  1. Developer / team submits a “pre-submission for approval” for a bounty
  2. Enigma reviews submissions, and selects an applicant (we don’t have a firm timeline for this, but hope to work quickly)
  3. Applicant completes the task satisfactorily and receives the bounty

If the task is not completed, or applicant is unable to continue work in a timely manner, Enigma will select another applicant.

To complete a pre-submission for approval, comment on this issue within github and indicate your interest. Then, please also complete this application form.

Resources

These materials should help you get started: Enigma Discovery Documentation Developer Quickstart Guide Secret Contracts Walkthrough Enigma-JS Walkthrough

gitcoinbot commented 5 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


This issue now has a funding of 1090.0 ENG attached to it as part of the enigmampc fund.

PeterMPhillips commented 5 years ago

Hi Ainsley,

I was looking to apply to this but I have a couple of questions.

The task says that the sender must be the contract owner. Is there a method within eng_wasm to tell who deployed it? If not, I assume the address will have to be passed to the constructor. Which brings me to the next question...

Is there any way to verify that the sender controls the address that is passed to the contract? Solidity has 'msg.sender', but I don't see an equivalent for Enigma. If that's case, will the user have to sign the message using their Ethereum private key and then pass the signature along with the rest of the data so that the secret contract may verify the sender? If so, it looks like some additional parameters would have to be passed to the 'sendSecretMessage' and 'readMessage' functions.

gitcoinbot commented 5 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work has been started.

These users each claimed they can complete the work by 2 years, 4 months ago. Please review their action plans below:

1) dcd018 has applied to start work _(Funders only: approve worker | reject worker)_.

Hi ainsleys, I would like to express my interest in starting work on this and do not have any specific questions at this time although I'm sure I will.

Planning:

Set up Enigma Developer Testnet, write Rust secret contract incorporating access-control logic and deploy via Enigma’s migration framework.

Test drive deployment and computation, transmitting encrypted messages to the secret contract, receiving and updating secret contract state and decrypting output return value with Enigma-JS client.

Abstract test into a React Container component wrapping two child components, one for saving a message and recipients, and another for viewing secret message.

Build Material-UI design system, integrate Material-UI UX components with each child component’s data flow, integration test user experience and data flow for each child component. 2) guix77 has been approved to start work.

Hello,

I'm interested as well. I've implemented an encrypted messaging system on classic Solidity + IPFS + RSA keys, but saving RSA keys is yet another UX problem Ethereum does really not need. I can see how a more robust and dedicated solution could be a lot helpful.

Plan:

1) dev the secret contract (install stack, then test-driven dev of the contract) 2) dev the UI (React app created with CRA, most simple possible to keep it very understandable: no routing, no redux, no UI toolkit) 3) release on GitHub, write an article on my blog and post it on Twitter + LinkedIn 4) ask for help (GitHub, Gitter, ...), report encountered problems

Dev platform: Linux (Ubuntu LTS Bionic), official Docker PPA, latest Node with NVM

Learn more on the Gitcoin Issue Details page.

ainsleys commented 5 years ago

Hi @dcd018, @guix77 and @ashleyoyt -- thanks for your applications! would you mind filling this form out once more or sending me an email at ainsley@enigma.co ? I forgot to add a field for email earlier and would like to have a way to reach out w/ further questions and updates.

gitcoinbot commented 5 years ago

@guix77 Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

gitcoinbot commented 5 years ago

@guix77 Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

guix77 commented 5 years ago

I'm active, here's the project so far: https://github.com/guix77/enigma-secret-access-control

Currently I'm stuck on 2 things:

1) I've implemented it as multiple messages, since 1 thought one would not make sense either for tests or UI. But when I'm trying to get Bob to read again his messages, his tasks fails whereas it does not fail the 1st time and it's the same code (https://github.com/guix77/enigma-secret-access-control/blob/c15e9ac6a723c368e03c7dd42f738d53123836d9/test/test_secret_access_control.js#L160)

2) I need to get the equivalent of msg.sender in Solidity here: https://github.com/guix77/enigma-secret-access-control/blob/c15e9ac6a723c368e03c7dd42f738d53123836d9/secret_contracts/secret_access_control/src/lib.rs#L58. The sender is the 5th argument in computeTask but I don't know how to get it here.

ainsleys commented 5 years ago

Thanks @guix77 -- and thanks for your patience. We're still working on this and hope to get back to you soon.

secretchaingirl commented 5 years ago

Hi @guix77,

On your stuck item #1, I was able to get Bob's messages on that second call after changing the gas limit and gas price to:

const taskGasLimit = 10000000; const taskGasPx = utils.toGrains(1e-7); I got those values from Adi's getting started blog here: https://blog.enigma.co/getting-started-with-enigma-a-front-end-demo-for-dapps-bc694d3d81b9

I was led to that as the issue by looking at the discovery network log, which had an error about the gas limit being violated for the transaction.

task-failed-gas-limit-violated

Now the output of discovery test looks like this (I'm still trying to figure out why the 1st message being returned looks like the entire Vector of secret messages).

bobs-messages
ainsleys commented 5 years ago

Hey @guix77 -- just want to make sure you saw the latest on your issue on our forum

gitcoinbot commented 5 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


@guix77 due to inactivity, we have escalated this issue to Gitcoin's moderation team. Let us know if you believe this has been done in error!

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

gitcoinbot commented 5 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


@guix77 due to inactivity, we have escalated this issue to Gitcoin's moderation team. Let us know if you believe this has been done in error!

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

guix77 commented 5 years ago

Yup, again on it now.

guix77 commented 5 years ago

Update on my work status:

  1. I'm still not getting how to use the workaround used in ERC-20 to replace the missing equivalent of msg.sender. As for now, I'm just adding a sender parameter for the 2 functions send_private_message() and read_messages(). Basically I only emulate "access control" but it's not really implemented like it should. I would welcome any help either here or on the forum.
  2. Otherwise, I did a little bit more by allowing to send secret messages multiple times, instead of just one secret message. A small battery of tests are implemented for this, including a check that only the owner can send a message and multiple checks that correct recipients get correct messages.
  3. Because of 1 which is kind of a blocking problem, I didn't work on the UI for now.

What would you like me to do? Implement an UI anyways or try to get a real access control with your help?

ainsleys commented 5 years ago

Thanks for the update @guix77 -- I think we'll modify the success parameters for now. 1 should be an easy fix once we have the msg.sender equivalent, but it's going to take some time to roll it out. Let's implement the UI and take it from there.

ainsleys commented 5 years ago

Hey @guix77 -- how's it going? Is this ready for us to have our devs take a look or are you blocked on something other than the msg.sender mockup?

guix77 commented 5 years ago

Hi @ainsleys,

I'm sorry, I replied to you but I didn't see that your email was a notification for writting me here. I replied to them and 2 emails were published here as comments from me. I deleted them and forwarded them to your email. We'll talk about it in private but I want to apologize here for letting this project down for so much time.

So, I just worked on it and almost finished everything. I just have a bug with decryptTaskResult : https://github.com/enigmampc/enigma-contract/issues/154#issuecomment-537087156. Weird thing is that I don't have that bug with the Mocha tests. I'll post this on Enigma's forum.

The repo is here: https://github.com/guix77/enigma-secret-access-control

[edit] removed video of version with bug

guix77 commented 5 years ago

The bug was because I simply forgot to getTaskResult before decryptTaskResult. It's fixed now.

Finally, it's finished ! I updated the quick video preview with the working version : https://youtu.be/yUjfwlTgEA8

ainsleys commented 5 years ago

Awesome!!! Will be able to check this out tomorrow.

On Tue, Oct 1, 2019 at 4:37 PM Guillaume Duveau notifications@github.com wrote:

The bug was because I simply forgot to getTaskResult before decryptTaskResult. It's fixed now.

Finally, it's finished ! I updated the quick video preview with the working version : https://youtu.be/yUjfwlTgEA8

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/enigmampc/EnigmaBounties/issues/1?email_source=notifications&email_token=AAJQWOL7OD5YEM327OLEAGLQMPNNNA5CNFSM4IFOL7EKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEADCTHY#issuecomment-537274783, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJQWOLTUTTVJ3AHJL7QZTTQMPNNNANCNFSM4IFOL7EA .

ainsleys commented 5 years ago

Hey @guix77 -- super! This is great. I consider this bounty complete.

gitcoinbot commented 5 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work for 1090.0 ENG (432.08 USD @ $0.4/ENG) has been submitted by:

  1. @guix77

@ainsleys please take a look at the submitted work:


gitcoinbot commented 5 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


The funding of 1090.0 ENG (432.08 USD @ $0.4/ENG) attached to this issue has been approved & issued to @guix77.