Skip to content

Commit

Permalink
fix: l1 avatar payload serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Orlando committed Aug 22, 2023
1 parent 33b96f9 commit 172745f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 34 deletions.
38 changes: 22 additions & 16 deletions ethereum/src/execution-strategies/L1AvatarExecutionStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,32 @@ contract L1AvatarExecutionStrategy is SimpleQuorumExecutionStrategy {
uint256 votesAbstain,
bytes32 executionHash
) internal {
uint256[] memory payload = new uint256[](15);
uint256[] memory payload = new uint256[](19);
payload[0] = space;
// The serialized Proposal struct
// TODO: this is probably an incorrect serialization
payload[1] = uint256(proposal.snapshotTimestamp);
payload[2] = uint256(proposal.startTimestamp);
payload[3] = uint256(proposal.minEndTimestamp);
payload[4] = uint256(proposal.maxEndTimestamp);

// The Cairo serialization of the Proposal struct where felts are uint256s
payload[1] = uint256(proposal.startTimestamp);
payload[2] = uint256(proposal.minEndTimestamp);
payload[3] = uint256(proposal.maxEndTimestamp);
payload[4] = uint256(proposal.finalizationStatus);
payload[5] = proposal.executionPayloadHash;
payload[6] = uint256(uint160(proposal.executionStrategy));
payload[7] = uint256(uint160(proposal.author));
payload[8] = uint256(proposal.finalizationStatus);
payload[9] = proposal.activeVotingStrategies;
payload[6] = proposal.executionStrategy;
payload[7] = proposal.authorAddressType;
payload[8] = proposal.author;
payload[9] = proposal.activeVotingStrategies >> 128;
payload[10] = proposal.activeVotingStrategies & (2 ** 128 - 1);

payload[11] = votesFor >> 128;
payload[12] = votesFor & (2 ** 128 - 1);

payload[13] = votesAgainst >> 128;
payload[14] = votesAgainst & (2 ** 128 - 1);

payload[10] = votesFor;
payload[11] = votesAgainst;
payload[12] = votesAbstain;
payload[15] = votesAbstain >> 128;
payload[16] = votesAbstain & (2 ** 128 - 1);

payload[13] = uint256(executionHash >> 128); // High 128 bits of executionHash
payload[14] = uint256(executionHash) & (2 ** 128 - 1); // Low 128 bits of executionHash
payload[17] = uint256(executionHash >> 128);
payload[18] = uint256(executionHash) & (2 ** 128 - 1);

// If proposal execution message did not exist/not received yet, then this will revert.
IStarknetCore(starknetCore).consumeMessageFromL2(executionRelayer, payload);
Expand Down
26 changes: 8 additions & 18 deletions ethereum/src/types.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,17 @@ enum FinalizationStatus {
Cancelled
}

// TODO: Equivalence with sx-evm Proposal struct
/// @notice The data stored for each proposal when it is created.
struct Proposal {
// The timestamp at which voting power for the proposal is calculated. Overflows at year ~2106.
uint64 snapshotTimestamp;
// We store the following 3 timestamps for each proposal despite the fact that they can be
// inferred from the votingDelay, minVotingDuration, and maxVotingDuration state variables
// because those variables may be updated during the lifetime of a proposal.
uint64 startTimestamp;
uint64 minEndTimestamp;
uint64 maxEndTimestamp;
// The hash of the execution payload. We do not store the payload itself to save gas.
uint256 executionPayloadHash;
// The address of execution strategy used for the proposal.
address executionStrategy;
// The address of the proposal creator.
address author;
// An enum that stores whether a proposal is pending, executed, or cancelled.
uint32 startTimestamp;
uint32 minEndTimestamp;
uint32 maxEndTimestamp;
FinalizationStatus finalizationStatus;
// Bit array where the index of each each bit corresponds to whether the voting strategy.
// at that index is active at the time of proposal creation.
uint256 executionPayloadHash;
uint256 executionStrategy;
// 0 for Starknet, 1 for Ethereum, 2 for custom
uint256 authorAddressType;
uint256 author;
uint256 activeVotingStrategies;
}

Expand Down

0 comments on commit 172745f

Please sign in to comment.