Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record witness access in EXTCODEHASH #370

Merged
merged 4 commits into from
Feb 15, 2024

Conversation

jsign
Copy link
Collaborator

@jsign jsign commented Feb 8, 2024

This PR adds access witness recording for EXTCODEHASH

Comment on lines +854 to +866
dummyContract := []byte{
0x60, 2, // PUSH1 2
0x60, 12, // PUSH1 12
0x60, 0x00, // PUSH1 0
0x39, // CODECOPY

0x60, 2, // PUSH1 2
0x60, 0x00, // PUSH1 0
0xF3, // RETURN

// Contract that auto-calls EXTCODEHASH
0x60, 42, // PUSH1 42
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Deploy dummyContract so we have some contract to use EXTCODEHASH later.

Comment on lines +868 to +882
extCodeHashContract := []byte{
0x60, 22, // PUSH1 22
0x60, 12, // PUSH1 12
0x60, 0x00, // PUSH1 0
0x39, // CODECOPY

0x60, 22, // PUSH1 22
0x60, 0x00, // PUSH1 0
0xF3, // RETURN

// Contract that auto-calls EXTCODEHASH
0x73, // PUSH20
0x3a, 0x22, 0x0f, 0x35, 0x12, 0x52, 0x08, 0x9d, 0x38, 0x5b, 0x29, 0xbe, 0xca, 0x14, 0xe2, 0x7f, 0x20, 0x4c, 0x29, 0x6a,
0x3F, // EXTCODEHASH
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Deploy another contract that actually makes the EXTCODEHASH to the previously deployed contract.

This was required to be super clear about witness checks. Initially, I made the dummy contract "auto call" EXTCODEHASH, but then is hard to distinguish why the witness have the contract code hash (e.g: from deployment or from EXTCODEHASH exec).

Comment on lines +888 to +894
// Create dummy contract.
tx, _ := types.SignTx(types.NewContractCreation(0, big.NewInt(0), 100_000, big.NewInt(875000000), dummyContract), signer, testKey)
gen.AddTx(tx)

// Create contract with EXTCODEHASH opcode.
tx, _ = types.SignTx(types.NewContractCreation(1, big.NewInt(0), 100_000, big.NewInt(875000000), extCodeHashContract), signer, testKey)
gen.AddTx(tx)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the first block deploy both contracts.

Comment on lines +896 to +897
tx, _ := types.SignTx(types.NewTransaction(2, extCodeHashContractAddr, big.NewInt(0), 100_000, big.NewInt(875000000), nil), signer, testKey)
gen.AddTx(tx)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the next block do the actual execution, so if the witness shows the contract code hash address then we know its' from EXTCODEHASH execution and not contract deployments.

if codeHashStateDiff.CurrentValue == nil {
t.Fatalf("codeHash.CurrentValue must not be empty")
}
expCodeHash := crypto.Keccak256Hash(dummyContract[12:])
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Avoiding magical hashes, so we know it's correct.

@jsign jsign marked this pull request as ready for review February 8, 2024 16:06
Copy link

@g11tech g11tech left a comment

Choose a reason for hiding this comment

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

good to see version access being added as well 👍

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Copy link
Owner

@gballet gballet left a comment

Choose a reason for hiding this comment

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

LGTM

@gballet gballet added this to the verkle-gen-devnet-5 milestone Feb 15, 2024
@gballet gballet merged commit 540fa4e into kaustinen-with-shapella Feb 15, 2024
1 of 3 checks passed
gballet pushed a commit that referenced this pull request May 7, 2024
* instructions: add access witness recording for EXTCODEHASH

* add test for EXTCODEHASH witness recording

* add test for access witness EXTCODEHASH

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* do not touch version

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
gballet pushed a commit that referenced this pull request May 8, 2024
* instructions: add access witness recording for EXTCODEHASH

* add test for EXTCODEHASH witness recording

* add test for access witness EXTCODEHASH

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* do not touch version

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
gballet pushed a commit that referenced this pull request May 8, 2024
* instructions: add access witness recording for EXTCODEHASH

* add test for EXTCODEHASH witness recording

* add test for access witness EXTCODEHASH

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* do not touch version

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
gballet pushed a commit that referenced this pull request May 8, 2024
* instructions: add access witness recording for EXTCODEHASH

* add test for EXTCODEHASH witness recording

* add test for access witness EXTCODEHASH

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* do not touch version

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
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.

None yet

3 participants