Skip to content

Instantly share code, notes, and snippets.

@Wizard1209
Created January 22, 2026 04:06
Show Gist options
  • Select an option

  • Save Wizard1209/d97ed4005e999349f675996fb7cd22d8 to your computer and use it in GitHub Desktop.

Select an option

Save Wizard1209/d97ed4005e999349f675996fb7cd22d8 to your computer and use it in GitHub Desktop.
test-classid-mismatch.mjs
/**
* Test manual bytecode conversion
*
* This script demonstrates that registry artifacts have correct data,
* but bytecode is stored as base64 string instead of Buffer.
* Converting base64 back to Buffer fixes the classId computation.
*
* HOW TO RUN:
* node scripts/test-classid-mismatch.mjs
*
* EXPECTED OUTPUT:
* All classIds should match (✅) after manual bytecode restoration
*/
import { readFileSync } from 'fs';
import { join } from 'path';
const LOCAL_FILE = 'example_contracts/pod_racing_contract-PodRacing.json';
const REGISTRY_URL = 'https://devnet.aztec-registry.xyz';
const TEST_CLASS_ID = '0x025d365ee817cf4dee0ad91d71aa1e6bbd6c610dcd5dc1f9eac5135096fcae2c';
// Convert base64 bytecode strings to Buffer in artifact
function restoreBytecodeBuffers(artifact) {
const restored = { ...artifact };
if (restored.functions) {
restored.functions = restored.functions.map(fn => ({
...fn,
bytecode: typeof fn.bytecode === 'string'
? Buffer.from(fn.bytecode, 'base64')
: fn.bytecode
}));
}
return restored;
}
async function main() {
const { loadContractArtifact } = await import('@aztec/stdlib/abi');
const { getContractClassFromArtifact } = await import('@aztec/stdlib/contract');
console.log('\n=== TEST MANUAL BYTECODE RESTORATION ===\n');
// Get local classId for reference
console.log(`[1] Computing local classId...`);
const localPath = join(process.cwd(), LOCAL_FILE);
const compiledContract = JSON.parse(readFileSync(localPath, 'utf-8'));
const localArtifact = loadContractArtifact(compiledContract);
const localClass = await getContractClassFromArtifact(localArtifact);
const localClassId = localClass.id.toString();
console.log(` Local classId: ${localClassId}`);
// Fetch registry artifact
console.log(`\n[2] Fetching registry artifact...`);
const response = await fetch(`${REGISTRY_URL}/api/artifacts/${TEST_CLASS_ID}`);
const registryArtifact = await response.json();
console.log(` Bytecode type before: ${typeof registryArtifact.functions[0].bytecode}`);
// Manually restore bytecode buffers
console.log(`\n[3] Manually restoring bytecode buffers...`);
const restoredArtifact = restoreBytecodeBuffers(registryArtifact);
console.log(` Bytecode type after: ${restoredArtifact.functions[0].bytecode?.constructor?.name}`);
console.log(` Bytecode length: ${restoredArtifact.functions[0].bytecode?.length}`);
// Compute classId from restored artifact
console.log(`\n[4] Computing classId from restored artifact...`);
const restoredClass = await getContractClassFromArtifact(restoredArtifact);
const restoredClassId = restoredClass.id.toString();
console.log(` Restored classId: ${restoredClassId}`);
// Compare
console.log(`\n[5] Comparison:`);
console.log(` URL classId: ${TEST_CLASS_ID}`);
console.log(` Local classId: ${localClassId} ${localClassId === TEST_CLASS_ID ? '✅' : '❌'}`);
console.log(` Restored classId: ${restoredClassId} ${restoredClassId === TEST_CLASS_ID ? '✅' : '❌'}`);
console.log(` Local == Restored: ${localClassId === restoredClassId ? '✅' : '❌'}`);
}
main().catch((err) => {
console.error('Error:', err);
process.exit(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment