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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to send private Transaction from Contract to Contract? [Question] #357

Closed
tzaika opened this issue Apr 25, 2018 · 2 comments
Closed

Comments

@tzaika
Copy link

tzaika commented Apr 25, 2018

Hi Guys once more 馃槂 .

I am trying quorum and read the documentation.
You have written that such behavior is possible:

The following transactions are allowed:

S: sender, (X): private, X: public, ->: direction, []: read only mode

1. S -> A -> B
2. S -> (A) -> (B)
3. S -> (A) -> [B -> C]

The following transaction are unsupported:

1. (S) -> A
2. (S) -> (A)

Link : Private/Public State

I am particularly interested in the line: 2. S -> (A) -> (B)

My Smart Contract (StorageContainer) looks like:

pragma solidity ^0.4.19;

import "./SimpleStorage.sol";

contract StorageContainer {
  uint constant ADD_STORAGE = 1;

  mapping(uint => address) storages;

  function addStorageContract(address storageContract) public {
    storages[ADD_STORAGE] = storageContract;
  }

  function setForAddStorage(uint value) public {
    SimpleStorage instance = SimpleStorage(storages[ADD_STORAGE]);
    instance.set(value);
  }

  function getFromAddStorage() public constant returns(uint value) {
    SimpleStorage instance = SimpleStorage(storages[ADD_STORAGE]);
    return instance.get();
  }
}

Smart Contract (SimpleStorage.sol) is same as (simplestorage.sol) in quorum-examples

So. I deploy (with truffle v4.1.3) StorageContainer as normal public contract.
But i deploy SimpleStorage as private Contract (with value for example : 45) for nedes 1 and 2 from 7nodes example

On node 1 i can properly add SimpleStorage-contract to StorageContainer and also i can get private value 45 from it. On node 7 or 4 i get value 0. So all works properly. In truffle-console it look like:

truffle(development)> SimpleStorage.deployed().then((inst) => {simpleStorage = inst});
undefined
truffle(development)> simpleStorage.get();
BigNumber { s: 1, e: 1, c: [ 45 ] }
truffle(development)> StorageContainer.deployed().then((inst) => {storageContainer = inst});
undefined
truffle(development)> storageContainer.addStorageContract(simpleStorage.address);
truffle(development)> storageContainer.getFromAddStorage();
BigNumber { s: 1, e: 1, c: [ 45 ] }

(Note: I have tried the same with truffle v4.1.7 and solc v0.4.23 and it seems not to work. (but nevermid))

After that i tried to call setForAddStorage:
truffle(development)> storageContainer.setForAddStorage(35, {privateFor: ['QfeDAys9MPDs2XHExtc84jKGHxZg/aj52DTh0vtA3Xc=']});
The transaction will be executed but if i call:

truffle(development)> storageContainer.getFromAddStorage();
BigNumber { s: 1, e: 1, c: [ 45 ] }

I see the same 45 and not 35.
After I call (without privateFor): truffle(development)> storageContainer.setForAddStorage(35); I see also 45 and not 35.

It means i send private transaction to public contract and this is not allowed. So i will send private transaction from public contract to private contract but i do not know how to do it.
It is this line 2. S -> (A) -> (B) so i think it is supported.

Can you help me with it?

Thank you in advance for your response.

@tzaika
Copy link
Author

tzaika commented Apr 25, 2018

I have found some another strage things 馃槂 .
With different versions of truffle I get different reuslts. It seems the problem is Solidity Compiler (solc), spacially version of it. Different truffle versions have different solc versions .

  • With truffle@4.1.3 (solc@0.4.19) I can send private transaction
storageContainer.setForAddStorage(35, {privateFor:['QfeDAys9MPDs2XHExtc84jKGHxZg/aj52DTh0vtA3Xc=']});

to private contract StorageContainer (this contract is deployed as private for node 1 and 2 yet) and this contract can call SimpleStorage. and I can see 35 calling storageContainer.getFromAddStorage();

  • With truffle@4.1.5 (solc@0.4.21) the same scenario above works not more
    I can see value 45 (default value that was deployed with contract) calling storageContainer.getFromAddStorage();
    but if I try to send transaction as above I see only 45 and not 35.

  • With truffle@4.1.7(solc@0.4.23) nothing works. I can not see 45 as well.

@jpmsam
Copy link
Contributor

jpmsam commented Apr 25, 2018

@tzaika the S in 2. S -> (A) -> (B) refers to the sending account(An externally owned account with an ether balance. All external accounts in Quorum are public). This means that a public account S can create a private transaction/contract (A) and (A) can interact or create another private transaction/Contract B. Given the separation of private and public states in Quorum, the only permitted operation between the private state and the public state is the ability to read the public state from a private state S -> (A) -> [B -> C].

I am not sure about the truffle issues, they shouldn't be related. We do have a few open issues on different solidity versions that we are debugging.

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

No branches or pull requests

2 participants