Genesis block output off by one Ada 😭 + Mainnet genesis test Ada?

If you run this query against cardano-db-sync’s cexplorer database:

select sum(value) / 1000000
from block 
inner join tx on = tx.block_id 
inner join tx_out on = tx_out.tx_id
  -- Get genesis block
where epoch_no is null 
  -- Filter "test ada" (idk ctrl f "test ada" here
  -- FYI there is 100,000,000 lovelace worth of "test ada"
  and tx_out.value <> 1000000


You will get 31,112,484,645 which is one ada less than the 31,112,484,646 ada the Cardano website claims was created in the genesis block.

Insight behind this single extra Ada would be greatly appreciated! (Or website should be updated??)

Insight into the “test ada” is welcome as well!

Anddd if you’re feeling extra helpful, I don’t understand the story behind why outputs are omitted from genesis after the Allegra hard fork.

Sorry for multiple questions, thanks in advance!

This has very little to do with ADA and a lot more to do with Postgres and SQL. Aggregate function SUM divided by a constant integer will ALWAYS floor! The referenced website is likely rounding up or using some kind of ceiling function. The classic “off by one” error is significantly less interesting when dealing with totaled values in the tens of billions anyway and more idiomatic for errors in loops or array bounds.

P.S. by definition a “hard fork” usually implies a new genesis block where the prior ledger history is no longer valid whereas a “soft fork” would remain backwards compatible and include old transactions from before the blockchain upgrade.

I could accept that, however it is actually off by 1,000,000 Lovelace, just converted to Ada for legibility.

Also I do believe it’s an important error to understand even if not necessarily significant.

Have you tried not dividing by integer type?

select 987654321 / 1000000 as i, 987654321 / 1000000.0 as f;
i f
987 987.6543210000000000

e.g. rounding up instead of flooring down for your query:

select round(sum(value) / 1000000.0)
from block 
inner join tx on = tx.block_id 
inner join tx_out on = tx_out.tx_id
where epoch_no is null and tx_out.value <> 1000000