Skip to content

Releases: ethereum/sourcify

v2.1.0

19 Apr 15:58
ec2ac91
Compare
Choose a tag to compare

What's Changed

  • Added basic test coverage
  • Fix: Handling Etherscan contracts with multiple sources
  • Use the respective solc binary according to the platform, save binaries locally
  • Update Etherscan chains
    • Users can now import contracts from other Etherscan instances: Polygonscan, Snowtrace etc.
  • Make use of immutableReferences on verification
    • This lets us verify contracts with immutables very often without needing alternative methods such as looking at the creatorTxHash or "simulation"
  • Fix addLibraryAddresses potential vulnerability with regex.

Fixed vulnerability

Thanks to @Hellobloc and @samczsun for reporting the vulnerability.

addLibraryAddress RegExp vulnerability

Risk Description

Previously the following code was used to replace libraryAddresses.

export function addLibraryAddresses(
  template: string,
  real: string
): {
  replaced: string;
  libraryMap: StringMap;
} {
  const PLACEHOLDER_START = '__$';
  const PLACEHOLDER_LENGTH = 40;

  const libraryMap: StringMap = {};

  let index = template.indexOf(PLACEHOLDER_START);
  for (; index !== -1; index = template.indexOf(PLACEHOLDER_START)) {
    const placeholder = template.slice(index, index + PLACEHOLDER_LENGTH);
    const address = real.slice(index, index + PLACEHOLDER_LENGTH);
    libraryMap[placeholder] = address;
    const regexCompatiblePlaceholder = placeholder
      .replace('__$', '__\\\\$')
      .replace('$__', '\\\\$__');
    const regex = RegExp(regexCompatiblePlaceholder, 'g');
    template = template.replace(regex, address);
  }
  return {
    replaced: template,
    libraryMap,
  };
}

The code replaced the library placeholders in the bytecode by identifying __$ and constructed regular matching expressions from the placeholder.
But note that not all versions use the hash of the library name as a placeholder. For example, the 0.4 Solidity version uses __{Path:FileName}__ placeholder.

https://i.imgur.com/BTSFsmO.png

This allows a malicious user to manipulate regular expressions, which in turn allows other parts of the bytecode to be marked as a library address.

Example

As with the risks mentioned above, we can achieve arbitrary regular expression tampering by changing the file name of the library contract.
An example is the following:

pragma solidity ^0.4.0;
import "./$.{37}|2{40}|cantbematchedcharacters__";
contract A {
    address constant public a = address(0x2222222222222222222222222222222222222222);
    uint public b;
    function cc() public{
        b = L_.get4();
    }
}

In the above code, a regular expression is written in the filename and the expression appears in the generated bytecode and is adopted by the addLibraryAddresses function.

https://i.imgur.com/gpsm01V.png

This regular expression will first replace itself, and then look for 22...22 to do the same. Here 2{40} can also be modified to 5b.{...} to perform arbitrary replacements of executable bytecode.

A real attack case(0x4AD29c9716569f3c466BB123Efdd0B9B43207dE1 in goerli) was constructed.

https://i.imgur.com/vU5KhnD.png

https://i.imgur.com/gwNwRLR.png

The tampering of constants in the above case is possible. Of course executable bytecode tampering is also possible, simply by changing
2{40} to 5b.{...}, and writing L_ address to the bytecode we want.

DOS Attack

In addition to performing bytecode tampering, one can also perform a DOS attack on Sourcify. Specifically, once can design a regular expression that will not have any matches in bytecode, resulting in __$ not being replaced, which in turn makes addLibraryAddresses a dead loop.

Solution

We replaced the regex replacement of the pattern with a simple string match to __ in the bytecode, and replacing the placeholder with a fixed length (40 chars = 20 bytes).

PRs

New Contributors

Full Changelog: v2.0.0...v2.1.0

v2.0.0

13 Mar 10:57
1d7c791
Compare
Choose a tag to compare

This is the release for the v2 of Sourcify. It is a MAJOR release because of the significant changes to the codebase. The server API does not have breaking changes but has additions.

  • Codebase refactoring with lib-sourcify library:
    • Removes the old npm packages @ethereum-sourcify/core -verification and -validation.
    • Maintain the main verification functionality in a reusable package @ethereum-sourcify/lib-sourcify, including types etc.
  • Fix Etherscan regex for the new Etherscan
  • Fix created contract address calculation with the nonce
  • Add monitoring support to Meter Network
  • Use local IPFS gateway in tests instead of ipfs.io/ipfs
  • Add creatorTxHash parameter to verification API
  • New Chains:
    • Bear Network Chain Mainnet #641230
    • Base Goerli Testnet #938

What's Changed

Full Changelog: v1.2.2...v2.0.0

v1.2.2

17 Feb 07:44
fdc30f3
Compare
Choose a tag to compare

What's Changed

Full Changelog: v1.2.1...v1.2.2

v1.2.1

15 Feb 09:33
84663e8
Compare
Choose a tag to compare

New Contributors

Full Changelog: v1.2.0...v1.2.1

v1.2.0

11 Jan 16:28
fb36eae
Compare
Choose a tag to compare
  • Changes to the ipfs node config to improve performance
  • Change how local node URLs are added to sourcify-chains
  • Require tests to pass to build and deploy server&monitor on CI
  • Emit events with EventManager and log events onto console and to a Grafana dashboard
  • Verification with simulation: Capability to verify contracts by executing the creation bytecode on an EthereumJS instance with additional contextVariables i.e. msgSenger and abiEncodedConstructorArguments. This enables verifying contracts created by a factory contract and that contain immutables.
  • Add contract-call-decoder as a package
  • Fix create2 verification logic
  • Handle nightly compiler CBOR encodings 1267f21 and inconsistent compiler version naming cee9d72
  • New chains:
    • Dexalot Mainnet #432204
    • Oasis Emerald Mainnet #42262
    • Oasis Emerald Testnet #42261
    • Oasis Sapphire Testnet #23295
    • Update Celo Mainnet contractFetchAddress 3069c98

New Contributors

Full Changelog: v1.1.0...v1.2.0

v1.1.0

21 Nov 13:44
d318763
Compare
Choose a tag to compare
  • create2
  • import from contract
  • repository now rewrites url
  • added chains (8217, 10200, 336, 28428)
  • npm script to update chains
  • bytecode-utils
  • typescript strict null check

v1.0.1

09 Nov 08:31
258968d
Compare
Choose a tag to compare

The release includes:

  • add chain 592, 1001
  • ui fixes for mobile
  • remove kovan and ropsten support for both L1 and L2

v1.0.0

19 Oct 15:28
6d40731
Compare
Choose a tag to compare

Initial release for Sourcify.

Sourcify is a Solidity source code and metadata verification tool and repository and acts as a base layer allowing other tools build on top of it. We aim to keep as much as smart contract metadata and verified source code open and available via IPFS, and facilitate an improved smart contract UX with verified sources and decoded transactions.

The release includes:

  • Server
  • Monitor
  • UI
  • Repository
  • external services: IPFS, s3
  • packages
    • verification
    • validation
    • core

https://sourcify.dev