Skip to content

Optimize attestation message construction #6

@martinjms

Description

@martinjms

Summary

In condition_attestation.move, the message for signature verification is built by creating 4 separate BCS-encoded vectors and appending them one by one:

let mut msg = vector[];
let char_bytes = bcs::to_bytes(&char_game_id);
let assembly_bytes = bcs::to_bytes(&assembly_id);
let condition_bytes = bcs::to_bytes(&condition_id);
let time_bytes = bcs::to_bytes(&timestamp_ms);
msg.append(char_bytes);
msg.append(assembly_bytes);
msg.append(condition_bytes);
msg.append(time_bytes);

This creates 4 allocations + 4 vector copies. Could be replaced with a single tuple encoding:

let msg = bcs::to_bytes(&(char_game_id, assembly_id, condition_id, timestamp_ms));

Impact

~30-50% gas reduction on attestation condition verification. Low effort change.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions