question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Paths in metadata

See original GitHub issue

(Following up on discussion in the Jan 8 source-verify meeting)

Am wondering about how the metadata is hashed and the importance of the source file paths. (Apologies in advance if I’ve misunderstood this…)

In the solidity docs there is a warning:

Since the bytecode of the resulting contract contains the metadata hash by default, any change to the metadata might result in a change of the bytecode. This includes changes to a filename or path, and since the metadata includes a hash of all the sources used, a single whitespace change results in different metadata, and different bytecode.

For example, A.sol, compiled with truffle compile and deployed using the data in the truffle artifact, has metadata source keys like:

"sources": {
  "/Users/cgewecke/code/ef/sv-truffle/contracts/A.sol": {
   "keccak256": "0xfc68a9ffdb0d7d3ec5456f5e2d2c4f855e684892f6c78fcb0dc1e482696d9bb7",
   "urls": [
    "bzz-raw://4d22457fe6215d956a57fcd0cb63f745d8fd718ba8d85a20d65c72232038779f",
    "dweb:/ipfs/QmPmUahXAjtq5mJTW9Qc6oNUVGEuocxb1un5371zLJAAb5"
   ]
  }
},

Running solc --metadata contracts/A.sol over the same source produces

"sources": {
  "contracts/A.sol": {
   "keccak256": "0xfc68a9ffdb0d7d3ec5456f5e2d2c4f855e684892f6c78fcb0dc1e482696d9bb7",
   "urls": [
    "bzz-raw://4d22457fe6215d956a57fcd0cb63f745d8fd718ba8d85a20d65c72232038779f",
    "dweb:/ipfs/QmPmUahXAjtq5mJTW9Qc6oNUVGEuocxb1un5371zLJAAb5"
   ]
  }
},

It seems like the file system context and tooling of the deployment and metadata compilations are not allowed to differ even when the sources are identical.

Not sure this would work but perhaps if the file’s keccak hash was used as a key instead, metadata could be matched to sources from anywhere as long as paths were associated with the files when uploading to the service for JSON-IO compilation.

If metadata was pathless, you could:

  • have a source-verify cli tool set up to run in CI on merge to a release branch
  • have a bot that searched Github for Solidity projects, cloning and compiling them, uploading all the metadata to SV to build a large sources DB.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
christoph2806commented, Aug 30, 2021

In the meantime (tested with truffle@5.4.8), they seem to have updated truffle’s metadata generator to create reasonable paths e.g. project:/contracts/shared/Delegator.sol so there should be no need to use the cumbersome workaround mentioned above.

1reaction
christoph2806commented, Jul 4, 2021

One possible workaround is to run truffle in a docker:

  1. Create an empty folder
  2. npm init -y
  3. npm i truffle
  4. create a Dockerfile with the following content:
FROM node:12
WORKDIR /usr/src/truffle
COPY package*.json ./
RUN npm install
COPY . .
WORKDIR /solc
CMD [ "/usr/src/truffle/node_modules/truffle/build/cli.bundled.js", "compile", "--all" ]
  1. Build docker with docker build -t truffle-docker
  2. run the docker container with docker run -v [your contracts folder]:/solc truffle-docker

In the resulting build the source paths are starting with /solc/… (thx to @chriseth for the tip)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Metadata from file paths - CatDV Product Manuals
This document will show how to extract metadata from file paths and use it in CatDV fields. The CatDV Worker can interpret the...
Read more >
PathAssistant | Metadata API Developer Guide
Represents Path records.This type extends the Metadata metadata type and inherits its fullName field. Where possible, we changed noninclusive terms to align ...
Read more >
Managing Metadata (File and File Store Attributes)
The getFileStore(Path) method fetches the file store for the specified file. The following code snippet prints the space usage for the file store...
Read more >
Support relative paths in Table Metadata · Issue #1617 - GitHub
Support relative paths in Table Metadata #1617 ... Table metadata references location that determines the base location of the table.
Read more >
Path Metadata in Beacons — SCION documentation - Anapaya
A path segment consists of a series of ASEntry s, one for each AS. An ASEntry describes the traversal of an AS for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found