Handling of byte types by either truffle or web3 seems to be incorrect
See original GitHub issueIssue
Handling of byte types by either truffle or web3 seems to be incorrect.
Steps to Reproduce
On-Chain:
contract MyContract {
function func(bytes4 x) public pure returns (bytes4) {
return x;
}
}
Off-Chain:
contract("Test", function() {
it("test", async function() {
let myContract = await artifacts.require("MyContract.sol").new();
let retVal = await myContract.func(0x00012345);
console.log(retVal);
});
});
Expected Behavior
Print 0x00012345
Actual Results
Print 0x12345000
It seems that every leading zero digit in hexadecimal format (i.e., every leading chunk of 4 zero bits) is forced to become trailing somehow.
This happens on client side for sure (you may confirm it by adding require(x == 0x12345000)
inside the on-chain function above.
It seems to be the case for other byte types as well (e.g. bytes1
, bytes2
, etc).
Environment
- Operating System: Windows 10
- Ethereum client: ganache-cli: 6.1.0
- truffle version: 4.1.3
- node version: 8.9.3
- npm version: 5.5.1
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Interact with your contracts - Truffle Suite
All three methods can be executed as either a transaction or a call. ... The easiest way to handle events is by processing...
Read more >ConsenSys/truffle - Gitter
I'm using Angular and @truffle/contract to interact with the MetaCoin Truffle box. It seems I am able to setup Ganache, deploy/migrate the MetaCoin...
Read more >Upgrading to Truffle 5 - Medium
Truffle 5 is a major overhaul and rework of the Truffle framework. ... All Web3 calls are async/await — either when using them...
Read more >How to Hash Data Without Errors (part 3) - Coder's Errand
All of them expect an argument of type bytes memory , and return an array of ... and so that misleading name was...
Read more >Tips for Unit Testing Ethereum Smart Contracts in Solidity
The below link is a Truffle unit test program for ERC-20 smart contract. ... Although it is not clear why web3.js supports two...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@cgewecke: Yes, thank you for clarifying it!
@barakman If you quote the bytes when you pass them into the function
does that resolve it? Think JS is interpreting the input as a number rather than bytes and Solidity formats these differently. It looks like
uint
is left-aligned in the word,bytes
right-aligned, based on encodings docs at over at solidity here.