Skip to content

Commit

Permalink
Check for EOFCreate subcontainer rules (hyperledger#7232)
Browse files Browse the repository at this point in the history
Check and test for the unused container rule, and only returncontract
targets can have truncated data rule.
Also test the other subcontainer rules in unit tests.

Signed-off-by: Danno Ferrin <danno@numisight.com>
  • Loading branch information
shemnon authored Jun 20, 2024
1 parent f5e5ad5 commit 3026268
Show file tree
Hide file tree
Showing 5 changed files with 480 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ public class EOFReferenceTestTools {

// TXCREATE still in tests, but has been removed
params.ignore("EOF1_undefined_opcodes_186");

// embedded containers rules changed
params.ignore("EOF1_embedded_container");

// truncated data is only allowed in embedded containers
params.ignore("ori/validInvalid-Prague\\[validInvalid_48\\]");
params.ignore("efExample/validInvalid-Prague\\[validInvalid_1\\]");
params.ignore("efValidation/EOF1_truncated_section-Prague\\[EOF1_truncated_section_3\\]");
params.ignore("efValidation/EOF1_truncated_section-Prague\\[EOF1_truncated_section_4\\]");
params.ignore("EIP3540/validInvalid-Prague\\[validInvalid_2\\]");
params.ignore("EIP3540/validInvalid-Prague\\[validInvalid_3\\]");

// Orphan containers are no longer allowed
params.ignore("efValidation/EOF1_returncontract_valid-Prague\\[EOF1_returncontract_valid_1\\]");
params.ignore("efValidation/EOF1_returncontract_valid-Prague\\[EOF1_returncontract_valid_2\\]");
params.ignore("efValidation/EOF1_eofcreate_valid-Prague\\[EOF1_eofcreate_valid_1\\]");
params.ignore("efValidation/EOF1_eofcreate_valid-Prague\\[EOF1_eofcreate_valid_2\\]");
params.ignore("efValidation/EOF1_section_order-Prague\\[EOF1_section_order_6\\]");
}

private EOFReferenceTestTools() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,25 @@ private CodeV1Validation() {
* @param layout The parsed EOFLayout of the code
* @return either null, indicating no error, or a String describing the validation error.
*/
@SuppressWarnings(
"ReferenceEquality") // comparison `container != layout` is deliberate and correct
public static String validate(final EOFLayout layout) {
Queue<EOFLayout> workList = new ArrayDeque<>(layout.getSubcontainerCount());
workList.add(layout);

while (!workList.isEmpty()) {
EOFLayout container = workList.poll();
workList.addAll(List.of(container.subContainers()));
if (container != layout && container.containerMode().get() == null) {
return "Unreferenced container #" + layout.indexOfSubcontainer(container);
}
if (container.containerMode().get() != RUNTIME
&& container.data().size() != container.dataLength()) {
return "Incomplete data section "
+ (container == layout
? " at root"
: " in container #" + layout.indexOfSubcontainer(container));
}

final String codeValidationError = CodeV1Validation.validateCode(container);
if (codeValidationError != null) {
Expand Down
10 changes: 10 additions & 0 deletions evm/src/main/java/org/hyperledger/besu/evm/code/EOFLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,16 @@ public EOFLayout getSubcontainer(final int i) {
return subContainers[i];
}

/**
* Finds the first instance of the subcontainer in the list of container, or -1 if not present
*
* @param container the container to search for
* @return the index of the container, or -1 if not found.
*/
public int indexOfSubcontainer(final EOFLayout container) {
return Arrays.asList(subContainers).indexOf(container);
}

/**
* Is valid.
*
Expand Down
Loading

0 comments on commit 3026268

Please sign in to comment.