4

I'm running the 7nodes example of quorum from truffle and the example functionalities work as expected. However, when I create a public contract to access the state of another public contract, I'm getting a 0 return value even when that is not the case. Strangely, the contract is able to set the state of the callee contract. I have added the details below. Can someone please tell what I'm doing wrong over here?

geth version: 1.7.2-stable truffle version: v4.1.7 solc-js version: v0.4.23

Public Contract 1:

pragma solidity ^0.4.17;

contract PublicStorage {
  uint public storedData;

  function PublicStorage(uint initVal) public {
    storedData = initVal;
  }

  function set(uint x) public {
    storedData = x;
  }

  function get() constant public returns (uint retVal) {
    return storedData;
  }
}

Public Contract 2:

pragma solidity ^0.4.17;

import './PublicStorage.sol';

contract PubStorageReader {
  uint public storedData;
  PublicStorage publicStorage;

  function PubStorageReader(uint initVal, address publStorageAddr) public {
    storedData = initVal;
    publicStorage = PublicStorage(publStorageAddr);
  }

  function setPublic(uint x) public {
    publicStorage.set(x);
  }

  function getPublic() constant public returns (uint publicRetVal) {
    return publicStorage.get();
  }
}

Deploy script:

deployer.deploy(PublicStorage, 102)
        .then(function() {
            return deployer.deploy(PubStorageReader, 202, PublicStorage.address);
        });

Invocation:

> PublicStorage.deployed().then(function(instance) { return instance.get(); })
{ [String: '102'] s: 1, e: 2, c: [ 102 ] }

> PubStorageReader.deployed().then(function(instance) { return instance.getPublic(); })
{ [String: '0'] s: 1, e: 0, c: [ 0 ] }

> PubStorageReader.deployed().then(function(instance) { return instance.setPublic(2); })
{ ... }

> PublicStorage.deployed().then(function(instance) { return instance.get(); })
{ [String: '2'] s: 1, e: 0, c: [ 2 ] }

Now running the same code on testrpc reads the state as expected. What is the mistake in this?

5 Answers 5

1

I've tried with the latest truffle (v5.0.9) and solc v0.5.0 and it works fine with those:

MacBook-Pro:truffle-workspace satpal$ truffle version
Truffle v5.0.9 (core: 5.0.9)
Solidity v0.5.0 (solc-js)
Node v8.11.4
Web3.js v1.0.0-beta.37


MacBook-Pro:truffle-workspace satpal$ truffle compile

Compiling your contracts...
===========================
> Compiling ./contracts/PubStorageReader.sol
> Compiling ./contracts/PublicStorage.sol
> Artifacts written to /Users/satpal/Documents/truffle-workspace/build/contracts
> Compiled successfully using:
   - solc: 0.5.0+commit.1d4f565a.Emscripten.clang


MacBook-Pro:truffle-workspace satpal$ truffle console
truffle(development)> migrate --reset

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.

Running migration: 1_initial_migration.js
Replacing Migrations...
Migrations: 0x10ae69385C79eF3Eb815AC008A7013D6878f1d38
Saving successful migration to network...
Saving artifacts...
Running migration: 7_public_storage.js
Deploying PublicStorage...
PublicStorage: 0xF597e754F2dab6aDB6A048ade0d9a2c38dc237b3
Deploying PubStorageReader...
PubStorageReader: 0x685e0b659C3be1c465d5BB37C03E6263EfcAE25B
Saving successful migration to network...
Saving artifacts...


truffle(development)> PublicStorage.deployed().then(function(instance) { return instance.get(); })
<BN: 66>                   //NB: truffle v5.0.9 returns hex result 0x66==102
truffle(development)> PubStorageReader.deployed().then(function(instance) { return instance.getPublic(); })
<BN: 66>


truffle(development)> PubStorageReader.deployed().then(function(instance) { return instance.setPublic(2); })
{ tx: '0x6b27ff734ef52f479118cb52f9497e7bb11393c434c52d2e0784552d843caa8a',
  receipt:
   { blockHash: '0x8daf2888fd33d342d599079badc74a8131163f1628b4287b517b58913d531f95',
     blockNumber: 54,
     contractAddress: null,
     cumulativeGasUsed: 28786,
     from: '0xed9d02e382b34818e88b88a309c7fe71e65f419d',
     gasUsed: 28786,
     logs: [],
     logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
     status: true,
     to: '0x685e0b659c3be1c465d5bb37c03e6263efcae25b',
     transactionHash: '0x6b27ff734ef52f479118cb52f9497e7bb11393c434c52d2e0784552d843caa8a',
     transactionIndex: 0,
     rawLogs: [] },
  logs: [] }
truffle(development)> PublicStorage.deployed().then(function(instance) { return instance.get(); })
<BN: 2>
1
  • Hi, Thanks for the answer. I'm no longer facing the issue. Probably was fixed in some later version.
    – KBhokray
    Mar 22, 2019 at 18:27
0

Exactly same issue.

I also note that, if you make function "getPublic()" not constant/view, the execution run out of gas.

1
  • Just a heads up, the issue I'm facing is only in Quorum blockchain
    – KBhokray
    Apr 25, 2018 at 2:32
0

I tried running these contracts in Remix and they worked as they should. Have you tried testing with the JavaScript VM? There might be a problem with testrpc.

2
  • The code works fine in Remix as well as testrpc. The issue I'm facing is only in Quorum blockchain
    – KBhokray
    Apr 25, 2018 at 2:30
  • I would recommend seeking help from the Quorum community. It might be helpful to explore their issues on github. For example I think this issue seems somewhat similar to yours. Apr 26, 2018 at 16:41
0

The issue can be solved using solc-js version: v0.4.20.

0

You should try adding is keyword to PubStorageReader contract as shown below.

pragma solidity ^0.4.17;

import './PublicStorage.sol';

contract PubStorageReader is PublicStorage{
//your contract
}

Some people have executed the code in Remix, and that executed successfully because both the contracts were written in same solidity file, and was not actually imported. The above is the way to import contracts in solidity which works for Ethereum and Quorum.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.