Merge pull request #219 from 8aff8265aa/master_2
Protections must be done before state changes
This commit is contained in:
commit
a232df1998
|
@ -100,6 +100,25 @@ public class TransactionExecutor {
|
|||
return;
|
||||
}
|
||||
|
||||
// GET TOTAL ETHER VALUE AVAILABLE FOR TX FEE
|
||||
BigInteger gasPrice = new BigInteger(1, tx.getGasPrice());
|
||||
BigInteger gasDebit = new BigInteger(1, tx.getGasLimit()).multiply(gasPrice);
|
||||
logger.info("Gas price limited to [{} wei]", gasDebit.toString());
|
||||
|
||||
// Debit the actual total gas value from the sender
|
||||
// the purchased gas will be available for
|
||||
// the contract in the execution state,
|
||||
// it can be retrieved using GAS op
|
||||
BigInteger txValue = new BigInteger(1, tx.getValue());
|
||||
if (track.getBalance(senderAddress).compareTo(gasDebit.add(txValue)) == -1) {
|
||||
logger.debug("No gas to start the execution: sender={}",
|
||||
Hex.toHexString(senderAddress));
|
||||
|
||||
receipt.setCumulativeGas(0);
|
||||
this.receipt = receipt;
|
||||
return;
|
||||
}
|
||||
|
||||
// FIND OUT THE TRANSACTION TYPE
|
||||
final byte[] receiverAddress;
|
||||
final byte[] code;
|
||||
|
@ -122,27 +141,6 @@ public class TransactionExecutor {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// GET TOTAL ETHER VALUE AVAILABLE FOR TX FEE
|
||||
BigInteger gasPrice = new BigInteger(1, tx.getGasPrice());
|
||||
BigInteger gasDebit = new BigInteger(1, tx.getGasLimit()).multiply(gasPrice);
|
||||
logger.info("Gas price limited to [{} wei]", gasDebit.toString());
|
||||
|
||||
// Debit the actual total gas value from the sender
|
||||
// the purchased gas will be available for
|
||||
// the contract in the execution state,
|
||||
// it can be retrieved using GAS op
|
||||
BigInteger txValue = new BigInteger(1, tx.getValue());
|
||||
if (track.getBalance(senderAddress).compareTo(gasDebit.add(txValue)) == -1) {
|
||||
logger.debug("No gas to start the execution: sender={}",
|
||||
Hex.toHexString(senderAddress));
|
||||
|
||||
receipt.setCumulativeGas(0);
|
||||
this.receipt = receipt;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// THE SIMPLE VALUE/BALANCE CHANGE
|
||||
if (track.getBalance(senderAddress).compareTo(txValue) >= 0) {
|
||||
|
||||
|
|
|
@ -322,10 +322,17 @@ public class Program {
|
|||
return;
|
||||
}
|
||||
|
||||
byte[] senderAddress = this.getOwnerAddress().getLast20Bytes();
|
||||
BigInteger endowment = value.value();
|
||||
BigInteger senderBalance = result.getRepository().getBalance(senderAddress);
|
||||
if (senderBalance.compareTo(endowment) < 0) {
|
||||
stackPushZero();
|
||||
return;
|
||||
}
|
||||
|
||||
// [1] FETCH THE CODE FROM THE MEMORY
|
||||
byte[] programCode = memoryChunk(memStart, memSize).array();
|
||||
|
||||
byte[] senderAddress = this.getOwnerAddress().getLast20Bytes();
|
||||
if (logger.isInfoEnabled())
|
||||
logger.info("creating a new contract inside contract run: [{}]", Hex.toHexString(senderAddress));
|
||||
|
||||
|
@ -346,12 +353,6 @@ public class Program {
|
|||
}
|
||||
|
||||
// [4] TRANSFER THE BALANCE
|
||||
BigInteger endowment = value.value();
|
||||
BigInteger senderBalance = result.getRepository().getBalance(senderAddress);
|
||||
if (senderBalance.compareTo(endowment) < 0) {
|
||||
stackPushZero();
|
||||
return;
|
||||
}
|
||||
result.getRepository().addBalance(senderAddress, endowment.negate());
|
||||
BigInteger newBalance = result.getRepository().addBalance(newAddress, endowment);
|
||||
|
||||
|
|
|
@ -44,9 +44,6 @@ public class GitHubStateTest {
|
|||
public void stInitCodeTest() throws ParseException { // [V]
|
||||
|
||||
Set<String> excluded = new HashSet<>();
|
||||
excluded.add("NotEnoughCashContractCreation");
|
||||
excluded.add("CallContractToCreateContractOOG");
|
||||
excluded.add("CallContractToCreateContractNoCash");
|
||||
excluded.add("CallContractToCreateContractWhichWouldCreateContractInInitCode");
|
||||
|
||||
String json = JSONReader.loadJSON("StateTests/stInitCodeTest.json");
|
||||
|
|
Loading…
Reference in New Issue