Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add witness tracing #8336

Open
wants to merge 1 commit into
base: verkle
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.datatypes;

import java.util.List;
import java.util.Optional;

import org.apache.tuweni.units.bigints.UInt256;
Expand Down Expand Up @@ -133,4 +134,11 @@ long touchAndChargeValueTransferSelfDestruct(
*/
long touchCodeChunks(
Address address, boolean isContractInDeployment, long offset, long readSize, long codeLength);

/**
* Get all of the access events that constitute accesses to leaves.
*
* @return list of leaf access events.
*/
List<LeafAccessKey> getLeafAccesses();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright contributors to Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.datatypes;

import org.apache.tuweni.units.bigints.UInt256;

/**
* The access event key corresponding to a branch (stem) access in the stateless trie.
*
* @param address address of the account being accessed.
* @param treeIndex stateless trie index of the branch being accessed, also called stem hash.
*/
public record BranchAccessKey(Address address, UInt256 treeIndex) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright contributors to Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.datatypes;

import org.apache.tuweni.units.bigints.UInt256;

/**
* The access event key corresponding to a leaf access in the stateless trie.
*
* @param branchAccessKey key to the stateless trie of the branch being accessed.
* @param leafIndex stateless trie index of the leaf being accessed.
*/
public record LeafAccessKey(BranchAccessKey branchAccessKey, UInt256 leafIndex) {

/**
* Prints a {@code toString()} version suitable printed in JSON format.
*
* @return the string
*/
public String toJsonObject() {
return String.format(
"{\"addr\": \"%s\",\"treeIndex\": \"%s\",\"subIndex\": \"%s\"}",
branchAccessKey.address(),
branchAccessKey.treeIndex().toShortHexString(),
leafIndex.toShortHexString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ protected TraceOptions buildTraceOptions(final Set<TraceTypeParameter.TraceType>
return new TraceOptions(
traceTypes.contains(TraceType.STATE_DIFF),
false,
traceTypes.contains(TraceType.TRACE) || traceTypes.contains(TraceType.VM_TRACE),
traceTypes.contains(TraceType.TRACE) || traceTypes.contains(TraceType.VM_TRACE));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ private TransactionTrace getTransactionTrace(final Block block, final Hash trans
.trace(
mutableWorldState,
block,
new DebugOperationTracer(new TraceOptions(false, false, true), false))
new DebugOperationTracer(
new TraceOptions(false, false, true, false), false))
.map(BlockTrace::getTransactionTraces)
.orElse(Collections.emptyList())
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ protected Object resultByBlockHash(
.trace(
mutableWorldState,
blockHash,
new DebugOperationTracer(new TraceOptions(false, true, true), false))
new DebugOperationTracer(
new TraceOptions(false, true, true, false), false))
.map(BlockTrace::getTransactionTraces)
.orElse(Collections.emptyList())
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected ArrayNodeWrapper traceBlock(

TransactionSource transactionSource = new TransactionSource(block);
DebugOperationTracer debugOperationTracer =
new DebugOperationTracer(new TraceOptions(false, false, true), false);
new DebugOperationTracer(new TraceOptions(false, false, true, false), false);
ExecuteTransactionStep executeTransactionStep =
new ExecuteTransactionStep(
chainUpdater,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private JsonRpcResponse traceFilterWithPipeline(
final ChainUpdater chainUpdater = new ChainUpdater(traceableState);

DebugOperationTracer debugOperationTracer =
new DebugOperationTracer(new TraceOptions(false, false, true), false);
new DebugOperationTracer(new TraceOptions(false, false, true, false), false);
ExecuteTransactionStep executeTransactionStep =
new ExecuteTransactionStep(
chainUpdater,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private ArrayNode traceBlock(final Block block, final TraceTypeParameter traceTy
final TransactionSource transactionSource = new TransactionSource(block);

final DebugOperationTracer debugOperationTracer =
new DebugOperationTracer(new TraceOptions(false, false, true), false);
new DebugOperationTracer(new TraceOptions(false, false, true, false), false);
final ExecuteTransactionStep executeTransactionStep =
new ExecuteTransactionStep(
chainUpdater,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ default boolean disableStack() {
return false;
}

@JsonProperty(value = "disableStatelessWitness")
@Value.Default
default boolean disableStatelessWitness() {
return false;
}

default TraceOptions traceOptions() {
return new TraceOptions(!disableStorage(), !disableMemory(), !disableStack());
return new TraceOptions(
!disableStorage(), !disableMemory(), !disableStack(), !disableStatelessWitness());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ private PrivateTransactionTrace getTransactionTrace(
.trace(
mutableWorldState,
block,
new DebugOperationTracer(new TraceOptions(false, false, true), false),
new DebugOperationTracer(
new TraceOptions(false, false, true, false), false),
enclaveKey,
privacyGroupId,
privateBlockMetadata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public List<String> traceTransactionToFile(
final boolean showMemory =
transactionTraceParams
.map(TransactionTraceParams::traceOptions)
.map(TraceOptions::isMemoryEnabled)
.map(TraceOptions::traceMemory)
.orElse(true);

if (!Files.isDirectory(traceDir) && !traceDir.toFile().mkdirs()) {
Expand Down Expand Up @@ -135,7 +135,7 @@ public List<String> traceTransactionToFile(
stackedUpdater,
transaction,
transactionProcessor,
new StandardJsonTracer(out, showMemory, true, true, false),
new StandardJsonTracer(out, showMemory, true, true, false, true),
blobGasPrice);
out.println(
summaryTrace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results;

import org.hyperledger.besu.datatypes.LeafAccessKey;
import org.hyperledger.besu.ethereum.debug.TraceFrame;

import java.util.Arrays;
Expand All @@ -27,7 +28,17 @@
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;

@JsonPropertyOrder({"pc", "op", "gas", "gasCost", "depth", "stack", "memory", "storage"})
@JsonPropertyOrder({
"pc",
"op",
"gas",
"gasCost",
"depth",
"stack",
"memory",
"storage",
"statelessWitness"
})
public class StructLog {

private final int depth;
Expand All @@ -38,6 +49,7 @@ public class StructLog {
private final int pc;
private final String[] stack;
private final Object storage;
private final String[] statelessWitness;
private final String reason;
static final String bytes32ZeroString = Bytes32.ZERO.toUnprefixedHexString();

Expand All @@ -50,6 +62,11 @@ public StructLog(final TraceFrame traceFrame) {
.getMemory()
.map(a -> Arrays.stream(a).map(Bytes::toUnprefixedHexString).toArray(String[]::new))
.orElse(null);
statelessWitness =
traceFrame
.getStatelessWitness()
.map(list -> list.stream().map(LeafAccessKey::toJsonObject).toArray(String[]::new))
.orElse(null);
op = traceFrame.getOpcode();
pc = traceFrame.getPc();
stack =
Expand Down Expand Up @@ -122,6 +139,11 @@ public Object storage() {
return storage;
}

@JsonGetter("statelessWitness")
public String[] statelessWitness() {
return statelessWitness;
}

@JsonGetter("reason")
public String reason() {
return reason;
Expand All @@ -143,14 +165,16 @@ public boolean equals(final Object o) {
&& Arrays.equals(memory, structLog.memory)
&& Objects.equals(op, structLog.op)
&& Arrays.equals(stack, structLog.stack)
&& Objects.equals(storage, structLog.storage);
&& Objects.equals(storage, structLog.storage)
&& Arrays.equals(statelessWitness, structLog.statelessWitness);
}

@Override
public int hashCode() {
int result = Objects.hash(depth, gas, gasCost, op, pc, storage);
result = 31 * result + Arrays.hashCode(memory);
result = 31 * result + Arrays.hashCode(stack);
result = 31 * result + Arrays.hashCode(statelessWitness);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public void shouldReturnCorrectResponse() {
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
null,
Optional.empty(),
Optional.empty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public void shouldReturnCorrectResponse() {
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
null,
Optional.empty(),
Optional.empty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public void shouldReturnCorrectResponse() {
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
null,
Optional.empty(),
Optional.empty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public void shouldTraceTheTransactionUsingTheTransactionTracer() {
Optional.of(stackBytes),
Optional.of(memoryBytes),
Optional.empty(),
Optional.empty(),
null,
Optional.of(Bytes.fromHexString("0x1122334455667788")),
Optional.empty(),
Expand Down Expand Up @@ -197,6 +198,7 @@ public void shouldNotTraceTheTransactionIfNotFound() {
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
null,
Optional.of(Bytes.fromHexString("0x1122334455667788")),
Optional.empty(),
Expand Down
Loading