mirror of https://github.com/hyperledger/besu
Add slow parsing detection to EOF layout fuzzing (#7516)
* Add slow parsing validation Add CLI flags and fuzzing logic to enable "slow" parsing to be a loggable error. * picocli final field issue * fix some array boundary issues in pretty print and testing Signed-off-by: Danno Ferrin <danno@numisight.com> Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com> --------- Signed-off-by: Danno Ferrin <danno@numisight.com> Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com> Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>pull/7530/head
parent
c656ece8fc
commit
c0e0103b2b
@ -0,0 +1,65 @@ |
||||
/* |
||||
* Copyright contributors to Hyperledger 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.testfuzz; |
||||
|
||||
import org.hyperledger.besu.evm.Code; |
||||
import org.hyperledger.besu.evm.EVM; |
||||
import org.hyperledger.besu.evm.MainnetEVMs; |
||||
import org.hyperledger.besu.evm.code.CodeInvalid; |
||||
import org.hyperledger.besu.evm.code.CodeV1; |
||||
import org.hyperledger.besu.evm.code.EOFLayout; |
||||
import org.hyperledger.besu.evm.code.EOFLayout.EOFContainerMode; |
||||
import org.hyperledger.besu.evm.internal.EvmConfiguration; |
||||
|
||||
import org.apache.tuweni.bytes.Bytes; |
||||
|
||||
class InternalClient implements FuzzingClient { |
||||
String name; |
||||
final EVM evm; |
||||
|
||||
public InternalClient(final String clientName) { |
||||
this.name = clientName; |
||||
this.evm = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT); |
||||
} |
||||
|
||||
@Override |
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
@Override |
||||
@SuppressWarnings("java:S2142") |
||||
public String differentialFuzz(final String data) { |
||||
try { |
||||
Bytes clientData = Bytes.fromHexString(data); |
||||
Code code = evm.getCodeUncached(clientData); |
||||
if (code.getEofVersion() < 1) { |
||||
return "err: legacy EVM"; |
||||
} else if (!code.isValid()) { |
||||
return "err: " + ((CodeInvalid) code).getInvalidReason(); |
||||
} else { |
||||
EOFLayout layout = ((CodeV1) code).getEofLayout(); |
||||
if (EOFContainerMode.INITCODE.equals(layout.containerMode().get())) { |
||||
return "err: initcode container when runtime mode expected"; |
||||
} |
||||
return "OK %d/%d/%d" |
||||
.formatted( |
||||
layout.getCodeSectionCount(), layout.getSubcontainerCount(), layout.dataLength()); |
||||
} |
||||
} catch (RuntimeException e) { |
||||
return "fail: " + e.getMessage(); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue