Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

The first byte of block-level logsBloom does not match transaction-level logsBloom #4534

Closed
YanhuiJessica opened this issue Oct 7, 2023 · 3 comments

Comments

@YanhuiJessica
Copy link

$ ganache --version
ganache v7.9.1 (@ganache/cli: 0.10.1, @ganache/core: 0.10.1)
$ ganache # start

Expected behaviour

The block-level logsBloom combines the logsBloom of each transaction.

Actual behaviour

The first byte of block-level logsBloom is 0x00, while there's a transaction-level logsBloom with non-zero first byte.

Steps to reproduce the behaviour

contract Test {
    event Transfer(address indexed, address indexed, uint256);
    function Log() external {
        emit Transfer(address(0x2), address(0x1337), 0);    // set the first byte of logsBloom to 0x44
    }
}

call Log()
Transaction Receipt

blockHash               0xc3568fd20d6e5fa46aaeca2db8bad32f6f8174a89eeb29ab00ed181080fb50a1
blockNumber             2
contractAddress         
cumulativeGasUsed       23274
effectiveGasPrice       3266499687
gasUsed                 23274
logs                    [{"address":"0x23fdb89edbabe32881186fda672ccf49f0ec1760","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000001337"],"data":"0x0000000000000000000000000000000000000000000000000000000000000000","blockHash":"0xc3568fd20d6e5fa46aaeca2db8bad32f6f8174a89eeb29ab00ed181080fb50a1","blockNumber":"0x2","transactionHash":"0x6d5679de2266de349177515c9907eeff9fd910c25399c687454d8a8a4a8f79c2","transactionIndex":"0x0","logIndex":"0x0","removed":false}]
logsBloom               0x4400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000020000000000000000000000000a000000000000000000010000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000008000000000000000000000
root                    
status                  1
transactionHash         0x6d5679de2266de349177515c9907eeff9fd910c25399c687454d8a8a4a8f79c2
transactionIndex        0
type                    2

Block

baseFeePerGas        766499687
difficulty           0
extraData            0x
gasLimit             30000000
gasUsed              23274
hash                 0xc3568fd20d6e5fa46aaeca2db8bad32f6f8174a89eeb29ab00ed181080fb50a1
logsBloom            0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000020000000000000000000000000a000000000000000000010000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000008000000000000000000000
miner                0x0000000000000000000000000000000000000000
mixHash              0x805bcd5133115e166bc0eca9510d45ee3f4198a23c85088c98f69bf69365347e
nonce                0x0000000000000000
number               2
parentHash           0x58c08382e219a2004fa42742ceed2a773ff04f94d3c9f35f4fdd28ea788df60e
receiptsRoot         0x8db6c89f4be92481354c076faa162827541acbfa6cca09a5b947103a051caaa7
sealFields           []
sha3Uncles           0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347
size                 668
stateRoot            0xeaf5087ea8e7d2947f2f9e1b286ac1e3b3aab03fd1261b1fdd8503b4efec1caf
timestamp            1696648972
withdrawalsRoot      0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
totalDifficulty      0
transactions:        [
	0x6d5679de2266de349177515c9907eeff9fd910c25399c687454d8a8a4a8f79c2
]
@davidmurdoch
Copy link
Member

It's been a while since I've looked into how the bloom works, but I think the block bloom is a bloom filter itself, not a contactination of the all the transaction logBlooms.

That's not to say the block logs bloom is absolutely correct here, there might be a bug, but I don't think the first byte must be set because the first transaction's bloom has its first byte set. I might be wrong, of course, so please do correct me if so.

@YanhuiJessica
Copy link
Author

In Ethereum Yellow Paper, the block-level logsBloom $H_b\equiv \bigvee_{r\in B_R}(r_b)$, where $B_R$ represents all the txn receipts in the block and $r_b$ represents transaction-level logsBloom.

I also tried anvil.

$ anvil # start

Transaction Receipt

blockHash               0x018c5487cabd986fe5bf6fb63f1c551a7124e87d574bfb30110eb8ec098df35f
blockNumber             2
contractAddress         
cumulativeGasUsed       23274
effectiveGasPrice       3375999642
gasUsed                 23274
logs                    [{"address":"0x5fbdb2315678afecb367f032d93f642f64180aa3","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000001337"],"data":"0x0000000000000000000000000000000000000000000000000000000000000000","blockHash":"0x018c5487cabd986fe5bf6fb63f1c551a7124e87d574bfb30110eb8ec098df35f","blockNumber":"0x2","transactionHash":"0x546c585e3ee7e1eed3a753dd830b8aad87f649dfc90221bdbadbb88be1021272","transactionIndex":"0x0","logIndex":"0x0","transactionLogIndex":"0x0","removed":false}]
logsBloom               0x4400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000004000000000000000000000000000a000000000000000000010000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000100000000000000000000000000000000000000000000000042000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000
root                    
status                  1
transactionHash         0x546c585e3ee7e1eed3a753dd830b8aad87f649dfc90221bdbadbb88be1021272
transactionIndex        0
type                    2

Block

baseFeePerGas        875999642
difficulty           0
extraData            0x
gasLimit             30000000
gasUsed              23274
hash                 0x018c5487cabd986fe5bf6fb63f1c551a7124e87d574bfb30110eb8ec098df35f
logsBloom            0x4400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000004000000000000000000000000000a000000000000000000010000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000100000000000000000000000000000000000000000000000042000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000
miner                0x0000000000000000000000000000000000000000
mixHash              0x0000000000000000000000000000000000000000000000000000000000000000
nonce                0x0000000000000000
number               2
parentHash           0xd619acf6229a2ea2326cb9ccfa8adf9ef9f4fc44c6bf313d0bc0613c6cdec053
receiptsRoot         0x92cffb4d820c3f1f43da148dcc831792ec6a28ce9860c7558bc9eb04471638d4
sealFields           [
	0x0000000000000000000000000000000000000000000000000000000000000000
	0x0000000000000000
]
sha3Uncles           0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347
size                 635
stateRoot            0xfbe79a6cbc3ce180a2fa34e6089e9aa3a1b1aa1f13205140981f610c75446656
timestamp            1696729796
withdrawalsRoot      
totalDifficulty      0
transactions:        [
	0x546c585e3ee7e1eed3a753dd830b8aad87f649dfc90221bdbadbb88be1021272
]

@davidmurdoch
Copy link
Member

There are 2 hard problems in computer science: cache invalidation, naming things, and off-by-1 errors. 😅

#4535

I just need to add a test before I can merge.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants