sevm
Version:
A Symbolic Ethereum Virtual Machine (EVM) bytecode decompiler & analyzer library & CLI
51 lines (50 loc) • 2.45 kB
TypeScript
import { arrayify } from './.bytes';
/**
* Represents the metadata hash protocols embedded in bytecode by `solc`.
*
* See https://docs.soliditylang.org/en/latest/metadata.html#encoding-of-the-metadata-hash-in-the-bytecode.
*/
export declare class Metadata {
[key: string]: string | Uint8Array | undefined | boolean | number;
protocol: 'bzzr0' | 'bzzr1' | 'ipfs' | '';
hash: string;
solc: string;
experimental?: boolean;
get url(): string;
get minor(): number | undefined;
}
/**
* Splits `buffer` into the executable EVM bytecode and the embedded metadata hash.
* The metadata hash may be placed by the
* [Solidity compiler](https://docs.soliditylang.org/en/latest/metadata.html#encoding-of-the-metadata-hash-in-the-bytecode)
* as a [compilation fingerprint](https://docs.sourcify.dev/blog/talk-about-onchain-metadata-hash/#introduction).
* It may include the
* [compiler version](https://blog.soliditylang.org/2019/05/28/solidity-0.5.9-release-announcement/)
* and the hash of the compilation input, _i.e._ the source code and compilation settings.
*
* The bytecode might have been compiled with no metadata or with a different language that does not include metadata.
* In this case the `metadata` property is `undefined` and the `bytecode` property is the original `buffer`.
*
* The metadata hash is placed at the end of the EVM bytecode and encoded using [CBOR](https://cbor.io/).
* We use [`cbor-js`](https://github.com/paroga/cbor-js) to decode the metadata hash.
* If `metadata` contains an IPFS hash, it is encoded using base 58.
* We use [`base58-js`](https://github.com/pur3miish/base58-js) to encode the IPFS hash.
* If metadata contains a Swarm hash, _i.e._ `bzzr0` or `bzzr1`, it is encoded using hexadecimal.
*
* @param buffer the contract or library bytecode to test for metadata hash.
* @returns An object where the `bytecode` is the executable code and
* `metadata` is the metadata hash when the metadata is present.
*/
export declare function splitMetadataHash(buffer: Parameters<typeof arrayify>[0]): {
/**
* The executable code without metadata when it is present.
* Otherwise, the original `bytecode`.
*/
bytecode: Uint8Array;
/**
* The metadata if present. Otherwise `undefined`.
*
* See https://docs.soliditylang.org/en/latest/metadata.html#encoding-of-the-metadata-hash-in-the-bytecode.
*/
metadata: Metadata | undefined;
};