Skip to content

Commit

Permalink
hack: count 32 line per empty contract
Browse files Browse the repository at this point in the history
  • Loading branch information
delehef committed Dec 7, 2023
1 parent 102fdd3 commit 5e41ce5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public int lineCount() {
for (RomChunk chunk : this.romLex.chunks) {
traceRowSize += chunkRowSize(chunk);
}
return traceRowSize;
return traceRowSize + 32 * this.romLex.emptyContractsCount.stream().mapToInt(x -> x).sum();
}

public int chunkRowSize(RomChunk chunk) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@

import java.math.BigInteger;
import java.nio.MappedByteBuffer;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Deque;
import java.util.List;
import java.util.Optional;

Expand All @@ -50,6 +52,7 @@ public class RomLex implements Module {
public int codeIdentifierBeforeLexOrder = 0;

public final StackedSet<RomChunk> chunks = new StackedSet<>();
public final Deque<Integer> emptyContractsCount = new ArrayDeque<>();
public final List<RomChunk> sortedChunks = new ArrayList<>();
private Bytes byteCode = Bytes.EMPTY;
private Address address = Address.ZERO;
Expand Down Expand Up @@ -90,11 +93,13 @@ public RomLex(Hub hub) {
@Override
public void enterTransaction() {
this.chunks.enter();
this.emptyContractsCount.push(0);
}

@Override
public void popTransaction() {
this.chunks.pop();
this.emptyContractsCount.pop();
}

public int getCFIById(int value) {
Expand Down Expand Up @@ -136,7 +141,7 @@ public void traceStartTx(WorldView worldView, Transaction tx) {
tx.getTo()
.map(worldView::get)
.map(AccountState::getCode)
.ifPresent(
.ifPresentOrElse(
code -> {
codeIdentifierBeforeLexOrder += 1;
int depNumber = hub.conflation().deploymentInfo().number(tx.getTo().get());
Expand All @@ -151,7 +156,8 @@ public void traceStartTx(WorldView worldView, Transaction tx) {
false,
codeIdentifierBeforeLexOrder,
code));
});
},
() -> this.emptyContractsCount.push(this.emptyContractsCount.pop() + 1));
}

@Override
Expand Down Expand Up @@ -208,7 +214,7 @@ public void tracePreOpcode(MessageFrame frame) {
final int depNumber = hub.conflation().deploymentInfo().number(frame.getContractAddress());
Optional.ofNullable(frame.getWorldUpdater().get(calledAddress))
.map(AccountState::getCode)
.ifPresent(
.ifPresentOrElse(
byteCode -> {
codeIdentifierBeforeLexOrder += 1;
this.chunks.add(
Expand All @@ -220,7 +226,8 @@ public void tracePreOpcode(MessageFrame frame) {
false,
codeIdentifierBeforeLexOrder,
byteCode));
});
},
() -> this.emptyContractsCount.push(this.emptyContractsCount.pop() + 1));
}

case EXTCODECOPY -> {
Expand All @@ -234,7 +241,7 @@ public void tracePreOpcode(MessageFrame frame) {
final int depNumber = hub.conflation().deploymentInfo().number(frame.getContractAddress());
Optional.ofNullable(frame.getWorldUpdater().get(calledAddress))
.map(AccountState::getCode)
.ifPresent(
.ifPresentOrElse(
byteCode -> {
if (!byteCode.isEmpty()) {
codeIdentifierBeforeLexOrder += 1;
Expand All @@ -248,7 +255,8 @@ public void tracePreOpcode(MessageFrame frame) {
codeIdentifierBeforeLexOrder,
byteCode));
}
});
},
() -> this.emptyContractsCount.push(this.emptyContractsCount.pop() + 1));
}
}
}
Expand Down

0 comments on commit 5e41ce5

Please sign in to comment.