Skip to content
Closed
Changes from 2 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
11 changes: 6 additions & 5 deletions gateway-contract/contracts/core_contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,32 @@ impl Contract {
proof: Bytes,
public_signals: PublicSignals,
) {
// ✅ CRITICAL FIX: enforce authentication FIRST
caller.require_auth();

let key = storage::DataKey::Resolver(commitment.clone());

if env.storage().persistent().has(&key) {
panic_with_error!(&env, CoreError::DuplicateCommitment);
}

let current_root = smt_root::SmtRoot::get_root(env.clone())
.unwrap_or_else(|| panic_with_error!(&env, CoreError::RootNotSet));

if public_signals.old_root != current_root {
panic_with_error!(&env, CoreError::StaleRoot);
}

if !zk_verifier::ZkVerifier::verify_groth16_proof(&env, &proof, &public_signals) {
panic_with_error!(&env, CoreError::InvalidProof);
}

let data = ResolveData {
wallet: caller.clone(),
memo: None,
};

env.storage().persistent().set(&key, &data);

smt_root::SmtRoot::update_root(&env, public_signals.new_root);

#[allow(deprecated)]
env.events()
.publish((REGISTER_EVENT,), (commitment, caller));
Expand Down
Loading