Skip to content
Closed
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 @@ -35,6 +35,8 @@ public class LogFilter {
@Setter
private Bloom[][] filterBlooms;

private final int maxTopicDepth = 4;
private final int maxSubWidth = 20;

public LogFilter() {
}
Expand All @@ -58,6 +60,9 @@ public LogFilter(FilterRequest fr) throws JsonRpcInvalidParamsException {
String.format("invalid address at index %d: %s", i, s));
}
}
if (addr.size() > maxSubWidth) {
throw new JsonRpcInvalidParamsException("address size should be <= " + maxSubWidth);
}
withContractAddress(addr.toArray(new byte[addr.size()][]));

} else if (fr.getAddress() != null) {
Expand All @@ -66,8 +71,8 @@ public LogFilter(FilterRequest fr) throws JsonRpcInvalidParamsException {

if (fr.getTopics() != null) {
//restrict depth of topics, because event has a signature and most 3 indexed parameters
if (fr.getTopics().length > 4) {
throw new JsonRpcInvalidParamsException("topics size should be <= 4");
if (fr.getTopics().length > maxTopicDepth) {
throw new JsonRpcInvalidParamsException("topics size should be <= " + maxTopicDepth);
}
for (Object topic : fr.getTopics()) {
if (topic == null) {
Expand All @@ -88,6 +93,10 @@ public LogFilter(FilterRequest fr) throws JsonRpcInvalidParamsException {
throw new JsonRpcInvalidParamsException("invalid topic(s): " + s);
}
}
if (t.size() > maxSubWidth) {
throw new JsonRpcInvalidParamsException(
"topic size of one row should be <= " + maxSubWidth);
}
withTopic(t.toArray(new byte[t.size()][]));
} else {
throw new JsonRpcInvalidParamsException("invalid topic(s)");
Expand Down
24 changes: 24 additions & 0 deletions framework/src/test/java/org/tron/core/jsonrpc/JsonRpcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,30 @@ public void testLogFilter() {
} catch (JsonRpcInvalidParamsException e) {
Assert.assertTrue(e.getMessage().contains("invalid address"));
}

//address size should be <= 20
List<String> addresses = new ArrayList<>();
for (int i = 0; i < 100; i++) {
addresses.add("0x1D3005237D6516EA794456BBEE9978B5B7AE491F");
}
try {
new LogFilter(new FilterRequest(null, null, addresses, null, null));
} catch (JsonRpcInvalidParamsException e) {
Assert.assertEquals("address size should be <= 20", e.getMessage());
}

//topic size of one row should be <= 20
List<String> subTopics = new ArrayList<>();
for (int i = 0; i < 100; i++) {
subTopics.add("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef");
}
Object[] topics = new Object[1];
topics[0] = subTopics;
try {
new LogFilter(new FilterRequest(null, null, null, topics, null));
} catch (JsonRpcInvalidParamsException e) {
Assert.assertEquals("topic size of one row should be <= 20", e.getMessage());
}
}

private int[] getBloomIndex(String s) {
Expand Down