From b6dacf68496d48ce5bfeeb368a08553586c96115 Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Mon, 16 Sep 2024 00:06:15 -0700 Subject: [PATCH] fix: add validations to block number params of trace generation and line counting JSON-RPC endpoints (#1191) Signed-off-by: Tsvetan Dimitrov --- .../rpc/counters/CountersRequestParams.java | 8 +++++- .../rpc/counters/GenerateCountersV2.java | 2 +- .../GenerateConflatedTracesV2.java | 2 +- .../tracegeneration/TraceRequestParams.java | 25 ++++++++++++++++--- linea-constraints | 2 +- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/plugins/rpc/counters/CountersRequestParams.java b/arithmetization/src/main/java/net/consensys/linea/plugins/rpc/counters/CountersRequestParams.java index 55dfdf959d..acfb07816c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/plugins/rpc/counters/CountersRequestParams.java +++ b/arithmetization/src/main/java/net/consensys/linea/plugins/rpc/counters/CountersRequestParams.java @@ -21,13 +21,19 @@ /** Holds needed parameters for sending an execution trace generation request. */ public record CountersRequestParams(long blockNumber, String expectedTracesEngineVersion) { - public void validateTracerVersion() { + public void validate() { if (!expectedTracesEngineVersion.equals(getTracerRuntime())) { throw new InvalidParameterException( String.format( "INVALID_TRACES_VERSION: Runtime version is %s, requesting version %s", getTracerRuntime(), expectedTracesEngineVersion)); } + + if (blockNumber < 0) { + throw new InvalidParameterException( + "INVALID_BLOCK_NUMBER: blockNumber: %d cannot be a negative number" + .formatted(blockNumber)); + } } private static String getTracerRuntime() { diff --git a/arithmetization/src/main/java/net/consensys/linea/plugins/rpc/counters/GenerateCountersV2.java b/arithmetization/src/main/java/net/consensys/linea/plugins/rpc/counters/GenerateCountersV2.java index 178f607471..2527b968cc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/plugins/rpc/counters/GenerateCountersV2.java +++ b/arithmetization/src/main/java/net/consensys/linea/plugins/rpc/counters/GenerateCountersV2.java @@ -81,7 +81,7 @@ public Counters execute(final PluginRpcRequest request) { final CountersRequestParams params = CONVERTER.fromJson(CONVERTER.toJson(rawParams[0]), CountersRequestParams.class); - params.validateTracerVersion(); + params.validate(); final long requestedBlockNumber = params.blockNumber(); diff --git a/arithmetization/src/main/java/net/consensys/linea/plugins/rpc/tracegeneration/GenerateConflatedTracesV2.java b/arithmetization/src/main/java/net/consensys/linea/plugins/rpc/tracegeneration/GenerateConflatedTracesV2.java index 5537028bac..bd38037812 100644 --- a/arithmetization/src/main/java/net/consensys/linea/plugins/rpc/tracegeneration/GenerateConflatedTracesV2.java +++ b/arithmetization/src/main/java/net/consensys/linea/plugins/rpc/tracegeneration/GenerateConflatedTracesV2.java @@ -83,7 +83,7 @@ public TraceFile execute(final PluginRpcRequest request) { TraceRequestParams params = CONVERTER.fromJson(CONVERTER.toJson(rawParams[0]), TraceRequestParams.class); - params.validateTracerVersion(); + params.validate(); final long fromBlock = params.startBlockNumber(); final long toBlock = params.endBlockNumber(); diff --git a/arithmetization/src/main/java/net/consensys/linea/plugins/rpc/tracegeneration/TraceRequestParams.java b/arithmetization/src/main/java/net/consensys/linea/plugins/rpc/tracegeneration/TraceRequestParams.java index 20d32574cb..60fc4e822e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/plugins/rpc/tracegeneration/TraceRequestParams.java +++ b/arithmetization/src/main/java/net/consensys/linea/plugins/rpc/tracegeneration/TraceRequestParams.java @@ -23,12 +23,29 @@ public record TraceRequestParams( long startBlockNumber, long endBlockNumber, String expectedTracesEngineVersion) { - public void validateTracerVersion() { + public void validate() { if (!expectedTracesEngineVersion.equals(getTracerRuntime())) { throw new InvalidParameterException( - String.format( - "INVALID_TRACES_VERSION: Runtime version is %s, requesting version %s", - getTracerRuntime(), expectedTracesEngineVersion)); + "INVALID_TRACES_VERSION: Runtime version is %s, requesting version %s" + .formatted(getTracerRuntime(), expectedTracesEngineVersion)); + } + + if (startBlockNumber < 0) { + throw new InvalidParameterException( + "INVALID_START_BLOCK_NUMBER: startBlockNumber: %d cannot be a negative number" + .formatted(startBlockNumber)); + } + + if (endBlockNumber < 0) { + throw new InvalidParameterException( + "INVALID_END_BLOCK_NUMBER: endBlockNumber: %d cannot be a negative number" + .formatted(endBlockNumber)); + } + + if (endBlockNumber - startBlockNumber < 0) { + throw new InvalidParameterException( + "INVALID_END_BLOCK_NUMBER: endBlockNumber: %d cannot be less than startBlockNumber: %d" + .formatted(endBlockNumber, startBlockNumber)); } } diff --git a/linea-constraints b/linea-constraints index e2767c5503..bea9ff5263 160000 --- a/linea-constraints +++ b/linea-constraints @@ -1 +1 @@ -Subproject commit e2767c5503953e8934eeb1381dd74f146ed7c921 +Subproject commit bea9ff52638ac0bf495aea3d0acc0b5a72433791