Skip to content

Add completed FraudVerifier and StateTransitioner contracts#184

Merged
smartcontracts merged 46 commits intomasterfrom
YAS-202/FraudVerifier/proofs
Jul 21, 2020
Merged

Add completed FraudVerifier and StateTransitioner contracts#184
smartcontracts merged 46 commits intomasterfrom
YAS-202/FraudVerifier/proofs

Conversation

@smartcontracts
Copy link
Contributor

Description

This PR implements the FraudVerifier and StateTransitioner contracts in full. Includes tests.

Metadata

Fixes

Contributing Agreement

Copy link
Collaborator

@ben-chain ben-chain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WOOT WOOT this is looking 🔥

Left a bunch of comments inline, main high level question I have is around nuance of proving storage vs. contracts. Seems like we should only prove contract updates once all storage is updated, which I'm not positive is being enforced right now. Additionally, if the same slot is updated multiple times, we should ignore all but the last update to that slot. Is that being handled right now? Not sure if I'm missing something but I don't see it.

Comment on lines +293 to +294
* @dev Likely to be changed (if not moved to another contract). Currently
* remaining here as to avoid modifying CanonicalTransactionChain. Unclear
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍👍👍

Note that will be made actionable once #183 gets merged as it has that encoding. Worth spawning a ticket if you wanna cover in a future PR.

