-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: duplicate factory code temporarily to unblock (#5099)
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
Showing
4 changed files
with
374 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
yarn-project/circuit-types/src/l2_block_code_to_purge.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.