Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(isHalting, { stack }, remaining, finalStatus) => {
if (!isHalting) {
return null; //not clear this'll do much good since this may get
//read as false, but, oh well, may as well
}
if (remaining <= 1) {
return finalStatus;
} else {
const ZERO_WORD = "00".repeat(Codec.Evm.Utils.WORD_SIZE);
return stack[stack.length - 1] !== ZERO_WORD;
}
}
),
(isCall, { stack }) => {
if (!isCall) {
return null;
}
let address = stack[stack.length - 2];
return Codec.Evm.Utils.toAddress(address);
}
),
export function* decode(definition, ref) {
let userDefinedTypes = yield select(data.views.userDefinedTypes);
let state = yield select(data.current.state);
let mappingKeys = yield select(data.views.mappingKeys);
let allocations = yield select(data.info.allocations);
let instances = yield select(data.views.instances);
let contexts = yield select(data.views.contexts);
let currentContext = yield select(data.current.context);
let internalFunctionsTable = yield select(
data.current.functionsByProgramCounter
);
let blockNumber = yield select(data.views.blockNumber);
let ZERO_WORD = new Uint8Array(Codec.Evm.Utils.WORD_SIZE); //automatically filled with zeroes
let NO_CODE = new Uint8Array(); //empty array
let decoder = Codec.decodeVariable(definition, ref, {
userDefinedTypes,
state,
mappingKeys,
allocations,
contexts,
currentContext,
internalFunctionsTable
});
debug("beginning decoding");
let result = decoder.next();
while (!result.done) {
debug("request received");
//the table). If the parent has a slot in the table already, then we
//alter the child slot by replacing its path with the parent slot. This
//will keep the slotAddress the same, but since the versions kept in the
//table here are supposed to preserve path information, we'll be
//replacing a fairly bare-bones Slot object with one with a full path.
//we do NOT want to distinguish between types with and without "_ptr" on
//the end here! (or _slice)
debug("typeIdentifier %s", typeIdentifier);
typeIdentifier = Codec.Ast.Utils.regularizeTypeIdentifier(typeIdentifier);
parentType = Codec.Ast.Utils.regularizeTypeIdentifier(parentType);
debug("slot %o", slot);
let hexSlotAddress = Codec.Conversion.toHexString(
Codec.Storage.Utils.slotAddress(slot),
Codec.Evm.Utils.WORD_SIZE
);
let parentAddress = slot.path
? Codec.Conversion.toHexString(
Codec.Storage.Utils.slotAddress(slot.path),
Codec.Evm.Utils.WORD_SIZE
)
: undefined;
//this is going to be messy and procedural, sorry. but let's start with
//the easy stuff: create the new address if needed, clone if not
let newState = {
...state,
byAddress: {
...state.byAddress,
[address]: {
byType: {
let result = decoder.next();
while (!result.done) {
debug("request received");
let request = result.value;
let response;
switch (request.type) {
case "storage":
//the debugger supplies all storage it knows at the beginning.
//any storage it does not know is presumed to be zero.
response = ZERO_WORD;
break;
case "code":
let address = request.address;
if (address in instances) {
response = instances[address];
} else if (address === Codec.Evm.Utils.ZERO_ADDRESS) {
//HACK: to avoid displaying the zero address to the user as an
//affected address just because they decoded a contract or external
//function variable that hadn't been initialized yet, we give the
//zero address's codelessness its own private cache :P
response = NO_CODE;
} else {
//I don't want to write a new web3 saga, so let's just use
//obtainBinaries with a one-element array
debug("fetching binary");
let binary = (yield* web3.obtainBinaries([address], blockNumber))[0];
debug("adding instance");
yield* evm.addInstance(address, binary);
response = Codec.Conversion.toBytes(binary);
}
break;
default:
//we do NOT want to distinguish between types with and without "_ptr" on
//the end here! (or _slice)
debug("typeIdentifier %s", typeIdentifier);
typeIdentifier = Codec.Ast.Utils.regularizeTypeIdentifier(typeIdentifier);
parentType = Codec.Ast.Utils.regularizeTypeIdentifier(parentType);
debug("slot %o", slot);
let hexSlotAddress = Codec.Conversion.toHexString(
Codec.Storage.Utils.slotAddress(slot),
Codec.Evm.Utils.WORD_SIZE
);
let parentAddress = slot.path
? Codec.Conversion.toHexString(
Codec.Storage.Utils.slotAddress(slot.path),
Codec.Evm.Utils.WORD_SIZE
)
: undefined;
//this is going to be messy and procedural, sorry. but let's start with
//the easy stuff: create the new address if needed, clone if not
let newState = {
...state,
byAddress: {
...state.byAddress,
[address]: {
byType: {
...(state.byAddress[address] || { byType: {} }).byType
}
}
}
};