Skip to content
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

Problem: contract verifier enforces the last 32 bytes metadata check #70

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions core/lib/contract_verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,29 @@ impl ContractVerifier {
tracing::info!(
"Bytecode mismatch req {}, deployed: 0x{}, compiled 0x{}",
request.id,
hex::encode(deployed_bytecode),
hex::encode(artifacts.bytecode)
hex::encode(deployed_bytecode.clone()),
hex::encode(artifacts.bytecode.clone())
);
return Err(ContractVerifierError::BytecodeMismatch);

// try without the last 32bytes which usually represents the compiler metadata
let mut deployed_bytecode_without_metadata: Vec<u8> = deployed_bytecode.clone();
// Check if the length of the vector is greater than or equal to 32
if deployed_bytecode_without_metadata.len() >= 32 {
// Remove the last 32 bytes
let new_len = deployed_bytecode_without_metadata.len() - 32;
deployed_bytecode_without_metadata.truncate(new_len);
if artifacts.bytecode.clone() != deployed_bytecode_without_metadata {
tracing::info!(
"Bytecode without metadata mismatch req {}, deployed: 0x{}, compiled 0x{}",
request.id,
hex::encode(deployed_bytecode_without_metadata.clone()),
hex::encode(artifacts.bytecode.clone())
);
return Err(ContractVerifierError::BytecodeMismatch);
}
} else {
return Err(ContractVerifierError::BytecodeMismatch);
}
}

match constructor_args {
Expand All @@ -107,7 +126,7 @@ impl ContractVerifier {

Ok(VerificationInfo {
request,
artifacts,
artifacts: artifacts.clone(),
verified_at: Utc::now(),
})
}
Expand Down
Loading