So I'm trying to work with two-dimensional byte arrays and am experiencing some results that I don't quite understand. I am using Truffle v2.0.4 for compiling/deploying my contracts with ethereumjs-testrpc as a blockchain backend.
Consider this super simple contract. It initilizes a 2D array of bytes, assigns the third element in the first array, and returns:
contract Sandbox {
function retArr()
public constant returns (byte[3][10] ret) {
ret[0][2] = byte(2);
}
}
I can then access this contract via Truffle's Web3 wrapper:
Sandbox.deployed().retArr().then(function(res) {
console.log(res)
})
Which produces the following output:
[ [ '0x00', '0x00', '0x02' ],
[ '0x00', '0x02', '0x00' ],
[ '0x02', '0x00', '0x00' ],
[ '0x00', '0x00', '0x00' ],
[ '0x00', '0x00', '0x00' ],
[ '0x00', '0x00', '0x00' ],
[ '0x00', '0x00', '0x00' ],
[ '0x00', '0x00', '0x00' ],
[ '0x00', '0x00', '0x00' ],
[ '0x00', '0x00', '0x00' ] ]
The first child array looks correct (0x02
is assigned to the third position), but then 0x02
pops up in the second and third arrays as well.
Why did multiple elements get assigned with one call? If this is expected behavior, what's the rationale behind this design decision? How can I only assign one element at a time in a 2D array?
bytes32
suggestion, I'll play around with that :)