Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions utils/udc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var (
// https://docs.openzeppelin.com/contracts-cairo/1.0.0/udc#udc_contract_address
udcAddressCairoV2, _ = new(
felt.Felt,
).SetString("0x04a64cd09a853868621d94cae9952b106f2c36a3f81260f85de6696c6b050221")
).SetString("0x02ceed65a4bd731034c01113685c831b01c15d7d432f71afb1cf1634b53a2125")

errInvalidUDCVersion = errors.New("invalid UDC version")
errClassHashNotProvided = errors.New("classHash not provided")
Expand All @@ -48,7 +48,15 @@ type UDCOptions struct {
//nolint:lll // The links would be unclickable if we break the line.
OriginIndependent bool
// The UDC version to be used. If not provided, UDCCairoV0 will be used.
UDCVersion UDCVersion
UDCVersion UDCVersion;
}

// Creates a new UDCOptions instance
// UDCCairoV2 will be used as the default UDC version
func NewUDCOptions() *UDCOptions {
return &UDCOptions{
UDCVersion: UDCCairoV2,
}
}

// Enum representing the UDC version to be used
Expand All @@ -59,7 +67,7 @@ const (
// address 0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf
UDCCairoV0 UDCVersion = iota
// Represents the UDC version with Cairo v2 code, with the
// address 0x04a64cd09a853868621d94cae9952b106f2c36a3f81260f85de6696c6b050221
// address 0x02ceed65a4bd731034c01113685c831b01c15d7d432f71afb1cf1634b53a2125
UDCCairoV2
)

Expand All @@ -86,7 +94,7 @@ func BuildUDCCalldata(
}

if opts == nil {
opts = new(UDCOptions)
opts = NewUDCOptions()
}

// salt
Expand Down
14 changes: 7 additions & 7 deletions utils/udc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestBuildUDCCalldata(t *testing.T) {
new(felt.Felt).SetUint64(100),
new(felt.Felt).SetUint64(200),
},
opts: nil,
opts: &UDCOptions{UDCVersion: UDCCairoV0},
expectedUDCAddress: udcAddressCairoV0,
expectedFunctionName: "deployContract",
expectedCallDataLen: 6, // classHash + salt + originInd + calldataLen + 2 constructor args
Expand All @@ -40,7 +40,7 @@ func TestBuildUDCCalldata(t *testing.T) {
name: "UDC Cairo V0 with custom salt",
classHash: internalUtils.DeadBeef,
constructorCalldata: []*felt.Felt{new(felt.Felt).SetUint64(100)},
opts: &UDCOptions{Salt: new(felt.Felt).SetUint64(999)},
opts: &UDCOptions{Salt: new(felt.Felt).SetUint64(999), UDCVersion: UDCCairoV0},
expectedUDCAddress: udcAddressCairoV0,
expectedFunctionName: "deployContract",
expectedCallDataLen: 5, // classHash + salt + originInd + calldataLen + 1 constructor arg
Expand All @@ -50,7 +50,7 @@ func TestBuildUDCCalldata(t *testing.T) {
name: "UDC Cairo V0 with origin independent",
classHash: internalUtils.DeadBeef,
constructorCalldata: []*felt.Felt{},
opts: &UDCOptions{OriginIndependent: true},
opts: &UDCOptions{OriginIndependent: true, UDCVersion: UDCCairoV0},
expectedUDCAddress: udcAddressCairoV0,
expectedFunctionName: "deployContract",
expectedCallDataLen: 4, // classHash + salt + originInd + calldataLen
Expand Down Expand Up @@ -98,8 +98,8 @@ func TestBuildUDCCalldata(t *testing.T) {
classHash: internalUtils.DeadBeef,
constructorCalldata: []*felt.Felt{},
opts: nil,
expectedUDCAddress: udcAddressCairoV0,
expectedFunctionName: "deployContract",
expectedUDCAddress: udcAddressCairoV2,
expectedFunctionName: "deploy_contract",
expectedCallDataLen: 4, // classHash + salt + originInd + calldataLen
checkCallDataContents: true,
},
Expand Down Expand Up @@ -175,11 +175,11 @@ func checkCallDataContents(
}

// Check the rest based on UDC version
if opts != nil && opts.UDCVersion == UDCCairoV2 {
if opts == nil || opts.UDCVersion == UDCCairoV2 {
// Cairo V2: [classHash, salt, originInd, calldataLen, ...constructorCalldata]
originInd := callData[2]
expectedOriginInd := new(felt.Felt).SetUint64(0)
if opts.OriginIndependent {
if opts != nil && opts.OriginIndependent {
expectedOriginInd.SetUint64(1)
}
assert.Equal(t, expectedOriginInd, originInd)
Expand Down