truffle
Version:
Truffle - Simple development framework for Ethereum
1,410 lines (1,277 loc) • 46.1 kB
JavaScript
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({
/***/ 92936:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
;
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ getAddress: () => (/* binding */ getAddress),
/* harmony export */ getContractAddress: () => (/* binding */ getContractAddress),
/* harmony export */ getCreate2Address: () => (/* binding */ getCreate2Address),
/* harmony export */ getIcapAddress: () => (/* binding */ getIcapAddress),
/* harmony export */ isAddress: () => (/* binding */ isAddress)
/* harmony export */ });
/* harmony import */ var _ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(46366);
/* harmony import */ var _ethersproject_bignumber__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(2593);
/* harmony import */ var _ethersproject_keccak256__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(38197);
/* harmony import */ var _ethersproject_rlp__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(50284);
/* harmony import */ var _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(66167);
/* harmony import */ var _version__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6915);
const logger = new _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd(_version__WEBPACK_IMPORTED_MODULE_1__/* .version */ .i);
function getChecksumAddress(address) {
if (!(0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .isHexString */ .A7)(address, 20)) {
logger.throwArgumentError("invalid address", "address", address);
}
address = address.toLowerCase();
const chars = address.substring(2).split("");
const expanded = new Uint8Array(40);
for (let i = 0; i < 40; i++) {
expanded[i] = chars[i].charCodeAt(0);
}
const hashed = (0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .arrayify */ .lE)((0,_ethersproject_keccak256__WEBPACK_IMPORTED_MODULE_3__/* .keccak256 */ .w)(expanded));
for (let i = 0; i < 40; i += 2) {
if ((hashed[i >> 1] >> 4) >= 8) {
chars[i] = chars[i].toUpperCase();
}
if ((hashed[i >> 1] & 0x0f) >= 8) {
chars[i + 1] = chars[i + 1].toUpperCase();
}
}
return "0x" + chars.join("");
}
// Shims for environments that are missing some required constants and functions
const MAX_SAFE_INTEGER = 0x1fffffffffffff;
function log10(x) {
if (Math.log10) {
return Math.log10(x);
}
return Math.log(x) / Math.LN10;
}
// See: https://en.wikipedia.org/wiki/International_Bank_Account_Number
// Create lookup table
const ibanLookup = {};
for (let i = 0; i < 10; i++) {
ibanLookup[String(i)] = String(i);
}
for (let i = 0; i < 26; i++) {
ibanLookup[String.fromCharCode(65 + i)] = String(10 + i);
}
// How many decimal digits can we process? (for 64-bit float, this is 15)
const safeDigits = Math.floor(log10(MAX_SAFE_INTEGER));
function ibanChecksum(address) {
address = address.toUpperCase();
address = address.substring(4) + address.substring(0, 2) + "00";
let expanded = address.split("").map((c) => { return ibanLookup[c]; }).join("");
// Javascript can handle integers safely up to 15 (decimal) digits
while (expanded.length >= safeDigits) {
let block = expanded.substring(0, safeDigits);
expanded = parseInt(block, 10) % 97 + expanded.substring(block.length);
}
let checksum = String(98 - (parseInt(expanded, 10) % 97));
while (checksum.length < 2) {
checksum = "0" + checksum;
}
return checksum;
}
;
function getAddress(address) {
let result = null;
if (typeof (address) !== "string") {
logger.throwArgumentError("invalid address", "address", address);
}
if (address.match(/^(0x)?[0-9a-fA-F]{40}$/)) {
// Missing the 0x prefix
if (address.substring(0, 2) !== "0x") {
address = "0x" + address;
}
result = getChecksumAddress(address);
// It is a checksummed address with a bad checksum
if (address.match(/([A-F].*[a-f])|([a-f].*[A-F])/) && result !== address) {
logger.throwArgumentError("bad address checksum", "address", address);
}
// Maybe ICAP? (we only support direct mode)
}
else if (address.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)) {
// It is an ICAP address with a bad checksum
if (address.substring(2, 4) !== ibanChecksum(address)) {
logger.throwArgumentError("bad icap checksum", "address", address);
}
result = (0,_ethersproject_bignumber__WEBPACK_IMPORTED_MODULE_4__/* ._base36To16 */ .g$)(address.substring(4));
while (result.length < 40) {
result = "0" + result;
}
result = getChecksumAddress("0x" + result);
}
else {
logger.throwArgumentError("invalid address", "address", address);
}
return result;
}
function isAddress(address) {
try {
getAddress(address);
return true;
}
catch (error) { }
return false;
}
function getIcapAddress(address) {
let base36 = (0,_ethersproject_bignumber__WEBPACK_IMPORTED_MODULE_4__/* ._base16To36 */ .t2)(getAddress(address).substring(2)).toUpperCase();
while (base36.length < 30) {
base36 = "0" + base36;
}
return "XE" + ibanChecksum("XE00" + base36) + base36;
}
// http://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed
function getContractAddress(transaction) {
let from = null;
try {
from = getAddress(transaction.from);
}
catch (error) {
logger.throwArgumentError("missing from address", "transaction", transaction);
}
const nonce = (0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .stripZeros */ .G1)((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .arrayify */ .lE)(_ethersproject_bignumber__WEBPACK_IMPORTED_MODULE_4__/* .BigNumber */ .O$.from(transaction.nonce).toHexString()));
return getAddress((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .hexDataSlice */ .p3)((0,_ethersproject_keccak256__WEBPACK_IMPORTED_MODULE_3__/* .keccak256 */ .w)((0,_ethersproject_rlp__WEBPACK_IMPORTED_MODULE_5__.encode)([from, nonce])), 12));
}
function getCreate2Address(from, salt, initCodeHash) {
if ((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .hexDataLength */ .E1)(salt) !== 32) {
logger.throwArgumentError("salt must be 32 bytes", "salt", salt);
}
if ((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .hexDataLength */ .E1)(initCodeHash) !== 32) {
logger.throwArgumentError("initCodeHash must be 32 bytes", "initCodeHash", initCodeHash);
}
return getAddress((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .hexDataSlice */ .p3)((0,_ethersproject_keccak256__WEBPACK_IMPORTED_MODULE_3__/* .keccak256 */ .w)((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .concat */ .zo)(["0xff", getAddress(from), salt, initCodeHash])), 12));
}
//# sourceMappingURL=index.js.map
/***/ }),
/***/ 20335:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
;
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ Ox: () => (/* binding */ parseFixed),
/* harmony export */ S5: () => (/* binding */ formatFixed),
/* harmony export */ xs: () => (/* binding */ FixedNumber)
/* harmony export */ });
/* unused harmony export FixedFormat */
/* harmony import */ var _ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(46366);
/* harmony import */ var _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(66167);
/* harmony import */ var _version__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(48794);
/* harmony import */ var _bignumber__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(2593);
const logger = new _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd(_version__WEBPACK_IMPORTED_MODULE_1__/* .version */ .i);
const _constructorGuard = {};
const Zero = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(0);
const NegativeOne = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(-1);
function throwFault(message, fault, operation, value) {
const params = { fault: fault, operation: operation };
if (value !== undefined) {
params.value = value;
}
return logger.throwError(message, _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd.errors.NUMERIC_FAULT, params);
}
// Constant to pull zeros from for multipliers
let zeros = "0";
while (zeros.length < 256) {
zeros += zeros;
}
// Returns a string "1" followed by decimal "0"s
function getMultiplier(decimals) {
if (typeof (decimals) !== "number") {
try {
decimals = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(decimals).toNumber();
}
catch (e) { }
}
if (typeof (decimals) === "number" && decimals >= 0 && decimals <= 256 && !(decimals % 1)) {
return ("1" + zeros.substring(0, decimals));
}
return logger.throwArgumentError("invalid decimal size", "decimals", decimals);
}
function formatFixed(value, decimals) {
if (decimals == null) {
decimals = 0;
}
const multiplier = getMultiplier(decimals);
// Make sure wei is a big number (convert as necessary)
value = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(value);
const negative = value.lt(Zero);
if (negative) {
value = value.mul(NegativeOne);
}
let fraction = value.mod(multiplier).toString();
while (fraction.length < multiplier.length - 1) {
fraction = "0" + fraction;
}
// Strip training 0
fraction = fraction.match(/^([0-9]*[1-9]|0)(0*)/)[1];
const whole = value.div(multiplier).toString();
if (multiplier.length === 1) {
value = whole;
}
else {
value = whole + "." + fraction;
}
if (negative) {
value = "-" + value;
}
return value;
}
function parseFixed(value, decimals) {
if (decimals == null) {
decimals = 0;
}
const multiplier = getMultiplier(decimals);
if (typeof (value) !== "string" || !value.match(/^-?[0-9.]+$/)) {
logger.throwArgumentError("invalid decimal value", "value", value);
}
// Is it negative?
const negative = (value.substring(0, 1) === "-");
if (negative) {
value = value.substring(1);
}
if (value === ".") {
logger.throwArgumentError("missing value", "value", value);
}
// Split it into a whole and fractional part
const comps = value.split(".");
if (comps.length > 2) {
logger.throwArgumentError("too many decimal points", "value", value);
}
let whole = comps[0], fraction = comps[1];
if (!whole) {
whole = "0";
}
if (!fraction) {
fraction = "0";
}
// Trim trailing zeros
while (fraction[fraction.length - 1] === "0") {
fraction = fraction.substring(0, fraction.length - 1);
}
// Check the fraction doesn't exceed our decimals size
if (fraction.length > multiplier.length - 1) {
throwFault("fractional component exceeds decimals", "underflow", "parseFixed");
}
// If decimals is 0, we have an empty string for fraction
if (fraction === "") {
fraction = "0";
}
// Fully pad the string with zeros to get to wei
while (fraction.length < multiplier.length - 1) {
fraction += "0";
}
const wholeValue = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(whole);
const fractionValue = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(fraction);
let wei = (wholeValue.mul(multiplier)).add(fractionValue);
if (negative) {
wei = wei.mul(NegativeOne);
}
return wei;
}
class FixedFormat {
constructor(constructorGuard, signed, width, decimals) {
if (constructorGuard !== _constructorGuard) {
logger.throwError("cannot use FixedFormat constructor; use FixedFormat.from", _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd.errors.UNSUPPORTED_OPERATION, {
operation: "new FixedFormat"
});
}
this.signed = signed;
this.width = width;
this.decimals = decimals;
this.name = (signed ? "" : "u") + "fixed" + String(width) + "x" + String(decimals);
this._multiplier = getMultiplier(decimals);
Object.freeze(this);
}
static from(value) {
if (value instanceof FixedFormat) {
return value;
}
if (typeof (value) === "number") {
value = `fixed128x${value}`;
}
let signed = true;
let width = 128;
let decimals = 18;
if (typeof (value) === "string") {
if (value === "fixed") {
// defaults...
}
else if (value === "ufixed") {
signed = false;
}
else {
const match = value.match(/^(u?)fixed([0-9]+)x([0-9]+)$/);
if (!match) {
logger.throwArgumentError("invalid fixed format", "format", value);
}
signed = (match[1] !== "u");
width = parseInt(match[2]);
decimals = parseInt(match[3]);
}
}
else if (value) {
const check = (key, type, defaultValue) => {
if (value[key] == null) {
return defaultValue;
}
if (typeof (value[key]) !== type) {
logger.throwArgumentError("invalid fixed format (" + key + " not " + type + ")", "format." + key, value[key]);
}
return value[key];
};
signed = check("signed", "boolean", signed);
width = check("width", "number", width);
decimals = check("decimals", "number", decimals);
}
if (width % 8) {
logger.throwArgumentError("invalid fixed format width (not byte aligned)", "format.width", width);
}
if (decimals > 80) {
logger.throwArgumentError("invalid fixed format (decimals too large)", "format.decimals", decimals);
}
return new FixedFormat(_constructorGuard, signed, width, decimals);
}
}
class FixedNumber {
constructor(constructorGuard, hex, value, format) {
if (constructorGuard !== _constructorGuard) {
logger.throwError("cannot use FixedNumber constructor; use FixedNumber.from", _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd.errors.UNSUPPORTED_OPERATION, {
operation: "new FixedFormat"
});
}
this.format = format;
this._hex = hex;
this._value = value;
this._isFixedNumber = true;
Object.freeze(this);
}
_checkFormat(other) {
if (this.format.name !== other.format.name) {
logger.throwArgumentError("incompatible format; use fixedNumber.toFormat", "other", other);
}
}
addUnsafe(other) {
this._checkFormat(other);
const a = parseFixed(this._value, this.format.decimals);
const b = parseFixed(other._value, other.format.decimals);
return FixedNumber.fromValue(a.add(b), this.format.decimals, this.format);
}
subUnsafe(other) {
this._checkFormat(other);
const a = parseFixed(this._value, this.format.decimals);
const b = parseFixed(other._value, other.format.decimals);
return FixedNumber.fromValue(a.sub(b), this.format.decimals, this.format);
}
mulUnsafe(other) {
this._checkFormat(other);
const a = parseFixed(this._value, this.format.decimals);
const b = parseFixed(other._value, other.format.decimals);
return FixedNumber.fromValue(a.mul(b).div(this.format._multiplier), this.format.decimals, this.format);
}
divUnsafe(other) {
this._checkFormat(other);
const a = parseFixed(this._value, this.format.decimals);
const b = parseFixed(other._value, other.format.decimals);
return FixedNumber.fromValue(a.mul(this.format._multiplier).div(b), this.format.decimals, this.format);
}
floor() {
const comps = this.toString().split(".");
if (comps.length === 1) {
comps.push("0");
}
let result = FixedNumber.from(comps[0], this.format);
const hasFraction = !comps[1].match(/^(0*)$/);
if (this.isNegative() && hasFraction) {
result = result.subUnsafe(ONE.toFormat(result.format));
}
return result;
}
ceiling() {
const comps = this.toString().split(".");
if (comps.length === 1) {
comps.push("0");
}
let result = FixedNumber.from(comps[0], this.format);
const hasFraction = !comps[1].match(/^(0*)$/);
if (!this.isNegative() && hasFraction) {
result = result.addUnsafe(ONE.toFormat(result.format));
}
return result;
}
// @TODO: Support other rounding algorithms
round(decimals) {
if (decimals == null) {
decimals = 0;
}
// If we are already in range, we're done
const comps = this.toString().split(".");
if (comps.length === 1) {
comps.push("0");
}
if (decimals < 0 || decimals > 80 || (decimals % 1)) {
logger.throwArgumentError("invalid decimal count", "decimals", decimals);
}
if (comps[1].length <= decimals) {
return this;
}
const factor = FixedNumber.from("1" + zeros.substring(0, decimals), this.format);
const bump = BUMP.toFormat(this.format);
return this.mulUnsafe(factor).addUnsafe(bump).floor().divUnsafe(factor);
}
isZero() {
return (this._value === "0.0" || this._value === "0");
}
isNegative() {
return (this._value[0] === "-");
}
toString() { return this._value; }
toHexString(width) {
if (width == null) {
return this._hex;
}
if (width % 8) {
logger.throwArgumentError("invalid byte width", "width", width);
}
const hex = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(this._hex).fromTwos(this.format.width).toTwos(width).toHexString();
return (0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__/* .hexZeroPad */ .$m)(hex, width / 8);
}
toUnsafeFloat() { return parseFloat(this.toString()); }
toFormat(format) {
return FixedNumber.fromString(this._value, format);
}
static fromValue(value, decimals, format) {
// If decimals looks more like a format, and there is no format, shift the parameters
if (format == null && decimals != null && !(0,_bignumber__WEBPACK_IMPORTED_MODULE_2__/* .isBigNumberish */ .Zm)(decimals)) {
format = decimals;
decimals = null;
}
if (decimals == null) {
decimals = 0;
}
if (format == null) {
format = "fixed";
}
return FixedNumber.fromString(formatFixed(value, decimals), FixedFormat.from(format));
}
static fromString(value, format) {
if (format == null) {
format = "fixed";
}
const fixedFormat = FixedFormat.from(format);
const numeric = parseFixed(value, fixedFormat.decimals);
if (!fixedFormat.signed && numeric.lt(Zero)) {
throwFault("unsigned value cannot be negative", "overflow", "value", value);
}
let hex = null;
if (fixedFormat.signed) {
hex = numeric.toTwos(fixedFormat.width).toHexString();
}
else {
hex = numeric.toHexString();
hex = (0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__/* .hexZeroPad */ .$m)(hex, fixedFormat.width / 8);
}
const decimal = formatFixed(numeric, fixedFormat.decimals);
return new FixedNumber(_constructorGuard, hex, decimal, fixedFormat);
}
static fromBytes(value, format) {
if (format == null) {
format = "fixed";
}
const fixedFormat = FixedFormat.from(format);
if ((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__/* .arrayify */ .lE)(value).length > fixedFormat.width / 8) {
throw new Error("overflow");
}
let numeric = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(value);
if (fixedFormat.signed) {
numeric = numeric.fromTwos(fixedFormat.width);
}
const hex = numeric.toTwos((fixedFormat.signed ? 0 : 1) + fixedFormat.width).toHexString();
const decimal = formatFixed(numeric, fixedFormat.decimals);
return new FixedNumber(_constructorGuard, hex, decimal, fixedFormat);
}
static from(value, format) {
if (typeof (value) === "string") {
return FixedNumber.fromString(value, format);
}
if ((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__/* .isBytes */ ._t)(value)) {
return FixedNumber.fromBytes(value, format);
}
try {
return FixedNumber.fromValue(value, 0, format);
}
catch (error) {
// Allow NUMERIC_FAULT to bubble up
if (error.code !== _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd.errors.INVALID_ARGUMENT) {
throw error;
}
}
return logger.throwArgumentError("invalid FixedNumber value", "value", value);
}
static isFixedNumber(value) {
return !!(value && value._isFixedNumber);
}
}
const ONE = FixedNumber.from(1);
const BUMP = FixedNumber.from("0.5");
//# sourceMappingURL=fixednumber.js.map
/***/ }),
/***/ 48829:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
module.exports = {
run: __webpack_require__(86295),
meta: __webpack_require__(3697)
};
/***/ }),
/***/ 3697:
/***/ ((module) => {
module.exports = {
command: "opcode",
description: "Print the compiled opcodes for a given contract",
builder: {
all: {
type: "boolean",
default: false
}
},
help: {
usage: "truffle opcode <contract_name>",
options: [
{
option: "<contract_name>",
description:
"Name of the contract to print opcodes for. Must be a contract name, not a file name. (required)"
}
],
allowedGlobalOptions: []
}
};
/***/ }),
/***/ 86295:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
module.exports = async function (options) {
const Config = __webpack_require__(20553);
const TruffleError = __webpack_require__(73321);
const WorkflowCompile = (__webpack_require__(37017)["default"]);
const CodeUtils = __webpack_require__(8135);
const { Conversion, Compilations } = __webpack_require__(20102);
if (options._.length === 0) {
throw new TruffleError("Please specify a contract name.");
}
const config = Config.detect(options);
await WorkflowCompile.compileAndSave(config);
const contractName = options._[0];
let Contract;
try {
Contract = config.resolver.require(contractName);
} catch (e) {
throw new TruffleError(
'Cannot find compiled contract with name "' + contractName + '"'
);
}
const bytecode = options.creation
? Contract.bytecode
: Contract.deployedBytecode;
const sourceMap = Compilations.Utils.simpleShimSourceMap(
options.creation ? Contract.sourceMap : Contract.deployedSourceMap
); //the shim is in case of an old-style Vyper source map
let numInstructions;
if (sourceMap) {
numInstructions = sourceMap.split(";").length;
}
const opcodes = CodeUtils.parseCode(bytecode, {
maxInstructionCount: numInstructions,
attemptStripMetadata: sourceMap === undefined
});
if (opcodes.length === 0) {
console.log(
"Contract has no bytecode. Please check to make sure it's not an `abstract contract` or an `interface`."
);
return;
}
const lastPCByteLength = Conversion.toBytes(
opcodes[opcodes.length - 1].pc
).byteLength;
opcodes.forEach(opcode => {
console.log(
Conversion.toHexString(opcode.pc, lastPCByteLength) + ":",
opcode.name,
opcode.pushData !== undefined && opcode.pushData !== "0x"
? opcode.pushData
: "" //display just "PUSH0", not "PUSH0 0x"
);
});
};
/***/ }),
/***/ 8135:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.parseCode = void 0;
const opcodes_1 = __webpack_require__(89537);
const cbor = __importStar(__webpack_require__(82141));
/**
* parseCode - return a list of instructions given a 0x-prefixed code string.
*
* The optional second options argument allows two options; both are ways of
* attempting to limit the disassembly to only the code section rather than the
* data section. If maxInstructionCount is used, the disassembly will be limited
* to the specified number of instructions (one may pass in here the number of
* instructions in the corresponding source map).
*
* If attemptStripMetadata is used, we will attempt to strip the metadata at the
* end of the code. This is not reliable, and should be avoided if better
* alternatives are available. It may be particularly unreliable when dealing with
* constructors that have had arguments attached to the end!
*
* These options can be combined, although I'm not sure why you'd want to.
*
* @param {String} hexString Hex string representing the code
* @return Array Array of instructions
*/
function parseCode(hexString, { maxInstructionCount, attemptStripMetadata } = {}) {
// Convert to an array of bytes
let code = new Uint8Array((hexString.slice(2).match(/(..?)/g) || []).map(hex => parseInt(hex, 16)));
if (attemptStripMetadata && code.length >= 2) {
// Remove the contract metadata; last two bytes encode its length (not
// including those two bytes)
let foundMetadata = false;
const metadataLength = (code[code.length - 2] << 8) + code[code.length - 1];
//check: is this actually valid CBOR?
if (metadataLength + 2 <= code.length) {
const metadata = code.subarray(-(metadataLength + 2), -2);
if (isValidCBOR(metadata)) {
code = code.subarray(0, -(metadataLength + 2));
foundMetadata = true;
}
}
if (!foundMetadata) {
const vyper034MetadataLength = 11; //vyper 0.3.4 (that version specifically;
//this will be corrected in 0.3.5, and earlier vyper versions do not include
//metadata) has metadata on the end but with no length information supplied
//afterward; instead it has a fixed length of 11
if (vyper034MetadataLength <= code.length) {
const metadata = code.subarray(-vyper034MetadataLength);
if (isValidCBOR(metadata)) {
code = code.subarray(0, -vyper034MetadataLength);
}
}
}
}
let instructions = [];
if (maxInstructionCount === undefined) {
//if maxInstructionCount wasn't passed, we'll set it to
//Infinity so that we don't limit the number of instructions
maxInstructionCount = Infinity;
}
for (let pc = 0; pc < code.length && instructions.length < maxInstructionCount; pc++) {
let opcode = {
pc,
name: (0, opcodes_1.parseOpcode)(code[pc])
};
if (opcode.name.slice(0, 4) === "PUSH") {
const length = code[pc] - 0x5f; //0x5f is code for PUSH0
let pushData = code.subarray(pc + 1, pc + length + 1);
if (pushData.length < length) {
//if we run out of bytes for our pushdata, fill the rest
//with zeroes
pushData = Uint8Array.from([
...pushData,
...new Uint8Array(length - pushData.length)
]);
}
// convert pushData to hex
opcode.pushData = `0x${Buffer.from(pushData).toString("hex")}`;
pc += length;
}
instructions.push(opcode);
}
return instructions;
}
exports.parseCode = parseCode;
function isValidCBOR(metadata) {
try {
//attempt to decode but discard the value
//note this *will* throw if there's data left over,
//which is what we want it to do
//HACK: this version of cbor doesn't accept Uint8Arrays,
//but it does accept Buffers. (Unfortunately newer versions
//cause problems. :-/ )
cbor.decodeFirstSync(Buffer.from(metadata));
}
catch (_a) {
return false;
}
return true;
}
//# sourceMappingURL=index.js.map
/***/ }),
/***/ 89537:
/***/ ((__unused_webpack_module, exports) => {
;
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.parseOpcode = void 0;
const codes = {
0x00: "STOP",
0x01: "ADD",
0x02: "MUL",
0x03: "SUB",
0x04: "DIV",
0x05: "SDIV",
0x06: "MOD",
0x07: "SMOD",
0x08: "ADDMOD",
0x09: "MULMOD",
0x0a: "EXP",
0x0b: "SIGNEXTEND",
// 0x10 range - bit ops
0x10: "LT",
0x11: "GT",
0x12: "SLT",
0x13: "SGT",
0x14: "EQ",
0x15: "ISZERO",
0x16: "AND",
0x17: "OR",
0x18: "XOR",
0x19: "NOT",
0x1a: "BYTE",
0x1b: "SHL",
0x1c: "SHR",
0x1d: "SAR",
// 0x20 range - crypto
0x20: "SHA3",
// 0x30 range - closure state
0x30: "ADDRESS",
0x31: "BALANCE",
0x32: "ORIGIN",
0x33: "CALLER",
0x34: "CALLVALUE",
0x35: "CALLDATALOAD",
0x36: "CALLDATASIZE",
0x37: "CALLDATACOPY",
0x38: "CODESIZE",
0x39: "CODECOPY",
0x3a: "GASPRICE",
0x3b: "EXTCODESIZE",
0x3c: "EXTCODECOPY",
0x3d: "RETURNDATASIZE",
0x3e: "RETURNDATACOPY",
0x3f: "EXTCODEHASH",
// 0x40 range - block operations
0x40: "BLOCKHASH",
0x41: "COINBASE",
0x42: "TIMESTAMP",
0x43: "NUMBER",
0x44: "PREVRANDAO|DIFFICULTY",
0x45: "GASLIMIT",
0x46: "CHAINID",
0x47: "SELFBALANCE",
0x48: "BASEFEE",
// 0x50 range - 'storage' and execution
0x50: "POP",
0x51: "MLOAD",
0x52: "MSTORE",
0x53: "MSTORE8",
0x54: "SLOAD",
0x55: "SSTORE",
0x56: "JUMP",
0x57: "JUMPI",
0x58: "PC",
0x59: "MSIZE",
0x5a: "GAS",
0x5b: "JUMPDEST",
// 0x60 & 0x70 range - pushes
0x5f: "PUSH0",
0x60: "PUSH1",
0x61: "PUSH2",
0x62: "PUSH3",
0x63: "PUSH4",
0x64: "PUSH5",
0x65: "PUSH6",
0x66: "PUSH7",
0x67: "PUSH8",
0x68: "PUSH9",
0x69: "PUSH10",
0x6a: "PUSH11",
0x6b: "PUSH12",
0x6c: "PUSH13",
0x6d: "PUSH14",
0x6e: "PUSH15",
0x6f: "PUSH16",
0x70: "PUSH17",
0x71: "PUSH18",
0x72: "PUSH19",
0x73: "PUSH20",
0x74: "PUSH21",
0x75: "PUSH22",
0x76: "PUSH23",
0x77: "PUSH24",
0x78: "PUSH25",
0x79: "PUSH26",
0x7a: "PUSH27",
0x7b: "PUSH28",
0x7c: "PUSH29",
0x7d: "PUSH30",
0x7e: "PUSH31",
0x7f: "PUSH32",
// 0x80 range - duplication
0x80: "DUP1",
0x81: "DUP2",
0x82: "DUP3",
0x83: "DUP4",
0x84: "DUP5",
0x85: "DUP6",
0x86: "DUP7",
0x87: "DUP8",
0x88: "DUP9",
0x89: "DUP10",
0x8a: "DUP11",
0x8b: "DUP12",
0x8c: "DUP13",
0x8d: "DUP14",
0x8e: "DUP15",
0x8f: "DUP16",
// 0x90 range - swaps
0x90: "SWAP1",
0x91: "SWAP2",
0x92: "SWAP3",
0x93: "SWAP4",
0x94: "SWAP5",
0x95: "SWAP6",
0x96: "SWAP7",
0x97: "SWAP8",
0x98: "SWAP9",
0x99: "SWAP10",
0x9a: "SWAP11",
0x9b: "SWAP12",
0x9c: "SWAP13",
0x9d: "SWAP14",
0x9e: "SWAP15",
0x9f: "SWAP16",
// '0xa0' range - logging
0xa0: "LOG0",
0xa1: "LOG1",
0xa2: "LOG2",
0xa3: "LOG3",
0xa4: "LOG4",
// '0xf0' range - closures
0xf0: "CREATE",
0xf1: "CALL",
0xf2: "CALLCODE",
0xf3: "RETURN",
0xf4: "DELEGATECALL",
0xf5: "CREATE2",
0xfa: "STATICCALL",
0xfd: "REVERT",
0xfe: "INVALID",
0xff: "SELFDESTRUCT"
};
const parseOpcode = (op) => op in codes ? codes[op] : "INVALID";
exports.parseOpcode = parseOpcode;
//# sourceMappingURL=opcodes.js.map
/***/ }),
/***/ 48511:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
;
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.Resolver = void 0;
const resolver_1 = __webpack_require__(43563);
Object.defineProperty(exports, "Resolver", ({ enumerable: true, get: function () { return resolver_1.Resolver; } }));
exports["default"] = resolver_1.Resolver;
//# sourceMappingURL=index.js.map
/***/ }),
/***/ 70972:
/***/ ((module) => {
;
module.exports = require("@truffle/db-loader");
/***/ }),
/***/ 44516:
/***/ ((module) => {
;
module.exports = require("original-require");
/***/ }),
/***/ 39491:
/***/ ((module) => {
;
module.exports = require("assert");
/***/ }),
/***/ 50852:
/***/ ((module) => {
;
module.exports = require("async_hooks");
/***/ }),
/***/ 14300:
/***/ ((module) => {
;
module.exports = require("buffer");
/***/ }),
/***/ 32081:
/***/ ((module) => {
;
module.exports = require("child_process");
/***/ }),
/***/ 22057:
/***/ ((module) => {
;
module.exports = require("constants");
/***/ }),
/***/ 6113:
/***/ ((module) => {
;
module.exports = require("crypto");
/***/ }),
/***/ 82361:
/***/ ((module) => {
;
module.exports = require("events");
/***/ }),
/***/ 57147:
/***/ ((module) => {
;
module.exports = require("fs");
/***/ }),
/***/ 73292:
/***/ ((module) => {
;
module.exports = require("fs/promises");
/***/ }),
/***/ 13685:
/***/ ((module) => {
;
module.exports = require("http");
/***/ }),
/***/ 95687:
/***/ ((module) => {
;
module.exports = require("https");
/***/ }),
/***/ 98188:
/***/ ((module) => {
;
module.exports = require("module");
/***/ }),
/***/ 41808:
/***/ ((module) => {
;
module.exports = require("net");
/***/ }),
/***/ 22037:
/***/ ((module) => {
;
module.exports = require("os");
/***/ }),
/***/ 71017:
/***/ ((module) => {
;
module.exports = require("path");
/***/ }),
/***/ 85477:
/***/ ((module) => {
;
module.exports = require("punycode");
/***/ }),
/***/ 63477:
/***/ ((module) => {
;
module.exports = require("querystring");
/***/ }),
/***/ 14521:
/***/ ((module) => {
;
module.exports = require("readline");
/***/ }),
/***/ 12781:
/***/ ((module) => {
;
module.exports = require("stream");
/***/ }),
/***/ 71576:
/***/ ((module) => {
;
module.exports = require("string_decoder");
/***/ }),
/***/ 24404:
/***/ ((module) => {
;
module.exports = require("tls");
/***/ }),
/***/ 76224:
/***/ ((module) => {
;
module.exports = require("tty");
/***/ }),
/***/ 57310:
/***/ ((module) => {
;
module.exports = require("url");
/***/ }),
/***/ 73837:
/***/ ((module) => {
;
module.exports = require("util");
/***/ }),
/***/ 59796:
/***/ ((module) => {
;
module.exports = require("zlib");
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ id: moduleId,
/******/ loaded: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = __webpack_modules__;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = __webpack_module_cache__;
/******/
/******/ // the startup function
/******/ __webpack_require__.x = () => {
/******/ // Load entry module and return exports
/******/ var __webpack_exports__ = __webpack_require__.O(undefined, [5158,9129,6127,5674,6674,439,406,7657,6434,1503,1698,1833,1071,9612,3613,8834,8100,794,553,4273,102,3077,7017], () => (__webpack_require__(48829)))
/******/ __webpack_exports__ = __webpack_require__.O(__webpack_exports__);
/******/ return __webpack_exports__;
/******/ };
/******/
/************************************************************************/
/******/ /* webpack/runtime/amd options */
/******/ (() => {
/******/ __webpack_require__.amdO = {};
/******/ })();
/******/
/******/ /* webpack/runtime/chunk loaded */
/******/ (() => {
/******/ var deferred = [];
/******/ __webpack_require__.O = (result, chunkIds, fn, priority) => {
/******/ if(chunkIds) {
/******/ priority = priority || 0;
/******/ for(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1];
/******/ deferred[i] = [chunkIds, fn, priority];
/******/ return;
/******/ }
/******/ var notFulfilled = Infinity;
/******/ for (var i = 0; i < deferred.length; i++) {
/******/ var [chunkIds, fn, priority] = deferred[i];
/******/ var fulfilled = true;
/******/ for (var j = 0; j < chunkIds.length; j++) {
/******/ if ((priority & 1 === 0 || notFulfilled >= priority) && Object.keys(__webpack_require__.O).every((key) => (__webpack_require__.O[key](chunkIds[j])))) {
/******/ chunkIds.splice(j--, 1);
/******/ } else {
/******/ fulfilled = false;
/******/ if(priority < notFulfilled) notFulfilled = priority;
/******/ }
/******/ }
/******/ if(fulfilled) {
/******/ deferred.splice(i--, 1)
/******/ var r = fn();
/******/ if (r !== undefined) result = r;
/******/ }
/******/ }
/******/ return result;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/compat get default export */
/******/ (() => {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = (module) => {
/******/ var getter = module && module.__esModule ?
/******/ () => (module['default']) :
/******/ () => (module);
/******/ __webpack_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/ensure chunk */
/******/ (() => {
/******/ __webpack_require__.f = {};
/******/ // This file contains only the entry chunk.
/******/ // The chunk loading function for additional chunks
/******/ __webpack_require__.e = (chunkId) => {
/******/ return Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key) => {
/******/ __webpack_require__.f[key](chunkId, promises);
/******/ return promises;
/******/ }, []));
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/get javascript chunk filename */
/******/ (() => {
/******/ // This function allow to reference async chunks and sibling chunks for the entrypoint
/******/ __webpack_require__.u = (chunkId) => {
/******/ // return url for filenames based on template
/******/ return "" + chunkId + ".bundled.js";
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/node module decorator */
/******/ (() => {
/******/ __webpack_require__.nmd = (module) => {
/******/ module.paths = [];
/******/ if (!module.children) module.children = [];
/******/ return module;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/require chunk loading */
/******/ (() => {
/******/ // no baseURI
/******/
/******/ // object to store loaded chunks
/******/ // "1" means "loaded", otherwise not loaded yet
/******/ var installedChunks = {
/******/ 718: 1
/******/ };
/******/
/******/ __webpack_require__.O.require = (chunkId) => (installedChunks[chunkId]);
/******/
/******/ var installChunk = (chunk) => {
/******/ var moreModules = chunk.modules, chunkIds = chunk.ids, runtime = chunk.runtime;
/******/ for(var moduleId in moreModules) {
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
/******/ }
/******/ }
/******/ if(runtime) runtime(__webpack_require__);
/******/ for(var i = 0; i < chunkIds.length; i++)
/******/ installedChunks[chunkIds[i]] = 1;
/******/ __webpack_require__.O();
/******/ };
/******/
/******/ // require() chunk loading for javascript
/******/ __webpack_require__.f.require = (chunkId, promises) => {
/******/ // "1" is the signal for "already loaded"
/******/ if(!installedChunks[chunkId]) {
/******/ if(true) { // all chunks have JS
/******/ installChunk(require("./" + __webpack_require__.u(chunkId)));
/******/ } else installedChunks[chunkId] = 1;
/******/ }
/******/ };
/******/
/******/ // no external install chunk
/******/
/******/ // no HMR
/******/
/******/ // no HMR manifest
/******/ })();
/******/
/******/ /* webpack/runtime/startup chunk dependencies */
/******/ (() => {
/******/ var next = __webpack_require__.x;
/******/ __webpack_require__.x = () => {
/******/ __webpack_require__.e(5158);
/******/ __webpack_require__.e(9129);
/******/ __webpack_require__.e(6127);
/******/ __webpack_require__.e(5674);
/******/ __webpack_require__.e(6674);
/******/ __webpack_require__.e(439);
/******/ __webpack_require__.e(406);
/******/ __webpack_require__.e(7657);
/******/ __webpack_require__.e(6434);
/******/ __webpack_require__.e(1503);
/******/ __webpack_require__.e(1698);
/******/ __webpack_require__.e(1833);
/******/ __webpack_require__.e(1071);
/******/ __webpack_require__.e(9612);
/******/ __webpack_require__.e(3613);
/******/ __webpack_require__.e(8834);
/******/ __webpack_require__.e(8100);
/******/ __webpack_require__.e(794);
/******/ __webpack_require__.e(553);
/******/ __webpack_require__.e(4273);
/******/ __webpack_require__.e(102);
/******/ __webpack_require__.e(3077);
/******/ __webpack_require__.e(7017);
/******/ return next();
/******/ };
/******/ })();
/******/
/************************************************************************/
/******/
/******/ // module cache are used so entry inlining is disabled
/******/ // run startup
/******/ var __webpack_exports__ = __webpack_require__.x();
/******/ var __webpack_export_target__ = exports;
/******/ for(var i in __webpack_exports__) __webpack_export_target__[i] = __webpack_exports__[i];
/******/ if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
/******/
/******/ })()
;
//# sourceMappingURL=opcode.bundled.js.map