Added dynamic RAM evaluation to Netscript to prevent exploits by evading RAM usage in NetscriptJS. Calling a HacknetNode API Netscript fn now immediately updates HacknetNodeWrappers

This commit is contained in:
danielyxie 2018-06-06 11:02:21 -05:00
parent f28ffcc49e
commit 82f1c14656
8 changed files with 52043 additions and 53977 deletions

52452
dist/engine.bundle.js vendored

File diff suppressed because one or more lines are too long

52518
dist/tests.bundle.js vendored

File diff suppressed because one or more lines are too long

@ -1682,6 +1682,7 @@ Bladeburner.prototype.createContent = function() {
document.getElementById("entire-game-container").appendChild(DomElems.bladeburnerDiv); document.getElementById("entire-game-container").appendChild(DomElems.bladeburnerDiv);
this.postToConsole("Bladeburner Console BETA"); this.postToConsole("Bladeburner Console BETA");
this.postToConsole("Type 'help' to see console commands");
DomElems.consoleInput.focus(); DomElems.consoleInput.focus();
} }

@ -486,13 +486,8 @@ let CONSTANTS = {
"World Stock Exchange account and TIX API Access<br>", "World Stock Exchange account and TIX API Access<br>",
LatestUpdate: LatestUpdate:
"v0.37.2<br>" + "v0.37.3<br>" +
"* After joining the Bladeburners division, there is now a button to go to the Bladeburner content " + "* Bug Fix: Fixed an exploit that allowed calling any Netscript function without incurring any RAM Cost in NetscriptJS<br>"
"in the 'City' page<br>" +
"* You now start with $250m in BitNode-8 (increased from $100m)<br>" +
"* Bug Fix: You can now no longer directly edit Hacknet Node values through NetscriptJS (hopefully)<br>" +
"* Bug Fix: Bladeburners is no longer accessible in BN-8<br>" +
"* Bug Fix: getBitNodeMultipliers() Netscript function now returns a copy rather than the original object<br>"
} }
export {CONSTANTS}; export {CONSTANTS};

@ -58,7 +58,7 @@ Crime.prototype.successRate = function() {
} }
const Crimes = { const Crimes = {
Shoplift: new Crime("Shoplift", CONSTANTS.CrimeShoplift, 2000, 15000, 1/20, 0.1, { Shoplift: new Crime("Shoplift", CONSTANTS.CrimeShoplift, 2e3, 15e3, 1/20, 0.1, {
dexterity_success_weight: 1, dexterity_success_weight: 1,
agility_success_weight: 1, agility_success_weight: 1,
@ -66,7 +66,7 @@ const Crimes = {
agility_exp: 2, agility_exp: 2,
}), }),
RobStore: new Crime("Rob Store", CONSTANTS.CrimeRobStore, 60000, 400000, 1/5, 0.5, { RobStore: new Crime("Rob Store", CONSTANTS.CrimeRobStore, 60e3, 400e3, 1/5, 0.5, {
hacking_exp: 30, hacking_exp: 30,
dexterity_exp: 45, dexterity_exp: 45,
agility_exp: 45, agility_exp: 45,
@ -78,9 +78,9 @@ const Crimes = {
intelligence_exp: 0.25 * CONSTANTS.IntelligenceCrimeBaseExpGain, intelligence_exp: 0.25 * CONSTANTS.IntelligenceCrimeBaseExpGain,
}), }),
Mug: new Crime("Mug", CONSTANTS.CrimeMug, 4000, 36000, 1/5, 0.25, { Mug: new Crime("Mug", CONSTANTS.CrimeMug, 4e3, 36e3, 1/5, 0.25, {
strength_exp: 3, strength_exp: 3,
defence_exp: 3, defense_exp: 3,
dexterity_exp: 3, dexterity_exp: 3,
agility_exp: 3, agility_exp: 3,
@ -90,7 +90,7 @@ const Crimes = {
agility_success_weight: 0.5, agility_success_weight: 0.5,
}), }),
Larceny: new Crime("Larceny", CONSTANTS.CrimeLarceny, 90000, 800000, 1/3, 1.5, { Larceny: new Crime("Larceny", CONSTANTS.CrimeLarceny, 90e3, 800e3, 1/3, 1.5, {
hacking_exp: 45, hacking_exp: 45,
dexterity_exp: 60, dexterity_exp: 60,
agility_exp: 60, agility_exp: 60,
@ -102,7 +102,7 @@ const Crimes = {
intelligence_exp: 0.5 * CONSTANTS.IntelligenceCrimeBaseExpGain, intelligence_exp: 0.5 * CONSTANTS.IntelligenceCrimeBaseExpGain,
}), }),
DealDrugs: new Crime("Deal Drugs", CONSTANTS.CrimeDrugs, 10000, 120000, 1, 0.5, { DealDrugs: new Crime("Deal Drugs", CONSTANTS.CrimeDrugs, 10e3, 120e3, 1, 0.5, {
dexterity_exp: 5, dexterity_exp: 5,
agility_exp: 5, agility_exp: 5,
charisma_exp: 10, charisma_exp: 10,
@ -112,20 +112,20 @@ const Crimes = {
agility_success_weight: 1, agility_success_weight: 1,
}), }),
BondForgery: new Crime("Bond Forgery", CONSTANTS.CrimeBondForgery, 300000, 4500000, 1/2, 0.1, { BondForgery: new Crime("Bond Forgery", CONSTANTS.CrimeBondForgery, 300e3, 4.5e6, 1/2, 0.1, {
hacking_exp: 100, hacking_exp: 100,
dexterity_exp: 150, dexterity_exp: 150,
charisma_exp: 15, charisma_exp: 15,
hacking_skill_success_weight: 0.1, hacking_skill_success_weight: 0.05,
dexterity_success_weight: 2.5, dexterity_success_weight: 1.25,
intelligence_exp: 2 * CONSTANTS.IntelligenceCrimeBaseExpGain, intelligence_exp: 2 * CONSTANTS.IntelligenceCrimeBaseExpGain,
}), }),
TraffickArms: new Crime("Traffick Arms", CONSTANTS.CrimeTraffickArms, 40000, 600000, 2, 1, { TraffickArms: new Crime("Traffick Arms", CONSTANTS.CrimeTraffickArms, 40e3, 600e3, 2, 1, {
strength_exp: 20, strength_exp: 20,
defence_exp: 20, defense_exp: 20,
dexterity_exp: 20, dexterity_exp: 20,
agility_exp: 20, agility_exp: 20,
charisma_exp: 40, charisma_exp: 40,
@ -137,9 +137,9 @@ const Crimes = {
agility_success_weight: 1, agility_success_weight: 1,
}), }),
Homicide: new Crime("Homicide", CONSTANTS.CrimeHomicide, 3000, 45000, 1, 3, { Homicide: new Crime("Homicide", CONSTANTS.CrimeHomicide, 3e3, 45e3, 1, 3, {
strength_exp: 2, strength_exp: 2,
defence_exp: 2, defense_exp: 2,
dexterity_exp: 2, dexterity_exp: 2,
agility_exp: 2, agility_exp: 2,
@ -151,9 +151,9 @@ const Crimes = {
kills: 1, kills: 1,
}), }),
GrandTheftAuto: new Crime("Grand Theft Auto", CONSTANTS.CrimeGrandTheftAuto, 80000, 1600000, 8, 5, { GrandTheftAuto: new Crime("Grand Theft Auto", CONSTANTS.CrimeGrandTheftAuto, 80e3, 1.6e6, 8, 5, {
strength_exp: 20, strength_exp: 20,
defence_exp: 20, defense_exp: 20,
dexterity_exp: 20, dexterity_exp: 20,
agility_exp: 80, agility_exp: 80,
charisma_exp: 40, charisma_exp: 40,
@ -167,9 +167,9 @@ const Crimes = {
intelligence_exp: CONSTANTS.IntelligenceCrimeBaseExpGain, intelligence_exp: CONSTANTS.IntelligenceCrimeBaseExpGain,
}), }),
Kidnap: new Crime("Kidnap", CONSTANTS.CrimeKidnap, 120000, 3600000, 5, 6, { Kidnap: new Crime("Kidnap", CONSTANTS.CrimeKidnap, 120e3, 3.6e6, 5, 6, {
strength_exp: 80, strength_exp: 80,
defence_exp: 80, defense_exp: 80,
dexterity_exp: 80, dexterity_exp: 80,
agility_exp: 80, agility_exp: 80,
charisma_exp: 80, charisma_exp: 80,
@ -182,9 +182,9 @@ const Crimes = {
intelligence_exp: 2 * CONSTANTS.IntelligenceCrimeBaseExpGain, intelligence_exp: 2 * CONSTANTS.IntelligenceCrimeBaseExpGain,
}), }),
Assassination: new Crime("Assassination", CONSTANTS.CrimeAssassination, 300000, 12000000, 8, 10, { Assassination: new Crime("Assassination", CONSTANTS.CrimeAssassination, 300e3, 12e6, 8, 10, {
strength_exp: 300, strength_exp: 300,
defence_exp: 300, defense_exp: 300,
dexterity_exp: 300, dexterity_exp: 300,
agility_exp: 300, agility_exp: 300,
@ -197,10 +197,10 @@ const Crimes = {
kills: 1, kills: 1,
}), }),
Heist: new Crime("Heist", CONSTANTS.CrimeHeist, 600000, 120000000, 18, 15, { Heist: new Crime("Heist", CONSTANTS.CrimeHeist, 600e3, 120e6, 18, 15, {
hacking_exp: 450, hacking_exp: 450,
strength_exp: 450, strength_exp: 450,
defence_exp: 450, defense_exp: 450,
dexterity_exp: 450, dexterity_exp: 450,
agility_exp: 450, agility_exp: 450,
charisma_exp: 450, charisma_exp: 450,

@ -109,7 +109,9 @@ HacknetNode.prototype.purchaseLevelUpgrade = function(levels=1) {
//Wrapper function for Netscript //Wrapper function for Netscript
HacknetNode.prototype.upgradeLevel = function(levels=1) { HacknetNode.prototype.upgradeLevel = function(levels=1) {
return this.purchaseLevelUpgrade(levels); let res = this.purchaseLevelUpgrade(levels);
createPlayerHacknetNodeWrappers();
return res;
} }
HacknetNode.prototype.calculateRamUpgradeCost = function() { HacknetNode.prototype.calculateRamUpgradeCost = function() {
@ -140,7 +142,9 @@ HacknetNode.prototype.purchaseRamUpgrade = function() {
//Wrapper function for Netscript //Wrapper function for Netscript
HacknetNode.prototype.upgradeRam = function() { HacknetNode.prototype.upgradeRam = function() {
return this.purchaseRamUpgrade(); let res = this.purchaseRamUpgrade();
createPlayerHacknetNodeWrappers();
return res;
} }
HacknetNode.prototype.calculateCoreUpgradeCost = function() { HacknetNode.prototype.calculateCoreUpgradeCost = function() {
@ -151,7 +155,9 @@ HacknetNode.prototype.calculateCoreUpgradeCost = function() {
//Wrapper function for Netscript //Wrapper function for Netscript
HacknetNode.prototype.getCoreUpgradeCost = function() { HacknetNode.prototype.getCoreUpgradeCost = function() {
return this.calculateCoreUpgradeCost(); let res = this.calculateCoreUpgradeCost();
createPlayerHacknetNodeWrappers();
return res;
} }
HacknetNode.prototype.purchaseCoreUpgrade = function() { HacknetNode.prototype.purchaseCoreUpgrade = function() {
@ -240,7 +246,10 @@ function purchaseHacknet() {
Player.loseMoney(cost); Player.loseMoney(cost);
Player.hacknetNodes.push(node); Player.hacknetNodes.push(node);
if (Engine.currentPage === Engine.Page.HacknetNodes) {
displayHacknetNodesContent(); displayHacknetNodesContent();
}
createPlayerHacknetNodeWrappers();
updateTotalHacknetProduction(); updateTotalHacknetProduction();
return numOwned; return numOwned;
} }

File diff suppressed because it is too large Load Diff

@ -31,8 +31,12 @@ function WorkerScript(runningScriptObj) {
this.delay = null; this.delay = null;
this.fnWorker = null; //Workerscript for a function call this.fnWorker = null; //Workerscript for a function call
this.checkingRam = false; this.checkingRam = false;
this.loadedFns = {}; //Stores names of fns that are "loaded" by this script, thus using RAM this.loadedFns = {}; //Stores names of fns that are "loaded" by this script, thus using RAM. Used for static RAM evaluation
this.disableLogs = {}; //Stores names of fns that should have logs disabled this.disableLogs = {}; //Stores names of fns that should have logs disabled
//Properties used for dynamic RAM evaluation
this.dynamicRamUsage = 1.4;
this.dynamicLoadedFns = {};
} }
//Returns the server on which the workerScript is running //Returns the server on which the workerScript is running