Skip to content

Commit

Permalink
Merge pull request #980 from rsksmart/remove_codereplace
Browse files Browse the repository at this point in the history
Remove CODEREPLACE opcode
  • Loading branch information
diega authored Oct 17, 2019
2 parents 5ad85ca + a7fe0a8 commit b80eba6
Show file tree
Hide file tree
Showing 10 changed files with 0 additions and 390 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public enum ConsensusRule {
RSKIP90("rskip90"),
RSKIP91("rskip91"),
RSKIP92("rskip92"),
RSKIP94("rskip94"),
RSKIP97("rskip97"),
RSKIP98("rskip98"),
RSKIP103("rskip103"),
Expand Down
1 change: 0 additions & 1 deletion rskj-core/src/main/java/org/ethereum/vm/GasCost.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public class GasCost {
public static final int SLOAD = 200;
public static final int STOP = 0;
public static final int SUICIDE = 5000;
public static final int CODEREPLACE = 15000;
public static final int CLEAR_SSTORE = 5000;
public static final int SET_SSTORE = 20000;
public static final int RESET_SSTORE = 5000;
Expand Down
5 changes: 0 additions & 5 deletions rskj-core/src/main/java/org/ethereum/vm/OpCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -608,11 +608,6 @@ public enum OpCode {
*/
TXINDEX(0xaa, 0, 1, BASE_TIER),

/**
* CODEREPLACE
*/
CODEREPLACE(0xab, 2, 1, SPECIAL_TIER,1), // [in_size] [in_offs] CODEREPLACE -> success

/* System operations */

/**
Expand Down
1 change: 0 additions & 1 deletion rskj-core/src/main/java/org/ethereum/vm/OpCodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,6 @@ private OpCodes() {
static final byte OP_DUPN = (byte)0xa8;
static final byte OP_SWAPN = (byte)0xa9;
static final byte OP_TXINDEX = (byte)0xaa;
static final byte OP_CODEREPLACE =(byte)0xab;

/**
* (0xf0) Create a new account with associated code
Expand Down
54 changes: 0 additions & 54 deletions rskj-core/src/main/java/org/ethereum/vm/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -1632,54 +1632,6 @@ protected void doSUICIDE(){
program.stop();
}

protected void doCODEREPLACE() {

DataWord size;
long newCodeSizeLong;
long newMemSize ;
if (computeGas) {
gasCost = GasCost.CODEREPLACE;
size = stack.get(stack.size() - 2);
newCodeSizeLong = Program.limitToMaxLong(size);
checkSizeArgument(newCodeSizeLong); // max 30 bits
newMemSize = memNeeded(stack.peek(), newCodeSizeLong); // max 30 bits
gasCost += calcMemGas(oldMemSize, newMemSize, 0); // max 32 bits
long oldCodeSize = program.getCode().length;

// If the contract is been created (initialization code is been executed)
// then the meaning of codereplace is less clear. It's better to disallow it.
long storedLength = program.getCodeAt(program.getOwnerAddress()).length;
if (storedLength == 0) { // rise OOG, but a specific exception would be better
throw Program.ExceptionHelper.notEnoughOpGas(op, Long.MAX_VALUE, program.getRemainingGas());
}

// every byte replaced pays REPLACE_DATA
// every byte added pays CREATE_DATA
if (newCodeSizeLong <= oldCodeSize) {
gasCost += GasCost.REPLACE_DATA * newCodeSizeLong; // max 38 bits
} else {
gasCost += GasCost.REPLACE_DATA * oldCodeSize;
gasCost += GasCost.CREATE_DATA * (newCodeSizeLong-oldCodeSize);
}

spendOpCodeGas();
}
// EXECUTION PHASE
DataWord memOffsetData = program.stackPop();
DataWord lengthData = program.stackPop();
byte[] buffer = program.memoryChunk(memOffsetData.intValue(), lengthData.intValue());
int resultInt = program.replaceCode(buffer);

DataWord result = DataWord.valueOf(resultInt);

if (isLogEnabled) {
hint = result.toString();
}

program.stackPush(result);
program.step();
}

protected void executeOpcode() {
// Execute operation
ActivationConfig.ForBlock activations = program.getActivations();
Expand Down Expand Up @@ -1942,12 +1894,6 @@ protected void executeOpcode() {
break;
case OpCodes.OP_SUICIDE: doSUICIDE();
break;
case OpCodes.OP_CODEREPLACE:
if (activations.isActive(RSKIP94)) {
throw Program.ExceptionHelper.invalidOpCode(program.getCurrentOp());
}
doCODEREPLACE();
break;
case OpCodes.OP_DUPN: doDUPN();
break;
case OpCodes.OP_HEADER:
Expand Down
1 change: 0 additions & 1 deletion rskj-core/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ blockchain = {
rskip90 = orchid,
rskip91 = orchid,
rskip92 = orchid,
rskip94 = orchid,
rskip97 = orchid,
rskip98 = orchid,
rskip103 = orchid060,
Expand Down
287 changes: 0 additions & 287 deletions rskj-core/src/test/java/co/rsk/core/CodeReplaceTest.java

This file was deleted.

Loading

0 comments on commit b80eba6

Please sign in to comment.