Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Swarm hash of compiled contracts is dependent on compilation path #1621

@spalladino

Description

@spalladino

Issue

Having the exact same project on two different paths yields two different swarm hashes for the same contract.

Steps to Reproduce

Set up a truffle project via truffle init and create a sample project with a small contract:

pragma solidity ^0.5.0;

contract Single {
  uint256 public value;
  constructor(uint256 x) public {
    value = x;
  }
}

Copy the same project via cp -a to a different path, and run truffle compile on both project folders, and then compare the ending of the bytecode for both of them:

~/Projects/tmp$ jq .bytecode truffle1/build/contracts/Single.json | tail -c200 
00000000900480633fa4f24514604a575b600080fd5b60506066565b6040518082815260200191505060405180910390f35b6000548156fea165627a7a7230582046c187cb0c8190f1380419de50c96cd3b50ead7d62a6db28356b11a3c2307fdd0029"
~/Projects/tmp$ jq .bytecode truffle2/build/contracts/Single.json | tail -c200 
00000000900480633fa4f24514604a575b600080fd5b60506066565b6040518082815260200191505060405180910390f35b6000548156fea165627a7a72305820821c5e2c55d7ceaa5cbc01a24c3ef3fcf69d49c80e741bb75db59c6d96e4d5090029"

Note that the ending (apparently the swarm hash) changes between them, and the only difference is their paths.

Expected Behavior

I would expect that the same contract, compiled with the same compiler version, yielded exactly the same bytecode. This is especially important now that EXTCODEHASH is around the corner, since it means that there is no unique codehash for a given contract source+compiler, but the same contract will have different codehashes depending on which path it was compiled.

My gut feeling is that this may be caused by truffle-compile passing absolute paths to solc. Perhaps using relative paths may help?

Environment

  • Operating System: Ubuntu 18.10
  • Truffle version (truffle version): v5.0.1 (installed globally with nvm)
  • node version (node --version): v10.13.0
  • npm version (npm --version): 6.4.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions