Skip to content

Commit

Permalink
Move creator address warmup from targetContractAddress generation met…
Browse files Browse the repository at this point in the history
…hod to createe frame (hyperledger#7415)

Signed-off-by: Luis Pinto <luis.pinto@consensys.net>
Signed-off-by: gconnect <agatevureglory@gmail.com>
  • Loading branch information
lu-pinto authored and gconnect committed Aug 26, 2024
1 parent 03fc632 commit ccbfcf9
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,7 @@ public MessageFrame build() {
newTxValues = parentMessageFrame.txValues;
updater = parentMessageFrame.getWorldUpdater().updater();
newStatic = isStatic || parentMessageFrame.isStatic;
parentMessageFrame.warmUpAddress(contract);
}

updater.setAuthorizedCodeService(authorizedCodeService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ protected int getPcIncrement() {
* @param initcode the initcode for the new contract.
* @return the address
*/
protected abstract Address targetContractAddress(MessageFrame frame, Code initcode);
protected abstract Address generateTargetContractAddress(MessageFrame frame, Code initcode);

/**
* Gets the initcode that will be run.
Expand All @@ -175,7 +175,7 @@ private void fail(final MessageFrame frame) {
private void spawnChildMessage(final MessageFrame parent, final Code code, final EVM evm) {
final Wei value = Wei.wrap(parent.getStackItem(0));

final Address contractAddress = targetContractAddress(parent, code);
final Address contractAddress = generateTargetContractAddress(parent, code);
final Bytes inputData = getInputData(parent);

final long childGasStipend =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,11 @@ public long cost(final MessageFrame frame, final Supplier<Code> unused) {
}

@Override
public Address targetContractAddress(final MessageFrame frame, final Code initcode) {
public Address generateTargetContractAddress(final MessageFrame frame, final Code initcode) {
final Address sender = frame.getRecipientAddress();
final Bytes32 salt = Bytes32.leftPad(frame.getStackItem(3));
final Bytes32 hash = keccak256(Bytes.concatenate(PREFIX, sender, salt, initcode.getCodeHash()));
final Address address = Address.extract(hash);
frame.warmUpAddress(address);
return address;
return Address.extract(hash);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,10 @@ public long cost(final MessageFrame frame, final Supplier<Code> unused) {
}

@Override
protected Address targetContractAddress(final MessageFrame frame, final Code initcode) {
protected Address generateTargetContractAddress(final MessageFrame frame, final Code initcode) {
final Account sender = frame.getWorldUpdater().get(frame.getRecipientAddress());
// Decrement nonce by 1 to normalize the effect of transaction execution
final Address address =
Address.contractAddress(frame.getRecipientAddress(), sender.getNonce() - 1L);
frame.warmUpAddress(address);
return address;
return Address.contractAddress(frame.getRecipientAddress(), sender.getNonce() - 1L);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,11 @@ public long cost(final MessageFrame frame, final Supplier<Code> codeSupplier) {
}

@Override
public Address targetContractAddress(final MessageFrame frame, final Code initcode) {
public Address generateTargetContractAddress(final MessageFrame frame, final Code initcode) {
final Address sender = frame.getRecipientAddress();
final Bytes32 salt = Bytes32.leftPad(frame.getStackItem(1));
final Bytes32 hash = keccak256(Bytes.concatenate(PREFIX, sender, salt, initcode.getCodeHash()));
final Address address = Address.extract(hash);
frame.warmUpAddress(address);
return address;
return Address.extract(hash);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public long cost(final MessageFrame frame, final Supplier<Code> unused) {
}

@Override
protected Address targetContractAddress(final MessageFrame frame, final Code initcode) {
protected Address generateTargetContractAddress(final MessageFrame frame, final Code initcode) {
final Account sender = frame.getWorldUpdater().get(frame.getRecipientAddress());
// Decrement nonce by 1 to normalize the effect of transaction execution
final Address address =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void shouldCalculateAddress(
final int ignoredExpectedGas) {
setUp(sender, salt, code);
final Address targetContractAddress =
operation.targetContractAddress(
operation.generateTargetContractAddress(
messageFrame, evm.getCodeUncached(Bytes.fromHexString(code)));
assertThat(targetContractAddress).isEqualTo(Address.fromHexString(expectedAddress));
}
Expand Down

0 comments on commit ccbfcf9

Please sign in to comment.