-
Notifications
You must be signed in to change notification settings - Fork 43
Adarsh/per decorator #479
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
base: master
Are you sure you want to change the base?
Adarsh/per decorator #479
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -495,26 +495,77 @@ class BoilerplateGenerator { | |
| ]; | ||
| }, | ||
|
|
||
| parameters({ mappingKeyName: k, mappingKeyTypeName: t }): string[] { | ||
| if (t === 'local') return []; | ||
| return [ | ||
| `private ${t ? t : 'field'} ${k}`, // must be a field, in case we need to do arithmetic on it. | ||
| ]; | ||
| /** | ||
| * Generate circuit parameters for mapping | ||
| * Includes domain parameters if present | ||
| */ | ||
| parameters({ mappingKeyName: k, mappingKeyTypeName: t, perParameters = [] }): string[] { | ||
| const params: string[] = []; | ||
|
|
||
| // Add domain parameters as private inputs | ||
| for (const domainParam of perParameters) { | ||
| params.push(`private field ${domainParam.name}`); | ||
| } | ||
|
|
||
| // Add mapping key parameter | ||
| if (t !== 'local') { | ||
| params.push(`private ${t ? t : 'field'} ${k}`); | ||
| } | ||
|
|
||
| return params; | ||
| }, | ||
|
|
||
| preStatements({ id: mappingId, mappingName: m }): string[] { | ||
| return [ | ||
| /** | ||
| * Generate pre-statements for mapping | ||
| * Includes domain parameter hashing if present | ||
| */ | ||
| preStatements({ id: mappingId, mappingName: m, perParameters = [] }): string[] { | ||
| const statements: string[] = [ | ||
| ` | ||
| // We need to hard-code the mappingId's of mappings into the circuit: | ||
| field ${m}_mappingId = ${mappingId};`, | ||
| ]; | ||
|
|
||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe just fix the indenting here |
||
| // Generate chained MiMC hashing for domain parameters | ||
| if (perParameters.length > 0) { | ||
| let currentHash = `${m}_mappingId`; | ||
|
|
||
| for (let i = 0; i < perParameters.length; i++) { | ||
| const domainParam = perParameters[i]; | ||
| const nextHashVar = `${m}_perHash_${i}`; | ||
|
|
||
| statements.push( | ||
| ` | ||
| // Chain domain parameter: ${domainParam.name} | ||
| field ${nextHashVar} = mimc2([${currentHash}, ${domainParam.name}]);`, | ||
| ); | ||
|
|
||
| currentHash = nextHashVar; | ||
| } | ||
|
|
||
| statements.push( | ||
| ` | ||
| // Final domain-chained hash | ||
| field ${m}_domainChainedId = ${currentHash};`, | ||
| ); | ||
| } | ||
|
|
||
| return statements; | ||
| }, | ||
|
|
||
| postStatements({ name: x, mappingName: m, mappingKeyName: k }): string[] { | ||
| // const x = `${m}_${k}`; | ||
| /** | ||
| * Generate post-statements for mapping | ||
| * Calculates final stateVarId with domain parameter support | ||
| */ | ||
| postStatements({ name: x, mappingName: m, mappingKeyName: k, perParameters = [] }): string[] { | ||
| // Use chained hash if domain parameters exist, otherwise use mappingId | ||
| const baseId = perParameters.length > 0 | ||
| ? `${m}_domainChainedId` | ||
| : `${m}_mappingId`; | ||
|
|
||
| return [ | ||
| ` | ||
| field ${x}_stateVarId_field = mimc2([${m}_mappingId, ${k}]);`, | ||
| field ${x}_stateVarId_field = mimc2([${baseId}, ${k}]);`, | ||
| ]; | ||
| }, | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,7 +80,13 @@ export async function getContractInstance(contractName, deployedAddress) { | |
|
|
||
| export async function getContractBytecode(contractName) { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this change necessary? |
||
| const contractInterface = await getContractInterface(contractName); | ||
| return contractInterface.evm.bytecode.object; | ||
| // Support both Hardhat format (bytecode) and Truffle/Solc format (evm.bytecode.object) | ||
| if (contractInterface.bytecode) { | ||
| return contractInterface.bytecode; | ||
| } else if (contractInterface.evm?.bytecode?.object) { | ||
| return contractInterface.evm.bytecode.object; | ||
| } | ||
| throw new Error(`Bytecode not found for contract ${contractName}`); | ||
| } | ||
|
|
||
| export async function deploy( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,11 +48,15 @@ function saveMetadata ( | |
| // console.log("hardhatArtifactPath: ", hardhatArtifactPath); | ||
|
|
||
| const compilationData = fs.readFileSync(hardhatArtifactPath, 'utf-8') | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are these changes necessary? |
||
| const abi = JSON.parse(compilationData).abi | ||
| const contractNameFromHardhat = JSON.parse(compilationData).contractName | ||
| const compiledContract = JSON.parse(compilationData) | ||
| const abi = compiledContract.abi | ||
| const contractNameFromHardhat = compiledContract.contractName | ||
| const bytecode = compiledContract.bytecode | ||
|
|
||
| deployedMetadata.abi = abi | ||
| deployedMetadata.contractName = contractNameFromHardhat | ||
| // Save bytecode for runtime deployment (needed for deployNFT endpoint) | ||
| deployedMetadata.bytecode = bytecode | ||
| deployedPositionMetadata.address = contractDeployedAddress | ||
| deployedPositionMetadata.blockNumber = blockNumber | ||
| deployedPositionMetadata.transactionHash = transactionHash | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for the merge into Starlight, this file could be deleted?