-
Notifications
You must be signed in to change notification settings - Fork 12
Sync v3 session encoding with wallet-contracts-v3 #365
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
Open
ScreamingHawk
wants to merge
4
commits into
master
Choose a base branch
from
fix/v3-session-encoding-sync
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ad0a480
Implement session call digest for v3 sessions
Agusx1211 9b27867
fix(v3): sync session encoding with wallet-contracts-v3
ScreamingHawk ca80af7
fix(v3): drop session wallet from call digest parent wallets
ScreamingHawk 05ac5ff
fix(v3): validate session deadline fits in uint64
ScreamingHawk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| package v3_test | ||
|
|
||
| import ( | ||
| "math/big" | ||
| "testing" | ||
|
|
||
| "github.com/0xsequence/ethkit/go-ethereum/common" | ||
| v3 "github.com/0xsequence/go-sequence/core/v3" | ||
| ) | ||
|
|
||
| // The expected digests below are reference vectors produced by | ||
| // SessionSig.hashPayloadCallIdx in 0xsequence/wallet-contracts-v3 (via a forge | ||
| // test constructing the identical payloads), so this test asserts parity with | ||
| // the on-chain verification. | ||
| func TestHashCallWithReplayProtection(t *testing.T) { | ||
| payload := v3.NewCallsPayload( | ||
| common.HexToAddress("0x1111111111111111111111111111111111111111"), | ||
| big.NewInt(42161), | ||
| []v3.Call{ | ||
| { | ||
| To: common.HexToAddress("0x2222222222222222222222222222222222222222"), | ||
| Value: new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil), // 1 ether | ||
| Data: common.Hex2Bytes("deadbeef"), | ||
| GasLimit: big.NewInt(100000), | ||
| BehaviorOnError: v3.BehaviorOnErrorRevert, | ||
| }, | ||
| { | ||
| To: common.HexToAddress("0x3333333333333333333333333333333333333333"), | ||
| DelegateCall: true, | ||
| OnlyFallback: true, | ||
| BehaviorOnError: v3.BehaviorOnErrorAbort, | ||
| }, | ||
| }, | ||
| big.NewInt(0), | ||
| big.NewInt(7), | ||
| ) | ||
|
|
||
| expectedPayloadHash := common.HexToHash("0x9c891ce70c80739f54b60eb7f8a0d0e80e7f90f2c9aea51a0c4f34ec1cee067e") | ||
| if digest := payload.Digest().Hash; digest != expectedPayloadHash { | ||
| t.Errorf("payload digest mismatch: got %v, expected %v", digest, expectedPayloadHash) | ||
| } | ||
|
|
||
| expectedCallHashes := []common.Hash{ | ||
| common.HexToHash("0x1957bab0f26824823a1f40bb132e9a6ab186db88c0adb7fb806351f6766ba66c"), | ||
| common.HexToHash("0xcb5346174462b1c9a0279b5acbdfe2458ba0825cb10d35eb912fa491c1ee5cdd"), | ||
| } | ||
| for i, expected := range expectedCallHashes { | ||
| hash, err := v3.HashCallWithReplayProtection(payload, i) | ||
| if err != nil { | ||
| t.Fatalf("HashCallWithReplayProtection(%v): %v", i, err) | ||
| } | ||
| if hash != expected { | ||
| t.Errorf("call %v hash mismatch: got %v, expected %v", i, hash, expected) | ||
| } | ||
| } | ||
|
|
||
| payload2 := v3.NewCallsPayload( | ||
| common.HexToAddress("0x5555555555555555555555555555555555555555"), | ||
| big.NewInt(1), | ||
| []v3.Call{ | ||
| { | ||
| To: common.HexToAddress("0x4444444444444444444444444444444444444444"), | ||
| Data: []byte{0x00}, | ||
| BehaviorOnError: v3.BehaviorOnErrorIgnore, | ||
| }, | ||
| }, | ||
| big.NewInt(12345), | ||
| big.NewInt(0), | ||
| ) | ||
|
|
||
| expected2 := common.HexToHash("0xde2ebba8ab9a581d22dbb5d066086ae1ab3d884f9becc493448b2875e7f3c6d4") | ||
| hash2, err := v3.HashCallWithReplayProtection(payload2, 0) | ||
| if err != nil { | ||
| t.Fatalf("HashCallWithReplayProtection: %v", err) | ||
| } | ||
| if hash2 != expected2 { | ||
| t.Errorf("vector 2 hash mismatch: got %v, expected %v", hash2, expected2) | ||
| } | ||
|
|
||
| if _, err := v3.HashCallWithReplayProtection(payload2, 1); err == nil { | ||
| t.Errorf("expected out-of-range error for call index 1") | ||
| } | ||
| if _, err := v3.HashCallWithReplayProtection(payload2, -1); err == nil { | ||
| t.Errorf("expected out-of-range error for call index -1") | ||
| } | ||
| } | ||
|
|
||
| // TestHashCallWithReplayProtectionParentWallets checks that the session wallet, | ||
| // which is the last parent wallet in the signing context, is dropped before | ||
| // hashing (on chain it is the verifying contract, not a parent). The expected | ||
| // digest was produced by SessionSig.hashPayloadCallIdx for the same payload | ||
| // carrying only the real parent wallet. | ||
| func TestHashCallWithReplayProtectionParentWallets(t *testing.T) { | ||
| wallet := common.HexToAddress("0x1111111111111111111111111111111111111111") | ||
| parent := common.HexToAddress("0x9999999999999999999999999999999999999999") | ||
|
|
||
| payload := v3.NewCallsPayload( | ||
| wallet, | ||
| big.NewInt(42161), | ||
| []v3.Call{ | ||
| { | ||
| To: common.HexToAddress("0x2222222222222222222222222222222222222222"), | ||
| BehaviorOnError: v3.BehaviorOnErrorRevert, | ||
| }, | ||
| }, | ||
| big.NewInt(0), | ||
| big.NewInt(7), | ||
| []common.Address{parent, wallet}, | ||
| ) | ||
|
|
||
| expected := common.HexToHash("0x29f4f05700f22db9cfe0272b824961355b2383109f0309542b9a5c495103b69f") | ||
| hash, err := v3.HashCallWithReplayProtection(payload, 0) | ||
| if err != nil { | ||
| t.Fatalf("HashCallWithReplayProtection: %v", err) | ||
| } | ||
| if hash != expected { | ||
| t.Errorf("digest mismatch: got %v, expected %v", hash, expected) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
When
AttestationFromJsonreceivesauthData.issuedAtas a JSON number rather than the string form, this direct cast accepts invalid values instead of returning an error: for example-1becomesmath.MaxUint64, and fractional/out-of-range numbers are truncated or implementation-dependent before being appended to the attestation bytes. This can make the library hash and sign a different attestation than the JSON input represents, so the numeric path should reject negatives, fractions, and values outsideuint64just like the string path does.Useful? React with 👍 / 👎.