5

I see strange behavior when I try to execute some test contracts. I have made 2 test contracts,

contract TestContract1 {
        uint public n;
        uint public testValue1;
        bytes6 public value;

        function TestContract1(bytes6 val, uint[] testArray) {
                n = testArray.length;
                testValue1 = testArray[0];
                value = val;
        }
}

and

contract TestContract4 {
        uint public n;
        uint public testValue1;
        uint public value;

        function TestContract4(uint val, uint[] testArray) {
                n = testArray.length;
                testValue1 = testArray[0];
                value = val;
        }
}

These contracts are identical, except for the val, parameter, which is a uint in TestContract4 and bytes6 in TestContract1.

I execute contract #4 by the following code from geth:

var testContract = web3.eth.contract(abiArray);
var test = testContract.new(
   0x313131314141, [123,456], 
   {
     data:contractCode,
     from: eth.accounts[0],
     gas: 1000000
   }, function(e, contract){
    console.log(e, contract);
    if (typeof contract.address != 'undefined') {
         console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
    }
 });

and I look at the different variables stored in the contract, all values are correctly stored and retrieved (i.e. n = 2, testValue1 = 123, value = 54087348470081).

When I execute contract #1 with the same code from geth, I get a correct value = 0x313131314141, but n and testValue1 have strange values (n = 10696049115004928, testValue1 = 562949953421312).

Can anyone tell me what's happening here? I.e. why runs the contract correctly when I define the first parameter as an uint and behaves strange when I specify it as a bytes6 type?

Thanks in advance.

  • That sounds an awful lot like a solidity compiler bug. What happens if you use different size bytesn types? – Nick Johnson Apr 21 '16 at 9:27
  • you can admin.setSolc("") in geth and test in browser solidity against the same version – euri10 Apr 21 '16 at 12:43
  • Tested with different size of bytesn types. It only works when I use bytes32. – hatemp Apr 22 '16 at 7:58
3

It may be a Geth bug because a quick test in Solidity Browser appears to work correctly .

enter image description here

  • Looks indeed as a bug in Geth. I noticed that I was running an old version of the solc compiler, but updating that to 0.3.2 resulted in same error. – hatemp Apr 22 '16 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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