Skip to content

Commit

Permalink
chore(avm): fix struct serialization and factory (#6903)
Browse files Browse the repository at this point in the history
  • Loading branch information
fcarreiro authored Jun 5, 2024
1 parent acc534c commit bee2646
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions yarn-project/circuits.js/src/structs/avm/avm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,17 @@ export class AvmKeyValueHint {
}

export class AvmExternalCallHint {
public readonly returnData: Vector<Fr>;

/**
* Creates a new instance.
* @param success whether the external call was successful (= did NOT revert).
* @param returnData the data returned by the external call.
* @param gasUsed gas used by the external call (not including the cost of the CALL opcode itself).
*/
constructor(public readonly success: Fr, public readonly returnData: Fr[], public readonly gasUsed: Gas) {}
constructor(public readonly success: Fr, returnData: Fr[], public readonly gasUsed: Gas) {
this.returnData = new Vector(returnData);
}

/**
* Serializes the inputs to a buffer.
Expand All @@ -102,7 +106,7 @@ export class AvmExternalCallHint {
* @returns whether all members are empty.
*/
isEmpty(): boolean {
return this.success.isZero() && this.returnData.length == 0 && this.gasUsed.isEmpty();
return this.success.isZero() && this.returnData.items.length == 0 && this.gasUsed.isEmpty();
}

/**
Expand All @@ -111,7 +115,7 @@ export class AvmExternalCallHint {
* @returns A new AvmHint instance.
*/
static from(fields: FieldsOf<AvmExternalCallHint>): AvmExternalCallHint {
return new AvmExternalCallHint(...AvmExternalCallHint.getFields(fields));
return new AvmExternalCallHint(fields.success, fields.returnData.items, fields.gasUsed);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/circuits.js/src/tests/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ export function makeAvmKeyValueHint(seed = 0): AvmKeyValueHint {
export function makeAvmExternalCallHint(seed = 0): AvmExternalCallHint {
return new AvmExternalCallHint(
new Fr(seed % 2),
makeArray(seed + 10, i => new Fr(i), seed + 0x1000),
makeArray((seed % 100) + 10, i => new Fr(i), seed + 0x1000),
new Gas(seed + 0x200, seed),
);
}
Expand Down Expand Up @@ -1317,8 +1317,8 @@ export function makeAvmExecutionHints(
*/
export function makeAvmCircuitInputs(seed = 0, overrides: Partial<FieldsOf<AvmCircuitInputs>> = {}): AvmCircuitInputs {
return AvmCircuitInputs.from({
bytecode: makeBytes(seed + 100, seed),
calldata: makeArray(seed + 10, i => new Fr(i), seed + 0x1000),
bytecode: makeBytes((seed % 100) + 100, seed),
calldata: makeArray((seed % 100) + 10, i => new Fr(i), seed + 0x1000),
publicInputs: makePublicCircuitPublicInputs(seed + 0x2000),
avmHints: makeAvmExecutionHints(seed + 0x3000),
...overrides,
Expand Down

0 comments on commit bee2646

Please sign in to comment.