-
Notifications
You must be signed in to change notification settings - Fork 13
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
Conversation
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 | ||
} |
There was a problem hiding this comment.
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.
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 | ||
} |
There was a problem hiding this comment.
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).
// 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) |
There was a problem hiding this comment.
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.
tx, _ := types.SignTx(types.NewTransaction(2, extCodeHashContractAddr, big.NewInt(0), 100_000, big.NewInt(875000000), nil), signer, testKey) | ||
gen.AddTx(tx) |
There was a problem hiding this comment.
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:]) |
There was a problem hiding this comment.
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.
There was a problem hiding this 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 <[email protected]>
7354ccc
to
e400860
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* instructions: add access witness recording for EXTCODEHASH * add test for EXTCODEHASH witness recording * add test for access witness EXTCODEHASH Signed-off-by: Ignacio Hagopian <[email protected]> * do not touch version Signed-off-by: Ignacio Hagopian <[email protected]> --------- Signed-off-by: Ignacio Hagopian <[email protected]>
* instructions: add access witness recording for EXTCODEHASH * add test for EXTCODEHASH witness recording * add test for access witness EXTCODEHASH Signed-off-by: Ignacio Hagopian <[email protected]> * do not touch version Signed-off-by: Ignacio Hagopian <[email protected]> --------- Signed-off-by: Ignacio Hagopian <[email protected]>
* instructions: add access witness recording for EXTCODEHASH * add test for EXTCODEHASH witness recording * add test for access witness EXTCODEHASH Signed-off-by: Ignacio Hagopian <[email protected]> * do not touch version Signed-off-by: Ignacio Hagopian <[email protected]> --------- Signed-off-by: Ignacio Hagopian <[email protected]>
This PR adds access witness recording for EXTCODEHASH