Comment on lines +39 to +47
interface OVMTransactionData {
timestamp: number
queueOrigin: number
ovmEntrypoint: string
callBytes: string
fromAddress: string
l1MsgSenderAddress: string
allowRevert: boolean
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above WRT consolidating types


expect(await stateManager.updatedStorageSlotCounter()).to.equal(3)

const newStateTrieRoot = await proveAllStorageUpdates(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to explicitly assert that the newStateTrieRoot has the final storage value set? (3 in this case I believe)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly possible. Checking newStateTrieRoot generated by the test helpers against the one inside the contract should be good enough (as that root is known to be correct).

it('does not fail if all the state is supplied', async () => {
await prepareStateForTransactionExecution()
await stateTransitioner.applyTransaction()
describe('proveUpdatedContract(...)', async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the contract creation tests here, I think the two other cases to watch out for would be:

  1. EOA nonce updates
  2. Contract nonce updates (but maybe this is covered already?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the nonce updates are covered - I actually don't have any code here for EOA accounts. Wasn't in the original sketch. I'll talk to Karl about this later today.

Copy link
Contributor

@karlfloersch karlfloersch Jul 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kfichter oh yeah so EOA accounts are actually (funny enough) covered by the transaction decoding logic. There are two ways to decode transactions (only one should be valid at a time):

  1. EOA transaction -- this encoding should have a v r and s which will be recoverable against the rest of the transaction. This is I believe similar to the tx decoding you sketched out in this PR. In this case, we set the from address equal to the recovered signature value.
  2. Non-EOA transaction -- this encoding is used when there is no v r and s present. In this case we will set the from address to ZERO_ADDRESS (and in the case that this is an L1->L2 transaction, we set the l1MessageSender as well)

Note that EOAs are literally just treated as contracts. Maybe we should ensure that there is no EOA address which == some contract address... But I've been operating under the assumption that we shouldn't find a conflict like that

@karlfloersch
Copy link
Contributor

@ben-chain wrt

if the same slot is updated multiple times, we should ignore all but the last update to that slot.

It turns out we actually don't need to enforce this because the way the data structure works is we don't actually store the intermediate values, so the worst thing that can happen here is that you waste gas re-proving the same slot multiple times. That said, I think @kfichter brought this issue up before & may have actually added some logic which prevents redundant proofs to save on gas.

@smartcontracts
Copy link
Contributor Author

smartcontracts commented Jul 13, 2020

@ben-chain this is actually something I need to change more generally. Same issue applies to contract nonces being changed. The existing PartialStateManager code will correctly assign the new state for each for pending update but still duplicate the updates (i.e., if a nonce goes 0 -> 1 -> 2 then we update the nonce to 2 three times). Should be easily addressable by tracking updates on a per-contract/per-slot basis.

@smartcontracts
Copy link
Contributor Author

Unfortunately we have another circular dependency issue w.r.t. rollup-core. PR may have to wait until we've resolved the dependency of rollup-core on rollup-contracts.

@ben-chain
Copy link
Collaborator

Another thought: Do we have code contract association logic? I see that we pass in the code hash to verifyContract, but need to make sure that connects to a code contract which has been deployed on L1 (might have missed it though)

@smartcontracts
Copy link
Contributor Author

Another thought: Do we have code contract association logic? I see that we pass in the code hash to verifyContract, but need to make sure that connects to a code contract which has been deployed on L1 (might have missed it though)

Yes -- the association occurs when the contract is created. Although that reminds me that I need to make sure it only happens during ovmCREATE and not ovmCREATE2.

@smartcontracts
Copy link
Contributor Author

Ok @ben-chain I just resolved all of the suggestions you made (besides some of the type consolidation). StateTransitioner.applyTransaction now takes _transactionData as a parameter, StateTransitioner no longer makes multiple updates for the same slot, ExecutionManager will only mark contracts created via ovmCREATE as verified (since contracts created via ovmCREATE2 may already exist and therefore need to be verified upfront via an inclusion proof).

@ben-chain
Copy link
Collaborator

need to make sure it only happens during ovmCREATE and not ovmCREATE2.

Not sure exactly what you mean here -- code contracts need to be associated during both right? For both CREATE and CREATE2 there is also the case where there might already be a code contract with that bytecode out there, so gotta make sure that works.

Also -- there's a non-creation code contract association which needs to occur too--previously deployed contracts need to have code contracts associated based on the hash verified in proveContract.

@smartcontracts smartcontracts changed the title Add completed FraudVerifier and StateTransitioner contracts` Add completed FraudVerifier and StateTransitioner contracts Jul 21, 2020
@smartcontracts smartcontracts merged commit 2f36cf2 into master Jul 21, 2020
@gakonst gakonst deleted the YAS-202/FraudVerifier/proofs branch March 18, 2021 15:02
snario pushed a commit that referenced this pull request Apr 14, 2021
Lredhdx pushed a commit to node-real/combo-optimism that referenced this pull request Jun 17, 2024
shenkeyao referenced this pull request in EspressoSystems/optimism-espresso-integration Mar 1, 2025
* Revert to using time.Now() for migration block

Instead of simply adding 5 to the parent block time.

We really do need a deterministic time for the migration block so that
all parties that run the migration arrive at the same migration block
but the problem is that op-geth requires that the L2 migration block
(aka l2 origin) occurs after the l1 origin (I guess the point where you
deploy the bridge contracts to the l1). When we migrate a partially
synced datadir the block before the transition block will be very old,
up to 4 years old! So of course it occurs before the l1 origin. So a fix
just to get things working is to use time.Now(), but probably we should
make this a configurable parameter.

* add flag to specify timestamp

* Update op-chain-ops/cmd/celo-migrate/main.go

---------

Co-authored-by: piersy <pierspowlesland@gmail.com>
QuentinI referenced this pull request in EspressoSystems/optimism-espresso-integration Mar 7, 2025
* Revert to using time.Now() for migration block

Instead of simply adding 5 to the parent block time.

We really do need a deterministic time for the migration block so that
all parties that run the migration arrive at the same migration block
but the problem is that op-geth requires that the L2 migration block
(aka l2 origin) occurs after the l1 origin (I guess the point where you
deploy the bridge contracts to the l1). When we migrate a partially
synced datadir the block before the transition block will be very old,
up to 4 years old! So of course it occurs before the l1 origin. So a fix
just to get things working is to use time.Now(), but probably we should
make this a configurable parameter.

* add flag to specify timestamp

* Update op-chain-ops/cmd/celo-migrate/main.go

---------

Co-authored-by: piersy <pierspowlesland@gmail.com>
theochap pushed a commit that referenced this pull request Dec 10, 2025
* feat(preimage): Async server components

Makes the server components in `kona-preimage` async to allow for remote
data fetching in the `host` program.

* feat(host): Host program scaffold

Introduces the scaffolding and initial implementation of the `kona-host`
program.

* feat(host): Add L1 txs, L1 receipts, & L1 precompile hint routes
theochap pushed a commit that referenced this pull request Jan 15, 2026
### Description

Releases `0.5.1`.

Unblocks @clabby from refactoring `kona-host` to remove the `debug_*`
endpoints since alloy-rs/op-alloy#183 was
merged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants