Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 10 additions & 10 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
LibDescribedByMetaEmitForDescribedAddressTest:testEmitForDescribedAddressHappy(bytes) (runs: 5099, μ: 262353, ~: 262297)
LibDescribedByMetaEmitForDescribedAddressTest:testEmitForDescribedAddressMismatch(bytes,bytes) (runs: 5099, μ: 264255, ~: 264233)
LibMetaCheckMetaHashedV1_2Test:testCheckMetaHashedV1_2BadMagicBadHash(bytes,bytes32) (runs: 5099, μ: 5634, ~: 5616)
LibMetaCheckMetaHashedV1_2Test:testCheckMetaHashedV1_2BadMagicGoodHash(bytes) (runs: 5099, μ: 5719, ~: 5694)
LibMetaCheckMetaHashedV1_2Test:testCheckMetaHashedV1_2GoodMagicBadHash(bytes,bytes32) (runs: 5099, μ: 5783, ~: 5771)
LibMetaCheckMetaHashedV1_2Test:testCheckMetaHashedV1_2Happy(bytes) (runs: 5099, μ: 1103, ~: 1095)
LibMetaCheckMetaUnhashedV1_2Test:testCheckMetaUnhashedV1_2Fuzz(bytes) (runs: 5099, μ: 5818, ~: 5797)
LibMetaIsRainMetaV1_2Test:testIsRainMetaV1_2Fuzz(bytes) (runs: 5099, μ: 4167, ~: 4162)
MetaBoardHashTest:testMetaboardHash(bytes) (runs: 5099, μ: 199676, ~: 199660)
MetaBoardTest:testEmitMeta(bytes32,bytes) (runs: 5099, μ: 207801, ~: 207693)
LibDescribedByMetaEmitForDescribedAddressTest:testEmitForDescribedAddressHappy(bytes) (runs: 5096, μ: 267020, ~: 266892)
LibDescribedByMetaEmitForDescribedAddressTest:testEmitForDescribedAddressMismatch(bytes,bytes) (runs: 5093, μ: 269394, ~: 269260)
LibMetaCheckMetaHashedV1_2Test:testCheckMetaHashedV1_2BadMagicBadHash(bytes,bytes32) (runs: 5096, μ: 6031, ~: 5974)
LibMetaCheckMetaHashedV1_2Test:testCheckMetaHashedV1_2BadMagicGoodHash(bytes) (runs: 5096, μ: 6515, ~: 6334)
LibMetaCheckMetaHashedV1_2Test:testCheckMetaHashedV1_2GoodMagicBadHash(bytes,bytes32) (runs: 5096, μ: 6383, ~: 6321)
LibMetaCheckMetaHashedV1_2Test:testCheckMetaHashedV1_2Happy(bytes) (runs: 5096, μ: 1275, ~: 1228)
LibMetaCheckMetaUnhashedV1_2Test:testCheckMetaUnhashedV1_2Fuzz(bytes) (runs: 5096, μ: 6780, ~: 6564)
LibMetaIsRainMetaV1_2Test:testIsRainMetaV1_2Fuzz(bytes) (runs: 5096, μ: 1197, ~: 1153)
MetaBoardHashTest:testMetaboardHash(bytes) (runs: 5096, μ: 200262, ~: 200200)
MetaBoardTest:testEmitMeta(bytes32,bytes) (runs: 5096, μ: 212497, ~: 212154)
42 changes: 21 additions & 21 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions foundry.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"lib/forge-std": {
"rev": "b8f065fda83b8cd94a6b2fec8fcd911dc3b444fd"
}
}
8 changes: 7 additions & 1 deletion src/concrete/MetaBoard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ contract MetaBoard is IMetaBoardV1_2 {
/// under its hash. This avoids the need to roll a new interface to include
/// hashes in the event logs.
function hash(bytes calldata data) external pure returns (bytes32) {
return keccak256(data);
bytes32 dataHash;
assembly ("memory-safe") {
let free := mload(0x40)
calldatacopy(free, data.offset, data.length)
dataHash := keccak256(free, data.length)
}
return dataHash;
}
}
1 change: 1 addition & 0 deletions src/interface/unstable/IMetaV1_2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.19;

//forge-lint: disable-next-line(unused-import)
import {UnexpectedMetaHash, NotRainMetaV1, META_MAGIC_NUMBER_V1} from "../deprecated/IMetaV1.sol";

/// @title IMetaV1_2
Expand Down
5 changes: 4 additions & 1 deletion src/lib/LibDescribedByMeta.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ library LibDescribedByMeta {
internal
{
bytes32 expected = described.describedByMetaV1();
bytes32 actual = keccak256(meta);
bytes32 actual;
assembly ("memory-safe") {
actual := keccak256(add(meta, 0x20), mload(meta))
}
if (actual != expected) {
revert MetadataMismatch(described, expected, actual);
}
Expand Down
6 changes: 5 additions & 1 deletion src/lib/LibMeta.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.19;

//forge-lint: disable-next-line(unused-import)
import {IMetaV1_2, UnexpectedMetaHash, NotRainMetaV1, META_MAGIC_NUMBER_V1} from "../interface/unstable/IMetaV1_2.sol";

/// @title LibMeta
Expand Down Expand Up @@ -36,7 +37,10 @@ library LibMeta {
/// `isRainMetaV1` OR it does not match the expected hash of its data.
/// @param meta The metadata to check.
function checkMetaHashedV1(bytes32 expectedHash, bytes memory meta) internal pure {
bytes32 actualHash = keccak256(meta);
bytes32 actualHash;
assembly ("memory-safe") {
actualHash := keccak256(add(meta, 0x20), mload(meta))
}
if (expectedHash != actualHash) {
revert UnexpectedMetaHash(expectedHash, actualHash);
}
Expand Down
6 changes: 3 additions & 3 deletions test/lib/LibDescribedByMeta.emitForDescribedAddress.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import {MetaBoard} from "src/concrete/MetaBoard.sol";
import {META_MAGIC_NUMBER_V1} from "src/interface/unstable/IMetaV1_2.sol";

contract TestDescribedByMetaV1 is IDescribedByMetaV1 {
bytes32 public immutable expected;
bytes32 public immutable EXPECTED;

constructor(bytes memory meta) {
expected = keccak256(meta);
EXPECTED = keccak256(meta);
}

function describedByMetaV1() external view override returns (bytes32) {
return expected;
return EXPECTED;
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/lib/LibMeta.checkMetaUnhashedV1_2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity =0.8.25;

import {Test} from "forge-std/Test.sol";
import {LibMeta} from "src/lib/LibMeta.sol";
import {UnexpectedMetaHash, NotRainMetaV1, META_MAGIC_NUMBER_V1} from "src/interface/unstable/IMetaV1_2.sol";
import {NotRainMetaV1, META_MAGIC_NUMBER_V1} from "src/interface/unstable/IMetaV1_2.sol";

contract LibMetaCheckMetaUnhashedV1_2Test is Test {
function checkMetaUnhashedV1External(bytes memory meta) external pure {
Expand Down
2 changes: 1 addition & 1 deletion test/lib/LibMeta.isRainMetaV1_2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity =0.8.25;

import {Test} from "forge-std/Test.sol";
import {LibMeta} from "src/lib/LibMeta.sol";
import {UnexpectedMetaHash, NotRainMetaV1, META_MAGIC_NUMBER_V1} from "src/interface/unstable/IMetaV1_2.sol";
import {META_MAGIC_NUMBER_V1} from "src/interface/unstable/IMetaV1_2.sol";

contract LibMetaIsRainMetaV1_2Test is Test {
/// All data with the magic number prefix will be considered to be rain meta
Expand Down