Skip to content

Commit

Permalink
feat(avm/brillig)!: revert/rethrow oracle (#9408)
Browse files Browse the repository at this point in the history
This PR introduces a revert oracle to be used when (and only when) rethrowing revertdata in public. The major difference with just doing `assert(false, data)` is that the latter will also add an error selector to the revertdata, which is not something we want when rethrowing.

* Creates a revert oracle to be used for rethrowing.
* Changes TRAP/REVERT to have a runtime size.
  • Loading branch information
fcarreiro authored and AztecBot committed Oct 26, 2024
1 parent 7531f88 commit 02a8199
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions aztec/src/context/public_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,14 @@ unconstrained fn avm_return<let N: u32>(returndata: [Field; N]) {
return_opcode(returndata)
}

// This opcode reverts using the exact data given. In general it should only be used
// to do rethrows, where the revert data is the same as the original revert data.
// For normal reverts, use Noir's `assert` which, on top of reverting, will also add
// an error selector to the revert data.
unconstrained fn avm_revert<let N: u32>(revertdata: [Field]) {
revert_opcode(revertdata)
}

unconstrained fn storage_read(storage_slot: Field) -> Field {
storage_read_opcode(storage_slot)
}
Expand Down Expand Up @@ -378,6 +386,13 @@ unconstrained fn calldata_copy_opcode<let N: u32>(cdoffset: u32, copy_size: u32)
#[oracle(avmOpcodeReturn)]
unconstrained fn return_opcode<let N: u32>(returndata: [Field; N]) {}

// This opcode reverts using the exact data given. In general it should only be used
// to do rethrows, where the revert data is the same as the original revert data.
// For normal reverts, use Noir's `assert` which, on top of reverting, will also add
// an error selector to the revert data.
#[oracle(avmOpcodeRevert)]
unconstrained fn revert_opcode(revertdata: [Field]) {}

#[oracle(avmOpcodeCall)]
unconstrained fn call_opcode<let RET_SIZE: u32>(
gas: [Field; 2], // gas allocation: [l2_gas, da_gas]
Expand Down

0 comments on commit 02a8199

Please sign in to comment.