Matching out-of-order Chainlink VRF results to separate draws

Two games request randomness before either result arrives. Assigning the next callback to the oldest open game can swap outcomes even though both proofs are valid.

Persist the request-to-draw relationship

Associate the returned VRF request ID with the application draw during submission. The example delivers request 42 before 41. Looking up each ID emits the blue draw first and the red draw second, with their respective words intact.

const drawFor = new Map([[41n,"red"], [42n,"blue"]]);
for (const [id,word] of [[42n,900n],[41n,700n]]) {
  console.log(drawFor.get(id), word.toString());
}

Freeze the inputs that determine the outcome

Before requesting randomness, close entries and save which participants belong to this draw. Correctly matching a word to an ID is insufficient if someone can later change the participant order. Persist the fulfilled state and use the authorized coordinator callback. For a delayed response, keep the original request association available for reconciliation; letting someone discard an unfavorable outcome and request another changes the fairness of the draw.

docs.chain.link VRF security considerations