Skip to content

Commit

Permalink
rename reverted to revertCode
Browse files Browse the repository at this point in the history
  • Loading branch information
just-mitch committed Mar 19, 2024
1 parent fa55d79 commit 474978e
Show file tree
Hide file tree
Showing 34 changed files with 213 additions and 115 deletions.
22 changes: 11 additions & 11 deletions l1-contracts/slither_output.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,41 +50,34 @@ src/core/Rollup.sol#L57-L96
Impact: Medium
Confidence: High
- [ ] ID-4
Dubious typecast in [TxsDecoder.decode(bytes)](src/core/libraries/decoders/TxsDecoder.sol#L78-L192):
bytes => bytes32 casting occurs in [vars.baseLeaf = bytes.concat(bytes32(slice(_body,offsets.reverted,0x20)),bytes.concat(sliceAndPad(_body,offsets.noteHash,counts.noteHash * 0x20,Constants.NOTE_HASHES_NUM_BYTES_PER_BASE_ROLLUP),sliceAndPad(_body,offsets.nullifier,counts.nullifier * 0x20,Constants.NULLIFIERS_NUM_BYTES_PER_BASE_ROLLUP),sliceAndPad(_body,offsets.l2ToL1Msgs,counts.l2ToL1Msgs * 0x20,Constants.L2_TO_L1_MSGS_NUM_BYTES_PER_BASE_ROLLUP),sliceAndPad(_body,offsets.publicData,counts.publicData * 0x40,Constants.PUBLIC_DATA_WRITES_NUM_BYTES_PER_BASE_ROLLUP)),bytes.concat(vars.encryptedLogsHash,vars.unencryptedLogsHash))](src/core/libraries/decoders/TxsDecoder.sol#L156-L185)

src/core/libraries/decoders/TxsDecoder.sol#L78-L192


- [ ] ID-5
Dubious typecast in [MessagesDecoder.read4(bytes,uint256)](src/core/libraries/decoders/MessagesDecoder.sol#L164-L166):
bytes => bytes4 casting occurs in [uint256(uint32(bytes4(_data)))](src/core/libraries/decoders/MessagesDecoder.sol#L165)

src/core/libraries/decoders/MessagesDecoder.sol#L164-L166


- [ ] ID-6
- [ ] ID-5
Dubious typecast in [Outbox.sendL1Messages(bytes32[])](src/core/messagebridge/Outbox.sol#L38-L46):
uint256 => uint32 casting occurs in [version = uint32(REGISTRY.getVersionFor(msg.sender))](src/core/messagebridge/Outbox.sol#L40)

src/core/messagebridge/Outbox.sol#L38-L46


- [ ] ID-7
- [ ] ID-6
Dubious typecast in [TxsDecoder.read1(bytes,uint256)](src/core/libraries/decoders/TxsDecoder.sol#L322-L324):
bytes => bytes1 casting occurs in [uint256(uint8(bytes1(slice(_data,_offset,1))))](src/core/libraries/decoders/TxsDecoder.sol#L323)

src/core/libraries/decoders/TxsDecoder.sol#L322-L324


- [ ] ID-8
- [ ] ID-7
Dubious typecast in [TxsDecoder.read4(bytes,uint256)](src/core/libraries/decoders/TxsDecoder.sol#L332-L334):
bytes => bytes4 casting occurs in [uint256(uint32(bytes4(slice(_data,_offset,4))))](src/core/libraries/decoders/TxsDecoder.sol#L333)

src/core/libraries/decoders/TxsDecoder.sol#L332-L334


- [ ] ID-9
- [ ] ID-8
Dubious typecast in [HeaderLib.decode(bytes)](src/core/libraries/HeaderLib.sol#L143-L184):
bytes => bytes32 casting occurs in [header.lastArchive = AppendOnlyTreeSnapshot(bytes32(_header),uint32(bytes4(_header)))](src/core/libraries/HeaderLib.sol#L151-L153)
bytes => bytes4 casting occurs in [header.lastArchive = AppendOnlyTreeSnapshot(bytes32(_header),uint32(bytes4(_header)))](src/core/libraries/HeaderLib.sol#L151-L153)
Expand All @@ -110,6 +103,13 @@ Dubious typecast in [HeaderLib.decode(bytes)](src/core/libraries/HeaderLib.sol#L
src/core/libraries/HeaderLib.sol#L143-L184


- [ ] ID-9
Dubious typecast in [TxsDecoder.decode(bytes)](src/core/libraries/decoders/TxsDecoder.sol#L78-L192):
bytes => bytes32 casting occurs in [vars.baseLeaf = bytes.concat(bytes32(slice(_body,offsets.revertCode,0x20)),bytes.concat(sliceAndPad(_body,offsets.noteHash,counts.noteHash * 0x20,Constants.NOTE_HASHES_NUM_BYTES_PER_BASE_ROLLUP),sliceAndPad(_body,offsets.nullifier,counts.nullifier * 0x20,Constants.NULLIFIERS_NUM_BYTES_PER_BASE_ROLLUP),sliceAndPad(_body,offsets.l2ToL1Msgs,counts.l2ToL1Msgs * 0x20,Constants.L2_TO_L1_MSGS_NUM_BYTES_PER_BASE_ROLLUP),sliceAndPad(_body,offsets.publicData,counts.publicData * 0x40,Constants.PUBLIC_DATA_WRITES_NUM_BYTES_PER_BASE_ROLLUP)),bytes.concat(vars.encryptedLogsHash,vars.unencryptedLogsHash))](src/core/libraries/decoders/TxsDecoder.sol#L156-L185)

src/core/libraries/decoders/TxsDecoder.sol#L78-L192


- [ ] ID-10
Dubious typecast in [MessagesDecoder.read1(bytes,uint256)](src/core/libraries/decoders/MessagesDecoder.sol#L154-L156):
bytes => bytes1 casting occurs in [uint256(uint8(bytes1(_data)))](src/core/libraries/decoders/MessagesDecoder.sol#L155)
Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/src/core/libraries/decoders/MessagesDecoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {Hash} from "../Hash.sol";
* | 0x4 | a * 0x20 | newL1ToL2Msgs
* | 0x4 + a * 0x20 = tx0Start | 0x4 | len(numTxs) (denoted t)
* | | | TxEffect 0 {
* | tx0Start | 0x20 | reverted
* | tx0Start | 0x20 | revertCode
* | tx0Start + 0x20 | 0x1 | len(newNoteHashes) (denoted b)
* | tx0Start + 0x20 + 0x1 | b * 0x20 | newNoteHashes
* | tx0Start + 0x20 + 0x1 + b * 0x20 | 0x1 | len(newNullifiers) (denoted c)
Expand Down Expand Up @@ -90,7 +90,7 @@ library MessagesDecoder {

// Now we iterate over the tx effects
for (uint256 i = 0; i < numTxs; i++) {
// reverted
// revertCode
offset += 0x20;

// Note hashes
Expand Down
12 changes: 6 additions & 6 deletions l1-contracts/src/core/libraries/decoders/TxsDecoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {Hash} from "../Hash.sol";
* | 0x4 | a * 0x20 | newL1ToL2Msgs
* | 0x4 + a * 0x20 = tx0Start | 0x4 | len(numTxs) (denoted t)
* | | | TxEffect 0 {
* | tx0Start | 0x20 | reverted
* | tx0Start | 0x20 | revertCode
* | tx0Start + 0x20 | 0x1 | len(newNoteHashes) (denoted b)
* | tx0Start + 0x20 + 0x1 | b * 0x20 | newNoteHashes
* | tx0Start + 0x20 + 0x1 + b * 0x20 | 0x1 | len(newNullifiers) (denoted c)
Expand All @@ -48,7 +48,7 @@ import {Hash} from "../Hash.sol";
*/
library TxsDecoder {
struct ArrayOffsets {
uint256 reverted;
uint256 revertCode;
uint256 noteHash;
uint256 nullifier;
uint256 l2ToL1Msgs;
Expand Down Expand Up @@ -98,7 +98,7 @@ library TxsDecoder {
/*
* Compute the leaf to insert.
* Leaf_i = (
* reverted,
* revertCode,
* newNoteHashesKernel,
* newNullifiersKernel,
* newPublicDataWritesKernel,
Expand All @@ -113,8 +113,8 @@ library TxsDecoder {
* Zero values.
*/

// Reverted flag
offsets.reverted = offset;
// Revert Code
offsets.revertCode = offset;
offset += 0x20;

// Note hashes
Expand Down Expand Up @@ -154,7 +154,7 @@ library TxsDecoder {

// Insertions are split into multiple `bytes.concat` to work around stack too deep.
vars.baseLeaf = bytes.concat(
bytes32(slice(_body, offsets.reverted, 0x20)),
bytes32(slice(_body, offsets.revertCode, 0x20)),
bytes.concat(
sliceAndPad(
_body,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ impl PrivateContext {
unencrypted_log_preimages_length: 0,
historical_header: Header::empty(),
prover_address: AztecAddress::zero(),
reverted: 0
revert_code: 0
},
is_execution_request: true
};
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/context/public_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl PublicContext {
unencrypted_log_preimages_length,
historical_header: self.inputs.historical_header,
prover_address: self.prover_address,
reverted: 0
revert_code: 0
};
pub_circuit_pub_inputs
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ pub fn validate_inputs(public_call: PublicCallData) {
}

pub fn validate_public_call_non_revert(public_call: PublicCallData) {
assert(public_call.call_stack_item.public_inputs.reverted == 0, "Public call cannot be reverted");
assert(public_call.call_stack_item.public_inputs.revert_code == 0, "Public call cannot be reverted");
}

pub fn initialize_reverted_flag(
pub fn initialize_revert_code(
previous_kernel: PublicKernelData,
public_call: PublicCallData,
circuit_outputs: &mut PublicKernelCircuitPublicInputsBuilder
) {
if previous_kernel.public_inputs.end_non_revertible.reverted != 0 {
circuit_outputs.end_non_revertible.reverted = previous_kernel.public_inputs.end_non_revertible.reverted;
} else if public_call.call_stack_item.public_inputs.reverted != 0 {
circuit_outputs.end_non_revertible.reverted = public_call.call_stack_item.public_inputs.reverted;
if previous_kernel.public_inputs.end_non_revertible.revert_code != 0 {
circuit_outputs.end_non_revertible.revert_code = previous_kernel.public_inputs.end_non_revertible.revert_code;
} else if public_call.call_stack_item.public_inputs.revert_code != 0 {
circuit_outputs.end_non_revertible.revert_code = public_call.call_stack_item.public_inputs.revert_code;
}
}

Expand All @@ -59,7 +59,7 @@ pub fn initialize_emitted_end_values(
) {
circuit_outputs.constants = previous_kernel.public_inputs.constants;

if circuit_outputs.end_non_revertible.reverted == 0 {
if circuit_outputs.end_non_revertible.revert_code == 0 {
let start = previous_kernel.public_inputs.end;
circuit_outputs.end.new_note_hashes = array_to_bounded_vec(start.new_note_hashes);
circuit_outputs.end.new_nullifiers = array_to_bounded_vec(start.new_nullifiers);
Expand Down Expand Up @@ -89,7 +89,7 @@ pub fn initialize_end_values(
) {
initialize_emitted_end_values(previous_kernel, circuit_outputs);

if circuit_outputs.end_non_revertible.reverted == 0 {
if circuit_outputs.end_non_revertible.revert_code == 0 {
let start = previous_kernel.public_inputs.end;
// circuit_outputs.end.private_call_stack = array_to_bounded_vec(start.private_call_stack); // This is enforced in the private tail to always be empty.
circuit_outputs.end.public_call_stack = array_to_bounded_vec(start.public_call_stack);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl PublicKernelAppLogicCircuitPrivateInputs {
fn public_kernel_app_logic(self) -> PublicKernelCircuitPublicInputs {
// construct the circuit outputs
let mut public_inputs: PublicKernelCircuitPublicInputsBuilder = unsafe::zeroed();
common::initialize_reverted_flag(self.previous_kernel, self.public_call, &mut public_inputs);
common::initialize_revert_code(self.previous_kernel, self.public_call, &mut public_inputs);

// initialise the end state with our provided previous kernel state
common::initialize_end_values(self.previous_kernel, &mut public_inputs);
Expand All @@ -36,7 +36,7 @@ impl PublicKernelAppLogicCircuitPrivateInputs {

common::update_validation_requests(self.public_call, &mut public_inputs);

if public_inputs.end_non_revertible.reverted == 0 {
if public_inputs.end_non_revertible.revert_code == 0 {
// Pops the item from the call stack and validates it against the current execution.
let call_request = public_inputs.end.public_call_stack.pop();
common::validate_call_against_request(self.public_call, call_request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl PublicKernelSetupCircuitPrivateInputs {
let mut public_inputs: PublicKernelCircuitPublicInputsBuilder = unsafe::zeroed();
// since this phase is non-revertible, we must assert the public call did not revert
common::validate_public_call_non_revert(self.public_call);
common::initialize_reverted_flag(self.previous_kernel, self.public_call, &mut public_inputs);
common::initialize_revert_code(self.previous_kernel, self.public_call, &mut public_inputs);

// initialise the end state with our provided previous kernel state
common::initialize_end_values(self.previous_kernel, &mut public_inputs);
Expand Down Expand Up @@ -507,7 +507,7 @@ mod tests {
#[test(should_fail_with="Public call cannot be reverted")]
fn fails_if_public_call_reverted() {
let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new();
builder.public_call.public_inputs.reverted = 1;
builder.public_call.public_inputs.revert_code = 1;

builder.failed();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ struct PublicKernelTailCircuitPrivateInputs {
}

impl PublicKernelTailCircuitPrivateInputs {
fn propagate_reverted_flag(self, public_inputs: &mut PublicKernelCircuitPublicInputsBuilder) {
public_inputs.end_non_revertible.reverted = self.previous_kernel.public_inputs.end_non_revertible.reverted;
fn propagate_revert_code(self, public_inputs: &mut PublicKernelCircuitPublicInputsBuilder) {
public_inputs.end_non_revertible.revert_code = self.previous_kernel.public_inputs.end_non_revertible.revert_code;
}

fn validate_inputs(self) {
Expand Down Expand Up @@ -105,7 +105,7 @@ impl PublicKernelTailCircuitPrivateInputs {

self.validate_inputs();

self.propagate_reverted_flag(&mut public_inputs);
self.propagate_revert_code(&mut public_inputs);

common::initialize_emitted_end_values(self.previous_kernel, &mut public_inputs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl PublicKernelTeardownCircuitPrivateInputs {
let mut public_inputs: PublicKernelCircuitPublicInputsBuilder = unsafe::zeroed();
// since this phase is non-revertible, we must assert the public call did not revert
common::validate_public_call_non_revert(self.public_call);
common::initialize_reverted_flag(self.previous_kernel, self.public_call, &mut public_inputs);
common::initialize_revert_code(self.previous_kernel, self.public_call, &mut public_inputs);

// initialise the end state with our provided previous kernel state
common::initialize_end_values(self.previous_kernel, &mut public_inputs);
Expand All @@ -47,7 +47,7 @@ impl PublicKernelTeardownCircuitPrivateInputs {

common::update_public_end_non_revertible_values(self.public_call, &mut public_inputs);

if public_inputs.end_non_revertible.reverted == 0 {
if public_inputs.end_non_revertible.revert_code == 0 {
common::accumulate_unencrypted_logs(
self.public_call,
self.previous_kernel.public_inputs.end.unencrypted_logs_hash,
Expand Down Expand Up @@ -374,7 +374,7 @@ mod tests {
#[test(should_fail_with="Public call cannot be reverted")]
fn fails_if_public_call_reverted() {
let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new();
builder.public_call.public_inputs.reverted = 1;
builder.public_call.public_inputs.revert_code = 1;

builder.failed();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub fn compute_tx_effects_hash(combined: CombinedAccumulatedData) -> [Field; NUM
// 1 unencrypted logs hash --> 1 sha256 hash -> 32 bytes -> 2 fields | Beware when populating bytes that it is only 32!
let mut txs_effects_hash_input = [0; TX_EFFECTS_HASH_INPUT_FIELDS];

let reverted = combined.reverted;
let revert_code = combined.revert_code;
let new_note_hashes = combined.new_note_hashes;
let new_nullifiers = combined.new_nullifiers;
let newL2ToL1msgs = combined.new_l2_to_l1_msgs;
Expand All @@ -156,7 +156,7 @@ pub fn compute_tx_effects_hash(combined: CombinedAccumulatedData) -> [Field; NUM

let mut offset = 0;

txs_effects_hash_input[offset] = reverted;
txs_effects_hash_input[offset] = revert_code;
offset += 1;

for j in 0..MAX_NEW_NOTE_HASHES_PER_TX {
Expand Down Expand Up @@ -216,7 +216,7 @@ pub fn compute_tx_effects_hash(combined: CombinedAccumulatedData) -> [Field; NUM

#[test]
fn consistent_TX_EFFECTS_HASH_INPUT_FIELDS() {
// 1 for reverted
// 1 for revert_code
let expected_size = 1
+ MAX_NEW_NOTE_HASHES_PER_TX
+ MAX_NEW_NULLIFIERS_PER_TX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::constants::{
};

struct AccumulatedNonRevertibleDataBuilder {
reverted: Field,
revert_code: Field,

new_note_hashes: BoundedVec<SideEffect, MAX_NON_REVERTIBLE_NOTE_HASHES_PER_TX>,
new_nullifiers: BoundedVec<SideEffectLinkedToNoteHash, MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX>,
Expand All @@ -27,15 +27,15 @@ struct AccumulatedNonRevertibleDataBuilder {
impl AccumulatedNonRevertibleDataBuilder {
pub fn to_private(self) -> PrivateAccumulatedNonRevertibleData {
PrivateAccumulatedNonRevertibleData {
reverted: self.reverted,
revert_code: self.revert_code,
new_note_hashes: self.new_note_hashes.storage,
new_nullifiers: self.new_nullifiers.storage,
public_call_stack: self.public_call_stack.storage
}
}
pub fn to_public(self) -> PublicAccumulatedNonRevertibleData {
PublicAccumulatedNonRevertibleData {
reverted: self.reverted,
revert_code: self.revert_code,
new_note_hashes: self.new_note_hashes.storage,
new_nullifiers: self.new_nullifiers.storage,
public_call_stack: self.public_call_stack.storage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::traits::is_empty;
use crate::utils::arrays::{array_cp, array_concat, array_to_bounded_vec};

struct CombinedAccumulatedData {
reverted: Field,
revert_code: Field,

new_note_hashes: [SideEffect; MAX_NEW_NOTE_HASHES_PER_TX],
new_nullifiers: [SideEffectLinkedToNoteHash; MAX_NEW_NULLIFIERS_PER_TX],
Expand Down Expand Up @@ -52,7 +52,7 @@ impl CombinedAccumulatedData {
revertible: PublicAccumulatedRevertibleData
) -> CombinedAccumulatedData {
CombinedAccumulatedData {
reverted: non_revertible.reverted,
revert_code: non_revertible.revert_code,
new_note_hashes: array_concat(non_revertible.new_note_hashes, revertible.new_note_hashes),
new_nullifiers: array_concat(non_revertible.new_nullifiers, revertible.new_nullifiers),
private_call_stack: revertible.private_call_stack,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::traits::is_empty;
use crate::utils::arrays::{array_cp, array_concat, array_to_bounded_vec};

struct CombinedAccumulatedDataBuilder {
reverted: Field,
revert_code: Field,

new_note_hashes: BoundedVec<SideEffect, MAX_NEW_NOTE_HASHES_PER_TX>,
new_nullifiers: BoundedVec<SideEffectLinkedToNoteHash, MAX_NEW_NULLIFIERS_PER_TX>,
Expand All @@ -51,7 +51,7 @@ impl CombinedAccumulatedDataBuilder {
revertible: PublicAccumulatedRevertibleData
) -> CombinedAccumulatedDataBuilder {
CombinedAccumulatedDataBuilder {
reverted: non_revertible.reverted,
revert_code: non_revertible.revert_code,
new_note_hashes: array_to_bounded_vec(array_concat(non_revertible.new_note_hashes, revertible.new_note_hashes)),
new_nullifiers: array_to_bounded_vec(array_concat(non_revertible.new_nullifiers, revertible.new_nullifiers)),
private_call_stack: array_to_bounded_vec(revertible.private_call_stack),
Expand All @@ -77,7 +77,7 @@ impl CombinedAccumulatedDataBuilder {

pub fn finish(self) -> CombinedAccumulatedData {
CombinedAccumulatedData {
reverted: self.reverted,
revert_code: self.revert_code,
new_note_hashes: self.new_note_hashes.storage,
new_nullifiers: self.new_nullifiers.storage,
private_call_stack: self.private_call_stack.storage,
Expand Down
Loading

0 comments on commit 474978e

Please sign in to comment.