Skip to content

Commit

Permalink
fix extCodeCopy mmuCall when empty account (and thus no cfi)
Browse files Browse the repository at this point in the history
Signed-off-by: F Bojarski <[email protected]>
  • Loading branch information
letypequividelespoubelles committed Oct 21, 2024
1 parent 70c7e38 commit d406e26
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall;
import net.consensys.linea.zktracer.module.romlex.ContractMetadata;
import net.consensys.linea.zktracer.types.EWord;
import org.apache.tuweni.bytes.Bytes;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.evm.internal.Words;
import org.hyperledger.besu.evm.worldstate.WorldView;
Expand All @@ -44,8 +45,7 @@ public ExtCodeCopy(final Hub hub) {
final Address foreignCodeAddress = Words.toAddress(hub.messageFrame().getStackItem(0));
this.contract = ContractMetadata.canonical(hub, foreignCodeAddress);

this.exoBytes(Optional.of(hub.romLex().getCodeByMetadata(contract)))
.targetId(hub.currentFrame().contextNumber())
this.targetId(hub.currentFrame().contextNumber())
.targetRamBytes(
Optional.of(
hub.currentFrame()
Expand All @@ -57,12 +57,24 @@ public ExtCodeCopy(final Hub hub) {
.setRom();
}

@Override
public Optional<Bytes> exoBytes() {
try {
return Optional.of(hub.romLex().getCodeByMetadata(contract));
} catch (Exception ignored) {
// Can be empty Bytes in case the ext account is empty. In this case, no associated CFI
return Optional.of(Bytes.EMPTY);
}
}

@Override
public long referenceSize() {
return hub.romLex()
.getChunkByMetadata(contract)
.map(chunk -> chunk.byteCode().size())
.orElse(0);
try {
return (hub.romLex().getCodeByMetadata(contract).size());
} catch (Exception ignored) {
// Can be 0 in case the ext account is empty. In this case, no associated CFI
return 0;
}
}

@Override
Expand Down

0 comments on commit d406e26

Please sign in to comment.