-
Notifications
You must be signed in to change notification settings - Fork 41
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
feat: make the trace deterministic #1346
Merged
letypequividelespoubelles
merged 5 commits into
arith-dev
from
1345-make-stateless-modules-produce-deterministic-trace
Oct 3, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dd5c4f3
feat: make the trace deterministic
letypequividelespoubelles a5d6a8f
missing modules
letypequividelespoubelles 12bd5de
add missing modules
letypequividelespoubelles fc956e4
address Dave comment
letypequividelespoubelles 1385093
Merge branch 'arith-dev' into 1345-make-stateless-modules-produce-det…
letypequividelespoubelles File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...ization/src/main/java/net/consensys/linea/zktracer/module/add/AddOperationComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright ConsenSys Inc. | ||
* | ||
* 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 net.consensys.linea.zktracer.module.add; | ||
|
||
import java.util.Comparator; | ||
|
||
public class AddOperationComparator implements Comparator<AddOperation> { | ||
public int compare(AddOperation op1, AddOperation op2) { | ||
// First sort by OpCode | ||
final int opCodeComp = op1.opCode().compareTo(op2.opCode()); | ||
if (opCodeComp != 0) { | ||
return opCodeComp; | ||
} | ||
// Second sort by Arg1 | ||
final int arg1Comp = op1.arg1().compareTo(op2.arg1()); | ||
if (arg1Comp != 0) { | ||
return arg1Comp; | ||
} | ||
// Third, sort by Arg2 | ||
return op1.arg2().compareTo(op2.arg2()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...ization/src/main/java/net/consensys/linea/zktracer/module/bin/BinOperationComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright ConsenSys Inc. | ||
* | ||
* 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 net.consensys.linea.zktracer.module.bin; | ||
|
||
import java.util.Comparator; | ||
|
||
public class BinOperationComparator implements Comparator<BinOperation> { | ||
public int compare(BinOperation op1, BinOperation op2) { | ||
// First sort by OpCode | ||
final int opCodeComp = op1.opCode().compareTo(op2.opCode()); | ||
if (opCodeComp != 0) { | ||
return opCodeComp; | ||
} | ||
// Second sort by Arg1 | ||
final int arg1Comp = op1.arg1().getBytes32().compareTo(op2.arg1().getBytes32()); | ||
if (arg1Comp != 0) { | ||
return arg1Comp; | ||
} | ||
// Third, sort by Arg2 | ||
return op1.arg2().getBytes32().compareTo(op2.arg2().getBytes32()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...ization/src/main/java/net/consensys/linea/zktracer/module/euc/EucOperationComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright ConsenSys Inc. | ||
* | ||
* 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 net.consensys.linea.zktracer.module.euc; | ||
|
||
import java.util.Comparator; | ||
|
||
public class EucOperationComparator implements Comparator<EucOperation> { | ||
public int compare(EucOperation op1, EucOperation op2) { | ||
// Second sort by Dividend | ||
final int arg1Comp = op1.dividend().compareTo(op2.dividend()); | ||
if (arg1Comp != 0) { | ||
return arg1Comp; | ||
} else { | ||
// Second, sort by Divisor | ||
return op1.divisor().compareTo(op2.divisor()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...ization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperationComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright ConsenSys Inc. | ||
* | ||
* 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 net.consensys.linea.zktracer.module.exp; | ||
|
||
import java.util.Comparator; | ||
|
||
public class ExpOperationComparator implements Comparator<ExpOperation> { | ||
@Override | ||
public int compare(ExpOperation op1, ExpOperation op2) { | ||
final int instructionComp = | ||
Integer.compare(op1.expCall().expInstruction(), op2.expCall().expInstruction()); | ||
if (instructionComp != 0) { | ||
return instructionComp; | ||
} | ||
|
||
return op1.expCall.compareTo(op2.expCall); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems odd that you've implemented all the
Comparators
separately from the class itself. You can have e.g. doneclass AddOperation extends ModuleOperation implements Comparable<AddOperation>
then added acompareTo()
method as required for the interface. Just saves lines I guess --- not a big deal though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose the reason for doing it this way is to avoid implemented a
Comparator
for allOperation
classes? I think you still could do it though by modifying the signature ofOperationSetModule.sortOperations()
. I'd have to check it worked though --- so not worth bothering!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still, one reason for having
AddOperation
implementComparable<AddOperation>
is that you can then modifyModuleOperationStackedSet
to require that its elements must be sortable like so:That just helps reduce the chance of a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made more consistent. For BlockHash we have to sort before commit time, as we have to trigger WCP.
added