Ethereum: Bugfix for binary differences between local and Remix
As a Solidity developer, you are not the only one who notices differences in binary results between local compilation with Truffle’s Solc compiler and deployment to the Ethereum network with Remix. In this article, we will explore the causes of these conflicts and provide advice on how to troubleshoot and resolve them.
Problem: Different binary formats
When you compile your Solidity code locally with solc (Solidity Compiler), it creates a binary with a specific format that is only compatible with the local machine architecture. However, when you deploy your contract to the Ethereum network with Remix, the same source code compiles into a different binary due to differences in the native compiler and the requirements of the Solana blockchain’s Ethereum Virtual Machine (EVM).
Problem: Solc compiler version
One possible reason for these binary differences is a mismatch between the version of the Solc compiler used locally and the version used by Remix. The compiler version “solc” may not be compatible with your local installation, resulting in different binary outputs when compiling and deploying on both platforms.
Testing with Remix
To confirm this hypothesis, we can test the scenario with Remix, which has its own Solana compiler (“solana”). We create a new contract and deploy it with Remix. Then we compare the binary output with the one generated locally.
Here is an updated version of your code:
“seriousness
pragma-strength 0,8,20;
Contract HelloWorld {
Function test() public in returns (bool) {}
}
// Deployment with Remix
Function main() public payable {
HelloWorld storage hello = hello();
require(hello.test() == true, “hello”);
}
Deployment in Remix
We will use Remix's web3.js library to interact with the local machine's blockchain and deploy our contract with a new account. The deployment process may produce different binaries depending on the Solana compiler used.
Testing with the Solc compiler version
Now let's test this scenario by comparing the locally generated binary output with the Remix implementation.
Local pickup
strokes
cd ~/truffle
solc -v solidity-0.8.20.js –bin HelloWorld.js
Remix deployment (with Solana)
To deploy our contract with Remix, we create a new account on the Solana blockchain and interact with it to test the deployment.
Javascript
const { Web3 } = require(‘web3’);
const web3 = new Web3();
async function main() {
const network name = “Mainnet”;
const account address = “0x…”; // Replace it with your own Solana address
try {
const transactionCount = await web3.eth.getTransactionCount(accountAddress);
const tx = await web3.eth.sendTransaction({
Sender: account address,
to: ‘0x…’, // Replace with the recipient’s address
Value: web3.utils.toWei(‘1’, ‘ether’),
Gas: 200,000,
Gas price: 20,
});
console.log(tx);
} Catch Errors {
Console. Errors(Error);
}
}
main();
Comparing Binary Outputs
We can compare the binary output generated locally and use Remix to determine the differences.
Comparing Results
If we run the code in local mode, we may see a different binary format than what we use with Remix. Let's look at the possible differences:
strokes
$ objdump -h HelloWorld_0x12345678.bin
File format bin
“`
We compare the output of “objdump” in both scenarios.
In this example, the locally built binary HelloWorld_0x12345678.bin has a different structure and layout than in Remix. This difference may be due to the Solana compiler used in Remix compared to the Solc compiler used locally.