Skip to content

Commit

Permalink
fix: remove timestamp from parsing + test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JordyRo1 committed Nov 4, 2024
1 parent b71b23e commit 599a3ed
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 16 deletions.
4 changes: 1 addition & 3 deletions solidity/src/Hyperlane.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ contract Hyperlane is IHyperlane {
index += 1;
require(hyMsg.version == VERSION, "unsupported version");


// Parse Signatures
uint256 signersLen = encodedHyMsg.toUint8(index);
index += 1;
Expand All @@ -133,9 +134,6 @@ contract Hyperlane is IHyperlane {
hyMsg.nonce = encodedHyMsg.toUint32(index);
index += 4;

hyMsg.timestamp = encodedHyMsg.toUint64(index);
index += 8;

hyMsg.emitterChainId = encodedHyMsg.toUint32(index);
index += 4;

Expand Down
3 changes: 2 additions & 1 deletion solidity/src/PragmaDecoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,11 @@ abstract contract PragmaDecoder {
// Extract header metadata
offset = extractMetadataFromheader(updateData, offset);
// Extract merkle root and number of updates from update data.
// uint256 offset;

bytes32 checkpointRoot;

(offset, checkpointRoot, numUpdates) = extractCheckpointRootAndNumUpdates(updateData, offset);

unchecked {
for (uint256 i = 0; i < numUpdates; i++) {
ParsedData memory parsedData;
Expand Down
11 changes: 10 additions & 1 deletion solidity/test/PragmaDecoder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,18 @@ contract PragmaHarnessTest is Test {
setupRealPragmaHarness();
// encoded update
bytes memory encodedUpdate =
hex"0100000170030100c1ec5070f1a4868b8e6bfa5bbd31ac77605c5af1a739bc4e7758d4ca1d88fa8835c1460646b647c4c4403b324c2297a04d70b84888dc873021f80d6d70ed015e1c00031b8b0000000067225b1100611a3d0060240f2bccef7e64f920eec05c5bfffbc48c6ceaa4efca8748772b60cbafc30536953cdd0dd5b8e24428e4fb6eab5c143daba15f62b24606e50d822508faefd53032e26a3b1d1510dfe82a2ab8d6c0fc0f010dcdd3c410ba2f9fdad3479b1400031b8b15704e0efd1955cfe1c1182ba083bd5309707bdd795397cbbbb106cfc9b29bb001000100000000000000000000004254432f555344000000000000000000000000000000000000000067225b1100080800000000000000000000068aa5cb9d63000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004254432f5553440000000067225b11";
hex"0100000130030100c1ec5070f1a4868b8e6bfa5bbd31ac77605c5af1a739bc4e7758d4ca1d88fa8835c1460646b647c4c4403b324c2297a04d70b84888dc873021f80d6d70ed015e1c00031b8b00611a3d0060240f2bccef7e64f920eec05c5bfffbc48c6ceaa4efca8748772b60cbafc30536953cdd0dd5b8e24428e4fb6eab5c143daba15f62b24606e50d822508faefd53032e26a3b1d1510dfe82a2ab8d6c0fc0f010dcdd3c410ba2f9fdad3479b1400031b8b15704e0efd1955cfe1c1182ba083bd5309707bdd795397cbbbb106cfc9b29bb00100010000000000000000000000000000000000000000000000000000004254432f5553440000000067225b110008080000000000000000000000000000000000000000000000000000068aa5cb9d630000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004254432f5553440000000067225b11";
uint8 numUpdates = pragmaHarness.exposed_updateDataInfoFromUpdate(encodedUpdate);
assertEq(numUpdates, 1, "Number of updates should be 1");
bytes32 feedId= bytes32(0x000000000000000000000000000000000000000000000000004254432f555344);
SpotMedian memory spotMedian = pragmaHarness.exposed_spotMedianFeeds(feedId);
assertEq(spotMedian.metadata.timestamp,uint64(0x67225b11), "Timestamp should match");
assertEq(spotMedian.metadata.numberOfSources, 8, "Number of sources should be 8");
assertEq(spotMedian.metadata.decimals, 8, "Decimals should be 8");
assertEq(spotMedian.metadata.feedId, feedId, "Feed ID should match");
assertEq(spotMedian.price, 0x68aa5cb9d63, "Price should match");
assertEq(spotMedian.volume, 0, "Volume should match");

}

function testUpdateDataInfoFromUpdateSpotMedian() public {
Expand Down
1 change: 0 additions & 1 deletion solidity/test/TestUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ library TestUtils {
TestConstantsLib.HYPERLANE_VERSION,
signatures,
uint32(0), // nonce
uint64(block.timestamp), // timestamp
uint32(1), // emitterChainId
bytes32(uint256(0x1234)), // emitterAddress
bytes32(uint256(0x12311)), // merkle tree hook address
Expand Down
9 changes: 0 additions & 9 deletions solidity/test/utils/HyperlaneTestUtils.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ abstract contract HyperlaneTestUtils is Test {

function generateUpdateData(
uint32 nonce,
uint64 timestamp,
uint32 emitterChainId,
bytes32 emitterAddress,
bytes32 merkleTreeHookAddress,
Expand Down Expand Up @@ -62,15 +61,12 @@ abstract contract HyperlaneTestUtils is Test {
signatures = abi.encodePacked(signatures, validatorIndex, r[i], s[i], v);
}

bytes32 domainHash = keccak256(abi.encodePacked(emitterChainId, merkleTreeHookAddress, "HYPERLANE"));
bytes32 _hash = keccak256(abi.encodePacked(domainHash, root, checkpointIndex, messageId));
// Construct the updateData by concatenating all parts
updateData = abi.encodePacked(
TestConstantsLib.HYPERLANE_VERSION,
numSigners,
signatures,
nonce,
timestamp,
emitterChainId,
emitterAddress,
merkleTreeHookAddress,
Expand All @@ -84,7 +80,6 @@ abstract contract HyperlaneTestUtils is Test {

contract HyperlaneTestUtilsTest is Test, HyperlaneTestUtils {
uint32 constant TEST_NONCE = 1234;
uint64 constant TEST_UPDATE_TIMESTAMP = 112;
uint32 constant TEST_EMITTER_CHAIN_ID = 7;
bytes32 constant TEST_EMITTER_ADDR = 0x0000000000000000000000000000000000000000000000000000000000000bad;
bytes32 constant TEST_MERKLE_TREE_ADDRESS = 0x0000000000000000000000000000000000000000000000000000000000000aaa;
Expand All @@ -104,7 +99,6 @@ contract HyperlaneTestUtilsTest is Test, HyperlaneTestUtils {
assertTrue(valid);
assertEq(reason, "");
assertEq(hyMsg.nonce, TEST_NONCE, "Nonce does not correspond");
assertEq(hyMsg.timestamp, TEST_UPDATE_TIMESTAMP, "Timestamp does not correspond");
assertEq(hyMsg.emitterChainId, TEST_EMITTER_CHAIN_ID, "Emitter chain id does not correspond");
assertEq(hyMsg.emitterAddress, TEST_EMITTER_ADDR, "Emitter address does not correspond");
assertEq(hyMsg.payload, TEST_PAYLOAD, "Payload does not correspond");
Expand All @@ -128,7 +122,6 @@ contract HyperlaneTestUtilsTest is Test, HyperlaneTestUtils {

bytes memory updateData = generateUpdateData(
TEST_NONCE,
TEST_UPDATE_TIMESTAMP,
TEST_EMITTER_CHAIN_ID,
TEST_EMITTER_ADDR,
TEST_MERKLE_TREE_ADDRESS,
Expand Down Expand Up @@ -165,7 +158,6 @@ contract HyperlaneTestUtilsTest is Test, HyperlaneTestUtils {
uint8(28), // v
// Rest of the message
uint32(1234), // nonce
uint64(block.timestamp), // timestamp
uint32(5), // emitterChainId
bytes32(uint256(6)), // emitterAddress
merkleTreeHookAddress, // merkleTreeHookAddress
Expand Down Expand Up @@ -197,7 +189,6 @@ contract HyperlaneTestUtilsTest is Test, HyperlaneTestUtils {
assertEq(parsedMsg.signatures[1].v, 28, "Incorrect v for second signature");

assertEq(parsedMsg.nonce, 1234, "Incorrect nonce");
assertEq(parsedMsg.timestamp, block.timestamp, "Incorrect timestamp");
assertEq(parsedMsg.emitterChainId, 5, "Incorrect emitter chain ID");
assertEq(uint256(parsedMsg.emitterAddress), 6, "Incorrect emitter address");
bytes32 domainHash = keccak256(abi.encodePacked(parsedMsg.emitterChainId, merkleTreeHookAddress, "HYPERLANE"));
Expand Down
1 change: 0 additions & 1 deletion solidity/test/utils/PragmaTestUtils.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ abstract contract PragmaTestUtils is Test, RandTestUtils, HyperlaneTestUtils {

bytes memory updateData = generateUpdateData(
MOCK_NONCE_VALUE,
MOCK_TIMESTAMP_VALUE,
config.source_chain_id,
config.source_emitter_address,
config.merkle_tree_hook_address,
Expand Down

0 comments on commit 599a3ed

Please sign in to comment.