Skip to content
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(avm): tag checking, raising errors and stop execution #9831

Merged
merged 13 commits into from
Nov 12, 2024

Conversation

jeanmon
Copy link
Contributor

@jeanmon jeanmon commented Nov 8, 2024

Resolves #9745

@jeanmon jeanmon force-pushed the jm/9745-direct-mem-tag-err branch 2 times, most recently from af823d6 to c4789cd Compare November 11, 2024 16:30
@jeanmon jeanmon marked this pull request as ready for review November 11, 2024 16:32
Copy link
Contributor

@dbanks12 dbanks12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I commented with some questions and notes.

In general, I think this is a big step closer to what we want. I do wonder if we could avoid having this error return type and instead let opcodes raise a "reverted" field on the TraceBuilder class. This is similar to how in the simulator opcodes raise context.machineState.reverted. And then at the bottom of the execution loop, we check trace_builder.reverted before continuing?

I don't feel strongly that you need to do it this way, especially not as a prerequisite to merge. BUT it would be a much smaller changeset I think.

I'm also surprised that you can change the tag types in a handful of places without changing brillig generation.

barretenberg/cpp/pil/avm/main.pil Outdated Show resolved Hide resolved
Comment on lines -1698 to +1765
assert(var == EnvironmentVariable::L2GASLEFT || var == EnvironmentVariable::DAGASLEFT);
ASSERT(var == EnvironmentVariable::L2GASLEFT || var == EnvironmentVariable::DAGASLEFT);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the difference?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt bytecode validation will check that the enum value is right. Same holds true about the runtime error thrown in the switch case statement in op_get_env_var. Both should raise error flag without throwing an exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to assert vs. ASSERT: It does not change anything AFAIK, but the latter was usually the adopted style throughout our code base.

It is really an assertion and not error handling because this function is called only from the externally exposed routines: op_l2gasleft() and op_dagasleft

In other words, this is a coding mistake.

Related to op_get_env_var, it is guarded by the first if. the "default" case in the switch is to make the compiler happy but we have the guarantee that it cannot happen. I will add a comment about this.

barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp Outdated Show resolved Hide resolved
barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp Outdated Show resolved Hide resolved
Comment on lines -92 to +90
memory.set(dstOffset + 2, new Field(dest.equals(Point.ZERO) ? 1 : 0));
memory.set(dstOffset + 2, new Uint1(dest.equals(Point.ZERO) ? 1 : 0));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised that we don't need to change Brillig for changes to opcodes like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly ECADD has never been used in brillig.

@jeanmon
Copy link
Contributor Author

jeanmon commented Nov 12, 2024

Nice work! I commented with some questions and notes.

In general, I think this is a big step closer to what we want. I do wonder if we could avoid having this error return type and instead let opcodes raise a "reverted" field on the TraceBuilder class. This is similar to how in the simulator opcodes raise context.machineState.reverted. And then at the bottom of the execution loop, we check trace_builder.reverted before continuing?

I don't feel strongly that you need to do it this way, especially not as a prerequisite to merge. BUT it would be a much smaller changeset I think.

I'm also surprised that you can change the tag types in a handful of places without changing brillig generation.

@dbanks12 True, setting the error/revert in trace_builder and having execution loop checking it at the end of the loop would have been less tedious change. The current change which sets the error at each opcode function call could have been avoided. As we plan a big refactoring in any case, I would not revert this now (especially you mentioned you can live with it.)
.cc @fcarreiro for awareness.

@jeanmon jeanmon merged commit eac5fb5 into master Nov 12, 2024
70 of 71 checks passed
@jeanmon jeanmon deleted the jm/9745-direct-mem-tag-err branch November 12, 2024 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle direct memory tag checks and raise operation error
2 participants