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

public-vm(transpiler): generate proper type tags #4268

Closed
Tracked by #3383
dbanks12 opened this issue Jan 29, 2024 · 1 comment · Fixed by #4545
Closed
Tracked by #3383

public-vm(transpiler): generate proper type tags #4268

dbanks12 opened this issue Jan 29, 2024 · 1 comment · Fixed by #4545
Assignees
Labels
avm AVM related tickets (aka public VM)

Comments

@dbanks12
Copy link
Contributor

dbanks12 commented Jan 29, 2024

The following AVM instructions have type tags:

  1. Arithmetic have inTag
  2. Bitwise have inTag
  3. Conditionals have inTag
  4. CAST has dstTag

For 1, 2, and 3, the Brillig instruction is flagged with a bit_size which will likely change to specify one of a few pre-known types (u8, ... u128).

Brillig's BinaryFieldOps can be transpiled to have field tag.

Brillig does not yet have CAST, but should eventually.

@dbanks12 dbanks12 added the avm AVM related tickets (aka public VM) label Jan 29, 2024
@dbanks12 dbanks12 self-assigned this Jan 30, 2024
@dbanks12 dbanks12 changed the title public-vm(transpiler): generate type tags public-vm(transpiler): generate proper type tags Feb 2, 2024
@dbanks12
Copy link
Contributor Author

dbanks12 commented Feb 2, 2024

Can accomplish this without Noir limiting types/sizes by triggering a transpiler error if a BinaryIntOp/Const bit_size is not a standard u8..u128. And just tag the generated instruction according to the bit size.

Blocked by #4385

@fcarreiro fcarreiro assigned fcarreiro and unassigned dbanks12 Feb 8, 2024
fcarreiro added a commit that referenced this issue Feb 12, 2024
Generates tags for
* `BinaryFieldOp`
* `BinaryIntOp`
* `Const` (SET on the AVM)
* CAST on the AVM

Gotcha (1): Brillig seems to only support fields of <= 126 bits. We now support CONST of a field (Brillig) and transpile it to a `SET<u128>` + `CAST<field>`.

It's very difficult to test this e2e in the `avm_test` contract since Noir does a lot of optimizations. Moreover, Noir currently generates code that compares different bit sizes and uses unsupported bit sizes.

As an example
```
#[aztec(public-vm)]
fn setOpcodeUint64() -> pub u64 {
    1 << 60 as u64
}
```

produces (using `nargo compile --package avm_test_contract --show-ssa --print-acir`)

```
Compiled ACIR for AvmTest::avm_setOpcodeUint64 (unoptimized):
current witness index : 0
public parameters indices : []
return value indices : [0]
BRILLIG: inputs: []
outputs: [Simple(Witness(0))]
[Const { destination: MemoryAddress(0), bit_size: 32, value: Value { inner: 1025 } }, CalldataCopy { destination_address: MemoryAddress(1024), size: 0, offset: 0 }, Call { location: 5 }, Mov { destination: MemoryAddress(1024), source: MemoryAddress(2) }, Stop { return_data_offset: 1024, return_data_size: 1 }, Const { destination: MemoryAddress(2), bit_size: 64, value: Value { inner: 2⁶⁰ } }, Mov { destination: MemoryAddress(3), source: MemoryAddress(2) }, Mov { destination: MemoryAddress(2), source: MemoryAddress(3) }, Return]

Initial SSA:
brillig fn avm_setOpcodeUint64 f0 {
  b0():
    call f1()
    return u64 2⁶⁰
}

...
After Dead Instruction Elimination:
brillig fn avm_setOpcodeUint64 f0 {
  b0():
    return u64 2⁶⁰
}
```

Closes #4268.
michaelelliot pushed a commit to Swoir/noir_rs that referenced this issue Feb 28, 2024
…l#4545)

Generates tags for
* `BinaryFieldOp`
* `BinaryIntOp`
* `Const` (SET on the AVM)
* CAST on the AVM

Gotcha (1): Brillig seems to only support fields of <= 126 bits. We now support CONST of a field (Brillig) and transpile it to a `SET<u128>` + `CAST<field>`.

It's very difficult to test this e2e in the `avm_test` contract since Noir does a lot of optimizations. Moreover, Noir currently generates code that compares different bit sizes and uses unsupported bit sizes.

As an example
```
#[aztec(public-vm)]
fn setOpcodeUint64() -> pub u64 {
    1 << 60 as u64
}
```

produces (using `nargo compile --package avm_test_contract --show-ssa --print-acir`)

```
Compiled ACIR for AvmTest::avm_setOpcodeUint64 (unoptimized):
current witness index : 0
public parameters indices : []
return value indices : [0]
BRILLIG: inputs: []
outputs: [Simple(Witness(0))]
[Const { destination: MemoryAddress(0), bit_size: 32, value: Value { inner: 1025 } }, CalldataCopy { destination_address: MemoryAddress(1024), size: 0, offset: 0 }, Call { location: 5 }, Mov { destination: MemoryAddress(1024), source: MemoryAddress(2) }, Stop { return_data_offset: 1024, return_data_size: 1 }, Const { destination: MemoryAddress(2), bit_size: 64, value: Value { inner: 2⁶⁰ } }, Mov { destination: MemoryAddress(3), source: MemoryAddress(2) }, Mov { destination: MemoryAddress(2), source: MemoryAddress(3) }, Return]

Initial SSA:
brillig fn avm_setOpcodeUint64 f0 {
  b0():
    call f1()
    return u64 2⁶⁰
}

...
After Dead Instruction Elimination:
brillig fn avm_setOpcodeUint64 f0 {
  b0():
    return u64 2⁶⁰
}
```

Closes AztecProtocol#4268.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
avm AVM related tickets (aka public VM)
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants