forked from visoftsolutions/noir_rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Canonical instance deployer contract (AztecProtocol#4436)
Implementation for the initial contract instance deployer contract. Tracks instance deployed events in nodes and stores them locally. Skips validations for class id and eth address for now. Fixes AztecProtocol#4071 Fixes AztecProtocol#4072
- Loading branch information
1 parent
34109eb
commit b4acc8c
Showing
21 changed files
with
394 additions
and
17 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
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
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
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
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
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
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
68 changes: 68 additions & 0 deletions
68
yarn-project/circuits.js/src/contract/contract_instance_deployed_event.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,68 @@ | ||
import { toBigIntBE } from '@aztec/foundation/bigint-buffer'; | ||
import { Fr } from '@aztec/foundation/fields'; | ||
import { BufferReader } from '@aztec/foundation/serialize'; | ||
import { ContractInstanceWithAddress } from '@aztec/types/contracts'; | ||
|
||
import { DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE } from '../constants.gen.js'; | ||
import { AztecAddress, EthAddress } from '../index.js'; | ||
|
||
/** Event emitted from the ContractInstanceDeployer. */ | ||
export class ContractInstanceDeployedEvent { | ||
constructor( | ||
public readonly address: AztecAddress, | ||
public readonly version: number, | ||
public readonly salt: Fr, | ||
public readonly contractClassId: Fr, | ||
public readonly initializationHash: Fr, | ||
public readonly portalContractAddress: EthAddress, | ||
public readonly publicKeysHash: Fr, | ||
public readonly universalDeploy: boolean, | ||
) {} | ||
|
||
static isContractInstanceDeployedEvent(log: Buffer) { | ||
return toBigIntBE(log.subarray(0, 32)) == DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE; | ||
} | ||
|
||
static fromLogData(log: Buffer) { | ||
if (!this.isContractInstanceDeployedEvent(log)) { | ||
const magicValue = DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE.toString(16); | ||
throw new Error(`Log data for ContractInstanceDeployedEvent is not prefixed with magic value 0x${magicValue}`); | ||
} | ||
const reader = new BufferReader(log.subarray(32)); | ||
const address = reader.readObject(AztecAddress); | ||
const version = reader.readObject(Fr).toNumber(); | ||
const salt = reader.readObject(Fr); | ||
const contractClassId = reader.readObject(Fr); | ||
const initializationHash = reader.readObject(Fr); | ||
const portalContractAddress = reader.readObject(EthAddress); | ||
const publicKeysHash = reader.readObject(Fr); | ||
const universalDeploy = reader.readObject(Fr).toBool(); | ||
|
||
return new ContractInstanceDeployedEvent( | ||
address, | ||
version, | ||
salt, | ||
contractClassId, | ||
initializationHash, | ||
portalContractAddress, | ||
publicKeysHash, | ||
universalDeploy, | ||
); | ||
} | ||
|
||
toContractInstance(): ContractInstanceWithAddress { | ||
if (this.version !== 1) { | ||
throw new Error(`Unexpected contract instance version ${this.version}`); | ||
} | ||
|
||
return { | ||
address: this.address, | ||
version: this.version, | ||
contractClassId: this.contractClassId, | ||
initializationHash: this.initializationHash, | ||
portalContractAddress: this.portalContractAddress, | ||
publicKeysHash: this.publicKeysHash, | ||
salt: this.salt, | ||
}; | ||
} | ||
} |
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
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.