Skip to content

Commit

Permalink
Problem: contract verifier enforces the last 64 bytes metadata check (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-nguy committed Aug 21, 2024
1 parent 0ca818e commit 5f4bdcb
Showing 1 changed file with 23 additions and 4 deletions.
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 64bytes 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 64
if deployed_bytecode_without_metadata.len() >= 64 {
// Remove the last 64 bytes
let new_len = deployed_bytecode_without_metadata.len() - 64;
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

0 comments on commit 5f4bdcb

Please sign in to comment.