Skip to content

Commit

Permalink
fix: duplicate factory code temporarily to unblock (#5099)
Browse files Browse the repository at this point in the history
A temporary crime against humanity to fix #5094 without making it a pain for @spalladino to finish what he is working on.

The purge files are to be deleted when a cleanup is performed.
  • Loading branch information
LHerskind committed Mar 11, 2024
1 parent 2e2554e commit 8b10600
Show file tree
Hide file tree
Showing 4 changed files with 374 additions and 2 deletions.
3 changes: 2 additions & 1 deletion yarn-project/circuit-types/src/l2_block.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Body, TxEffect, TxHash } from '@aztec/circuit-types';
import { AppendOnlyTreeSnapshot, Header, STRING_ENCODING } from '@aztec/circuits.js';
import { makeAppendOnlyTreeSnapshot, makeHeader } from '@aztec/circuits.js/testing';
import { sha256 } from '@aztec/foundation/crypto';
import { Fr } from '@aztec/foundation/fields';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';

import { makeAppendOnlyTreeSnapshot, makeHeader } from './l2_block_code_to_purge.js';

/**
* The data that makes up the rollup proof, with encoder decoder functions.
*/
Expand Down
101 changes: 101 additions & 0 deletions yarn-project/circuit-types/src/l2_block_code_to_purge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import {
AppendOnlyTreeSnapshot,
AztecAddress,
ContentCommitment,
EthAddress,
Fr,
GlobalVariables,
Header,
NUM_BYTES_PER_SHA256,
PartialStateReference,
StateReference,
} from '@aztec/circuits.js';
import { toBufferBE } from '@aztec/foundation/bigint-buffer';

/**
* Makes header.
*/
export function makeHeader(
seed = 0,
blockNumber: number | undefined = undefined,
txsEffectsHash: Buffer | undefined = undefined,
): Header {
return new Header(
makeAppendOnlyTreeSnapshot(seed + 0x100),
makeContentCommitment(seed + 0x200, txsEffectsHash),
makeStateReference(seed + 0x600),
makeGlobalVariables((seed += 0x700), blockNumber),
);
}

/**
* Makes arbitrary append only tree snapshot.
* @param seed - The seed to use for generating the append only tree snapshot.
* @returns An append only tree snapshot.
*/
export function makeAppendOnlyTreeSnapshot(seed = 1): AppendOnlyTreeSnapshot {
return new AppendOnlyTreeSnapshot(new Fr(seed), seed);
}

/**
* Makes content commitment
*/
function makeContentCommitment(seed = 0, txsEffectsHash: Buffer | undefined = undefined): ContentCommitment {
return new ContentCommitment(
new Fr(seed),
txsEffectsHash ?? toBufferBE(BigInt(seed + 0x100), NUM_BYTES_PER_SHA256),
toBufferBE(BigInt(seed + 0x200), NUM_BYTES_PER_SHA256),
toBufferBE(BigInt(seed + 0x300), NUM_BYTES_PER_SHA256),
);
}

/**
* Makes arbitrary state reference.
* @param seed - The seed to use for generating the state reference.
* @returns A state reference.
*/
function makeStateReference(seed = 0): StateReference {
return new StateReference(makeAppendOnlyTreeSnapshot(seed), makePartialStateReference(seed + 1));
}

/**
* Makes arbitrary partial state reference.
* @param seed - The seed to use for generating the partial state reference.
* @returns A partial state reference.
*/
function makePartialStateReference(seed = 0): PartialStateReference {
return new PartialStateReference(
makeAppendOnlyTreeSnapshot(seed),
makeAppendOnlyTreeSnapshot(seed + 1),
makeAppendOnlyTreeSnapshot(seed + 2),
makeAppendOnlyTreeSnapshot(seed + 3),
);
}

/**
* Makes global variables.
* @param seed - The seed to use for generating the global variables.
* @param blockNumber - The block number to use for generating the global variables.
* If blockNumber is undefined, it will be set to seed + 2.
* @returns Global variables.
*/
export function makeGlobalVariables(seed = 1, blockNumber: number | undefined = undefined): GlobalVariables {
if (blockNumber !== undefined) {
return new GlobalVariables(
new Fr(seed),
new Fr(seed + 1),
new Fr(blockNumber),
new Fr(seed + 3),
EthAddress.fromField(new Fr(seed + 4)),
AztecAddress.fromField(new Fr(seed + 5)),
);
}
return new GlobalVariables(
new Fr(seed),
new Fr(seed + 1),
new Fr(seed + 2),
new Fr(seed + 3),
EthAddress.fromField(new Fr(seed + 4)),
AztecAddress.fromField(new Fr(seed + 5)),
);
}
2 changes: 1 addition & 1 deletion yarn-project/circuit-types/src/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX,
Proof,
} from '@aztec/circuits.js';
import { makePrivateKernelTailCircuitPublicInputs, makePublicCallRequest } from '@aztec/circuits.js/testing';
import { ContractArtifact } from '@aztec/foundation/abi';
import { makeTuple } from '@aztec/foundation/array';
import { times } from '@aztec/foundation/collection';
Expand All @@ -18,6 +17,7 @@ import { ContractInstanceWithAddress, SerializableContractInstance } from '@azte
import { ExtendedContractData } from './contract_data.js';
import { DeployedContract } from './interfaces/index.js';
import { FunctionL2Logs, Note, TxL2Logs } from './logs/index.js';
import { makePrivateKernelTailCircuitPublicInputs, makePublicCallRequest } from './mocks_to_purge.js';
import { ExtendedNote } from './notes/index.js';
import { Tx, TxHash } from './tx/index.js';

Expand Down
Loading

0 comments on commit 8b10600

Please sign in to comment.