-
Notifications
You must be signed in to change notification settings - Fork 50
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
feat(sessions): updating the cosign signing and the bundler #715
Conversation
@@ -466,8 +466,7 @@ impl JsonRpcClient for SelfProvider { | |||
let id = SystemTime::now() | |||
.duration_since(UNIX_EPOCH) | |||
.expect("Time should't go backwards") | |||
.as_millis() | |||
.to_string(); | |||
.as_secs(); |
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.
We have a shared JsonRPC request struct and the bundler complained that the Id
should be the int.
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.
I'm not a fan of that expect outside of initialization code. Would you rather make it an error instead?
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.
Makes sense. We are using this in many places so this should be a follow-up. #716 was created for this. Thanks for catching this!
eb01bed
to
36f02ed
Compare
pub fn add_eip191(message: &str) -> String { | ||
format!("\x19Ethereum Signed Message:\n{}{}", message.len(), message) | ||
/// Convert message to EIP-191 compatible format | ||
pub fn to_eip191_message(message: &[u8]) -> Vec<u8> { |
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.
Changing this function to use bytes instead of Strings, to remove double conversions since we are using bytes for the keccak256 hashing.
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.
Nice refactor
} | ||
|
||
/// Pack signature into a single byte array to Ethereum compatible format | ||
pub fn pack_signature(unpacked: &EthSignature) -> Bytes { |
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.
Packing of s,r,v
of the ecdsa signature into the Ethereum format.
// Update the userOp with the signature | ||
user_op.signature = get_signature_result; | ||
// Todo: remove this debug line before production stage | ||
info!("UserOpPacked final JSON: {:?}", serde_json::json!(user_op)); |
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.
We need this userOp json to trace it in case of issues for the alpha version. Since there is no any traffic to this endpoint, there shouldn't be a problem with the Cloudwatch cost.
.context | ||
.permissions_context | ||
.clone() | ||
.trim_start_matches("0x"), |
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.
Can we avoid this trim by having the original data or the client-facing API not provide this? Should be normalized one way or the other vs being permissive here and trimming it
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.
The client sends this as a String representation of eth hex bytes "0x...", to pass this to the contract we need to convert this representation into ethers::Bytes
as the contract expects the Bytes format. To do this we need to hex decode it and trim 0x
to decode. That's why we need to trim 0x
when converting it.
/// Convert message to EIP-191 compatible format | ||
pub fn to_eip191_message(message: &[u8]) -> Vec<u8> { | ||
let prefix = format!("\x19Ethereum Signed Message:\n{}", message.len()); | ||
let mut eip191_message = Vec::with_capacity(prefix.len() + message.len()); |
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.
Nice using with_capacity
src/utils/crypto.rs
Outdated
r.to_big_endian(&mut r_bytes); | ||
s.to_big_endian(&mut s_bytes); | ||
// Pack r, s, and v into a single byte array | ||
let mut packed_signature = Vec::with_capacity(65); |
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.
Self-documenting where what the size is based on
let mut packed_signature = Vec::with_capacity(65); | |
let mut packed_signature = Vec::with_capacity(r_bytes.len() + s_bytes.len() + 1); |
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.
Makes sense! Changed it. Thanks.
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
We'll need tests here soon!
Totally! I'm testing by the manual run of the integration test now, since we need a gas to make the full flow. |
47d9a34
to
ee8a1fa
Compare
Description
This PR is making the following changes to the Co-Signing endpoint:
LocalWallet
and packing the signature.BICONOMY_BUNDLER_*
->BUNDLER_*
) and changing the default bundler to the Pimlico.userOperation
struct to bev07
fromv06
to proper calculation of the packedUserOperation
.paymaster
,factory
) for the packedUserOperation
structure builder to support paymasters.How Has This Been Tested?
This flow was tested manually with the testing dapp cosigning flow.
Due Diligence