Skip to content

Commit

Permalink
Merge pull request #6214 from raymondliu0711/fix/tstore_revert
Browse files Browse the repository at this point in the history
fix(tvm): revert tstore in staticcall
  • Loading branch information
CodeNinjaEvan authored Mar 6, 2025
2 parents 9a70395 + f187e10 commit 7e374ec
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions actuator/src/main/java/org/tron/core/vm/OperationActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,9 @@ public static void tLoadAction(Program program) {
}

public static void tStoreAction(Program program) {
if (program.isStaticCall()) {
throw new Program.StaticCallModificationException();
}
DataWord key = program.stackPop();
DataWord value = program.stackPop();
DataWord address = program.getContractAddress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ public void setOwnerAddress(byte[] ownerAddress) {
this.ownerAddress = Arrays.clone(ownerAddress);
}

public void setStaticCall(boolean isStatic) {
isStaticCall = isStatic;
}

@Override
public boolean isStaticCall() {
return isStaticCall;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,15 @@ public void testTransientStorageOperations() throws ContractValidateException {

// TSTORE = 0x5d;
op = new byte[] {0x60, 0x01, 0x60, 0x01, 0x5d};

invoke.setStaticCall(true);
program = new Program(op, op, invoke, interTrx);
testOperations(program);
Assert.assertEquals(20000, program.getResult().getEnergyUsed());
Assert.assertTrue(program.getResult().getException()
instanceof Program.StaticCallModificationException);

invoke.setStaticCall(false);
program = new Program(op, op, invoke, interTrx);
testOperations(program);
Assert.assertEquals(106, program.getResult().getEnergyUsed());
Expand Down

0 comments on commit 7e374ec

Please sign in to comment.